diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/TPCHUtil.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/TPCHUtil.java index 93f0a141b..cd6cbb73c 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/TPCHUtil.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/TPCHUtil.java @@ -99,4 +99,19 @@ public static String getRegionFromRegionKey(int regionKey) { } } + /** + * Generates a random brand string of the form 'Brand#MN' where M and N are + * two single character strings representing two numbers randomly and + * independently selected within [1 .. 5] + * + * @param rand Random generator to use + * @return A random brand conforming to the TPCH specification + */ + public static String randomBrand(RandomGenerator rand) { + int M = rand.number(1, 5); + int N = rand.number(1, 5); + + return String.format("Brand#%d%d", M, N); + } + } diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/TPCHWorker.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/TPCHWorker.java index 387eab712..fa26f8e32 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/TPCHWorker.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/TPCHWorker.java @@ -41,7 +41,7 @@ public TPCHWorker(TPCHBenchmark benchmarkModule, int id) { protected TransactionStatus executeWork(Connection conn, TransactionType nextTransaction) throws UserAbortException, SQLException { try { GenericQuery proc = (GenericQuery) this.getProcedure(nextTransaction.getProcedureClass()); - proc.run(conn, rand); + proc.run(conn, rand, this.configuration.getScaleFactor()); } catch (ClassCastException e) { throw new RuntimeException(e); } diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/GenericQuery.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/GenericQuery.java index 466066721..4b5f8bacd 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/GenericQuery.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/GenericQuery.java @@ -31,11 +31,11 @@ public abstract class GenericQuery extends Procedure { protected static final Logger LOG = LoggerFactory.getLogger(GenericQuery.class); - protected abstract PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException; + protected abstract PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException; - public void run(Connection conn, RandomGenerator rand) throws SQLException { + public void run(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { - try (PreparedStatement stmt = getStatement(conn, rand); ResultSet rs = stmt.executeQuery()) { + try (PreparedStatement stmt = getStatement(conn, rand, scaleFactor); ResultSet rs = stmt.executeQuery()) { while (rs.next()) { //do nothing } diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q1.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q1.java index 0a1d0bdcc..d6d901576 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q1.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q1.java @@ -52,7 +52,7 @@ public class Q1 extends GenericQuery { ); @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { String delta = String.valueOf(rand.number(60, 120)); PreparedStatement stmt = this.getPreparedStatement(conn, query_stmt); diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q10.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q10.java index 111fa41a5..4ecac97d8 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q10.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q10.java @@ -27,7 +27,7 @@ public class Q10 extends GenericQuery { - public final SQLStmt query_stmt = new SQLStmt(""" + public final SQLStmt query_stmt = new SQLStmt(""" SELECT c_custkey, c_name, @@ -63,7 +63,7 @@ public class Q10 extends GenericQuery { ); @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { // DATE is the first day of a randomly selected month from the second month of 1993 to the first month of 1995 int year = rand.number(1993, 1995); int month = rand.number(year == 1993 ? 2 : 1, year == 1995 ? 1 : 12); diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q11.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q11.java index 1e75c0088..131c151f7 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q11.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q11.java @@ -28,7 +28,7 @@ public class Q11 extends GenericQuery { - public final SQLStmt query_stmt = new SQLStmt(""" + public final SQLStmt query_stmt = new SQLStmt(""" SELECT ps_partkey, SUM(ps_supplycost * ps_availqty) AS VALUE @@ -39,7 +39,7 @@ public class Q11 extends GenericQuery { WHERE ps_suppkey = s_suppkey AND s_nationkey = n_nationkey - AND n_name = 'ETHIOPIA' + AND n_name = ? GROUP BY ps_partkey HAVING @@ -58,17 +58,17 @@ public class Q11 extends GenericQuery { ); @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { // NATION is randomly selected within the list of values defined for N_NAME in Clause 4.2.3 String nation = TPCHUtil.choice(TPCHConstants.N_NAME, rand); // FRACTION is chosen as 0.0001 / SF - // TODO: we should technically pass dbgen's SF down here somehow - double fraction = 0.0001; + double fraction = 0.0001 / scaleFactor; PreparedStatement stmt = this.getPreparedStatement(conn, query_stmt); - stmt.setDouble(1, fraction); - stmt.setString(2, nation); + stmt.setString(1, nation); + stmt.setDouble(2, fraction); + stmt.setString(3, nation); return stmt; } } diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q12.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q12.java index 8c7755982..b394cd2b7 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q12.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q12.java @@ -29,37 +29,48 @@ public class Q12 extends GenericQuery { - public final SQLStmt query_stmt = new SQLStmt(""" + public final SQLStmt query_stmt = new SQLStmt(""" SELECT - ps_partkey, - SUM(ps_supplycost * ps_availqty) AS VALUE + l_shipmode, + SUM( + CASE + WHEN + o_orderpriority = '1-URGENT' OR o_orderpriority = '2-HIGH' + THEN + 1 + ELSE + 0 + END + ) AS high_line_count, + SUM( + CASE + WHEN + o_orderpriority <> '1-URGENT' AND o_orderpriority <> '2-HIGH' + THEN + 1 + ELSE + 0 + END + ) AS low_line_count FROM - partsupp, - supplier, - nation + orders, + lineitem WHERE - ps_suppkey = s_suppkey - AND s_nationkey = n_nationkey - AND n_name = 'ETHIOPIA' + o_orderkey = l_orderkey + AND l_shipmode IN (?, ?) + AND l_commitdate < l_receiptdate + AND l_shipdate < l_commitdate + AND l_receiptdate >= DATE ? + AND l_receiptdate < DATE ? + INTERVAL '1' YEAR GROUP BY - ps_partkey - HAVING - SUM(ps_supplycost * ps_availqty) > ( - SELECT - SUM(ps_supplycost * ps_availqty) * ? - FROM - partsupp, supplier, nation - WHERE - ps_suppkey = s_suppkey - AND s_nationkey = n_nationkey - AND n_name = ? ) - ORDER BY - VALUE DESC + l_shipmode + ORDER BY + l_shipmode """ ); @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { // SHIPMODE1 is randomly selected within the list of values defined for Modes in Clause 4.2.2.13 String shipMode1 = TPCHUtil.choice(TPCHConstants.MODES, rand); diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q13.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q13.java index 9017bead4..21e228cfd 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q13.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q13.java @@ -27,7 +27,7 @@ public class Q13 extends GenericQuery { - public final SQLStmt query_stmt = new SQLStmt(""" + public final SQLStmt query_stmt = new SQLStmt(""" SELECT c_count, COUNT(*) AS custdist @@ -55,7 +55,7 @@ public class Q13 extends GenericQuery { ); @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { // WORD1 is randomly selected from 4 possible values: special, pending, unusual, express String word1 = TPCHUtil.choice(new String[]{"special", "pending", "unusual", "express"}, rand); diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q14.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q14.java index 16aab6233..9f32516ff 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q14.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q14.java @@ -27,7 +27,7 @@ public class Q14 extends GenericQuery { - public final SQLStmt query_stmt = new SQLStmt(""" + public final SQLStmt query_stmt = new SQLStmt(""" SELECT 100.00 * SUM( CASE @@ -49,7 +49,7 @@ public class Q14 extends GenericQuery { ); @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { // DATE is the first day of a month randomly selected from a random year within [1993 .. 1997] int year = rand.number(1993, 1997); int month = rand.number(1, 12); diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q15.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q15.java index db802862d..5aca587c1 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q15.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q15.java @@ -42,7 +42,7 @@ CREATE view revenue0 (supplier_no, total_revenue) AS """ ); - public final SQLStmt query_stmt = new SQLStmt(""" + public final SQLStmt query_stmt = new SQLStmt(""" SELECT s_suppkey, s_name, @@ -71,7 +71,7 @@ CREATE view revenue0 (supplier_no, total_revenue) AS ); @Override - public void run(Connection conn, RandomGenerator rand) throws SQLException { + public void run(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { // With this query, we have to set up a view before we execute the // query, then drop it once we're done. try (Statement stmt = conn.createStatement()) { @@ -85,7 +85,7 @@ public void run(Connection conn, RandomGenerator rand) throws SQLException { String sql = createview_stmt.getSQL(); sql = sql.replace("?", String.format("'%s'", date)); stmt.execute(sql); - super.run(conn, rand); + super.run(conn, rand, scaleFactor); } finally { String sql = dropview_stmt.getSQL(); stmt.execute(sql); @@ -95,7 +95,7 @@ public void run(Connection conn, RandomGenerator rand) throws SQLException { } @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { return this.getPreparedStatement(conn, query_stmt); } } diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q16.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q16.java index f77f33893..70487115f 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q16.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q16.java @@ -30,7 +30,7 @@ public class Q16 extends GenericQuery { - public final SQLStmt query_stmt = new SQLStmt(""" + public final SQLStmt query_stmt = new SQLStmt(""" SELECT p_brand, p_type, @@ -66,12 +66,8 @@ AND p_size IN (?, ?, ?, ?, ?, ?, ?, ?) ); @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { - // BRAND = Brand#MN where M and N are two single character strings representing two numbers randomly and - // independently selected within [1 .. 5]; - int M = rand.number(1, 5); - int N = rand.number(1, 5); - String brand = String.format("BRAND#%d%d", M, N); + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { + String brand = TPCHUtil.randomBrand(rand); // TYPE is made of the first 2 syllables of a string randomly selected within the // list of 3-syllable strings defined for Types in Clause 4.2.2.13 diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q17.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q17.java index c1a602e83..c72fcb4ab 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q17.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q17.java @@ -28,7 +28,7 @@ public class Q17 extends GenericQuery { - public final SQLStmt query_stmt = new SQLStmt(""" + public final SQLStmt query_stmt = new SQLStmt(""" SELECT SUM(l_extendedprice) / 7.0 AS avg_yearly FROM @@ -49,12 +49,8 @@ public class Q17 extends GenericQuery { ); @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { - // BRAND = 'Brand#MN' where MN is a two character string representing two numbers randomly and independently - // selected within [1 .. 5] - int M = rand.number(1, 5); - int N = rand.number(1, 5); - String brand = String.format("BRAND#%d%d", M, N); + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { + String brand = TPCHUtil.randomBrand(rand); // CONTAINER is randomly selected within the list of 2-syllable strings defined for Containers in Clause // 4.2.2.13 diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q18.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q18.java index 195977642..5ae8bc433 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q18.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q18.java @@ -65,7 +65,7 @@ public class Q18 extends GenericQuery { ); @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { // QUANTITY is randomly selected within [312..315] int quantity = rand.number(312, 315); diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q19.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q19.java index 73829ad9b..fbb93e04d 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q19.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q19.java @@ -18,6 +18,7 @@ package com.oltpbenchmark.benchmarks.tpch.procedures; import com.oltpbenchmark.api.SQLStmt; +import com.oltpbenchmark.benchmarks.tpch.TPCHUtil; import com.oltpbenchmark.util.RandomGenerator; import java.sql.Connection; @@ -69,7 +70,7 @@ AND l_shipmode IN ('AIR', 'AIR REG') ); @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { // QUANTITY1 is randomly selected within [1..10] int quantity1 = rand.number(1, 10); @@ -81,17 +82,9 @@ protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) // BRAND1, BRAND2, BRAND3 = 'Brand#MN' where each MN is a two character string representing two numbers // randomly and independently selected within [1 .. 5] - int M; - int N; - M = rand.number(1, 5); - N = rand.number(1, 5); - String brand1 = String.format("BRAND#%d%d", M, N); - M = rand.number(1, 5); - N = rand.number(1, 5); - String brand2 = String.format("BRAND#%d%d", M, N); - M = rand.number(1, 5); - N = rand.number(1, 5); - String brand3 = String.format("BRAND#%d%d", M, N); + String brand1 = TPCHUtil.randomBrand(rand); + String brand2 = TPCHUtil.randomBrand(rand); + String brand3 = TPCHUtil.randomBrand(rand); PreparedStatement stmt = this.getPreparedStatement(conn, query_stmt); stmt.setString(1, brand1); diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q2.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q2.java index 6981b2aac..ff3b55bda 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q2.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q2.java @@ -77,7 +77,7 @@ public class Q2 extends GenericQuery { ); @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { int size = rand.number(1, 50); String type = TPCHUtil.choice(TPCHConstants.TYPE_S3, rand); String region = TPCHUtil.choice(TPCHConstants.R_NAME, rand); diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q20.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q20.java index 362077f14..5cb274589 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q20.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q20.java @@ -29,7 +29,7 @@ public class Q20 extends GenericQuery { - public final SQLStmt query_stmt = new SQLStmt(""" + public final SQLStmt query_stmt = new SQLStmt(""" SELECT s_name, s_address @@ -72,7 +72,7 @@ public class Q20 extends GenericQuery { ); @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { // COLOR is randomly selected within the list of values defined for the generation of P_NAME String color = TPCHUtil.choice(TPCHConstants.P_NAME_GENERATOR, rand) + "%"; diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q21.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q21.java index 40a69b615..eeacb04ac 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q21.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q21.java @@ -28,7 +28,7 @@ public class Q21 extends GenericQuery { - public final SQLStmt query_stmt = new SQLStmt(""" + public final SQLStmt query_stmt = new SQLStmt(""" SELECT s_name, COUNT(*) AS numwait @@ -74,7 +74,7 @@ public class Q21 extends GenericQuery { ); @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { // NATION is randomly selected within the list of values defined for N_NAME in Clause 4.2.3 String nation = TPCHUtil.choice(TPCHConstants.N_NAME, rand); diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q22.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q22.java index e187d5f6c..6b29285df 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q22.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q22.java @@ -28,7 +28,7 @@ public class Q22 extends GenericQuery { - public final SQLStmt query_stmt = new SQLStmt(""" + public final SQLStmt query_stmt = new SQLStmt(""" SELECT cntrycode, COUNT(*) AS numcust, @@ -42,7 +42,7 @@ public class Q22 extends GenericQuery { customer WHERE SUBSTRING(c_phone FROM 1 FOR 2) IN (?, ?, ?, ?, ?, ?, ?) - AND c_acctbal > + AND c_acctbal > ( SELECT AVG(c_acctbal) @@ -71,7 +71,7 @@ AND SUBSTRING(c_phone FROM 1 FOR 2) IN (?, ?, ?, ?, ?, ?, ?) ); @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { // I1 - I7 are randomly selected without repetition from the possible values diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q3.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q3.java index 80a232a91..bc8fc3afc 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q3.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q3.java @@ -29,7 +29,7 @@ public class Q3 extends GenericQuery { - public final SQLStmt query_stmt = new SQLStmt(""" + public final SQLStmt query_stmt = new SQLStmt(""" SELECT l_orderkey, SUM(l_extendedprice * (1 - l_discount)) AS revenue, @@ -56,7 +56,7 @@ public class Q3 extends GenericQuery { ); @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { String segment = TPCHUtil.choice(TPCHConstants.SEGMENTS, rand); // date must be randomly selected between [1995-03-01, 1995-03-31] diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q4.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q4.java index 98dca1261..46081bfb8 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q4.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q4.java @@ -27,7 +27,7 @@ public class Q4 extends GenericQuery { - public final SQLStmt query_stmt = new SQLStmt(""" + public final SQLStmt query_stmt = new SQLStmt(""" SELECT o_orderpriority, COUNT(*) AS order_count @@ -54,7 +54,7 @@ public class Q4 extends GenericQuery { ); @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { int year = rand.number(1993, 1997); int month = rand.number(1, 10); String date = String.format("%d-%02d-01", year, month); diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q5.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q5.java index 5ea9d9e0f..1bd7932bf 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q5.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q5.java @@ -58,7 +58,7 @@ public class Q5 extends GenericQuery { ); @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { String region = TPCHUtil.choice(TPCHConstants.R_NAME, rand); int year = rand.number(1993, 1997); diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q6.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q6.java index 8c9e037a6..40e1cd414 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q6.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q6.java @@ -27,7 +27,7 @@ public class Q6 extends GenericQuery { - public final SQLStmt query_stmt = new SQLStmt(""" + public final SQLStmt query_stmt = new SQLStmt(""" SELECT SUM(l_extendedprice * l_discount) AS revenue FROM @@ -41,7 +41,7 @@ public class Q6 extends GenericQuery { ); @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { // DATE is the first of January of a randomly selected year within [1993 .. 1997] int year = rand.number(1993, 1997); String date = String.format("%d-01-01", year); diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q7.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q7.java index 5eac395ec..c4f09e761 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q7.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q7.java @@ -77,7 +77,7 @@ public class Q7 extends GenericQuery { ); @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { // NATION1 is randomly selected within the list of values defined for N_NAME in Clause 4.2.3 String nation1 = TPCHUtil.choice(TPCHConstants.N_NAME, rand); diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q8.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q8.java index 12ad68365..ae2366852 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q8.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q8.java @@ -79,7 +79,7 @@ public class Q8 extends GenericQuery { ); @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { // NATION is randomly selected within the list of values defined for N_NAME in Clause 4.2.3 String nation = TPCHUtil.choice(TPCHConstants.N_NAME, rand); diff --git a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q9.java b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q9.java index a6748d01a..7de35a9bf 100644 --- a/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q9.java +++ b/src/main/java/com/oltpbenchmark/benchmarks/tpch/procedures/Q9.java @@ -28,7 +28,7 @@ public class Q9 extends GenericQuery { - public final SQLStmt query_stmt = new SQLStmt(""" + public final SQLStmt query_stmt = new SQLStmt(""" SELECT nation, o_year, @@ -68,7 +68,7 @@ public class Q9 extends GenericQuery { ); @Override - protected PreparedStatement getStatement(Connection conn, RandomGenerator rand) throws SQLException { + protected PreparedStatement getStatement(Connection conn, RandomGenerator rand, double scaleFactor) throws SQLException { // COLOR is randomly selected within the list of values defined for the generation of P_NAME in Clause 4.2.3 String color = "%" + TPCHUtil.choice(TPCHConstants.P_NAME_GENERATOR, rand) + "%"; diff --git a/src/main/resources/benchmarks/tpch/dialect-cockroachdb.xml b/src/main/resources/benchmarks/tpch/dialect-cockroachdb.xml index ca931486f..e3ae38032 100644 --- a/src/main/resources/benchmarks/tpch/dialect-cockroachdb.xml +++ b/src/main/resources/benchmarks/tpch/dialect-cockroachdb.xml @@ -45,7 +45,7 @@ - select ps_partkey, sum(ps_supplycost * ps_availqty) as value from partsupp, supplier, nation where ps_suppkey = s_suppkey and s_nationkey = n_nationkey and n_name = 'ETHIOPIA' group by ps_partkey having sum(ps_supplycost * ps_availqty) > ( select sum(ps_supplycost * ps_availqty) * CAST(? AS DECIMAL) from partsupp, supplier, nation where ps_suppkey = s_suppkey and s_nationkey = n_nationkey and n_name = ? ) order by value desc + select ps_partkey, sum(ps_supplycost * ps_availqty) as value from partsupp, supplier, nation where ps_suppkey = s_suppkey and s_nationkey = n_nationkey and n_name = ? group by ps_partkey having sum(ps_supplycost * ps_availqty) > ( select sum(ps_supplycost * ps_availqty) * CAST(? AS DECIMAL) from partsupp, supplier, nation where ps_suppkey = s_suppkey and s_nationkey = n_nationkey and n_name = ? ) order by value desc