Example Code Snippet That Sets Performance Tuning Variables - Aster Client

Teradata Aster® Client Guide

Product
Aster Client
Release Number
7.00
Published
May 2017
Language
English (United States)
Last Update
2018-04-13
dita:mapPath
hki1475000360386.ditamap
dita:ditavalPath
Generic_no_ie_no_tempfilter.ditaval
dita:id
B700-2005
lifecycle
previous
Product Category
Software

This example (PerformanceTuning.java) shows you how you can set some performance tuning variables for a particular transaction:

package userguide;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class PerformanceTuning {
public static void main(String[] args) {
String username = "db_superuser";
String password = "db_superuser";
String url = "jdbc:ncluster://153.65.197.125:2406/beehive";
Connection conn = null;
try
{
conn =
DriverManager.getConnection(url, username, password);
// Remember the current autocommit state
boolean autoCommit = conn.getAutoCommit();
// Turn off auto commits
conn.setAutoCommit(false);
// create a statement with transaction variables set
// which will be used for this query
Statement stmt = conn.createStatement();
stmt.executeUpdate("SET enable_hashjoin = 'false'");
stmt.executeUpdate("SET enable_mergejoin = 'false'");
stmt.executeUpdate("SET enable_nestloop='true'");
stmt.executeUpdate("SET random_page_cost = '4.0'");
Statement statement = conn.createStatement();
String query="select * from knn_test";
ResultSet resultSet = statement.executeQuery(query);
// Process the result set
while (resultSet.next()) {
// do something
}
// commit the transaction
conn.commit();
resultSet.close();
stmt.close();
// Set the autocommit state back
conn.setAutoCommit(autoCommit);
} catch (SQLException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
}
}

In the example above, the scope of the SET variables is limited to the commands between the autoCommit(false) and commit() lines.