diff --git a/src/com/oltpbenchmark/DBWorkload.java b/src/com/oltpbenchmark/DBWorkload.java index b3f7414..eab7462 100644 --- a/src/com/oltpbenchmark/DBWorkload.java +++ b/src/com/oltpbenchmark/DBWorkload.java @@ -305,6 +305,7 @@ public static void main(String[] args) throws Exception { } if (argsLine.hasOption("start-warehouse-id")) { wrkld.setShouldEnableForeignKeys(false); + wrkld.setCreateSQLProcedures(false); } if (xmlConfig.containsKey("batchSize")) { @@ -655,6 +656,7 @@ else if (serial) for (BenchmarkModule benchmark : benchList) { LOG.info("Creating new " + benchmark.getBenchmarkName().toUpperCase() + " database..."); runCreator(benchmark, verbose); + benchmark.createSqlProcedures(); LOG.info("Finished!"); LOG.info(SINGLE_LINE); } diff --git a/src/com/oltpbenchmark/WorkloadConfiguration.java b/src/com/oltpbenchmark/WorkloadConfiguration.java index fc8a4a3..4908e9b 100644 --- a/src/com/oltpbenchmark/WorkloadConfiguration.java +++ b/src/com/oltpbenchmark/WorkloadConfiguration.java @@ -62,6 +62,7 @@ public void setBenchmarkName(String benchmarkName) { private boolean useThinkTime = true; private boolean enableForeignKeysAfterLoad = true; private boolean shouldEnableForeignKeys = true; + private boolean createSQLProcedures = true; private int batchSize = 128; private int hikariConnectionTimeout = 60000; private boolean needsExecution = false; @@ -366,6 +367,13 @@ public void setShouldEnableForeignKeys(boolean shouldEnableForeignKeys) { this.shouldEnableForeignKeys = shouldEnableForeignKeys; } + public boolean getCreateSQLProcedures() { + return createSQLProcedures; + } + public void setCreateSQLProcedures(boolean createSQLProcedures) { + this.createSQLProcedures = createSQLProcedures; + } + public int getBatchSize() { return batchSize; } diff --git a/src/com/oltpbenchmark/benchmarks/tpcc/TPCCBenchmark.java b/src/com/oltpbenchmark/benchmarks/tpcc/TPCCBenchmark.java index 5d572ae..75e1a08 100644 --- a/src/com/oltpbenchmark/benchmarks/tpcc/TPCCBenchmark.java +++ b/src/com/oltpbenchmark/benchmarks/tpcc/TPCCBenchmark.java @@ -19,6 +19,8 @@ import java.io.IOException; import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.Statement; import java.sql.SQLException; import java.sql.Timestamp; import java.util.ArrayList; @@ -162,9 +164,34 @@ public void enableForeignKeys() throws Exception { loader.EnableForeignKeyConstraints(makeConnection()); } + // This function creates SQL procedures that the execution would need. Currently we have + // procedures only to update the Stock table. public void createSqlProcedures() throws Exception { - TPCCLoader loader = new TPCCLoader(this); - loader.CreateSqlProcedures(makeConnection()); + try { + Connection conn = makeConnection(); + Statement st = conn.createStatement(); + + StringBuilder argsSb = new StringBuilder(); + StringBuilder updateStatements = new StringBuilder(); + + argsSb.append("wid int"); + for (int i = 1; i <= 15; ++i) { + argsSb.append(String.format(", i%d int, q%d int, y%d int, r%d int", i, i, i, i)); + updateStatements.append(String.format( + "UPDATE STOCK SET S_QUANTITY = q%d, S_YTD = y%d, S_ORDER_CNT = S_ORDER_CNT + 1, " + + "S_REMOTE_CNT = r%d WHERE S_W_ID = wid AND S_I_ID = i%d;", + i, i, i, i)); + String updateStmt = + String.format("CREATE PROCEDURE updatestock%d (%s) AS '%s' LANGUAGE SQL;", + i, argsSb.toString(), updateStatements.toString()); + + st.execute(String.format("DROP PROCEDURE IF EXISTS updatestock%d", i)); + st.execute(updateStmt); + } + } catch (SQLException se) { + LOG.error(se.getMessage()); + throw se; + } } public void test() throws Exception { diff --git a/src/com/oltpbenchmark/benchmarks/tpcc/TPCCLoader.java b/src/com/oltpbenchmark/benchmarks/tpcc/TPCCLoader.java index 33d4c54..d78db2d 100644 --- a/src/com/oltpbenchmark/benchmarks/tpcc/TPCCLoader.java +++ b/src/com/oltpbenchmark/benchmarks/tpcc/TPCCLoader.java @@ -132,9 +132,6 @@ public void load(Connection conn) throws SQLException { workConf.getShouldEnableForeignKeys()) { EnableForeignKeyConstraints(conn); } - if (workConf.getUseStoredProcedures()) { - CreateSqlProcedures(conn); - } } }); return (threads); @@ -215,35 +212,6 @@ protected void EnableForeignKeyConstraints(Connection conn) { } } - // This function creates SQL procedures that the execution would need. Currently we have - // procedures only to update the Stock table. - protected void CreateSqlProcedures(Connection conn) throws SQLException { - try { - Statement st = conn.createStatement(); - - StringBuilder argsSb = new StringBuilder(); - StringBuilder updateStatements = new StringBuilder(); - - argsSb.append("wid int"); - for (int i = 1; i <= 15; ++i) { - argsSb.append(String.format(", i%d int, q%d int, y%d int, r%d int", i, i, i, i)); - updateStatements.append(String.format( - "UPDATE STOCK SET S_QUANTITY = q%d, S_YTD = y%d, S_ORDER_CNT = S_ORDER_CNT + 1, " + - "S_REMOTE_CNT = r%d WHERE S_W_ID = wid AND S_I_ID = i%d;", - i, i, i, i)); - String updateStmt = - String.format("CREATE PROCEDURE updatestock%d (%s) AS '%s' LANGUAGE SQL;", - i, argsSb.toString(), updateStatements.toString()); - - st.execute(String.format("DROP PROCEDURE IF EXISTS updatestock%d", i)); - st.execute(updateStmt); - } - } catch (SQLException se) { - LOG.error(se.getMessage()); - throw se; - } - } - protected int loadItems(Connection conn, int itemKount) { int k = 0; int randPct = 0;