|
| 1 | +-- Copyright (C) 2006-2017 Vadim Tkachenko, Percona |
| 2 | + |
| 3 | +-- This program is free software; you can redistribute it and/or modify |
| 4 | +-- it under the terms of the GNU General Public License as published by |
| 5 | +-- the Free Software Foundation; either version 2 of the License, or |
| 6 | +-- (at your option) any later version. |
| 7 | + |
| 8 | +-- This program is distributed in the hope that it will be useful, |
| 9 | +-- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | +-- GNU General Public License for more details. |
| 12 | + |
| 13 | +-- You should have received a copy of the GNU General Public License |
| 14 | +-- along with this program; if not, write to the Free Software |
| 15 | +-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 16 | + |
| 17 | +-- ----------------------------------------------------------------------------- |
| 18 | +-- Check data code for TPCC benchmarks. |
| 19 | +-- ----------------------------------------------------------------------------- |
| 20 | + |
| 21 | + |
| 22 | +require("tpcc_common") |
| 23 | + |
| 24 | + |
| 25 | +function check_tables(drv, con, warehouse_num) |
| 26 | + |
| 27 | + local pass1 = 1 |
| 28 | + for table_num = 1, sysbench.opt.tables do |
| 29 | + -- print(string.format("Checking tables: %d for warehouse: %d\n", table_num, warehouse_num)) |
| 30 | + 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") |
| 31 | + |
| 32 | + for i = 1, rs.nrows do |
| 33 | + row = rs:fetch_row() |
| 34 | + local d_tax = tonumber(row[2]) |
| 35 | + if d_tax ~= 0 then |
| 36 | + pass1=0 |
| 37 | + end |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + if pass1 == 1 then |
| 42 | + print(string.format("Check 1, warehouse: %d PASSED", warehouse_num)) |
| 43 | + else |
| 44 | + print(string.format("Check 1, warehouse: %d FAILED!!!", warehouse_num)) |
| 45 | + end |
| 46 | + |
| 47 | +-- CHECK 2 |
| 48 | +-- select dis.d_id, d_next_o_id-1,mo,mno from district1 dis, (select o_d_id,max(o_id) mo from orders1 where o_w_id=1 group by o_d_id) q, (select no_d_id,max(no_o_id) mno from new_orders1 where no_w_id=1 group by no_d_id) no where d_w_id=1 and q.o_d_id=dis.d_id and no.no_d_id=dis.d_id |
| 49 | + |
| 50 | + |
| 51 | + local pass2 = 1 |
| 52 | + for table_num = 1, sysbench.opt.tables do |
| 53 | + -- print(string.format("Checking tables: %d for warehouse: %d\n", table_num, warehouse_num)) |
| 54 | + rs = con:query(string.format("SELECT dis.d_id, d_next_o_id-1,mo,mno FROM district%d dis, (SELECT o_d_id,max(o_id) mo FROM orders%d WHERE o_w_id=%d GROUP BY o_d_id) q, (select no_d_id,max(no_o_id) mno from new_orders%d where no_w_id=%d group by no_d_id) no where d_w_id=%d and q.o_d_id=dis.d_id and no.no_d_id=dis.d_id", table_num,table_num,warehouse_num, table_num, warehouse_num, warehouse_num)) |
| 55 | + |
| 56 | + for i = 1, rs.nrows do |
| 57 | + row = rs:fetch_row() |
| 58 | + local d1 = tonumber(row[2]) |
| 59 | + local d2 = tonumber(row[3]) |
| 60 | + local d3 = tonumber(row[4]) |
| 61 | + if d1 ~= d2 then |
| 62 | + pass2=0 |
| 63 | + end |
| 64 | + if d1 ~= d3 then |
| 65 | + pass2=0 |
| 66 | + end |
| 67 | + end |
| 68 | + end |
| 69 | + |
| 70 | + if pass2 == 1 then |
| 71 | + print(string.format("Check 2, warehouse: %d PASSED", warehouse_num)) |
| 72 | + else |
| 73 | + print(string.format("Check 2, warehouse: %d FAILED!!!", warehouse_num)) |
| 74 | + end |
| 75 | + |
| 76 | + local pass3 = 1 |
| 77 | + for table_num = 1, sysbench.opt.tables do |
| 78 | + -- print(string.format("Checking tables: %d for warehouse: %d\n", table_num, warehouse_num)) |
| 79 | + rs = con:query(string.format("select no_d_id,max(no_o_id)-min(no_o_id)+1,count(*) from new_orders%d where no_w_id=%d group by no_d_id",table_num, warehouse_num)) |
| 80 | + |
| 81 | + for i = 1, rs.nrows do |
| 82 | + row = rs:fetch_row() |
| 83 | + local d1 = tonumber(row[2]) |
| 84 | + local d2 = tonumber(row[3]) |
| 85 | + if d1 ~= d2 then |
| 86 | + pass3=0 |
| 87 | + end |
| 88 | + end |
| 89 | + end |
| 90 | + |
| 91 | + if pass3 == 1 then |
| 92 | + print(string.format("Check 3, warehouse: %d PASSED", warehouse_num)) |
| 93 | + else |
| 94 | + print(string.format("Check 3, warehouse: %d FAILED!!!", warehouse_num)) |
| 95 | + end |
| 96 | + |
| 97 | + local pass4 = 1 |
| 98 | + for table_num = 1, sysbench.opt.tables do |
| 99 | + -- print(string.format("Checking tables: %d for warehouse: %d\n", table_num, warehouse_num)) |
| 100 | + 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)) |
| 101 | + |
| 102 | + for i = 1, rs.nrows do |
| 103 | + row = rs:fetch_row() |
| 104 | + local d1 = tonumber(row[1]) |
| 105 | + if d1 ~= 0 then |
| 106 | + pass4=0 |
| 107 | + end |
| 108 | + end |
| 109 | + end |
| 110 | + |
| 111 | + if pass4 == 1 then |
| 112 | + print(string.format("Check 4, warehouse: %d PASSED", warehouse_num)) |
| 113 | + else |
| 114 | + print(string.format("Check 4, warehouse: %d FAILED!!!", warehouse_num)) |
| 115 | + end |
| 116 | + |
| 117 | + local pass8 = 1 |
| 118 | + for table_num = 1, sysbench.opt.tables do |
| 119 | + -- print(string.format("Checking tables: %d for warehouse: %d\n", table_num, warehouse_num)) |
| 120 | + rs = con:query(string.format("SELECT count(*) cn FROM (SELECT w_id,w_ytd,SUM(h_amount) sm FROM history%d,warehouse%d WHERE h_w_id=w_id GROUP BY w_id) t1 WHERE w_ytd<>sm",table_num, table_num)) |
| 121 | + |
| 122 | + for i = 1, rs.nrows do |
| 123 | + row = rs:fetch_row() |
| 124 | + local d1 = tonumber(row[1]) |
| 125 | + if d1 ~= 0 then |
| 126 | + pass8=0 |
| 127 | + end |
| 128 | + end |
| 129 | + end |
| 130 | + |
| 131 | + if pass8 == 1 then |
| 132 | + print(string.format("Check 8, warehouse: %d PASSED", warehouse_num)) |
| 133 | + else |
| 134 | + print(string.format("Check 8, warehouse: %d FAILED!!!", warehouse_num)) |
| 135 | + end |
| 136 | + |
| 137 | + local pass9 = 1 |
| 138 | + for table_num = 1, sysbench.opt.tables do |
| 139 | + -- print(string.format("Checking tables: %d for warehouse: %d\n", table_num, warehouse_num)) |
| 140 | + rs = con:query(string.format("SELECT COUNT(*) FROM (select d_id,d_w_id,sum(d_ytd) s1 from district%d group by d_id,d_w_id) d,(select h_d_id,h_w_id,sum(h_amount) s2 from history%d group by h_d_id, h_w_id) h WHERE h_d_id=d_id AND d_w_id=h_w_id and s1<>s2",table_num, table_num)) |
| 141 | + |
| 142 | + for i = 1, rs.nrows do |
| 143 | + row = rs:fetch_row() |
| 144 | + local d1 = tonumber(row[1]) |
| 145 | + if d1 ~= 0 then |
| 146 | + pass9=0 |
| 147 | + end |
| 148 | + end |
| 149 | + end |
| 150 | + |
| 151 | + if pass9 == 1 then |
| 152 | + print(string.format("Check 9, warehouse: %d PASSED", warehouse_num)) |
| 153 | + else |
| 154 | + print(string.format("Check 9, warehouse: %d FAILED!!!", warehouse_num)) |
| 155 | + end |
| 156 | +end |
| 157 | + |
| 158 | + |
| 159 | +-- vim:ts=4 ss=4 sw=4 expandtab |
0 commit comments