Skip to content

Commit

Permalink
Merge pull request Percona-Lab#4 from alexey2k/fixes.n1
Browse files Browse the repository at this point in the history
Fixes: compatibility, core, tpcc scenario
  • Loading branch information
vadimtk authored Apr 4, 2018
2 parents 2359a12 + e3a20ea commit 11db9ad
Show file tree
Hide file tree
Showing 4 changed files with 413 additions and 369 deletions.
16 changes: 11 additions & 5 deletions tpcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ require("tpcc_run")
require("tpcc_check")

function thread_init()

drv = sysbench.sql.driver()
con = drv:connect()

set_isolation_level(drv,con)
con:query("SET autocommit=0")

if drv:name() == "mysql" then
con:query("SET autocommit=0")
end

end

Expand All @@ -46,11 +50,13 @@ function event()
trx="stocklevel"
end

-- Repeat transaction execution until success
while not pcall(function () _G[trx]() end ) do
con:query("ROLLBACK")
end
-- Execute transaction
_G[trx]()

end

function sysbench.hooks.before_restart_event(err)
con:query("ROLLBACK")
end

function sysbench.hooks.report_intermediate(stat)
Expand Down
42 changes: 38 additions & 4 deletions tpcc_check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ require("tpcc_common")

function check_tables(drv, con, warehouse_num)

straight_join_hint=","

if drv:name() == "mysql" then
straight_join_hint = "STRAIGHT_JOIN"
end


local pass1 = 1
for table_num = 1, sysbench.opt.tables do
-- print(string.format("Checking tables: %d for warehouse: %d\n", table_num, warehouse_num))
rs = con:query("SELECT d_w_id,sum(d_ytd)-w_ytd diff FROM district"..table_num..",warehouse"..table_num.." where d_w_id=w_id AND w_id="..warehouse_num.." group by d_w_id")
rs = con:query("SELECT d_w_id,sum(d_ytd)-max(w_ytd) diff FROM district"..table_num..",warehouse"..table_num.." WHERE d_w_id=w_id AND w_id="..warehouse_num.." group by d_w_id")

for i = 1, rs.nrows do
row = rs:fetch_row()
Expand All @@ -41,6 +48,8 @@ function check_tables(drv, con, warehouse_num)

if pass1 ~= 1 then
print(string.format("Check 1, warehouse: %d FAILED!!!", warehouse_num))
else
print(string.format("Check 1, warehouse: %d PASSED", warehouse_num))
end

-- CHECK 2
Expand Down Expand Up @@ -96,7 +105,13 @@ function check_tables(drv, con, warehouse_num)
local pass4 = 1
for table_num = 1, sysbench.opt.tables do
-- print(string.format("Checking tables: %d for warehouse: %d\n", table_num, warehouse_num))
rs = con:query(string.format("SELECT count(*) FROM (SELECT o_d_id, SUM(o_ol_cnt) sm1, cn FROM orders%d,(SELECT ol_d_id, COUNT(*) cn FROM order_line%d WHERE ol_w_id=%d GROUP BY ol_d_id) ol WHERE O_w_id=%d AND ol_d_id=o_d_id GROUP BY o_d_id) t1 WHERE sm1<>cn",table_num, table_num, warehouse_num, warehouse_num))
rs = con:query(string.format([[SELECT count(*)
FROM (SELECT o_d_id, SUM(o_ol_cnt) sm1, MAX(cn) as cn
FROM orders%d,(SELECT ol_d_id, COUNT(*) cn
FROM order_line%d
WHERE ol_w_id=%d GROUP BY ol_d_id) ol
WHERE o_w_id=%d AND ol_d_id=o_d_id GROUP BY o_d_id) t1
WHERE sm1<>cn]],table_num, table_num, warehouse_num, warehouse_num))

for i = 1, rs.nrows do
row = rs:fetch_row()
Expand Down Expand Up @@ -196,7 +211,22 @@ function check_tables(drv, con, warehouse_num)
local pass10 = 1
for table_num = 1, sysbench.opt.tables do
-- print(string.format("Checking tables: %d for warehouse: %d\n", table_num, warehouse_num))
rs = con:query(string.format("SELECT count(*) FROM ( SELECT c.c_id, c.c_d_id, c.c_w_id, c.c_balance c1, (SELECT sum(ol_amount) FROM orders%d STRAIGHT_JOIN order_line%d WHERE OL_W_ID=O_W_ID AND OL_D_ID = O_D_ID AND OL_O_ID = O_ID AND OL_DELIVERY_D IS NOT NULL AND O_W_ID=c.c_w_id AND O_D_ID=c.C_D_ID AND O_C_ID=c.C_ID) sm, (SELECT sum(h_amount) from history%d WHERE H_C_W_ID=c.C_W_ID AND H_C_D_ID=c.C_D_ID AND H_C_ID=c.C_ID) smh FROM customer%d c WHERE c.c_w_id=%d ) t where c1<>sm-smh",table_num, table_num, table_num, table_num, warehouse_num))
rs = con:query(string.format([[SELECT count(*)
FROM ( SELECT c.c_id, c.c_d_id, c.c_w_id, c.c_balance c1,
(SELECT sum(ol_amount) FROM orders%d ]] .. straight_join_hint .. [[ order_line%d
WHERE OL_W_ID=O_W_ID
AND OL_D_ID = O_D_ID
AND OL_O_ID = O_ID
AND OL_DELIVERY_D IS NOT NULL
AND O_W_ID=c.c_w_id
AND O_D_ID=c.C_D_ID
AND O_C_ID=c.C_ID) sm, (SELECT sum(h_amount) from history%d
WHERE H_C_W_ID=c.C_W_ID
AND H_C_D_ID=c.C_D_ID
AND H_C_ID=c.C_ID) smh
FROM customer%d c
WHERE c.c_w_id=%d ) t
WHERE c1<>sm-smh]],table_num, table_num, table_num, table_num, warehouse_num))

for i = 1, rs.nrows do
row = rs:fetch_row()
Expand All @@ -216,7 +246,11 @@ function check_tables(drv, con, warehouse_num)
local pass12 = 1
for table_num = 1, sysbench.opt.tables do
-- print(string.format("Checking tables: %d for warehouse: %d\n", table_num, warehouse_num))
rs = con:query(string.format("SELECT count(*) FROM (SELECT c.c_id, c.c_d_id, c.c_balance c1, c_ytd_payment, (SELECT sum(ol_amount) FROM orders%d STRAIGHT_JOIN order_line%d WHERE OL_W_ID=O_W_ID AND OL_D_ID = O_D_ID AND OL_O_ID = O_ID AND OL_DELIVERY_D IS NOT NULL AND O_W_ID=c.c_w_id AND O_D_ID=c.C_D_ID AND O_C_ID=c.C_ID) sm FROM customer%d c WHERE c.c_w_id=%d) t1 WHERE c1+c_ytd_payment <> sm " ,table_num, table_num, table_num, warehouse_num))
rs = con:query(string.format([[SELECT count(*) FROM (SELECT c.c_id, c.c_d_id, c.c_balance c1, c_ytd_payment,
(SELECT sum(ol_amount) FROM orders%d ]] .. straight_join_hint .. [[ order_line%d
WHERE OL_W_ID=O_W_ID AND OL_D_ID = O_D_ID AND OL_O_ID = O_ID AND OL_DELIVERY_D IS NOT NULL AND
O_W_ID=c.c_w_id AND O_D_ID=c.C_D_ID AND O_C_ID=c.C_ID) sm FROM customer%d c WHERE c.c_w_id=%d) t1
WHERE c1+c_ytd_payment <> sm ]] ,table_num, table_num, table_num, warehouse_num))

for i = 1, rs.nrows do
row = rs:fetch_row()
Expand Down
Loading

0 comments on commit 11db9ad

Please sign in to comment.