Skip to content
This repository was archived by the owner on Aug 23, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions config/tpcc_config_clickhouse.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0"?>
<parameters>

<!-- Connection details -->
<dbtype>clickhouse</dbtype>
<driver>ru.yandex.clickhouse.ClickHouseDriver</driver>
<DBUrl>jdbc:clickhouse://localhost:8123/TPCC</DBUrl>
<username>default</username>
<password></password>
<isolation>TRANSACTION_READ_COMMITTED</isolation>

<!-- Scale factor is the number of warehouses in TPCC -->
<scalefactor>16</scalefactor>

<!-- The workload -->
<terminals>64</terminals>
<works>
<work>
<time>300</time>
<rate>unlimited</rate>
<weights>45,43,4,4,4</weights>
</work>
</works>

<!-- TPCC specific -->
<transactiontypes>
<transactiontype>
<name>NewOrder</name>
</transactiontype>
<transactiontype>
<name>Payment</name>
</transactiontype>
<transactiontype>
<name>OrderStatus</name>
</transactiontype>
<transactiontype>
<name>Delivery</name>
</transactiontype>
<transactiontype>
<name>StockLevel</name>
</transactiontype>
</transactiontypes>
</parameters>
Binary file not shown.
39 changes: 26 additions & 13 deletions src/com/oltpbenchmark/benchmarks/tpcc/TPCCLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void load(Connection conn) throws SQLException {
} // FOR
return (threads);
}

private PreparedStatement getInsertStatement(Connection conn, String tableName) throws SQLException {
Table catalog_tbl = this.benchmark.getTableCatalog(tableName);
assert(catalog_tbl != null);
Expand Down Expand Up @@ -312,6 +312,17 @@ protected int loadStock(Connection conn, int w_id, int numItems) {
+ TPCCUtil.randomStr(len - startORIGINAL - 9);
}

stock.s_dist_01 = TPCCUtil.randomStr(24);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase on the master branch to remove this regression.

stock.s_dist_02 = TPCCUtil.randomStr(24);
stock.s_dist_03 = TPCCUtil.randomStr(24);
stock.s_dist_04 = TPCCUtil.randomStr(24);
stock.s_dist_05 = TPCCUtil.randomStr(24);
stock.s_dist_06 = TPCCUtil.randomStr(24);
stock.s_dist_07 = TPCCUtil.randomStr(24);
stock.s_dist_08 = TPCCUtil.randomStr(24);
stock.s_dist_09 = TPCCUtil.randomStr(24);
stock.s_dist_10 = TPCCUtil.randomStr(24);

k++;
int idx = 1;
stckPrepStmt.setLong(idx++, stock.s_w_id);
Expand All @@ -321,16 +332,16 @@ protected int loadStock(Connection conn, int w_id, int numItems) {
stckPrepStmt.setLong(idx++, stock.s_order_cnt);
stckPrepStmt.setLong(idx++, stock.s_remote_cnt);
stckPrepStmt.setString(idx++, stock.s_data);
stckPrepStmt.setString(idx++, TPCCUtil.randomStr(24));
stckPrepStmt.setString(idx++, TPCCUtil.randomStr(24));
stckPrepStmt.setString(idx++, TPCCUtil.randomStr(24));
stckPrepStmt.setString(idx++, TPCCUtil.randomStr(24));
stckPrepStmt.setString(idx++, TPCCUtil.randomStr(24));
stckPrepStmt.setString(idx++, TPCCUtil.randomStr(24));
stckPrepStmt.setString(idx++, TPCCUtil.randomStr(24));
stckPrepStmt.setString(idx++, TPCCUtil.randomStr(24));
stckPrepStmt.setString(idx++, TPCCUtil.randomStr(24));
stckPrepStmt.setString(idx++, TPCCUtil.randomStr(24));
stckPrepStmt.setString(idx++, stock.s_dist_01);
stckPrepStmt.setString(idx++, stock.s_dist_02);
stckPrepStmt.setString(idx++, stock.s_dist_03);
stckPrepStmt.setString(idx++, stock.s_dist_04);
stckPrepStmt.setString(idx++, stock.s_dist_05);
stckPrepStmt.setString(idx++, stock.s_dist_06);
stckPrepStmt.setString(idx++, stock.s_dist_07);
stckPrepStmt.setString(idx++, stock.s_dist_08);
stckPrepStmt.setString(idx++, stock.s_dist_09);
stckPrepStmt.setString(idx++, stock.s_dist_10);
stckPrepStmt.addBatch();
if ((k % TPCCConfig.configCommitCount) == 0) {
stckPrepStmt.executeBatch();
Expand Down Expand Up @@ -592,7 +603,8 @@ protected int loadOrders(Connection conn, int w_id, int districtsPerWarehouse, i
if (oorder.o_carrier_id != null) {
ordrPrepStmt.setInt(idx++, oorder.o_carrier_id);
} else {
ordrPrepStmt.setNull(idx++, Types.INTEGER);
ordrPrepStmt.setInt(idx++, -1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this Clickhouse specific? What does "-1" mean?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 is just an arbitrary choice. This is supposed to replace the null value but -1 might not be a good choice.

//ordrPrepStmt.setNull(idx++, Types.INTEGER);
}
ordrPrepStmt.setInt(idx++, oorder.o_ol_cnt);
ordrPrepStmt.setInt(idx++, oorder.o_all_local);
Expand Down Expand Up @@ -645,7 +657,8 @@ protected int loadOrders(Connection conn, int w_id, int districtsPerWarehouse, i
if (order_line.ol_delivery_d != null) {
orlnPrepStmt.setTimestamp(idx++, order_line.ol_delivery_d);
} else {
orlnPrepStmt.setNull(idx++, 0);
orlnPrepStmt.setTimestamp(idx++, this.benchmark.getTimestamp(0));
//orlnPrepStmt.setNull(idx++, 0);
}
orlnPrepStmt.setDouble(idx++, order_line.ol_amount);
orlnPrepStmt.setLong(idx++, order_line.ol_supply_w_id);
Expand Down
30 changes: 15 additions & 15 deletions src/com/oltpbenchmark/benchmarks/tpcc/TPCCUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ public static Customer newCustomerFromResults(ResultSet rs)
throws SQLException {
Customer c = new Customer();
// TODO: Use column indices: probably faster?
c.c_first = rs.getString("c_first");
c.c_middle = rs.getString("c_middle");
c.c_street_1 = rs.getString("c_street_1");
c.c_street_2 = rs.getString("c_street_2");
c.c_city = rs.getString("c_city");
c.c_state = rs.getString("c_state");
c.c_zip = rs.getString("c_zip");
c.c_phone = rs.getString("c_phone");
c.c_credit = rs.getString("c_credit");
c.c_credit_lim = rs.getFloat("c_credit_lim");
c.c_discount = rs.getFloat("c_discount");
c.c_balance = rs.getFloat("c_balance");
c.c_ytd_payment = rs.getFloat("c_ytd_payment");
c.c_payment_cnt = rs.getInt("c_payment_cnt");
c.c_since = rs.getTimestamp("c_since");
c.c_first = rs.getString("C_FIRST");
c.c_middle = rs.getString("C_MIDDLE");
c.c_street_1 = rs.getString("C_STREET_1");
c.c_street_2 = rs.getString("C_STREET_2");
c.c_city = rs.getString("C_CITY");
c.c_state = rs.getString("C_STATE");
c.c_zip = rs.getString("C_ZIP");
c.c_phone = rs.getString("C_PHONE");
c.c_credit = rs.getString("C_CREDIT");
c.c_credit_lim = rs.getFloat("C_CREDIT_LIM");
c.c_discount = rs.getFloat("C_DISCOUNT");
c.c_balance = rs.getFloat("C_BALANCE");
c.c_ytd_payment = rs.getFloat("C_YTD_PAYMENT");
c.c_payment_cnt = rs.getInt("C_PAYMENT_CNT");
c.c_since = rs.getTimestamp("C_SINCE");
return c;
}
private static final RandomGenerator ran = new RandomGenerator(0);
Expand Down
163 changes: 163 additions & 0 deletions src/com/oltpbenchmark/benchmarks/tpcc/ddls/tpcc-clickhouse-ddl.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
-- TODO: c_since ON UPDATE CURRENT_TIMESTAMP,

DROP TABLE IF EXISTS TPCC.ORDER_LINE;
CREATE TABLE TPCC.ORDER_LINE (
OL_W_ID int,
OL_D_ID int,
OL_O_ID int,
OL_NUMBER int,
OL_I_ID int,
OL_DELIVERY_D DateTime,
OL_AMOUNT Float32,
OL_SUPPLY_W_ID int,
OL_QUANTITY Float32,
OL_DIST_INFO FixedString(24),
EventDate Date DEFAULT toDate(now()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make the column names match the case of the other columns in the table. Also, add comments that explain what this does and why it is needed.

version DateTime DEFAULT now()
) ENGINE = ReplacingMergeTree(EventDate, (OL_W_ID, OL_D_ID, OL_O_ID, OL_NUMBER), 8192, version);

DROP TABLE IF EXISTS TPCC.NEW_ORDER;
CREATE TABLE TPCC.NEW_ORDER (
NO_W_ID int,
NO_D_ID int,
NO_O_ID int,
EventDate Date DEFAULT toDate(now()),
version DateTime DEFAULT now()
) ENGINE = ReplacingMergeTree(EventDate, (NO_W_ID, NO_D_ID, NO_O_ID), 8192, version);

DROP TABLE IF EXISTS TPCC.STOCK;
CREATE TABLE TPCC.STOCK (
S_W_ID int,
S_I_ID int,
S_QUANTITY Float32,
S_YTD Float32,
S_ORDER_CNT int,
S_REMOTE_CNT int,
S_DATA String,
S_DIST_01 FixedString(24),
S_DIST_02 FixedString(24),
S_DIST_03 FixedString(24),
S_DIST_04 FixedString(24),
S_DIST_05 FixedString(24),
S_DIST_06 FixedString(24),
S_DIST_07 FixedString(24),
S_DIST_08 FixedString(24),
S_DIST_09 FixedString(24),
S_DIST_10 FixedString(24),
EventDate Date DEFAULT toDate(now()),
version DateTime DEFAULT now()
) ENGINE = ReplacingMergeTree(EventDate, (S_W_ID, S_I_ID), 8192, version);

-- TODO: o_entry_d ON UPDATE CURRENT_TIMESTAMP
DROP TABLE IF EXISTS TPCC.OORDER;
CREATE TABLE TPCC.OORDER (
O_W_ID int,
O_D_ID int,
O_ID int,
O_C_ID int,
O_CARRIER_ID int,
O_OL_CNT Float32,
O_ALL_LOCAL Float32,
O_ENTRY_D DateTime DEFAULT now(),
EventDate Date DEFAULT toDate(now()),
version DateTime DEFAULT now()
) ENGINE = ReplacingMergeTree(EventDate, (O_W_ID,O_D_ID,O_ID), 8192, version);

-- TODO: h_date ON UPDATE CURRENT_TIMESTAMP
DROP TABLE IF EXISTS TPCC.HISTORY;
CREATE TABLE TPCC.HISTORY (
H_C_ID int,
H_C_D_ID int,
H_C_W_ID int,
H_D_ID int,
H_W_ID int,
H_DATE DateTime DEFAULT now(),
H_AMOUNT Float32,
H_DATA String,
EventDate Date DEFAULT toDate(now()),
version DateTime DEFAULT now()
) ENGINE = ReplacingMergeTree(EventDate, (H_C_ID, H_C_D_ID, H_C_W_ID, H_D_ID, H_W_ID), 8192, version);

DROP TABLE IF EXISTS TPCC.CUSTOMER;
CREATE TABLE TPCC.CUSTOMER (
C_W_ID int,
C_D_ID int,
C_ID int,
C_DISCOUNT Float32,
C_CREDIT FixedString(2),
C_LAST String,
C_FIRST String,
C_CREDIT_LIM Float64,
C_BALANCE Float64,
C_YTD_PAYMENT Float64,
C_PAYMENT_CNT int,
C_DELIVERY_CNT int,
C_STREET_1 String,
C_STREET_2 String,
C_CITY String,
C_STATE FixedString(2),
C_ZIP FixedString(9),
C_PHONE FixedString(16),
C_SINCE DateTime DEFAULT now(),
C_MIDDLE FixedString(2),
C_DATA String,
EventDate Date DEFAULT toDate(now()),
version DateTime DEFAULT now()
) ENGINE = ReplacingMergeTree(EventDate, (C_W_ID, C_D_ID, C_ID), 8192, version);

DROP TABLE IF EXISTS TPCC.DISTRICT;
CREATE TABLE TPCC.DISTRICT (
D_W_ID int,
D_ID int,
D_YTD Float64,
D_TAX Float32,
D_NEXT_O_ID int,
D_NAME String,
D_STREET_1 String,
D_STREET_2 String,
D_CITY String,
D_STATE String,
D_ZIP String,
EventDate Date DEFAULT toDate(now()),
version DateTime DEFAULT now()
) ENGINE = ReplacingMergeTree(EventDate, (D_W_ID, D_ID), 8192, version);


DROP TABLE IF EXISTS TPCC.ITEM;
CREATE TABLE TPCC.ITEM (
I_ID int,
I_NAME String,
I_PRICE Float32,
I_DATA String,
I_IM_ID int,
EventDate Date DEFAULT toDate(now()),
version DateTime DEFAULT now()
) ENGINE = ReplacingMergeTree(EventDate, (I_ID), 8192, version);

DROP TABLE IF EXISTS TPCC.WAREHOUSE;
CREATE TABLE TPCC.WAREHOUSE (
W_ID int,
W_YTD Float64,
W_TAX Float32,
W_NAME String,
W_STREET_1 String,
W_STREET_2 String,
W_CITY String,
W_STATE FixedString(2),
W_ZIP FixedString(9),
EventDate Date DEFAULT toDate(now()),
version DateTime DEFAULT now()
) ENGINE = ReplacingMergeTree(EventDate, (W_ID), 8192, version);

--add 'ON DELETE CASCADE' to clear table work correctly

--ALTER TABLE district ADD CONSTRAINT fkey_district_1 FOREIGN KEY(d_w_id) REFERENCES warehouse(w_id) ON DELETE CASCADE;
--ALTER TABLE customer ADD CONSTRAINT fkey_customer_1 FOREIGN KEY(c_w_id,c_d_id) REFERENCES district(d_w_id,d_id) ON DELETE CASCADE ;
--ALTER TABLE history ADD CONSTRAINT fkey_history_1 FOREIGN KEY(h_c_w_id,h_c_d_id,h_c_id) REFERENCES customer(c_w_id,c_d_id,c_id) ON DELETE CASCADE;
--ALTER TABLE history ADD CONSTRAINT fkey_history_2 FOREIGN KEY(h_w_id,h_d_id) REFERENCES district(d_w_id,d_id) ON DELETE CASCADE;
--ALTER TABLE new_order ADD CONSTRAINT fkey_new_order_1 FOREIGN KEY(no_w_id,no_d_id,no_o_id) REFERENCES oorder(o_w_id,o_d_id,o_id) ON DELETE CASCADE;
--ALTER TABLE oorder ADD CONSTRAINT fkey_order_1 FOREIGN KEY(o_w_id,o_d_id,o_c_id) REFERENCES customer(c_w_id,c_d_id,c_id) ON DELETE CASCADE;
--ALTER TABLE order_line ADD CONSTRAINT fkey_order_line_1 FOREIGN KEY(ol_w_id,ol_d_id,ol_o_id) REFERENCES oorder(o_w_id,o_d_id,o_id) ON DELETE CASCADE;
--ALTER TABLE order_line ADD CONSTRAINT fkey_order_line_2 FOREIGN KEY(ol_supply_w_id,ol_i_id) REFERENCES stock(s_w_id,s_i_id) ON DELETE CASCADE;
--ALTER TABLE stock ADD CONSTRAINT fkey_stock_1 FOREIGN KEY(s_w_id) REFERENCES warehouse(w_id) ON DELETE CASCADE;
--ALTER TABLE stock ADD CONSTRAINT fkey_stock_2 FOREIGN KEY(s_i_id) REFERENCES item(i_id) ON DELETE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0"?>
<dialects>
<dialect type="CLICKHOUSE">
<procedure name="Delivery">
<statement name="delivDeleteNewOrderSQL">
/*? ? ?*/
</statement>
<statement name="delivUpdateCarrierIdSQL">
INSERT INTO OORDER SELECT O_W_ID, O_D_ID, O_ID, O_C_ID, ?, O_OL_CNT, O_ALL_LOCAL, O_ENTRY_D, EventDate FROM OORDER WHERE O_ID = ? AND O_D_ID = ? AND O_W_ID = ?
</statement>
<statement name="delivUpdateDeliveryDateSQL">
INSERT INTO ORDER_LINE SELECT OL_W_ID, OL_D_ID, OL_O_ID, OL_NUMBER, OL_I_ID, ?, OL_AMOUNT, OL_SUPPLY_W_ID, OL_QUANTITY, OL_DIST_INFO, EventDate FROM ORDER_LINE WHERE OL_O_ID = ? AND OL_D_ID = ? AND OL_W_ID = ?
</statement>
<statement name="delivUpdateCustBalDelivCntSQL">
INSERT INTO CUSTOMER SELECT C_W_ID, C_D_ID, C_ID, C_DISCOUNT, C_CREDIT, C_LAST, C_FIRST, C_CREDIT_LIM, ?, C_YTD_PAYMENT, C_PAYMENT_CNT, toInt32(C_DELIVERY_CNT + 1), C_STREET_1, C_STREET_2, C_CITY, C_STATE, C_ZIP, C_PHONE, C_SINCE, C_MIDDLE, C_DATA, EventDate FROM CUSTOMER WHERE C_W_ID = ? AND C_D_ID = ? AND C_ID = ?
</statement>
</procedure>
<procedure name="NewOrder">
<statement name="stmtInsertNewOrderSQL">
INSERT INTO NEW_ORDER (NO_OD_ID, NO_D_ID, NO_W, ID, EventDate, version) VALUES ( ?, ?, ?, toDate(now()), now())
</statement>
<statement name="stmtUpdateDistSQL">
INSERT INTO DISTRICT SELECT D_W_ID, D_ID, D_YTD, D_TAX, toInt32(D_NEXT_OD_ID + 1), D_NAME, D_STREET_1, D_STREET_2, D_CITY, D_STATE, D_ZIP, EventDate FROM DISTRICT WHERE D_W_ID = ? AND D_ID = ?
</statement>
<statement name="stmtInsertOOrderSQL">
INSERT INTO OORDER (O_ID, O_D_ID, O_W_ID, O_C_ID, O_ENTRY_D, O_OL_CNT, O_ALL_LOCAL, EventDate, version) VALUES (?, ?, ?, ?, ?, ?, ?, toDate(now()), now())
</statement>
<statement name="stmtUpdateStockSQL">
INSERT INTO STOCK SELECT S_W_ID, S_I_ID, ?, ?, ?, ?, S_DATA, S_DIST_01, S_DIST_02, S_DIST_03, S_DIST_04, S_DIST_05, S_DIST_06, S_DIST_07, S_DIST_08, S_DIST_09, S_DIST_10, EventDate FROM STOCK WHERE S_I_ID = ? AND S_W_ID = ?
</statement>
<statement name="stmtInsertOrderLineSQL">
INSERT INTO ORDER_LINE (OL_O_ID, OL_D_ID, OL_W_ID, OL_NUMBER, OL_I_ID, OL_SUPPLY_W_ID, OL_QUANTITY, OL_AMOUNT, OL_DIST_INFO, EventDate, version) VALUES (?,?,?,?,?,?,?,?,?, toDate(now()), now())
</statement>
</procedure>
<procedure name="Payment">
<statement name="payUpdateWhseSQL">
INSERT INTO WAREHOUSE SELECT W_ID, toFloat64(W_YTD + ?), W_TAX, W_NAME, W_STREET_1, W_STREET_2, W_CITY, W_STATE, W_ZIP, EventDate FROM WAREHOUSE WHERE W_ID = ?
</statement>
<statement name="payUpdateDistSQL">
INSERT INTO DISTRICT SELECT D_W_ID, D_ID, toFloat64(D_YTD + ?), D_TAX, D_NEXT_O_ID, D_NAME, D_STREET_1, D_STREET_2, D_CITY, D_STATE, D_ZIP, EventDate FROM DISTRICT WHERE D_W_ID = ? AND D_ID = ?
</statement>
<statement name="payUpdateCustBalCdataSQL">
INSERT INTO CUSTOMER SELECT C_W_ID, C_D_ID, C_ID, C_DISCOUNT, C_CREDIT, C_LAST, C_FIRST, C_CREDIT_LIM, ?, ?, ?, C_DELIVERY_CNT, C_STREET_1, C_STREET_2, C_CITY, C_STATE, C_ZIP, C_PHONE, C_SINCE, C_MIDDLE, ?, EventDate FROM CUSTOMER WHERE C_W_ID = ? AND C_D_ID = ? AND C_ID = ?

</statement>
<statement name="payUpdateCustBalSQL">
INSERT INTO CUSTOMER SELECT C_W_ID, C_D_ID, C_ID, C_DISCOUNT, C_CREDIT, C_LAST, C_FIRST, C_CREDIT_LIM, ?, ?, ?, C_DELIVERY_CNT, C_STREET_1, C_STREET_2, C_CITY, C_STATE, C_ZIP, C_PHONE, C_SINCE, C_MIDDLE, C_DATA, EventDate FROM CUSTOMER WHERE C_W_ID = ? AND C_D_ID = ? AND C_ID = ?
</statement>
<statement name="payInsertHistSQL">
INSERT INTO HISTORY (H_C_D_ID, H_C_W_ID, H_C_ID, H_D_ID, H_W_ID, H_DATE, H_AMOUNT, H_DATA, EventDate, version) VALUES (?,?,?,?,?,?,?,?, toDate(now()), now())
</statement>
</procedure>
</dialect>
</dialects>
3 changes: 2 additions & 1 deletion src/com/oltpbenchmark/types/DatabaseType.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public enum DatabaseType {
MONETDB("nl.cwi.monetdb.jdbc.MonetDriver", false, false),
NUODB("com.nuodb.jdbc.Driver", true, false),
TIMESTEN("com.timesten.jdbc.TimesTenDriver", true, false),
PELOTON("org.postgresql.Driver", false, false)
PELOTON("org.postgresql.Driver", false, false),
CLICKHOUSE("ru.yandex.clickhouse.ClickHouseDriver", true, false)
;

private DatabaseType(String driver, boolean escapeNames, boolean includeColNames) {
Expand Down
Loading