From a79bd105d0da0c456a18dc77b781085a87aacd1e Mon Sep 17 00:00:00 2001 From: digoal Date: Thu, 13 Sep 2018 13:40:27 +0800 Subject: [PATCH 01/14] improve --- README.md | 33 ++ tpcc.lua | 271 ++++++++++++++- tpcc.lua.old | 75 +++++ tpcc_common.lua | 2 +- tpcc_common.lua.old | 645 +++++++++++++++++++++++++++++++++++ tpcc_run.lua | 754 ++++++++++++++++++++++------------------- tpcc_run.lua.old | 795 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 2227 insertions(+), 348 deletions(-) mode change 100755 => 100644 tpcc.lua create mode 100755 tpcc.lua.old create mode 100644 tpcc_common.lua.old mode change 100755 => 100644 tpcc_run.lua create mode 100755 tpcc_run.lua.old diff --git a/README.md b/README.md index a06fc2f..3c22dd9 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,39 @@ TPCC-like workload for sysbench 1.0.x. **Make sure you are using sysbench 1.0.14 or better!** +# modified by digoal +1\. Use prepared statement for postgresql. + +2\. Use Read committed by default + +3\. modified file: ```tpcc_common.lua, tpcc.lua, tpcc_run.lua``` + +# PostgreSQL example (use modified prepared statement by digoal) +for exp. + +``` +unixsocket_dir='/tmp' +port=1921 +user=postgres +dbname=postgres +``` + +## PostgreSQL: prepare data and tables +``` +./tpcc.lua --pgsql-host=/tmp --pgsql-port=1921 --pgsql-user=postgres --pgsql-db=postgres --time=300 --threads=64 --report-interval=1 --tables=10 --scale=100 --trx_level=RC --db-ps-mode=auto --db-driver=pgsql prepare +``` + +## PostgreSQL: Run benchmark +``` +./tpcc.lua --pgsql-host=/tmp --pgsql-port=1921 --pgsql-user=postgres --pgsql-db=postgres --time=300 --threads=64 --report-interval=1 --tables=10 --scale=100 --trx_level=RC --db-ps-mode=auto --db-driver=pgsql run +``` + +## PostgreSQL: Cleanup +``` +./tpcc.lua --pgsql-host=/tmp --pgsql-port=1921 --pgsql-user=postgres --pgsql-db=postgres --time=300 --threads=64 --report-interval=1 --tables=10 --scale=100 --trx_level=RC --db-ps-mode=auto --db-driver=pgsql cleanup +``` + +# for MySQL # prepare data and tables ` diff --git a/tpcc.lua b/tpcc.lua old mode 100755 new mode 100644 index d14b4d4..dc1036c --- a/tpcc.lua +++ b/tpcc.lua @@ -32,7 +32,272 @@ function thread_init() if drv:name() == "mysql" then con:query("SET autocommit=0") end - + + + -- prepare statement for postgresql + + if drv:name() == "pgsql" then + for table_num = 1, sysbench.opt.tables + do + + con:query(([[prepare p_new_order1_%d(int2,int2,int4) as SELECT c_discount, c_last, c_credit, w_tax + FROM customer%d, warehouse%d + WHERE w_id = $1 + AND c_w_id = w_id + AND c_d_id = $2 + AND c_id = $3]]): + format(table_num, table_num, table_num)) + + con:query(([[prepare p_new_order2_%d(int2,int2) as SELECT d_next_o_id, d_tax + FROM district%d + WHERE d_w_id = $1 + AND d_id = $2 FOR UPDATE]]): + format(table_num, table_num)) + + + con:query(([[prepare p_new_order3_%d(int4,int2,int2) as UPDATE district%d + SET d_next_o_id = $1 + WHERE d_id = $2 AND d_w_id= $3]]):format(table_num, table_num)) + + con:query(([[prepare p_new_order4_%d(int4,int2,int2,int4,int2,int2) as INSERT INTO orders%d + (o_id, o_d_id, o_w_id, o_c_id, o_entry_d, o_ol_cnt, o_all_local) + VALUES ($1,$2,$3,$4,NOW(),$5,$6)]]): + format(table_num, table_num)) + + con:query(([[prepare p_new_order5_%d(int4,int2,int2) as INSERT INTO new_orders%d (no_o_id, no_d_id, no_w_id) + VALUES ($1,$2,$3)]]): + format(table_num, table_num)) + + con:query(([[prepare p_new_order6_%d(int4) as SELECT i_price, i_name, i_data + FROM item%d + WHERE i_id = $1]]): + format(table_num, table_num)) + + for d_id = 1, DIST_PER_WARE + do + con:query(([[prepare p_new_order7_%d_%s(int4,int2) as SELECT s_quantity, s_data, s_dist_%s s_dist + FROM stock%d + WHERE s_i_id = $1 AND s_w_id= $2 FOR UPDATE]]): + format(table_num, string.format("%02d",d_id), string.format("%02d",d_id), table_num)) + end + + con:query(([[prepare p_new_order8_%d(int2,int4,int2) as UPDATE stock%d + SET s_quantity =$1 + WHERE s_i_id = $2 + AND s_w_id= $3]]): + format(table_num, table_num)) + + + con:query(([[prepare p_new_order9_%d(int4,int2,int2,int2,int4,int2,int2,numeric,text) as INSERT INTO order_line%d + (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) + VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)]]): + format(table_num, table_num)) + + + con:query(([[prepare p_payment1_%d(numeric,int2) as UPDATE warehouse%d + SET w_ytd = w_ytd + $1 + WHERE w_id = $2]]):format(table_num, table_num)) + + con:query(([[prepare p_payment2_%d(int2) as SELECT w_street_1, w_street_2, w_city, w_state, w_zip, w_name + FROM warehouse%d + WHERE w_id = $1]]):format(table_num, table_num)) + + con:query(([[prepare p_payment3_%d(numeric,int2,int2) as UPDATE district%d + SET d_ytd = d_ytd + $1 + WHERE d_w_id = $2 + AND d_id= $3]]):format(table_num, table_num)) + + con:query(([[prepare p_payment4_%d(int2,int2) as SELECT d_street_1, d_street_2, d_city, d_state, d_zip, d_name + FROM district%d + WHERE d_w_id = $1 + AND d_id = $2]]):format(table_num, table_num)) + + con:query(([[prepare p_payment5_%d(int2,int2,text) as SELECT count(c_id) namecnt + FROM customer%d + WHERE c_w_id = $1 + AND c_d_id=$2 + AND c_last=$3]]):format(table_num, table_num)) + + con:query(([[prepare p_payment6_%d(int2,int2,text) as SELECT c_id + FROM customer%d + WHERE c_w_id = $1 AND c_d_id= $2 + AND c_last=$3 ORDER BY c_first]]):format(table_num, table_num)) + + con:query(([[prepare p_payment7_%d(int2,int2,int4) as SELECT c_first, c_middle, c_last, c_street_1, + c_street_2, c_city, c_state, c_zip, c_phone, + c_credit, c_credit_lim, c_discount, c_balance, c_ytd_payment, c_since + FROM customer%d + WHERE c_w_id = $1 + AND c_d_id= $2 + AND c_id=$3 FOR UPDATE]]) + :format(table_num, table_num)) + + con:query(([[prepare p_payment8_%d(int2,int2,int4) as SELECT c_data + FROM customer%d + WHERE c_w_id = $1 + AND c_d_id = $2 + AND c_id= $3]]): + format(table_num, table_num)) + + con:query(([[prepare p_payment9_%d(numeric,numeric,text,int2,int2,int4) as UPDATE customer%d + SET c_balance=$1, c_ytd_payment=$2, c_data=$3 + WHERE c_w_id = $4 + AND c_d_id = $5 + AND c_id = $6]]) + :format(table_num, table_num )) + + con:query(([[prepare p_payment10_%d(numeric,numeric,int2,int2,int4) as UPDATE customer%d + SET c_balance=$1, c_ytd_payment=$2 + WHERE c_w_id = $3 + AND c_d_id = $4 + AND c_id = $5]]) + :format(table_num, table_num )) + + con:query(([[prepare p_payment11_%d(int2,int2,int4,int2,int2,numeric,text) as INSERT INTO history%d + (h_c_d_id, h_c_w_id, h_c_id, h_d_id, h_w_id, h_date, h_amount, h_data) + VALUES ($1,$2,$3,$4,$5,NOW(),$6,$7)]]) + :format(table_num, table_num)) + + + con:query(([[prepare p_orderstatus1_%d(int2,int2,text) as SELECT count(c_id) namecnt + FROM customer%d + WHERE c_w_id = $1 + AND c_d_id= $2 + AND c_last=$3]]): + format(table_num, table_num)) + + + con:query(([[prepare p_orderstatus2_%d(int2,int2,text) as SELECT c_balance, c_first, c_middle, c_id + FROM customer%d + WHERE c_w_id = $1 + AND c_d_id= $2 + AND c_last=$3 ORDER BY c_first]]): + format(table_num, table_num)) + + con:query(([[prepare p_orderstatus3_%d(int2,int2,int4) as SELECT c_balance, c_first, c_middle, c_last + FROM customer%d + WHERE c_w_id = $1 + AND c_d_id= $2 + AND c_id=$3]]) + :format(table_num, table_num )) + + con:query(([[prepare p_orderstatus4_%d(int2,int2,int4) as SELECT o_id, o_carrier_id, o_entry_d + FROM orders%d + WHERE o_w_id = $1 + AND o_d_id = $2 + AND o_c_id = $3 + ORDER BY o_id DESC]]): + format(table_num, table_num )) + + con:query(([[prepare p_orderstatus5_%d(int2,int2,int4) as SELECT ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_delivery_d + FROM order_line%d WHERE ol_w_id = $1 AND ol_d_id = $2 AND ol_o_id = $3]]) + :format(table_num, table_num )) + + + con:query(([[prepare p_delivery1_%d(int2,int2) as SELECT no_o_id + FROM new_orders%d + WHERE no_d_id = $1 + AND no_w_id = $2 + ORDER BY no_o_id ASC LIMIT 1 FOR UPDATE]]) + :format(table_num, table_num)) + + con:query(([[prepare p_delivery2_%d(int4,int2,int2) as DELETE FROM new_orders%d + WHERE no_o_id = $1 + AND no_d_id = $2 + AND no_w_id = $3]]) + :format(table_num, table_num)) + + con:query(([[prepare p_delivery3_%d(int4,int2,int2) as SELECT o_c_id + FROM orders%d + WHERE o_id = $1 + AND o_d_id = $2 + AND o_w_id = $3]]) + :format(table_num, table_num)) + + con:query(([[prepare p_delivery4_%d(int2,int4,int2,int2) as UPDATE orders%d + SET o_carrier_id = $1 + WHERE o_id = $2 + AND o_d_id = $3 + AND o_w_id = $4]]) + :format(table_num, table_num)) + + con:query(([[prepare p_delivery5_%d(int4,int2,int2) as UPDATE order_line%d + SET ol_delivery_d = NOW() + WHERE ol_o_id = $1 + AND ol_d_id = $2 + AND ol_w_id = $3]]) + :format(table_num, table_num)) + + con:query(([[prepare p_delivery6_%d(int4,int2,int2) as SELECT SUM(ol_amount) sm + FROM order_line%d + WHERE ol_o_id = $1 + AND ol_d_id = $2 + AND ol_w_id = $3]]) + :format(table_num, table_num)) + + + con:query(([[prepare p_delivery7_%d(numeric,int4,int2,int2) as UPDATE customer%d + SET c_balance = c_balance + $1, + c_delivery_cnt = c_delivery_cnt + 1 + WHERE c_id = $2 + AND c_d_id = $3 + AND c_w_id = $4]]) + :format(table_num, table_num)) + + + + con:query(([[prepare p_stocklevel1_%d(int2,int2) as SELECT d_next_o_id + FROM district%d + WHERE d_id = $1 AND d_w_id= $2]]) + :format( table_num, table_num )) + + + con:query(([[prepare p_stocklevel2_%d(int2,int2,int4,int4,int2,int2) as SELECT COUNT(DISTINCT (s_i_id)) + FROM order_line%d, stock%d + WHERE ol_w_id = $1 + AND ol_d_id = $2 + AND ol_o_id < $3 + AND ol_o_id >= $4 + AND s_w_id= $5 + AND s_i_id=ol_i_id + AND s_quantity < $6 ]]) + :format(table_num, table_num, table_num )) + + con:query(([[prepare p_stocklevel3_%d(int2,int2,int4,int4) as SELECT DISTINCT ol_i_id FROM order_line%d + WHERE ol_w_id = $1 AND ol_d_id = $2 + AND ol_o_id < $3 AND ol_o_id >= $4]]) + :format(table_num, table_num )) + + con:query(([[prepare p_stocklevel4_%d(int2,int4,int2) as SELECT count(*) FROM stock%d + WHERE s_w_id = $1 AND s_i_id = $2 + AND s_quantity < $3]]) + :format(table_num, table_num) ) + + + + + con:query(([[prepare p_purge1_%d(int2,int2) as SELECT min(no_o_id) mo + FROM new_orders%d + WHERE no_w_id = $1 AND no_d_id = $2]]) + :format(table_num, table_num)) + + con:query(([[prepare p_purge2_%d(int2,int2,int4) as SELECT o_id FROM orders%d o, + (SELECT o_c_id,o_w_id,o_d_id,count(distinct o_id) FROM orders%d WHERE o_w_id=$1 AND o_d_id=$2 AND o_id > 2100 + AND o_id < $3 GROUP BY o_c_id,o_d_id,o_w_id having count( distinct o_id) > 1 limit 1) t + WHERE t.o_w_id=o.o_w_id and t.o_d_id=o.o_d_id and t.o_c_id=o.o_c_id limit 1 ]]) + :format(table_num, table_num, table_num)) + + con:query(([[prepare p_purge3_%d(int2,int2,int4) as DELETE FROM order_line%d where ol_w_id=$1 AND ol_d_id=$2 AND ol_o_id=$3]]) + :format(table_num, table_num)) + + con:query(([[prepare p_purge4_%d(int2,int2,int4) as DELETE FROM orders%d where o_w_id=$1 AND o_d_id=$2 and o_id=$3]]) + :format(table_num, table_num)) + + con:query(([[prepare p_purge5_%d(int2,int2) as DELETE FROM history%d where ctid = any (array(select ctid from history%d where h_w_id=$1 AND h_d_id=$2 LIMIT 10))]]) + :format(table_num, table_num, table_num )) + + end + end end function event() @@ -65,9 +330,9 @@ end function sysbench.hooks.report_intermediate(stat) -- -- print("my stat: ", val) if sysbench.opt.report_csv == "yes" then - sysbench.report_csv(stat) + sysbench.report_csv(stat) else - sysbench.report_default(stat) + sysbench.report_default(stat) end end diff --git a/tpcc.lua.old b/tpcc.lua.old new file mode 100755 index 0000000..d14b4d4 --- /dev/null +++ b/tpcc.lua.old @@ -0,0 +1,75 @@ +#!/usr/bin/env sysbench + +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. + +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +-- ---------------------------------------------------------------------- +-- TPCC-like workload +-- ---------------------------------------------------------------------- + +require("tpcc_common") +require("tpcc_run") +require("tpcc_check") + +function thread_init() + + drv = sysbench.sql.driver() + con = drv:connect() + + set_isolation_level(drv,con) + + if drv:name() == "mysql" then + con:query("SET autocommit=0") + end + +end + +function event() + -- print( NURand (1023,1,3000)) + local max_trx = sysbench.opt.enable_purge == "yes" and 24 or 23 + local trx_type = sysbench.rand.uniform(1,max_trx) + if trx_type <= 10 then + trx="new_order" + elseif trx_type <= 20 then + trx="payment" + elseif trx_type <= 21 then + trx="orderstatus" + elseif trx_type <= 22 then + trx="delivery" + elseif trx_type <= 23 then + trx="stocklevel" + elseif trx_type <= 24 then + trx="purge" + end + +-- Execute transaction + _G[trx]() + +end + +function sysbench.hooks.before_restart_event(err) + con:query("ROLLBACK") +end + +function sysbench.hooks.report_intermediate(stat) +-- -- print("my stat: ", val) + if sysbench.opt.report_csv == "yes" then + sysbench.report_csv(stat) + else + sysbench.report_default(stat) + end +end + + +-- vim:ts=4 ss=4 sw=4 expandtab diff --git a/tpcc_common.lua b/tpcc_common.lua index 13660c4..1465dd2 100644 --- a/tpcc_common.lua +++ b/tpcc_common.lua @@ -52,7 +52,7 @@ sysbench.cmdline.options = { force_pk = {"Force using auto-inc PK on history table", 0}, trx_level = - {"Transaction isolation level (RC, RR or SER)", "RR"}, + {"Transaction isolation level (RC, RR or SER)", "RC"}, enable_purge = {"Use purge transaction (yes, no)", "no"}, report_csv = diff --git a/tpcc_common.lua.old b/tpcc_common.lua.old new file mode 100644 index 0000000..13660c4 --- /dev/null +++ b/tpcc_common.lua.old @@ -0,0 +1,645 @@ +-- Copyright (C) 2006-2017 Vadim Tkachenko, Percona + +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. + +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +-- ----------------------------------------------------------------------------- +-- Common code for TPCC benchmarks. +-- ----------------------------------------------------------------------------- + +ffi = require("ffi") + +ffi.cdef[[ +void sb_counter_inc(int, sb_counter_type); +typedef uint32_t useconds_t; +int usleep(useconds_t useconds); +]] + + +function init() + assert(event ~= nil, + "this script is meant to be included by other TPCC scripts and " .. + "should not be called directly.") +end + +if sysbench.cmdline.command == nil then + error("Command is required. Supported commands: prepare, run, cleanup, help") +end + +MAXITEMS=100000 +DIST_PER_WARE=10 +CUST_PER_DIST=3000 + +-- Command line options +sysbench.cmdline.options = { + scale = + {"Scale factor (warehouses)", 100}, + tables = + {"Number of tables", 1}, + use_fk = + {"Use foreign keys", 1}, + force_pk = + {"Force using auto-inc PK on history table", 0}, + trx_level = + {"Transaction isolation level (RC, RR or SER)", "RR"}, + enable_purge = + {"Use purge transaction (yes, no)", "no"}, + report_csv = + {"Report output in csv (yes, no)", "no"}, + mysql_storage_engine = + {"Storage engine, if MySQL is used", "innodb"}, + mysql_table_options = + {"Extra table options, if MySQL is used. e.g. 'COLLATE latin1_bin'", ""} +} + +function sleep(n) + os.execute("sleep " .. tonumber(n)) +end + +-- Create the tables and Prepare the dataset. This command supports parallel execution, i.e. will +-- benefit from executing with --threads > 1 as long as --scale > 1 +function cmd_prepare() + local drv = sysbench.sql.driver() + local con = drv:connect() + local show_query="SHOW TABLES" + + if drv:name() == "mysql" then + con:query("SET FOREIGN_KEY_CHECKS=0") + end + + -- create tables in parallel table per thread + for i = sysbench.tid % sysbench.opt.threads + 1, sysbench.opt.tables, + sysbench.opt.threads do + create_tables(drv, con, i) + end + + -- make sure all tables are created before we load data + + print("Waiting on tables 30 sec\n") + sleep(30) + + for i = sysbench.tid % sysbench.opt.threads + 1, sysbench.opt.scale, + sysbench.opt.threads do + load_tables(drv, con, i) + end + +end + +-- Check consistency +-- benefit from executing with --threads > 1 as long as --scale > 1 +function cmd_check() + local drv = sysbench.sql.driver() + local con = drv:connect() + + for i = sysbench.tid % sysbench.opt.threads + 1, sysbench.opt.scale, + sysbench.opt.threads do + check_tables(drv, con, i) + end + +end + +-- Implement parallel prepare and prewarm commands +sysbench.cmdline.commands = { + prepare = {cmd_prepare, sysbench.cmdline.PARALLEL_COMMAND}, + check = {cmd_check, sysbench.cmdline.PARALLEL_COMMAND} +} + + +function create_tables(drv, con, table_num) + local id_index_def, id_def + local engine_def = "" + local extra_table_options = "" + local query + local tinyint_type="smallint" + local datetime_type="timestamp" + + if drv:name() == "mysql" or drv:name() == "attachsql" or + drv:name() == "drizzle" + then + engine_def = "/*! ENGINE = " .. sysbench.opt.mysql_storage_engine .. " */" + extra_table_options = sysbench.opt.mysql_table_options or "" + tinyint_type="tinyint" + datetime_type="datetime" + end + + print(string.format("Creating tables: %d\n", table_num)) + + query = string.format([[ + CREATE TABLE IF NOT EXISTS warehouse%d ( + w_id smallint not null, + w_name varchar(10), + w_street_1 varchar(20), + w_street_2 varchar(20), + w_city varchar(20), + w_state char(2), + w_zip char(9), + w_tax decimal(4,2), + w_ytd decimal(12,2), + primary key (w_id) + ) %s %s]], + table_num, engine_def, extra_table_options) + + con:query(query) + + query = string.format([[ + create table IF NOT EXISTS district%d ( + d_id ]] .. tinyint_type .. [[ not null, + d_w_id smallint not null, + d_name varchar(10), + d_street_1 varchar(20), + d_street_2 varchar(20), + d_city varchar(20), + d_state char(2), + d_zip char(9), + d_tax decimal(4,2), + d_ytd decimal(12,2), + d_next_o_id int, + primary key (d_w_id, d_id) + ) %s %s]], + table_num, engine_def, extra_table_options) + + con:query(query) + +-- CUSTOMER TABLE + + query = string.format([[ + create table IF NOT EXISTS customer%d ( + c_id int not null, + c_d_id ]] .. tinyint_type .. [[ not null, + c_w_id smallint not null, + c_first varchar(16), + c_middle char(2), + c_last varchar(16), + c_street_1 varchar(20), + c_street_2 varchar(20), + c_city varchar(20), + c_state char(2), + c_zip char(9), + c_phone char(16), + c_since ]] .. datetime_type .. [[, + c_credit char(2), + c_credit_lim bigint, + c_discount decimal(4,2), + c_balance decimal(12,2), + c_ytd_payment decimal(12,2), + c_payment_cnt smallint, + c_delivery_cnt smallint, + c_data text, + PRIMARY KEY(c_w_id, c_d_id, c_id) + ) %s %s]], + table_num, engine_def, extra_table_options) + + con:query(query) + +-- HISTORY TABLE + local hist_auto_inc="" + local hist_pk="" + if sysbench.opt.force_pk == 1 then + hist_auto_inc="id int NOT NULL AUTO_INCREMENT," + hist_pk=",PRIMARY KEY(id)" + end + query = string.format([[ + create table IF NOT EXISTS history%d ( + %s + h_c_id int, + h_c_d_id ]] .. tinyint_type .. [[, + h_c_w_id smallint, + h_d_id ]] .. tinyint_type .. [[, + h_w_id smallint, + h_date ]] .. datetime_type .. [[, + h_amount decimal(6,2), + h_data varchar(24) %s + ) %s %s]], + table_num, hist_auto_inc, hist_pk, engine_def, extra_table_options) + + con:query(query) + + query = string.format([[ + create table IF NOT EXISTS orders%d ( + o_id int not null, + o_d_id ]] .. tinyint_type .. [[ not null, + o_w_id smallint not null, + o_c_id int, + o_entry_d ]] .. datetime_type .. [[, + o_carrier_id ]] .. tinyint_type .. [[, + o_ol_cnt ]] .. tinyint_type .. [[, + o_all_local ]] .. tinyint_type .. [[, + PRIMARY KEY(o_w_id, o_d_id, o_id) + ) %s %s]], + table_num, engine_def, extra_table_options) + + con:query(query) + +-- NEW_ORDER table + + query = string.format([[ + create table IF NOT EXISTS new_orders%d ( + no_o_id int not null, + no_d_id ]] .. tinyint_type .. [[ not null, + no_w_id smallint not null, + PRIMARY KEY(no_w_id, no_d_id, no_o_id) + ) %s %s]], + table_num, engine_def, extra_table_options) + + con:query(query) + + query = string.format([[ + create table IF NOT EXISTS order_line%d ( + ol_o_id int not null, + ol_d_id ]] .. tinyint_type .. [[ not null, + ol_w_id smallint not null, + ol_number ]] .. tinyint_type .. [[ not null, + ol_i_id int, + ol_supply_w_id smallint, + ol_delivery_d ]] .. datetime_type .. [[, + ol_quantity ]] .. tinyint_type .. [[, + ol_amount decimal(6,2), + ol_dist_info char(24), + PRIMARY KEY(ol_w_id, ol_d_id, ol_o_id, ol_number) + ) %s %s]], + table_num, engine_def, extra_table_options) + + con:query(query) + +-- STOCK table + + query = string.format([[ + create table IF NOT EXISTS stock%d ( + s_i_id int not null, + s_w_id smallint not null, + s_quantity smallint, + s_dist_01 char(24), + s_dist_02 char(24), + s_dist_03 char(24), + s_dist_04 char(24), + s_dist_05 char(24), + s_dist_06 char(24), + s_dist_07 char(24), + s_dist_08 char(24), + s_dist_09 char(24), + s_dist_10 char(24), + s_ytd decimal(8,0), + s_order_cnt smallint, + s_remote_cnt smallint, + s_data varchar(50), + PRIMARY KEY(s_w_id, s_i_id) + ) %s %s]], + table_num, engine_def, extra_table_options) + + con:query(query) + + local i = table_num + + query = string.format([[ + create table IF NOT EXISTS item%d ( + i_id int not null, + i_im_id int, + i_name varchar(24), + i_price decimal(5,2), + i_data varchar(50), + PRIMARY KEY(i_id) + ) %s %s]], + i, engine_def, extra_table_options) + + con:query(query) + + con:bulk_insert_init("INSERT INTO item" .. i .." (i_id, i_im_id, i_name, i_price, i_data) values") + for j = 1 , MAXITEMS do + local i_im_id = sysbench.rand.uniform(1,10000) + local i_price = sysbench.rand.uniform_double()*100+1 + -- i_name is not generated as prescribed by standard, but we want to provide a better compression + local i_name = string.format("item-%d-%f-%s", i_im_id, i_price, sysbench.rand.string("@@@@@")) + local i_data = string.format("data-%s-%s", i_name, sysbench.rand.string("@@@@@")) + + query = string.format([[(%d,%d,'%s',%f,'%s')]], + j, i_im_id, i_name:sub(1,24), i_price, i_data:sub(1,50)) + con:bulk_insert_next(query) + + end + con:bulk_insert_done() + + print(string.format("Adding indexes %d ... \n", i)) + con:query("CREATE INDEX idx_customer"..i.." ON customer"..i.." (c_w_id,c_d_id,c_last,c_first)") + con:query("CREATE INDEX idx_orders"..i.." ON orders"..i.." (o_w_id,o_d_id,o_c_id,o_id)") + con:query("CREATE INDEX fkey_stock_2"..i.." ON stock"..i.." (s_i_id)") + con:query("CREATE INDEX fkey_order_line_2"..i.." ON order_line"..i.." (ol_supply_w_id,ol_i_id)") + con:query("CREATE INDEX fkey_history_1"..i.." ON history"..i.." (h_c_w_id,h_c_d_id,h_c_id)") + con:query("CREATE INDEX fkey_history_2"..i.." ON history"..i.." (h_w_id,h_d_id )") + if sysbench.opt.use_fk == 1 then + print(string.format("Adding FK %d ... \n", i)) + con:query("ALTER TABLE new_orders"..i.." ADD CONSTRAINT fkey_new_orders_1_"..table_num.." FOREIGN KEY(no_w_id,no_d_id,no_o_id) REFERENCES orders"..i.."(o_w_id,o_d_id,o_id)") + con:query("ALTER TABLE orders"..i.." ADD CONSTRAINT fkey_orders_1_"..table_num.." FOREIGN KEY(o_w_id,o_d_id,o_c_id) REFERENCES customer"..i.."(c_w_id,c_d_id,c_id)") + con:query("ALTER TABLE customer"..i.." ADD CONSTRAINT fkey_customer_1_"..table_num.." FOREIGN KEY(c_w_id,c_d_id) REFERENCES district"..i.."(d_w_id,d_id)") + con:query("ALTER TABLE history"..i.." ADD CONSTRAINT fkey_history_1_"..table_num.." FOREIGN KEY(h_c_w_id,h_c_d_id,h_c_id) REFERENCES customer"..i.."(c_w_id,c_d_id,c_id)") + con:query("ALTER TABLE history"..i.." ADD CONSTRAINT fkey_history_2_"..table_num.." FOREIGN KEY(h_w_id,h_d_id) REFERENCES district"..i.."(d_w_id,d_id)") + con:query("ALTER TABLE district"..i.." ADD CONSTRAINT fkey_district_1_"..table_num.." FOREIGN KEY(d_w_id) REFERENCES warehouse"..i.."(w_id)") + con:query("ALTER TABLE order_line"..i.." ADD CONSTRAINT fkey_order_line_1_"..table_num.." FOREIGN KEY(ol_w_id,ol_d_id,ol_o_id) REFERENCES orders"..i.."(o_w_id,o_d_id,o_id)") + con:query("ALTER TABLE order_line"..i.." ADD CONSTRAINT fkey_order_line_2_"..table_num.." FOREIGN KEY(ol_supply_w_id,ol_i_id) REFERENCES stock"..i.."(s_w_id,s_i_id)") + con:query("ALTER TABLE stock"..i.." ADD CONSTRAINT fkey_stock_1_"..table_num.." FOREIGN KEY(s_w_id) REFERENCES warehouse"..i.."(w_id)") + con:query("ALTER TABLE stock"..i.." ADD CONSTRAINT fkey_stock_2_"..table_num.." FOREIGN KEY(s_i_id) REFERENCES item"..i.."(i_id)") + end + +end + + +function set_isolation_level(drv,con) + if drv:name() == "mysql" + then + if sysbench.opt.trx_level == "RR" then + isolation_level="REPEATABLE-READ" + elseif sysbench.opt.trx_level == "RC" then + isolation_level="READ-COMMITTED" + elseif sysbench.opt.trx_level == "SER" then + isolation_level="SERIALIZABLE" + end + + isolation_variable=con:query_row("SHOW VARIABLES LIKE 't%_isolation'") + + con:query("SET SESSION " .. isolation_variable .. "='".. isolation_level .."'") + end + + if drv:name() == "pgsql" + then + if sysbench.opt.trx_level == "RR" then + isolation_level="REPEATABLE READ" + elseif sysbench.opt.trx_level == "RC" then + isolation_level="READ COMMITTED" + elseif sysbench.opt.trx_level == "SER" then + isolation_level="SERIALIZABLE" + end + + con:query("SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL " .. isolation_level ) + end + +end + + + +function load_tables(drv, con, warehouse_num) + local id_index_def, id_def + local engine_def = "" + local extra_table_options = "" + local query + + set_isolation_level(drv,con) + + -- print(string.format("Creating warehouse: %d\n", warehouse_num)) + + for table_num = 1, sysbench.opt.tables do + + print(string.format("loading tables: %d for warehouse: %d\n", table_num, warehouse_num)) + + con:bulk_insert_init("INSERT INTO warehouse" .. table_num .. + " (w_id, w_name, w_street_1, w_street_2, w_city, w_state, w_zip, w_tax, w_ytd) values") + + query = string.format([[(%d, '%s','%s','%s', '%s', '%s', '%s', %f,300000)]], + warehouse_num, sysbench.rand.string("name-@@@@@"), sysbench.rand.string("street1-@@@@@@@@@@"), + sysbench.rand.string("street2-@@@@@@@@@@"), sysbench.rand.string("city-@@@@@@@@@@"), + sysbench.rand.string("@@"),sysbench.rand.string("zip-#####"),sysbench.rand.uniform_double()*0.2 ) + con:bulk_insert_next(query) + + con:bulk_insert_done() + + con:bulk_insert_init("INSERT INTO district" .. table_num .. + " (d_id, d_w_id, d_name, d_street_1, d_street_2, d_city, d_state, d_zip, d_tax, d_ytd, d_next_o_id) values") + + for d_id = 1 , DIST_PER_WARE do + + query = string.format([[(%d, %d, '%s','%s','%s', '%s', '%s', '%s', %f,30000,3001)]], + d_id, warehouse_num, sysbench.rand.string("name-@@@@@"), sysbench.rand.string("street1-@@@@@@@@@@"), + sysbench.rand.string("street2-@@@@@@@@@@"), sysbench.rand.string("city-@@@@@@@@@@"), + sysbench.rand.string("@@"),sysbench.rand.string("zip-#####"),sysbench.rand.uniform_double()*0.2 ) + con:bulk_insert_next(query) + + end + con:bulk_insert_done() + +-- CUSTOMER TABLE + + con:bulk_insert_init("INSERT INTO customer" .. table_num .. [[ + (c_id, c_d_id, c_w_id, c_first, c_middle, c_last, c_street_1, c_street_2, c_city, c_state, c_zip, + c_phone, c_since, c_credit, c_credit_lim, c_discount, c_balance, c_ytd_payment, c_payment_cnt, c_delivery_cnt, + c_data) values]]) + + for d_id = 1 , DIST_PER_WARE do + for c_id = 1 , CUST_PER_DIST do + local c_last + + if c_id <= 1000 then + c_last = Lastname(c_id - 1) + else + c_last = Lastname(NURand(255, 0, 999)) + end + + query = string.format([[(%d, %d, %d, '%s','OE','%s','%s', '%s', '%s', '%s', '%s','%s',NOW(),'%s',50000,%f,-10,10,1,0,'%s' )]], + c_id, d_id, warehouse_num, + sysbench.rand.string("first-"..string.rep("@",sysbench.rand.uniform(2,10))), + c_last, + sysbench.rand.string("street1-@@@@@@@@@@"), + sysbench.rand.string("street2-@@@@@@@@@@"), sysbench.rand.string("city-@@@@@@@@@@"), + sysbench.rand.string("@@"),sysbench.rand.string("zip-#####"), + sysbench.rand.string(string.rep("#",16)), + (sysbench.rand.uniform(1,100) > 10) and "GC" or "BC", + sysbench.rand.uniform_double()*0.5, + string.rep(sysbench.rand.string("@"),sysbench.rand.uniform(300,500)) + + ) + con:bulk_insert_next(query) + + end + end + + con:bulk_insert_done() + +-- HISTORY TABLE + + con:bulk_insert_init("INSERT INTO history" .. table_num .. [[ + (h_c_id, h_c_d_id, h_c_w_id, h_d_id, h_w_id, h_date, h_amount, h_data) values]]) + + for d_id = 1 , DIST_PER_WARE do + for c_id = 1 , CUST_PER_DIST do + + query = string.format([[(%d, %d, %d, %d, %d, NOW(), 10, '%s' )]], + c_id, d_id, warehouse_num, d_id, warehouse_num, + string.rep(sysbench.rand.string("@"),sysbench.rand.uniform(12,24)) + ) + con:bulk_insert_next(query) + + end + end + + con:bulk_insert_done() + + local tab = {} + local a_counts = {} + + for i = 1, 3000 do + tab[i] = i + end + + for i = 1, 3000 do + local j = math.random(i, 3000) + tab[i], tab[j] = tab[j], tab[i] + end + + con:bulk_insert_init("INSERT INTO orders" .. table_num .. [[ + (o_id, o_d_id, o_w_id, o_c_id, o_entry_d, o_carrier_id, o_ol_cnt, o_all_local) values]]) + + a_counts[warehouse_num] = {} + + for d_id = 1 , DIST_PER_WARE do + a_counts[warehouse_num][d_id] = {} + for o_id = 1 , 3000 do +-- 3,000 rows in the ORDER table with + a_counts[warehouse_num][d_id][o_id] = sysbench.rand.uniform(5,15) + + query = string.format([[(%d, %d, %d, %d, NOW(), %s, %d, 1 )]], + o_id, d_id, warehouse_num, tab[o_id], + o_id < 2101 and sysbench.rand.uniform(1,10) or "NULL", + a_counts[warehouse_num][d_id][o_id] + ) + con:bulk_insert_next(query) + + end + end + + con:bulk_insert_done() + +-- STOCK table + + con:bulk_insert_init("INSERT INTO stock" .. table_num .. + " (s_i_id, s_w_id, s_quantity, 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, s_ytd, s_order_cnt, s_remote_cnt, s_data) values") + + for s_id = 1 , 100000 do + + query = string.format([[(%d, %d, %d,'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s',0,0,0,'%s')]], + s_id, warehouse_num, sysbench.rand.uniform(10,100), + string.rep(sysbench.rand.string("@"),24), + string.rep(sysbench.rand.string("@"),24), + string.rep(sysbench.rand.string("@"),24), + string.rep(sysbench.rand.string("@"),24), + string.rep(sysbench.rand.string("@"),24), + string.rep(sysbench.rand.string("@"),24), + string.rep(sysbench.rand.string("@"),24), + string.rep(sysbench.rand.string("@"),24), + string.rep(sysbench.rand.string("@"),24), + string.rep(sysbench.rand.string("@"),24), + string.rep(sysbench.rand.string("@"),sysbench.rand.uniform(26,50))) + con:bulk_insert_next(query) + + end + con:bulk_insert_done() + + con:query(string.format("INSERT INTO new_orders%d (no_o_id, no_d_id, no_w_id) SELECT o_id, o_d_id, o_w_id FROM orders%d WHERE o_id>2100 and o_w_id=%d", table_num, table_num, warehouse_num)) + + con:bulk_insert_init("INSERT INTO order_line" .. table_num .. [[ + (ol_o_id, ol_d_id, ol_w_id, ol_number, ol_i_id, ol_supply_w_id, ol_delivery_d, + ol_quantity, ol_amount, ol_dist_info ) values]]) + + for d_id = 1 , DIST_PER_WARE do + for o_id = 1 , 3000 do + for ol_id = 1, a_counts[warehouse_num][d_id][o_id] do + + query = string.format([[(%d, %d, %d, %d, %d, %d, %s, 5, %f, '%s' )]], + o_id, d_id, warehouse_num, ol_id, sysbench.rand.uniform(1, MAXITEMS), warehouse_num, + o_id < 2101 and "NOW()" or "NULL", + o_id < 2101 and 0 or sysbench.rand.uniform_double()*9999.99, + string.rep(sysbench.rand.string("@"),24) + ) + res=con:bulk_insert_next(query) + + end + end + end + + con:bulk_insert_done() + + end + +end + +function thread_init() + drv = sysbench.sql.driver() + con = drv:connect() + con:query("SET AUTOCOMMIT=0") + +end + +function thread_done() + con:disconnect() +end + +function cleanup() + local drv = sysbench.sql.driver() + local con = drv:connect() + + if drv:name() == "mysql" then + con:query("SET FOREIGN_KEY_CHECKS=0") + end + + for i = 1, sysbench.opt.tables do + print(string.format("Dropping tables '%d'...", i)) + con:query("DROP TABLE IF EXISTS history" .. i ) + con:query("DROP TABLE IF EXISTS new_orders" .. i ) + con:query("DROP TABLE IF EXISTS order_line" .. i ) + con:query("DROP TABLE IF EXISTS orders" .. i ) + con:query("DROP TABLE IF EXISTS customer" .. i ) + con:query("DROP TABLE IF EXISTS district" .. i ) + con:query("DROP TABLE IF EXISTS stock" .. i ) + con:query("DROP TABLE IF EXISTS item" .. i ) + con:query("DROP TABLE IF EXISTS warehouse" .. i ) + end +end + +function Lastname(num) + local n = {"BAR", "OUGHT", "ABLE", "PRI", "PRES", "ESE", "ANTI", "CALLY", "ATION", "EING"} + + name =n[math.floor(num / 100) + 1] .. n[ math.floor(num / 10)%10 + 1] .. n[num%10 + 1] + + return name +end + +local init_rand=1 +local C_255 +local C_1023 +local C_8191 + +function NURand (A, x, y) + local C + + if init_rand + then + C_255 = sysbench.rand.uniform(0, 255) + C_1023 = sysbench.rand.uniform(0, 1023) + C_8191 = sysbench.rand.uniform(0, 8191) + init_rand = 0 + end + + if A==255 + then + C = C_255 + elseif A==1023 + then + C = C_1023 + elseif A==8191 + then + C = C_8191 + end + + -- return ((( sysbench.rand.uniform(0, A) | sysbench.rand.uniform(x, y)) + C) % (y-x+1)) + x; + return ((( bit.bor(sysbench.rand.uniform(0, A), sysbench.rand.uniform(x, y))) + C) % (y-x+1)) + x; +end + +-- vim:ts=4 ss=4 sw=4 expandtab diff --git a/tpcc_run.lua b/tpcc_run.lua old mode 100755 new mode 100644 index f44b4bb..2d066e4 --- a/tpcc_run.lua +++ b/tpcc_run.lua @@ -55,11 +55,11 @@ function new_order() do itemid[i] = NURand(8191, 1, MAXITEMS) if ((i == ol_cnt - 1) and (rbk == 1)) - then + then itemid[i] = -1 end if sysbench.rand.uniform(1, 100) ~= 1 - then + then supware[i] = w_id else supware[i] = other_ware(w_id) @@ -84,13 +84,14 @@ function new_order() local c_credit local w_tax - c_discount, c_last, c_credit, w_tax = con:query_row(([[SELECT c_discount, c_last, c_credit, w_tax - FROM customer%d, warehouse%d - WHERE w_id = %d - AND c_w_id = w_id - AND c_d_id = %d - AND c_id = %d]]): - format(table_num, table_num, w_id, d_id, c_id)) + c_discount, c_last, c_credit, w_tax = con:query_row(([[execute p_new_order1_%d(%d,%d,%d)]]):format(table_num, w_id, d_id, c_id)) +-- c_discount, c_last, c_credit, w_tax = con:query_row(([[SELECT c_discount, c_last, c_credit, w_tax +-- FROM customer%d, warehouse%d +-- WHERE w_id = %d +-- AND c_w_id = w_id +-- AND c_d_id = %d +-- AND c_id = %d]]): +-- format(table_num, table_num, w_id, d_id, c_id)) -- SELECT d_next_o_id, d_tax INTO :d_next_o_id, :d_tax -- FROM district @@ -100,19 +101,21 @@ function new_order() local d_next_o_id local d_tax - d_next_o_id, d_tax = con:query_row(([[SELECT d_next_o_id, d_tax - FROM district%d - WHERE d_w_id = %d - AND d_id = %d FOR UPDATE]]): - format(table_num, w_id, d_id)) + d_next_o_id, d_tax = con:query_row(([[execute p_new_order2_%d(%d,%d)]]):format(table_num, w_id, d_id)) +-- d_next_o_id, d_tax = con:query_row(([[SELECT d_next_o_id, d_tax +-- FROM district%d +-- WHERE d_w_id = %d +-- AND d_id = %d FOR UPDATE]]): +-- format(table_num, w_id, d_id)) -- UPDATE district SET d_next_o_id = :d_next_o_id + 1 -- WHERE d_id = :d_id -- AND d_w_id = :w_id; - con:query(([[UPDATE district%d - SET d_next_o_id = %d - WHERE d_id = %d AND d_w_id= %d]]):format(table_num, d_next_o_id + 1, d_id, w_id)) + con:query(([[execute p_new_order3_%d(%d,%d,%d)]]):format(table_num, d_next_o_id + 1, d_id, w_id)) +-- con:query(([[UPDATE district%d +-- SET d_next_o_id = %d +-- WHERE d_id = %d AND d_w_id= %d]]):format(table_num, d_next_o_id + 1, d_id, w_id)) --INSERT INTO orders (o_id, o_d_id, o_w_id, o_c_id, -- o_entry_d, o_ol_cnt, o_all_local) @@ -120,102 +123,107 @@ function new_order() -- :datetime, -- :o_ol_cnt, :o_all_local); - con:query(([[INSERT INTO orders%d - (o_id, o_d_id, o_w_id, o_c_id, o_entry_d, o_ol_cnt, o_all_local) - VALUES (%d,%d,%d,%d,NOW(),%d,%d)]]): - format(table_num, d_next_o_id, d_id, w_id, c_id, ol_cnt, all_local)) + con:query(([[execute p_new_order4_%d(%d,%d,%d,%d,%d,%d)]]):format(table_num, d_next_o_id, d_id, w_id, c_id, ol_cnt, all_local)) +-- con:query(([[INSERT INTO orders%d +-- (o_id, o_d_id, o_w_id, o_c_id, o_entry_d, o_ol_cnt, o_all_local) +-- VALUES (%d,%d,%d,%d,NOW(),%d,%d)]]): +-- format(table_num, d_next_o_id, d_id, w_id, c_id, ol_cnt, all_local)) -- INSERT INTO new_orders (no_o_id, no_d_id, no_w_id) -- VALUES (:o_id,:d_id,:w_id); */ - con:query(([[INSERT INTO new_orders%d (no_o_id, no_d_id, no_w_id) - VALUES (%d,%d,%d)]]): - format(table_num, d_next_o_id, d_id, w_id)) + con:query(([[execute p_new_order5_%d(%d,%d,%d)]]):format(table_num, d_next_o_id, d_id, w_id)) +-- con:query(([[INSERT INTO new_orders%d (no_o_id, no_d_id, no_w_id) +-- VALUES (%d,%d,%d)]]): +-- format(table_num, d_next_o_id, d_id, w_id)) for ol_number=1, ol_cnt do - local ol_supply_w_id = supware[ol_number] - local ol_i_id = itemid[ol_number] - local ol_quantity = qty[ol_number] + local ol_supply_w_id = supware[ol_number] + local ol_i_id = itemid[ol_number] + local ol_quantity = qty[ol_number] -- SELECT i_price, i_name, i_data --- INTO :i_price, :i_name, :i_data --- FROM item --- WHERE i_id = :ol_i_id;*/ +-- INTO :i_price, :i_name, :i_data +-- FROM item +-- WHERE i_id = :ol_i_id;*/ - rs = con:query(([[SELECT i_price, i_name, i_data - FROM item%d - WHERE i_id = %d]]): - format(table_num, ol_i_id)) + rs = con:query(([[execute p_new_order6_%d(%d)]]):format(table_num, ol_i_id)) +-- rs = con:query(([[SELECT i_price, i_name, i_data +-- FROM item%d +-- WHERE i_id = %d]]): +-- format(table_num, ol_i_id)) - local i_price - local i_name - local i_data + local i_price + local i_name + local i_data - if rs.nrows == 0 then + if rs.nrows == 0 then -- print("ROLLBACK") ffi.C.sb_counter_inc(sysbench.tid, ffi.C.SB_CNT_ERROR) con:query("ROLLBACK") - return + return end i_price, i_name, i_data = unpack(rs:fetch_row(), 1, rs.nfields) -- SELECT s_quantity, 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 --- INTO :s_quantity, :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 --- FROM stock --- WHERE s_i_id = :ol_i_id --- AND s_w_id = :ol_supply_w_id --- FOR UPDATE;*/ +-- s_dist_03, s_dist_04, s_dist_05, s_dist_06, +-- s_dist_07, s_dist_08, s_dist_09, s_dist_10 +-- INTO :s_quantity, :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 +-- FROM stock +-- WHERE s_i_id = :ol_i_id +-- AND s_w_id = :ol_supply_w_id +-- FOR UPDATE;*/ local s_quantity local s_data local ol_dist_info - s_quantity, s_data, ol_dist_info = con:query_row(([[SELECT s_quantity, s_data, s_dist_%s s_dist - FROM stock%d - WHERE s_i_id = %d AND s_w_id= %d FOR UPDATE]]): - format(string.format("%02d",d_id),table_num,ol_i_id,ol_supply_w_id )) + s_quantity, s_data, ol_dist_info = con:query_row(([[execute p_new_order7_%d_%s(%d,%d)]]):format(table_num, string.format("%02d",d_id), ol_i_id, ol_supply_w_id)) +-- s_quantity, s_data, ol_dist_info = con:query_row(([[SELECT s_quantity, s_data, s_dist_%s s_dist +-- FROM stock%d +-- WHERE s_i_id = %d AND s_w_id= %d FOR UPDATE]]): +-- format(string.format("%02d",d_id),table_num,ol_i_id,ol_supply_w_id )) s_quantity=tonumber(s_quantity) - if (s_quantity > ol_quantity) then - s_quantity = s_quantity - ol_quantity - else - s_quantity = s_quantity - ol_quantity + 91 - end + if (s_quantity > ol_quantity) then + s_quantity = s_quantity - ol_quantity + else + s_quantity = s_quantity - ol_quantity + 91 + end -- UPDATE stock SET s_quantity = :s_quantity --- WHERE s_i_id = :ol_i_id --- AND s_w_id = :ol_supply_w_id;*/ - - con:query(([[UPDATE stock%d - SET s_quantity = %d - WHERE s_i_id = %d - AND s_w_id= %d]]): - format(table_num, s_quantity, ol_i_id, ol_supply_w_id)) +-- WHERE s_i_id = :ol_i_id +-- AND s_w_id = :ol_supply_w_id;*/ + + con:query(([[execute p_new_order8_%d(%d,%d,%d)]]):format(table_num, s_quantity, ol_i_id, ol_supply_w_id)) +-- con:query(([[UPDATE stock%d +-- SET s_quantity = %d +-- WHERE s_i_id = %d +-- AND s_w_id= %d]]): +-- format(table_num, s_quantity, ol_i_id, ol_supply_w_id)) i_price=tonumber(i_price) w_tax=tonumber(w_tax) d_tax=tonumber(d_tax) c_discount=tonumber(c_discount) - ol_amount = ol_quantity * i_price * (1 + w_tax + d_tax) * (1 - c_discount); + ol_amount = ol_quantity * i_price * (1 + w_tax + d_tax) * (1 - c_discount); -- 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) --- VALUES (:o_id, :d_id, :w_id, :ol_number, :ol_i_id, --- :ol_supply_w_id, :ol_quantity, :ol_amount, --- :ol_dist_info); - - con:query(([[INSERT INTO order_line%d - (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) - VALUES (%d,%d,%d,%d,%d,%d,%d,%d,'%s')]]): - format(table_num, d_next_o_id, d_id, w_id, ol_number, ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_dist_info)) +-- ol_number, ol_i_id, +-- ol_supply_w_id, ol_quantity, +-- ol_amount, ol_dist_info) +-- VALUES (:o_id, :d_id, :w_id, :ol_number, :ol_i_id, +-- :ol_supply_w_id, :ol_quantity, :ol_amount, +-- :ol_dist_info); + con:query(([[execute p_new_order9_%d(%d,%d,%d,%d,%d,%d,%d,%d,'%s')]]):format(table_num, d_next_o_id, d_id, w_id, ol_number, ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_dist_info)) +-- con:query(([[INSERT INTO order_line%d +-- (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) +-- VALUES (%d,%d,%d,%d,%d,%d,%d,%d,'%s')]]): +-- format(table_num, d_next_o_id, d_id, w_id, ol_number, ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_dist_info)) end @@ -255,155 +263,176 @@ function payment() con:query("BEGIN") - con:query(([[UPDATE warehouse%d - SET w_ytd = w_ytd + %d - WHERE w_id = %d]]):format(table_num, h_amount, w_id )) + con:query(([[execute p_payment1_%d(%d,%d)]]):format(table_num, h_amount, w_id)) +-- con:query(([[UPDATE warehouse%d +-- SET w_ytd = w_ytd + %d +-- WHERE w_id = %d]]):format(table_num, h_amount, w_id )) -- SELECT w_street_1, w_street_2, w_city, w_state, w_zip, --- w_name --- INTO :w_street_1, :w_street_2, :w_city, :w_state, --- :w_zip, :w_name --- FROM warehouse --- WHERE w_id = :w_id;*/ +-- w_name +-- INTO :w_street_1, :w_street_2, :w_city, :w_state, +-- :w_zip, :w_name +-- FROM warehouse +-- WHERE w_id = :w_id;*/ local w_street_1, w_street_2, w_city, w_state, w_zip, w_name - w_street_1, w_street_2, w_city, w_state, w_zip, w_name = - con:query_row(([[SELECT w_street_1, w_street_2, w_city, w_state, w_zip, w_name - FROM warehouse%d - WHERE w_id = %d]]):format(table_num, w_id)) + w_street_1, w_street_2, w_city, w_state, w_zip, w_name = con:query_row(([[execute p_payment2_%d(%d)]]):format(table_num, w_id)) +-- w_street_1, w_street_2, w_city, w_state, w_zip, w_name = +-- con:query_row(([[SELECT w_street_1, w_street_2, w_city, w_state, w_zip, w_name +-- FROM warehouse%d +-- WHERE w_id = %d]]):format(table_num, w_id)) -- UPDATE district SET d_ytd = d_ytd + :h_amount --- WHERE d_w_id = :w_id --- AND d_id = :d_id;*/ +-- WHERE d_w_id = :w_id +-- AND d_id = :d_id;*/ - con:query(([[UPDATE district%d - SET d_ytd = d_ytd + %d - WHERE d_w_id = %d - AND d_id= %d]]):format(table_num, h_amount, w_id, d_id)) + con:query(([[execute p_payment3_%d(%d,%d,%d)]]):format(table_num, h_amount, w_id, d_id)) +-- con:query(([[UPDATE district%d +-- SET d_ytd = d_ytd + %d +-- WHERE d_w_id = %d +-- AND d_id= %d]]):format(table_num, h_amount, w_id, d_id)) local d_street_1,d_street_2, d_city, d_state, d_zip, d_name - d_street_1,d_street_2, d_city, d_state, d_zip, d_name = - con:query_row(([[SELECT d_street_1, d_street_2, d_city, d_state, d_zip, d_name - FROM district%d - WHERE d_w_id = %d - AND d_id = %d]]):format(table_num, w_id, d_id )) + d_street_1,d_street_2, d_city, d_state, d_zip, d_name = con:query_row(([[execute p_payment4_%d(%d,%d)]]):format(table_num, w_id, d_id)) +-- d_street_1,d_street_2, d_city, d_state, d_zip, d_name = +-- con:query_row(([[SELECT d_street_1, d_street_2, d_city, d_state, d_zip, d_name +-- FROM district%d +-- WHERE d_w_id = %d +-- AND d_id = %d]]):format(table_num, w_id, d_id )) if byname == 1 then -- SELECT count(c_id) --- FROM customer --- WHERE c_w_id = :c_w_id --- AND c_d_id = :c_d_id --- AND c_last = :c_last;*/ +-- FROM customer +-- WHERE c_w_id = :c_w_id +-- AND c_d_id = :c_d_id +-- AND c_last = :c_last;*/ - local namecnt = con:query_row(([[SELECT count(c_id) namecnt - FROM customer%d - WHERE c_w_id = %d - AND c_d_id= %d - AND c_last='%s']]):format(table_num, w_id, c_d_id, c_last )) --- SELECT c_id --- FROM customer --- WHERE c_w_id = :c_w_id --- AND c_d_id = :c_d_id --- AND c_last = :c_last --- ORDER BY c_first; - - if namecnt % 2 == 0 then - namecnt = namecnt + 1 - end - - rs = con:query(([[SELECT c_id - FROM customer%d - WHERE c_w_id = %d AND c_d_id= %d - AND c_last='%s' ORDER BY c_first]] - ):format(table_num, w_id, c_d_id, c_last )) - - for i = 1, (namecnt / 2 ) + 1 do - row = rs:fetch_row() - c_id = row[1] - end - end -- byname + local namecnt = con:query_row(([[execute p_payment5_%d(%d,%d,'%s')]]):format(table_num, w_id, c_d_id, c_last)) +-- local namecnt = con:query_row(([[SELECT count(c_id) namecnt +-- FROM customer%d +-- WHERE c_w_id = %d +-- AND c_d_id= %d +-- AND c_last='%s']]):format(table_num, w_id, c_d_id, c_last )) + + +-- SELECT c_id +-- FROM customer +-- WHERE c_w_id = :c_w_id +-- AND c_d_id = :c_d_id +-- AND c_last = :c_last +-- ORDER BY c_first; + + if namecnt % 2 == 0 then + namecnt = namecnt + 1 + end + + rs = con:query(([[execute p_payment6_%d(%d,%d,'%s')]]):format(table_num, w_id, c_d_id, c_last)) +-- rs = con:query(([[SELECT c_id +-- FROM customer%d +-- WHERE c_w_id = %d AND c_d_id= %d +-- AND c_last='%s' ORDER BY c_first]] +-- ):format(table_num, w_id, c_d_id, c_last )) + + for i = 1, (namecnt / 2 ) + 1 do + row = rs:fetch_row() + c_id = row[1] + end + end -- byname -- SELECT c_first, c_middle, c_last, c_street_1, --- c_street_2, c_city, c_state, c_zip, c_phone, --- c_credit, c_credit_lim, c_discount, c_balance, --- c_since --- FROM customer --- WHERE c_w_id = :c_w_id --- AND c_d_id = :c_d_id --- AND c_id = :c_id --- FOR UPDATE; +-- c_street_2, c_city, c_state, c_zip, c_phone, +-- c_credit, c_credit_lim, c_discount, c_balance, +-- c_since +-- FROM customer +-- WHERE c_w_id = :c_w_id +-- AND c_d_id = :c_d_id +-- AND c_id = :c_id +-- FOR UPDATE; local c_first, c_middle, c_last, c_street_1, c_street_2, c_city, c_state, c_zip, c_phone, c_credit, c_credit_lim, c_discount, c_balance, c_ytd_payment, c_since c_first, c_middle, c_last, c_street_1, c_street_2, c_city, c_state, c_zip, c_phone, c_credit, c_credit_lim, c_discount, c_balance, c_ytd_payment, c_since = - con:query_row(([[SELECT c_first, c_middle, c_last, c_street_1, - c_street_2, c_city, c_state, c_zip, c_phone, - c_credit, c_credit_lim, c_discount, c_balance, c_ytd_payment, c_since - FROM customer%d - WHERE c_w_id = %d - AND c_d_id= %d - AND c_id=%d FOR UPDATE]]) - :format(table_num, w_id, c_d_id, c_id )) + con:query_row(([[execute p_payment7_%d(%d,%d,%d)]]):format(table_num, w_id, c_d_id, c_id)) + +-- c_first, c_middle, c_last, c_street_1, c_street_2, c_city, c_state, c_zip, +-- c_phone, c_credit, c_credit_lim, c_discount, c_balance, c_ytd_payment, c_since = +-- con:query_row(([[SELECT c_first, c_middle, c_last, c_street_1, +-- c_street_2, c_city, c_state, c_zip, c_phone, +-- c_credit, c_credit_lim, c_discount, c_balance, c_ytd_payment, c_since +-- FROM customer%d +-- WHERE c_w_id = %d +-- AND c_d_id= %d +-- AND c_id=%d FOR UPDATE]]) +-- :format(table_num, w_id, c_d_id, c_id )) + c_balance = tonumber(c_balance) - h_amount c_ytd_payment = tonumber(c_ytd_payment) + h_amount if c_credit == "BC" then -- SELECT c_data --- INTO :c_data --- FROM customer --- WHERE c_w_id = :c_w_id --- AND c_d_id = :c_d_id --- AND c_id = :c_id; */ +-- INTO :c_data +-- FROM customer +-- WHERE c_w_id = :c_w_id +-- AND c_d_id = :c_d_id +-- AND c_id = :c_id; */ local c_data - c_data = con:query_row(([[SELECT c_data - FROM customer%d - WHERE c_w_id = %d - AND c_d_id=%d - AND c_id= %d]]): - format(table_num, w_id, c_d_id, c_id )) + + c_data = con:query_row(([[execute p_payment8_%d(%d,%d,%d)]]):format(table_num, w_id, c_d_id, c_id)) +-- c_data = con:query_row(([[SELECT c_data +-- FROM customer%d +-- WHERE c_w_id = %d +-- AND c_d_id=%d +-- AND c_id= %d]]): +-- format(table_num, w_id, c_d_id, c_id )) local c_new_data=string.sub(string.format("| %4d %2d %4d %2d %4d $%7.2f %12s %24s", c_id, c_d_id, c_w_id, d_id, w_id, h_amount, os.time(), c_data), 1, 500); - -- UPDATE customer - -- SET c_balance = :c_balance, c_data = :c_new_data - -- WHERE c_w_id = :c_w_id - -- AND c_d_id = :c_d_id - -- AND c_id = :c_id - con:query(([[UPDATE customer%d - SET c_balance=%f, c_ytd_payment=%f, c_data='%s' - WHERE c_w_id = %d - AND c_d_id=%d - AND c_id=%d]]) - :format(table_num, c_balance, c_ytd_payment, c_new_data, w_id, c_d_id, c_id )) + -- UPDATE customer + -- SET c_balance = :c_balance, c_data = :c_new_data + -- WHERE c_w_id = :c_w_id + -- AND c_d_id = :c_d_id + -- AND c_id = :c_id + + + con:query(([[execute p_payment9_%d(%f,%f,'%s',%d,%d,%d)]]):format(table_num, c_balance, c_ytd_payment, c_new_data, w_id, c_d_id, c_id)) +-- con:query(([[UPDATE customer%d +-- SET c_balance=%f, c_ytd_payment=%f, c_data='%s' +-- WHERE c_w_id = %d +-- AND c_d_id=%d +-- AND c_id=%d]]) +-- :format(table_num, c_balance, c_ytd_payment, c_new_data, w_id, c_d_id, c_id )) else - con:query(([[UPDATE customer%d - SET c_balance=%f, c_ytd_payment=%f - WHERE c_w_id = %d - AND c_d_id=%d - AND c_id=%d]]) - :format(table_num, c_balance, c_ytd_payment, w_id, c_d_id, c_id )) + + con:query(([[execute p_payment10_%d(%f,%f,%d,%d,%d)]]):format(table_num, c_balance, c_ytd_payment, w_id, c_d_id, c_id)) +-- con:query(([[UPDATE customer%d +-- SET c_balance=%f, c_ytd_payment=%f +-- WHERE c_w_id = %d +-- AND c_d_id=%d +-- AND c_id=%d]]) +-- :format(table_num, c_balance, c_ytd_payment, w_id, c_d_id, c_id )) end --- 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) --- VALUES(:c_d_id, :c_w_id, :c_id, :d_id, --- :w_id, --- :datetime, --- :h_amount, :h_data);*/ - - con:query(([[INSERT INTO history%d - (h_c_d_id, h_c_w_id, h_c_id, h_d_id, h_w_id, h_date, h_amount, h_data) - VALUES (%d,%d,%d,%d,%d,NOW(),%d,'%s')]]) - :format(table_num, c_d_id, c_w_id, c_id, d_id, w_id, h_amount, string.format("%10s %10s ",w_name,d_name))) +-- 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) +-- VALUES(:c_d_id, :c_w_id, :c_id, :d_id, +-- :w_id, +-- :datetime, +-- :h_amount, :h_data);*/ + + con:query(([[execute p_payment11_%d(%d,%d,%d,%d,%d,%d,'%s')]]):format(table_num, c_d_id, c_w_id, c_id, d_id, w_id, h_amount, string.format("%10s %10s ",w_name,d_name))) +-- con:query(([[INSERT INTO history%d +-- (h_c_d_id, h_c_w_id, h_c_id, h_d_id, h_w_id, h_date, h_amount, h_data) +-- VALUES (%d,%d,%d,%d,%d,NOW(),%d,'%s')]]) +-- :format(table_num, c_d_id, c_w_id, c_id, d_id, w_id, h_amount, string.format("%10s %10s ",w_name,d_name))) con:query("COMMIT") @@ -437,12 +466,15 @@ function orderstatus() -- AND c_last = :c_last;*/ local namecnt - namecnt = con:query_row(([[SELECT count(c_id) namecnt - FROM customer%d - WHERE c_w_id = %d - AND c_d_id= %d - AND c_last='%s']]): - format(table_num, w_id, d_id, c_last )) + + namecnt = con:query_row(([[execute p_orderstatus1_%d(%d,%d,'%s')]]):format(table_num, w_id, d_id, c_last)) +-- namecnt = con:query_row(([[SELECT count(c_id) namecnt +-- FROM customer%d +-- WHERE c_w_id = %d +-- AND c_d_id= %d +-- AND c_last='%s']]): +-- format(table_num, w_id, d_id, c_last )) + -- SELECT c_balance, c_first, c_middle, c_id -- FROM customer @@ -451,12 +483,13 @@ function orderstatus() -- AND c_last = :c_last -- ORDER BY c_first; - rs = con:query(([[SELECT c_balance, c_first, c_middle, c_id - FROM customer%d - WHERE c_w_id = %d - AND c_d_id= %d - AND c_last='%s' ORDER BY c_first]]) - :format(table_num, w_id, d_id, c_last )) + rs = con:query(([[execute p_orderstatus2_%d(%d,%d,'%s')]]):format(table_num, w_id, d_id, c_last)) +-- rs = con:query(([[SELECT c_balance, c_first, c_middle, c_id +-- FROM customer%d +-- WHERE c_w_id = %d +-- AND c_d_id= %d +-- AND c_last='%s' ORDER BY c_first]]) +-- :format(table_num, w_id, d_id, c_last )) if namecnt % 2 == 0 then namecnt = namecnt + 1 @@ -469,18 +502,23 @@ function orderstatus() c_id = row[4] end else --- SELECT c_balance, c_first, c_middle, c_last --- FROM customer --- WHERE c_w_id = :c_w_id --- AND c_d_id = :c_d_id --- AND c_id = :c_id;*/ +-- SELECT c_balance, c_first, c_middle, c_last +-- FROM customer +-- WHERE c_w_id = :c_w_id +-- AND c_d_id = :c_d_id +-- AND c_id = :c_id;*/ + c_balance, c_first, c_middle, c_last = - con:query_row(([[SELECT c_balance, c_first, c_middle, c_last - FROM customer%d - WHERE c_w_id = %d - AND c_d_id=%d - AND c_id=%d]]) - :format(table_num, w_id, d_id, c_id )) + con:query_row(([[execute p_orderstatus3_%d(%d,%d,%d)]]):format(table_num, w_id, d_id, c_id)) + +-- c_balance, c_first, c_middle, c_last = +-- con:query_row(([[SELECT c_balance, c_first, c_middle, c_last +-- FROM customer%d +-- WHERE c_w_id = %d +-- AND c_d_id=%d +-- AND c_id=%d]]) +-- :format(table_num, w_id, d_id, c_id )) + end --[=[ Initial query SELECT o_id, o_entry_d, COALESCE(o_carrier_id,0) FROM orders @@ -502,13 +540,15 @@ function orderstatus() -]] local o_id - o_id = con:query_row(([[SELECT o_id, o_carrier_id, o_entry_d - FROM orders%d - WHERE o_w_id = %d - AND o_d_id = %d - AND o_c_id = %d - ORDER BY o_id DESC]]): - format(table_num, w_id, d_id, c_id)) + o_id = con:query_row(([[execute p_orderstatus4_%d(%d,%d,%d)]]):format(table_num, w_id, d_id, c_id)) +-- o_id = con:query_row(([[SELECT o_id, o_carrier_id, o_entry_d +-- FROM orders%d +-- WHERE o_w_id = %d +-- AND o_d_id = %d +-- AND o_c_id = %d +-- ORDER BY o_id DESC]]): +-- format(table_num, w_id, d_id, c_id)) + -- rs = con:query(([[SELECT o_id, o_carrier_id, o_entry_d -- FROM orders%d @@ -518,23 +558,25 @@ function orderstatus() -- ORDER BY o_id DESC]]): -- format(table_num, w_id, d_id, c_id)) -- if rs.nrows == 0 then --- print(string.format("Error o_id %d, %d, %d, %d\n", table_num , w_id , d_id , c_id)) +-- print(string.format("Error o_id %d, %d, %d, %d\n", table_num , w_id , d_id , c_id)) -- end -- for i = 1, rs.nrows do -- row = rs:fetch_row() --- o_id= row[1] +-- o_id= row[1] -- end --- SELECT ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, +-- SELECT ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, -- ol_delivery_d --- FROM order_line --- WHERE ol_w_id = :c_w_id --- AND ol_d_id = :c_d_id --- AND ol_o_id = :o_id;*/ - - rs = con:query(([[SELECT ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_delivery_d - FROM order_line%d WHERE ol_w_id = %d AND ol_d_id = %d AND ol_o_id = %d]]) - :format(table_num, w_id, d_id, d_id, o_id)) +-- FROM order_line +-- WHERE ol_w_id = :c_w_id +-- AND ol_d_id = :c_d_id +-- AND ol_o_id = :o_id;*/ + + rs = con:query(([[execute p_orderstatus5_%d(%d,%d,%d)]]):format(table_num, w_id, d_id, o_id)) +-- rs = con:query(([[SELECT ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_delivery_d +-- FROM order_line%d WHERE ol_w_id = %d AND ol_d_id = %d AND ol_o_id = %d]]) +-- :format(table_num, w_id, d_id, d_id, o_id)) + for i = 1, rs.nrows do row = rs:fetch_row() local ol_i_id = row[1] @@ -555,22 +597,23 @@ function delivery() con:query("BEGIN") for d_id = 1, DIST_PER_WARE do --- SELECT COALESCE(MIN(no_o_id),0) INTO :no_o_id --- FROM new_orders --- WHERE no_d_id = :d_id AND no_w_id = :w_id;*/ - +-- SELECT COALESCE(MIN(no_o_id),0) INTO :no_o_id +-- FROM new_orders +-- WHERE no_d_id = :d_id AND no_w_id = :w_id;*/ + -- rs = con:query(([[SELECT COALESCE(MIN(no_o_id),0) no_o_id -- FROM new_orders%d WHERE no_d_id = %d AND no_w_id = %d FOR UPDATE]]) -- :format(table_num, d_id, w_id)) local no_o_id - rs = con:query(([[SELECT no_o_id - FROM new_orders%d - WHERE no_d_id = %d - AND no_w_id = %d - ORDER BY no_o_id ASC LIMIT 1 FOR UPDATE]]) - :format(table_num, d_id, w_id)) + rs = con:query(([[execute p_delivery1_%d(%d,%d)]]):format(table_num, d_id, w_id)) +-- rs = con:query(([[SELECT no_o_id +-- FROM new_orders%d +-- WHERE no_d_id = %d +-- AND no_w_id = %d +-- ORDER BY no_o_id ASC LIMIT 1 FOR UPDATE]]) +-- :format(table_num, d_id, w_id)) if (rs.nrows > 0) then no_o_id=unpack(rs:fetch_row(), 1, rs.nfields) @@ -578,74 +621,84 @@ function delivery() if (no_o_id ~= nil ) then --- DELETE FROM new_orders WHERE no_o_id = :no_o_id AND no_d_id = :d_id --- AND no_w_id = :w_id;*/ +-- DELETE FROM new_orders WHERE no_o_id = :no_o_id AND no_d_id = :d_id +-- AND no_w_id = :w_id;*/ - con:query(([[DELETE FROM new_orders%d - WHERE no_o_id = %d - AND no_d_id = %d - AND no_w_id = %d]]) - :format(table_num, no_o_id, d_id, w_id)) + con:query(([[execute p_delivery2_%d(%d,%d,%d)]]):format(table_num, no_o_id, d_id, w_id)) +-- con:query(([[DELETE FROM new_orders%d +-- WHERE no_o_id = %d +-- AND no_d_id = %d +-- AND no_w_id = %d]]) +-- :format(table_num, no_o_id, d_id, w_id)) -- SELECT o_c_id INTO :c_id FROM orders --- WHERE o_id = :no_o_id AND o_d_id = :d_id --- AND o_w_id = :w_id;*/ +-- WHERE o_id = :no_o_id AND o_d_id = :d_id +-- AND o_w_id = :w_id;*/ local o_c_id - o_c_id = con:query_row(([[SELECT o_c_id - FROM orders%d - WHERE o_id = %d - AND o_d_id = %d - AND o_w_id = %d]]) - :format(table_num, no_o_id, d_id, w_id)) - --- UPDATE orders SET o_carrier_id = :o_carrier_id --- WHERE o_id = :no_o_id AND o_d_id = :d_id AND --- o_w_id = :w_id;*/ - - con:query(([[UPDATE orders%d - SET o_carrier_id = %d - WHERE o_id = %d - AND o_d_id = %d - AND o_w_id = %d]]) - :format(table_num, o_carrier_id, no_o_id, d_id, w_id)) + o_c_id = con:query_row(([[execute p_delivery3_%d(%d,%d,%d)]]):format(table_num, no_o_id, d_id, w_id)) +-- o_c_id = con:query_row(([[SELECT o_c_id +-- FROM orders%d +-- WHERE o_id = %d +-- AND o_d_id = %d +-- AND o_w_id = %d]]) +-- :format(table_num, no_o_id, d_id, w_id)) + +-- UPDATE orders SET o_carrier_id = :o_carrier_id +-- WHERE o_id = :no_o_id AND o_d_id = :d_id AND +-- o_w_id = :w_id;*/ + + con:query(([[execute p_delivery4_%d(%d,%d,%d,%d)]]):format(table_num, o_carrier_id, no_o_id, d_id, w_id)) +-- con:query(([[UPDATE orders%d +-- SET o_carrier_id = %d +-- WHERE o_id = %d +-- AND o_d_id = %d +-- AND o_w_id = %d]]) +-- :format(table_num, o_carrier_id, no_o_id, d_id, w_id)) -- UPDATE order_line --- SET ol_delivery_d = :datetime --- WHERE ol_o_id = :no_o_id AND ol_d_id = :d_id AND --- ol_w_id = :w_id;*/ - con:query(([[UPDATE order_line%d - SET ol_delivery_d = NOW() - WHERE ol_o_id = %d - AND ol_d_id = %d - AND ol_w_id = %d]]) - :format(table_num, no_o_id, d_id, w_id)) - --- SELECT SUM(ol_amount) INTO :ol_total --- FROM order_line --- WHERE ol_o_id = :no_o_id AND ol_d_id = :d_id --- AND ol_w_id = :w_id;*/ +-- SET ol_delivery_d = :datetime +-- WHERE ol_o_id = :no_o_id AND ol_d_id = :d_id AND +-- ol_w_id = :w_id;*/ + + con:query(([[execute p_delivery5_%d(%d,%d,%d)]]):format(table_num, no_o_id, d_id, w_id)) +-- con:query(([[UPDATE order_line%d +-- SET ol_delivery_d = NOW() +-- WHERE ol_o_id = %d +-- AND ol_d_id = %d +-- AND ol_w_id = %d]]) +-- :format(table_num, no_o_id, d_id, w_id)) + + +-- SELECT SUM(ol_amount) INTO :ol_total +-- FROM order_line +-- WHERE ol_o_id = :no_o_id AND ol_d_id = :d_id +-- AND ol_w_id = :w_id;*/ local sm_ol_amount - sm_ol_amount = con:query_row(([[SELECT SUM(ol_amount) sm - FROM order_line%d - WHERE ol_o_id = %d - AND ol_d_id = %d - AND ol_w_id = %d]]) - :format(table_num, no_o_id, d_id, w_id)) - --- UPDATE customer SET c_balance = c_balance + :ol_total , --- c_delivery_cnt = c_delivery_cnt + 1 --- WHERE c_id = :c_id AND c_d_id = :d_id AND --- c_w_id = :w_id;*/ --- print(string.format("update customer table %d, cid %d, did %d, wid %d balance %f",table_num, o_c_id, d_id, w_id, sm_ol_amount)) - con:query(([[UPDATE customer%d - SET c_balance = c_balance + %f, - c_delivery_cnt = c_delivery_cnt + 1 - WHERE c_id = %d - AND c_d_id = %d - AND c_w_id = %d]]) - :format(table_num, sm_ol_amount, o_c_id, d_id, w_id)) + sm_ol_amount = con:query_row(([[execute p_delivery6_%d(%d,%d,%d)]]):format(table_num, no_o_id, d_id, w_id)) +-- sm_ol_amount = con:query_row(([[SELECT SUM(ol_amount) sm +-- FROM order_line%d +-- WHERE ol_o_id = %d +-- AND ol_d_id = %d +-- AND ol_w_id = %d]]) +-- :format(table_num, no_o_id, d_id, w_id)) + +-- UPDATE customer SET c_balance = c_balance + :ol_total , +-- c_delivery_cnt = c_delivery_cnt + 1 +-- WHERE c_id = :c_id AND c_d_id = :d_id AND +-- c_w_id = :w_id;*/ +-- print(string.format("update customer table %d, cid %d, did %d, wid %d balance %f",table_num, o_c_id, d_id, w_id, sm_ol_amount)) + + + con:query(([[execute p_delivery7_%d(%d,%d,%d,%d)]]):format(table_num, sm_ol_amount, o_c_id, d_id, w_id)) +-- con:query(([[UPDATE customer%d +-- SET c_balance = c_balance + %f, +-- c_delivery_cnt = c_delivery_cnt + 1 +-- WHERE c_id = %d +-- AND c_d_id = %d +-- AND c_w_id = %d]]) +-- :format(table_num, sm_ol_amount, o_c_id, d_id, w_id)) end end @@ -661,10 +714,10 @@ function stocklevel() con:query("BEGIN") --- /*EXEC_SQL SELECT d_next_o_id --- FROM district --- WHERE d_id = :d_id --- AND d_w_id = :w_id;*/ +-- /*EXEC_SQL SELECT d_next_o_id +-- FROM district +-- WHERE d_id = :d_id +-- AND d_w_id = :w_id;*/ -- What variant of queries to use for stock_level transaction -- case1 - specification @@ -674,10 +727,11 @@ function stocklevel() local d_next_o_id - d_next_o_id = con:query_row(([[SELECT d_next_o_id - FROM district%d - WHERE d_id = %d AND d_w_id= %d]]) - :format( table_num, d_id, w_id)) + d_next_o_id = con:query_row(([[execute p_stocklevel1_%d(%d,%d)]]):format(table_num, d_id, w_id)) +-- d_next_o_id = con:query_row(([[SELECT d_next_o_id +-- FROM district%d +-- WHERE d_id = %d AND d_w_id= %d]]) +-- :format( table_num, d_id, w_id)) if stock_level_queries == "case1" then @@ -687,33 +741,35 @@ function stocklevel() WHERE ol_w_id=:w_id AND ol_d_id=:d_id AND ol_o_id<:o_id AND ol_o_id>=:o_id-20 AND s_w_id=:w_id AND s_i_id=ol_i_id AND s_quantity < :threshold; --]] - rs = con:query(([[SELECT COUNT(DISTINCT (s_i_id)) - FROM order_line%d, stock%d - WHERE ol_w_id = %d - AND ol_d_id = %d - AND ol_o_id < %d - AND ol_o_id >= %d - AND s_w_id= %d - AND s_i_id=ol_i_id - AND s_quantity < %d ]]) - :format(table_num, table_num, w_id, d_id, d_next_o_id, d_next_o_id - 20, w_id, level )) + rs = con:query(([[execute p_stocklevel2_%d(%d,%d,%d,%d,%d,%d)]]):format(table_num, w_id, d_id, d_next_o_id, d_next_o_id - 20, w_id, level)) +-- rs = con:query(([[SELECT COUNT(DISTINCT (s_i_id)) +-- FROM order_line%d, stock%d +-- WHERE ol_w_id = %d +-- AND ol_d_id = %d +-- AND ol_o_id < %d +-- AND ol_o_id >= %d +-- AND s_w_id= %d +-- AND s_i_id=ol_i_id +-- AND s_quantity < %d ]]) +-- :format(table_num, table_num, w_id, d_id, d_next_o_id, d_next_o_id - 20, w_id, level )) --- SELECT DISTINCT ol_i_id --- FROM order_line --- WHERE ol_w_id = :w_id --- AND ol_d_id = :d_id --- AND ol_o_id < :d_next_o_id --- AND ol_o_id >= (:d_next_o_id - 20); +-- SELECT DISTINCT ol_i_id +-- FROM order_line +-- WHERE ol_w_id = :w_id +-- AND ol_d_id = :d_id +-- AND ol_o_id < :d_next_o_id +-- AND ol_o_id >= (:d_next_o_id - 20); else - rs = con:query(([[SELECT DISTINCT ol_i_id FROM order_line%d - WHERE ol_w_id = %d AND ol_d_id = %d - AND ol_o_id < %d AND ol_o_id >= %d]]) - :format(table_num, w_id, d_id, d_next_o_id, d_next_o_id - 20 )) + rs = con:query(([[execute p_stocklevel3_%d(%d,%d,%d,%d)]]):format(table_num, w_id, d_id, d_next_o_id, d_next_o_id - 20)) +-- rs = con:query(([[SELECT DISTINCT ol_i_id FROM order_line%d +-- WHERE ol_w_id = %d AND ol_d_id = %d +-- AND ol_o_id < %d AND ol_o_id >= %d]]) +-- :format(table_num, w_id, d_id, d_next_o_id, d_next_o_id - 20 )) local ol_i_id @@ -727,10 +783,12 @@ function stocklevel() -- AND s_i_id = :ol_i_id -- AND s_quantity < :level;*/ - rs1 = con:query(([[SELECT count(*) FROM stock%d - WHERE s_w_id = %d AND s_i_id = %d - AND s_quantity < %d]]) - :format(table_num, w_id, ol_i_id, level ) ) + rs1 = con:query(([[execute p_stocklevel4_%d(%d,%d,%d)]]):format(table_num, w_id, ol_i_id, level)) +-- rs1 = con:query(([[SELECT count(*) FROM stock%d +-- WHERE s_w_id = %d AND s_i_id = %d +-- AND s_quantity < %d]]) +-- :format(table_num, w_id, ol_i_id, level ) ) + local cnt for i = 1, rs1.nrows do cnt = unpack(rs1:fetch_row(), 1, rs1.nfields) @@ -755,10 +813,11 @@ function purge() local m_o_id - rs = con:query(([[SELECT min(no_o_id) mo - FROM new_orders%d - WHERE no_w_id = %d AND no_d_id = %d]]) - :format(table_num, w_id, d_id)) + rs = con:query(([[execute p_purge1_%d(%d,%d)]]):format(table_num, w_id, d_id)) +-- rs = con:query(([[SELECT min(no_o_id) mo +-- FROM new_orders%d +-- WHERE no_w_id = %d AND no_d_id = %d]]) +-- :format(table_num, w_id, d_id)) if (rs.nrows > 0) then m_o_id=unpack(rs:fetch_row(), 1, rs.nfields) @@ -766,10 +825,13 @@ function purge() if (m_o_id ~= nil ) then -- select o_id,o.o_d_id from orders2 o, (select o_c_id,o_w_id,o_d_id,count(distinct o_id) from orders2 where o_w_id=1 and o_id > 2100 and o_id < 11153 group by o_c_id,o_d_id,o_w_id having count( distinct o_id) > 1 limit 1) t where t.o_w_id=o.o_w_id and t.o_d_id=o.o_d_id and t.o_c_id=o.o_c_id limit 1; - -- find an order to delete - rs = con:query(([[SELECT o_id FROM orders%d o, (SELECT o_c_id,o_w_id,o_d_id,count(distinct o_id) FROM orders%d WHERE o_w_id=%d AND o_d_id=%d AND o_id > 2100 AND o_id < %d GROUP BY o_c_id,o_d_id,o_w_id having count( distinct o_id) > 1 limit 1) t WHERE t.o_w_id=o.o_w_id and t.o_d_id=o.o_d_id and t.o_c_id=o.o_c_id limit 1 ]]) - :format(table_num, table_num, w_id, d_id, m_o_id)) - + + + -- find an order to delete + rs = con:query(([[execute p_purge2_%d(%d,%d,%d)]]):format(table_num, w_id, d_id, m_o_id)) +-- rs = con:query(([[SELECT o_id FROM orders%d o, (SELECT o_c_id,o_w_id,o_d_id,count(distinct o_id) FROM orders%d WHERE o_w_id=%d AND o_d_id=%d AND o_id > 2100 AND o_id < %d GROUP BY o_c_id,o_d_id,o_w_id having count( distinct o_id) > 1 limit 1) t WHERE t.o_w_id=o.o_w_id and t.o_d_id=o.o_d_id and t.o_c_id=o.o_c_id limit 1 ]]) +-- :format(table_num, table_num, w_id, d_id, m_o_id)) + local del_o_id if (rs.nrows > 0) then del_o_id=unpack(rs:fetch_row(), 1, rs.nfields) @@ -777,14 +839,18 @@ function purge() if (del_o_id ~= nil ) then - con:query(([[DELETE FROM order_line%d where ol_w_id=%d AND ol_d_id=%d AND ol_o_id=%d]]) - :format(table_num, w_id, d_id, del_o_id)) - con:query(([[DELETE FROM orders%d where o_w_id=%d AND o_d_id=%d and o_id=%d]]) - :format(table_num, w_id, d_id, del_o_id)) - con:query(([[DELETE FROM history%d where h_w_id=%d AND h_d_id=%d LIMIT 10]]) - :format(table_num, w_id, d_id )) - - end + con:query(([[execute p_purge3_%d(%d,%d,%d)]]):format(table_num, w_id, d_id, del_o_id)) + con:query(([[execute p_purge4_%d(%d,%d,%d)]]):format(table_num, w_id, d_id, del_o_id)) + con:query(([[execute p_purge5_%d(%d,%d)]]):format(table_num, w_id, d_id)) + +-- con:query(([[DELETE FROM order_line%d where ol_w_id=%d AND ol_d_id=%d AND ol_o_id=%d]]) +-- :format(table_num, w_id, d_id, del_o_id)) +-- con:query(([[DELETE FROM orders%d where o_w_id=%d AND o_d_id=%d and o_id=%d]]) +-- :format(table_num, w_id, d_id, del_o_id)) +-- con:query(([[DELETE FROM history%d where h_w_id=%d AND h_d_id=%d LIMIT 10]]) +-- :format(table_num, w_id, d_id )) + + end end diff --git a/tpcc_run.lua.old b/tpcc_run.lua.old new file mode 100755 index 0000000..f44b4bb --- /dev/null +++ b/tpcc_run.lua.old @@ -0,0 +1,795 @@ +#!/usr/bin/env sysbench + +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. + +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +-- ---------------------------------------------------------------------- +-- TPCC-like workload +-- ---------------------------------------------------------------------- + +require("tpcc_common") + + +-- +-- produce the id of a valid warehouse other than home_ware +-- (assuming there is one) +-- +function other_ware (home_ware) + local tmp + + if sysbench.opt.scale == 1 then return home_ware end + repeat + tmp = sysbench.rand.uniform(1, sysbench.opt.scale) + until tmp == home_ware + return tmp +end + +function new_order() + +-- prep work + + local table_num = sysbench.rand.uniform(1, sysbench.opt.tables) + local w_id = sysbench.rand.uniform(1, sysbench.opt.scale) + local d_id = sysbench.rand.uniform(1, DIST_PER_WARE) + local c_id = NURand(1023, 1, CUST_PER_DIST) + + local ol_cnt = sysbench.rand.uniform(5, 15); + local rbk = sysbench.rand.uniform(1, 100); + local itemid = {} + local supware = {} + local qty = {} + local all_local = 1 + + for i = 1, ol_cnt + do + itemid[i] = NURand(8191, 1, MAXITEMS) + if ((i == ol_cnt - 1) and (rbk == 1)) + then + itemid[i] = -1 + end + if sysbench.rand.uniform(1, 100) ~= 1 + then + supware[i] = w_id + else + supware[i] = other_ware(w_id) + all_local = 0 + end + qty[i] = sysbench.rand.uniform(1, 10) + end + + +-- SELECT c_discount, c_last, c_credit, w_tax +-- INTO :c_discount, :c_last, :c_credit, :w_tax +-- FROM customer, warehouse +-- WHERE w_id = :w_id +-- AND c_w_id = w_id +-- AND c_d_id = :d_id +-- AND c_id = :c_id; + + con:query("BEGIN") + + local c_discount + local c_last + local c_credit + local w_tax + + c_discount, c_last, c_credit, w_tax = con:query_row(([[SELECT c_discount, c_last, c_credit, w_tax + FROM customer%d, warehouse%d + WHERE w_id = %d + AND c_w_id = w_id + AND c_d_id = %d + AND c_id = %d]]): + format(table_num, table_num, w_id, d_id, c_id)) + +-- SELECT d_next_o_id, d_tax INTO :d_next_o_id, :d_tax +-- FROM district +-- WHERE d_id = :d_id +-- AND d_w_id = :w_id +-- FOR UPDATE + local d_next_o_id + local d_tax + + d_next_o_id, d_tax = con:query_row(([[SELECT d_next_o_id, d_tax + FROM district%d + WHERE d_w_id = %d + AND d_id = %d FOR UPDATE]]): + format(table_num, w_id, d_id)) + +-- UPDATE district SET d_next_o_id = :d_next_o_id + 1 +-- WHERE d_id = :d_id +-- AND d_w_id = :w_id; + + con:query(([[UPDATE district%d + SET d_next_o_id = %d + WHERE d_id = %d AND d_w_id= %d]]):format(table_num, d_next_o_id + 1, d_id, w_id)) + +--INSERT INTO orders (o_id, o_d_id, o_w_id, o_c_id, +-- o_entry_d, o_ol_cnt, o_all_local) +-- VALUES(:o_id, :d_id, :w_id, :c_id, +-- :datetime, +-- :o_ol_cnt, :o_all_local); + + con:query(([[INSERT INTO orders%d + (o_id, o_d_id, o_w_id, o_c_id, o_entry_d, o_ol_cnt, o_all_local) + VALUES (%d,%d,%d,%d,NOW(),%d,%d)]]): + format(table_num, d_next_o_id, d_id, w_id, c_id, ol_cnt, all_local)) + +-- INSERT INTO new_orders (no_o_id, no_d_id, no_w_id) +-- VALUES (:o_id,:d_id,:w_id); */ + + con:query(([[INSERT INTO new_orders%d (no_o_id, no_d_id, no_w_id) + VALUES (%d,%d,%d)]]): + format(table_num, d_next_o_id, d_id, w_id)) + + for ol_number=1, ol_cnt do + local ol_supply_w_id = supware[ol_number] + local ol_i_id = itemid[ol_number] + local ol_quantity = qty[ol_number] + +-- SELECT i_price, i_name, i_data +-- INTO :i_price, :i_name, :i_data +-- FROM item +-- WHERE i_id = :ol_i_id;*/ + + rs = con:query(([[SELECT i_price, i_name, i_data + FROM item%d + WHERE i_id = %d]]): + format(table_num, ol_i_id)) + + local i_price + local i_name + local i_data + + if rs.nrows == 0 then +-- print("ROLLBACK") + ffi.C.sb_counter_inc(sysbench.tid, ffi.C.SB_CNT_ERROR) + con:query("ROLLBACK") + return + end + + i_price, i_name, i_data = unpack(rs:fetch_row(), 1, rs.nfields) + +-- SELECT s_quantity, 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 +-- INTO :s_quantity, :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 +-- FROM stock +-- WHERE s_i_id = :ol_i_id +-- AND s_w_id = :ol_supply_w_id +-- FOR UPDATE;*/ + + local s_quantity + local s_data + local ol_dist_info + + s_quantity, s_data, ol_dist_info = con:query_row(([[SELECT s_quantity, s_data, s_dist_%s s_dist + FROM stock%d + WHERE s_i_id = %d AND s_w_id= %d FOR UPDATE]]): + format(string.format("%02d",d_id),table_num,ol_i_id,ol_supply_w_id )) + + s_quantity=tonumber(s_quantity) + if (s_quantity > ol_quantity) then + s_quantity = s_quantity - ol_quantity + else + s_quantity = s_quantity - ol_quantity + 91 + end + +-- UPDATE stock SET s_quantity = :s_quantity +-- WHERE s_i_id = :ol_i_id +-- AND s_w_id = :ol_supply_w_id;*/ + + con:query(([[UPDATE stock%d + SET s_quantity = %d + WHERE s_i_id = %d + AND s_w_id= %d]]): + format(table_num, s_quantity, ol_i_id, ol_supply_w_id)) + + i_price=tonumber(i_price) + w_tax=tonumber(w_tax) + d_tax=tonumber(d_tax) + c_discount=tonumber(c_discount) + + ol_amount = ol_quantity * i_price * (1 + w_tax + d_tax) * (1 - c_discount); + +-- 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) +-- VALUES (:o_id, :d_id, :w_id, :ol_number, :ol_i_id, +-- :ol_supply_w_id, :ol_quantity, :ol_amount, +-- :ol_dist_info); + + con:query(([[INSERT INTO order_line%d + (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) + VALUES (%d,%d,%d,%d,%d,%d,%d,%d,'%s')]]): + format(table_num, d_next_o_id, d_id, w_id, ol_number, ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_dist_info)) + + end + + con:query("COMMIT") + +end + +function payment() +-- prep work + + local table_num = sysbench.rand.uniform(1, sysbench.opt.tables) + local w_id = sysbench.rand.uniform(1, sysbench.opt.scale) + local d_id = sysbench.rand.uniform(1, DIST_PER_WARE) + local c_id = NURand(1023, 1, CUST_PER_DIST) + local h_amount = sysbench.rand.uniform(1,5000) + local byname + local c_w_id + local c_d_id + local c_last = Lastname(NURand(255,0,999)) + + if sysbench.rand.uniform(1, 100) <= 60 then + byname = 1 -- select by last name + else + byname = 0 -- select by customer id + end + + if sysbench.rand.uniform(1, 100) <= 85 then + c_w_id = w_id + c_d_id = d_id + else + c_w_id = other_ware(w_id) + c_d_id = sysbench.rand.uniform(1, DIST_PER_WARE) + end + +-- UPDATE warehouse SET w_ytd = w_ytd + :h_amount +-- WHERE w_id =:w_id + + con:query("BEGIN") + + con:query(([[UPDATE warehouse%d + SET w_ytd = w_ytd + %d + WHERE w_id = %d]]):format(table_num, h_amount, w_id )) + +-- SELECT w_street_1, w_street_2, w_city, w_state, w_zip, +-- w_name +-- INTO :w_street_1, :w_street_2, :w_city, :w_state, +-- :w_zip, :w_name +-- FROM warehouse +-- WHERE w_id = :w_id;*/ + local w_street_1, w_street_2, w_city, w_state, w_zip, w_name + + w_street_1, w_street_2, w_city, w_state, w_zip, w_name = + con:query_row(([[SELECT w_street_1, w_street_2, w_city, w_state, w_zip, w_name + FROM warehouse%d + WHERE w_id = %d]]):format(table_num, w_id)) + +-- UPDATE district SET d_ytd = d_ytd + :h_amount +-- WHERE d_w_id = :w_id +-- AND d_id = :d_id;*/ + + con:query(([[UPDATE district%d + SET d_ytd = d_ytd + %d + WHERE d_w_id = %d + AND d_id= %d]]):format(table_num, h_amount, w_id, d_id)) + + + local d_street_1,d_street_2, d_city, d_state, d_zip, d_name + + d_street_1,d_street_2, d_city, d_state, d_zip, d_name = + con:query_row(([[SELECT d_street_1, d_street_2, d_city, d_state, d_zip, d_name + FROM district%d + WHERE d_w_id = %d + AND d_id = %d]]):format(table_num, w_id, d_id )) + + if byname == 1 then + +-- SELECT count(c_id) +-- FROM customer +-- WHERE c_w_id = :c_w_id +-- AND c_d_id = :c_d_id +-- AND c_last = :c_last;*/ + + local namecnt = con:query_row(([[SELECT count(c_id) namecnt + FROM customer%d + WHERE c_w_id = %d + AND c_d_id= %d + AND c_last='%s']]):format(table_num, w_id, c_d_id, c_last )) +-- SELECT c_id +-- FROM customer +-- WHERE c_w_id = :c_w_id +-- AND c_d_id = :c_d_id +-- AND c_last = :c_last +-- ORDER BY c_first; + + if namecnt % 2 == 0 then + namecnt = namecnt + 1 + end + + rs = con:query(([[SELECT c_id + FROM customer%d + WHERE c_w_id = %d AND c_d_id= %d + AND c_last='%s' ORDER BY c_first]] + ):format(table_num, w_id, c_d_id, c_last )) + + for i = 1, (namecnt / 2 ) + 1 do + row = rs:fetch_row() + c_id = row[1] + end + end -- byname + +-- SELECT c_first, c_middle, c_last, c_street_1, +-- c_street_2, c_city, c_state, c_zip, c_phone, +-- c_credit, c_credit_lim, c_discount, c_balance, +-- c_since +-- FROM customer +-- WHERE c_w_id = :c_w_id +-- AND c_d_id = :c_d_id +-- AND c_id = :c_id +-- FOR UPDATE; + + local c_first, c_middle, c_last, c_street_1, c_street_2, c_city, c_state, c_zip, + c_phone, c_credit, c_credit_lim, c_discount, c_balance, c_ytd_payment, c_since + + c_first, c_middle, c_last, c_street_1, c_street_2, c_city, c_state, c_zip, + c_phone, c_credit, c_credit_lim, c_discount, c_balance, c_ytd_payment, c_since = + con:query_row(([[SELECT c_first, c_middle, c_last, c_street_1, + c_street_2, c_city, c_state, c_zip, c_phone, + c_credit, c_credit_lim, c_discount, c_balance, c_ytd_payment, c_since + FROM customer%d + WHERE c_w_id = %d + AND c_d_id= %d + AND c_id=%d FOR UPDATE]]) + :format(table_num, w_id, c_d_id, c_id )) + + c_balance = tonumber(c_balance) - h_amount + c_ytd_payment = tonumber(c_ytd_payment) + h_amount + + if c_credit == "BC" then +-- SELECT c_data +-- INTO :c_data +-- FROM customer +-- WHERE c_w_id = :c_w_id +-- AND c_d_id = :c_d_id +-- AND c_id = :c_id; */ + + local c_data + c_data = con:query_row(([[SELECT c_data + FROM customer%d + WHERE c_w_id = %d + AND c_d_id=%d + AND c_id= %d]]): + format(table_num, w_id, c_d_id, c_id )) + + local c_new_data=string.sub(string.format("| %4d %2d %4d %2d %4d $%7.2f %12s %24s", + c_id, c_d_id, c_w_id, d_id, w_id, h_amount, os.time(), c_data), 1, 500); + + -- UPDATE customer + -- SET c_balance = :c_balance, c_data = :c_new_data + -- WHERE c_w_id = :c_w_id + -- AND c_d_id = :c_d_id + -- AND c_id = :c_id + con:query(([[UPDATE customer%d + SET c_balance=%f, c_ytd_payment=%f, c_data='%s' + WHERE c_w_id = %d + AND c_d_id=%d + AND c_id=%d]]) + :format(table_num, c_balance, c_ytd_payment, c_new_data, w_id, c_d_id, c_id )) + else + con:query(([[UPDATE customer%d + SET c_balance=%f, c_ytd_payment=%f + WHERE c_w_id = %d + AND c_d_id=%d + AND c_id=%d]]) + :format(table_num, c_balance, c_ytd_payment, w_id, c_d_id, c_id )) + + end + +-- 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) +-- VALUES(:c_d_id, :c_w_id, :c_id, :d_id, +-- :w_id, +-- :datetime, +-- :h_amount, :h_data);*/ + + con:query(([[INSERT INTO history%d + (h_c_d_id, h_c_w_id, h_c_id, h_d_id, h_w_id, h_date, h_amount, h_data) + VALUES (%d,%d,%d,%d,%d,NOW(),%d,'%s')]]) + :format(table_num, c_d_id, c_w_id, c_id, d_id, w_id, h_amount, string.format("%10s %10s ",w_name,d_name))) + + con:query("COMMIT") + +end + +function orderstatus() + + local table_num = sysbench.rand.uniform(1, sysbench.opt.tables) + local w_id = sysbench.rand.uniform(1, sysbench.opt.scale) + local d_id = sysbench.rand.uniform(1, DIST_PER_WARE) + local c_id = NURand(1023, 1, CUST_PER_DIST) + local byname + local c_last = Lastname(NURand(255,0,999)) + + if sysbench.rand.uniform(1, 100) <= 60 then + byname = 1 -- select by last name + else + byname = 0 -- select by customer id + end + + local c_balance + local c_first + local c_middle + con:query("BEGIN") + + if byname == 1 then +-- /*EXEC_SQL SELECT count(c_id) +-- FROM customer +-- WHERE c_w_id = :c_w_id +-- AND c_d_id = :c_d_id +-- AND c_last = :c_last;*/ + + local namecnt + namecnt = con:query_row(([[SELECT count(c_id) namecnt + FROM customer%d + WHERE c_w_id = %d + AND c_d_id= %d + AND c_last='%s']]): + format(table_num, w_id, d_id, c_last )) + +-- SELECT c_balance, c_first, c_middle, c_id +-- FROM customer +-- WHERE c_w_id = :c_w_id +-- AND c_d_id = :c_d_id +-- AND c_last = :c_last +-- ORDER BY c_first; + + rs = con:query(([[SELECT c_balance, c_first, c_middle, c_id + FROM customer%d + WHERE c_w_id = %d + AND c_d_id= %d + AND c_last='%s' ORDER BY c_first]]) + :format(table_num, w_id, d_id, c_last )) + + if namecnt % 2 == 0 then + namecnt = namecnt + 1 + end + for i = 1, (namecnt / 2 ) + 1 do + row = rs:fetch_row() + c_balance = row[1] + c_first = row[2] + c_middle = row[3] + c_id = row[4] + end + else +-- SELECT c_balance, c_first, c_middle, c_last +-- FROM customer +-- WHERE c_w_id = :c_w_id +-- AND c_d_id = :c_d_id +-- AND c_id = :c_id;*/ + c_balance, c_first, c_middle, c_last = + con:query_row(([[SELECT c_balance, c_first, c_middle, c_last + FROM customer%d + WHERE c_w_id = %d + AND c_d_id=%d + AND c_id=%d]]) + :format(table_num, w_id, d_id, c_id )) + end +--[=[ Initial query + SELECT o_id, o_entry_d, COALESCE(o_carrier_id,0) FROM orders + WHERE o_w_id = ? AND o_d_id = ? AND o_c_id = ? AND o_id = + (SELECT MAX(o_id) FROM orders WHERE o_w_id = ? AND o_d_id = ? AND o_c_id = ?) + + rs = con:query(([[SELECT o_id, o_entry_d, COALESCE(o_carrier_id,0) + FROM orders%d WHERE o_w_id = %d AND o_d_id = %d AND o_c_id = %d AND o_id = + (SELECT MAX(o_id) FROM orders%d WHERE o_w_id = %d AND o_d_id = %d AND o_c_id = %d)]]) + :format(table_num, w_id, d_id, c_id, table_num, w_id, d_id, c_id)) +--]=] + +--[[ Query from tpcc standard + + EXEC SQL SELECT o_id, o_carrier_id, o_entry_d + INTO :o_id, :o_carrier_id, :entdate + FROM orders + ORDER BY o_id DESC; +-]] + local o_id + + o_id = con:query_row(([[SELECT o_id, o_carrier_id, o_entry_d + FROM orders%d + WHERE o_w_id = %d + AND o_d_id = %d + AND o_c_id = %d + ORDER BY o_id DESC]]): + format(table_num, w_id, d_id, c_id)) + +-- rs = con:query(([[SELECT o_id, o_carrier_id, o_entry_d +-- FROM orders%d +-- WHERE o_w_id = %d +-- AND o_d_id = %d +-- AND o_c_id = %d +-- ORDER BY o_id DESC]]): +-- format(table_num, w_id, d_id, c_id)) +-- if rs.nrows == 0 then +-- print(string.format("Error o_id %d, %d, %d, %d\n", table_num , w_id , d_id , c_id)) +-- end +-- for i = 1, rs.nrows do +-- row = rs:fetch_row() +-- o_id= row[1] +-- end + +-- SELECT ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, +-- ol_delivery_d +-- FROM order_line +-- WHERE ol_w_id = :c_w_id +-- AND ol_d_id = :c_d_id +-- AND ol_o_id = :o_id;*/ + + rs = con:query(([[SELECT ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_delivery_d + FROM order_line%d WHERE ol_w_id = %d AND ol_d_id = %d AND ol_o_id = %d]]) + :format(table_num, w_id, d_id, d_id, o_id)) + for i = 1, rs.nrows do + row = rs:fetch_row() + local ol_i_id = row[1] + local ol_supply_w_id = row[2] + local ol_quantity = row[3] + local ol_amount = row[4] + local ol_delivery_d = row[5] + end + con:query("COMMIT") + +end + +function delivery() + local table_num = sysbench.rand.uniform(1, sysbench.opt.tables) + local w_id = sysbench.rand.uniform(1, sysbench.opt.scale) + local o_carrier_id = sysbench.rand.uniform(1, 10) + + con:query("BEGIN") + for d_id = 1, DIST_PER_WARE do + +-- SELECT COALESCE(MIN(no_o_id),0) INTO :no_o_id +-- FROM new_orders +-- WHERE no_d_id = :d_id AND no_w_id = :w_id;*/ + +-- rs = con:query(([[SELECT COALESCE(MIN(no_o_id),0) no_o_id +-- FROM new_orders%d WHERE no_d_id = %d AND no_w_id = %d FOR UPDATE]]) +-- :format(table_num, d_id, w_id)) + + local no_o_id + + rs = con:query(([[SELECT no_o_id + FROM new_orders%d + WHERE no_d_id = %d + AND no_w_id = %d + ORDER BY no_o_id ASC LIMIT 1 FOR UPDATE]]) + :format(table_num, d_id, w_id)) + + if (rs.nrows > 0) then + no_o_id=unpack(rs:fetch_row(), 1, rs.nfields) + end + + if (no_o_id ~= nil ) then + +-- DELETE FROM new_orders WHERE no_o_id = :no_o_id AND no_d_id = :d_id +-- AND no_w_id = :w_id;*/ + + con:query(([[DELETE FROM new_orders%d + WHERE no_o_id = %d + AND no_d_id = %d + AND no_w_id = %d]]) + :format(table_num, no_o_id, d_id, w_id)) + +-- SELECT o_c_id INTO :c_id FROM orders +-- WHERE o_id = :no_o_id AND o_d_id = :d_id +-- AND o_w_id = :w_id;*/ + + local o_c_id + o_c_id = con:query_row(([[SELECT o_c_id + FROM orders%d + WHERE o_id = %d + AND o_d_id = %d + AND o_w_id = %d]]) + :format(table_num, no_o_id, d_id, w_id)) + +-- UPDATE orders SET o_carrier_id = :o_carrier_id +-- WHERE o_id = :no_o_id AND o_d_id = :d_id AND +-- o_w_id = :w_id;*/ + + con:query(([[UPDATE orders%d + SET o_carrier_id = %d + WHERE o_id = %d + AND o_d_id = %d + AND o_w_id = %d]]) + :format(table_num, o_carrier_id, no_o_id, d_id, w_id)) + +-- UPDATE order_line +-- SET ol_delivery_d = :datetime +-- WHERE ol_o_id = :no_o_id AND ol_d_id = :d_id AND +-- ol_w_id = :w_id;*/ + con:query(([[UPDATE order_line%d + SET ol_delivery_d = NOW() + WHERE ol_o_id = %d + AND ol_d_id = %d + AND ol_w_id = %d]]) + :format(table_num, no_o_id, d_id, w_id)) + +-- SELECT SUM(ol_amount) INTO :ol_total +-- FROM order_line +-- WHERE ol_o_id = :no_o_id AND ol_d_id = :d_id +-- AND ol_w_id = :w_id;*/ + + local sm_ol_amount + sm_ol_amount = con:query_row(([[SELECT SUM(ol_amount) sm + FROM order_line%d + WHERE ol_o_id = %d + AND ol_d_id = %d + AND ol_w_id = %d]]) + :format(table_num, no_o_id, d_id, w_id)) + +-- UPDATE customer SET c_balance = c_balance + :ol_total , +-- c_delivery_cnt = c_delivery_cnt + 1 +-- WHERE c_id = :c_id AND c_d_id = :d_id AND +-- c_w_id = :w_id;*/ +-- print(string.format("update customer table %d, cid %d, did %d, wid %d balance %f",table_num, o_c_id, d_id, w_id, sm_ol_amount)) + con:query(([[UPDATE customer%d + SET c_balance = c_balance + %f, + c_delivery_cnt = c_delivery_cnt + 1 + WHERE c_id = %d + AND c_d_id = %d + AND c_w_id = %d]]) + :format(table_num, sm_ol_amount, o_c_id, d_id, w_id)) + end + + end + con:query("COMMIT") + +end + +function stocklevel() + local table_num = sysbench.rand.uniform(1, sysbench.opt.tables) + local w_id = sysbench.rand.uniform(1, sysbench.opt.scale) + local d_id = sysbench.rand.uniform(1, DIST_PER_WARE) + local level = sysbench.rand.uniform(10, 20) + + con:query("BEGIN") + +-- /*EXEC_SQL SELECT d_next_o_id +-- FROM district +-- WHERE d_id = :d_id +-- AND d_w_id = :w_id;*/ + +-- What variant of queries to use for stock_level transaction +-- case1 - specification +-- case2 - modified/simplified + + local stock_level_queries="case1" + local d_next_o_id + + + d_next_o_id = con:query_row(([[SELECT d_next_o_id + FROM district%d + WHERE d_id = %d AND d_w_id= %d]]) + :format( table_num, d_id, w_id)) + + if stock_level_queries == "case1" then + +--[[ + SELECT COUNT(DISTINCT (s_i_id)) INTO :stock_count + FROM order_line, stock + WHERE ol_w_id=:w_id AND ol_d_id=:d_id AND ol_o_id<:o_id AND ol_o_id>=:o_id-20 AND s_w_id=:w_id AND s_i_id=ol_i_id AND s_quantity < :threshold; +--]] + + rs = con:query(([[SELECT COUNT(DISTINCT (s_i_id)) + FROM order_line%d, stock%d + WHERE ol_w_id = %d + AND ol_d_id = %d + AND ol_o_id < %d + AND ol_o_id >= %d + AND s_w_id= %d + AND s_i_id=ol_i_id + AND s_quantity < %d ]]) + :format(table_num, table_num, w_id, d_id, d_next_o_id, d_next_o_id - 20, w_id, level )) + + + +-- SELECT DISTINCT ol_i_id +-- FROM order_line +-- WHERE ol_w_id = :w_id +-- AND ol_d_id = :d_id +-- AND ol_o_id < :d_next_o_id +-- AND ol_o_id >= (:d_next_o_id - 20); + + + else + + rs = con:query(([[SELECT DISTINCT ol_i_id FROM order_line%d + WHERE ol_w_id = %d AND ol_d_id = %d + AND ol_o_id < %d AND ol_o_id >= %d]]) + :format(table_num, w_id, d_id, d_next_o_id, d_next_o_id - 20 )) + + local ol_i_id + + for i = 1, rs.nrows do + ol_i_id = unpack(rs:fetch_row(), 1, rs.nfields) + + +-- SELECT count(*) INTO :i_count +-- FROM stock +-- WHERE s_w_id = :w_id +-- AND s_i_id = :ol_i_id +-- AND s_quantity < :level;*/ + + rs1 = con:query(([[SELECT count(*) FROM stock%d + WHERE s_w_id = %d AND s_i_id = %d + AND s_quantity < %d]]) + :format(table_num, w_id, ol_i_id, level ) ) + local cnt + for i = 1, rs1.nrows do + cnt = unpack(rs1:fetch_row(), 1, rs1.nfields) + end + + end + end + + con:query("COMMIT") + +end + +-- function purge to remove all orders, this is useful if we want to limit data directory in size + +function purge() + for i = 1, 10 do + local table_num = sysbench.rand.uniform(1, sysbench.opt.tables) + local w_id = sysbench.rand.uniform(1, sysbench.opt.scale) + local d_id = sysbench.rand.uniform(1, DIST_PER_WARE) + + con:query("BEGIN") + + local m_o_id + + rs = con:query(([[SELECT min(no_o_id) mo + FROM new_orders%d + WHERE no_w_id = %d AND no_d_id = %d]]) + :format(table_num, w_id, d_id)) + + if (rs.nrows > 0) then + m_o_id=unpack(rs:fetch_row(), 1, rs.nfields) + end + + if (m_o_id ~= nil ) then +-- select o_id,o.o_d_id from orders2 o, (select o_c_id,o_w_id,o_d_id,count(distinct o_id) from orders2 where o_w_id=1 and o_id > 2100 and o_id < 11153 group by o_c_id,o_d_id,o_w_id having count( distinct o_id) > 1 limit 1) t where t.o_w_id=o.o_w_id and t.o_d_id=o.o_d_id and t.o_c_id=o.o_c_id limit 1; + -- find an order to delete + rs = con:query(([[SELECT o_id FROM orders%d o, (SELECT o_c_id,o_w_id,o_d_id,count(distinct o_id) FROM orders%d WHERE o_w_id=%d AND o_d_id=%d AND o_id > 2100 AND o_id < %d GROUP BY o_c_id,o_d_id,o_w_id having count( distinct o_id) > 1 limit 1) t WHERE t.o_w_id=o.o_w_id and t.o_d_id=o.o_d_id and t.o_c_id=o.o_c_id limit 1 ]]) + :format(table_num, table_num, w_id, d_id, m_o_id)) + + local del_o_id + if (rs.nrows > 0) then + del_o_id=unpack(rs:fetch_row(), 1, rs.nfields) + end + + if (del_o_id ~= nil ) then + + con:query(([[DELETE FROM order_line%d where ol_w_id=%d AND ol_d_id=%d AND ol_o_id=%d]]) + :format(table_num, w_id, d_id, del_o_id)) + con:query(([[DELETE FROM orders%d where o_w_id=%d AND o_d_id=%d and o_id=%d]]) + :format(table_num, w_id, d_id, del_o_id)) + con:query(([[DELETE FROM history%d where h_w_id=%d AND h_d_id=%d LIMIT 10]]) + :format(table_num, w_id, d_id )) + + end + + end + + con:query("COMMIT") + end +end + +-- vim:ts=4 ss=4 sw=4 expandtab From ed486684cbe106ac6d250dd22d94753160278f31 Mon Sep 17 00:00:00 2001 From: digoal Date: Thu, 13 Sep 2018 13:43:07 +0800 Subject: [PATCH 02/14] improve --- result_pg_11_tpcc.txt | 285 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 285 insertions(+) create mode 100644 result_pg_11_tpcc.txt diff --git a/result_pg_11_tpcc.txt b/result_pg_11_tpcc.txt new file mode 100644 index 0000000..12599a8 --- /dev/null +++ b/result_pg_11_tpcc.txt @@ -0,0 +1,285 @@ +# test env +Aliyun ECS + +free -g + total used free shared buff/cache available +Mem: 503 3 240 65 259 432 +Swap: 0 0 0 + +lscpu +Architecture: x86_64 +CPU op-mode(s): 32-bit, 64-bit +Byte Order: Little Endian +CPU(s): 64 +On-line CPU(s) list: 0-63 +Thread(s) per core: 2 +Core(s) per socket: 32 +Socket(s): 1 +NUMA node(s): 1 +Vendor ID: GenuineIntel +CPU family: 6 +Model: 85 +Model name: Intel(R) Xeon(R) Platinum 8163 CPU @ 2.50GHz +Stepping: 4 +CPU MHz: 2500.008 +BogoMIPS: 5000.01 +Hypervisor vendor: KVM +Virtualization type: full +L1d cache: 32K +L1i cache: 32K +L2 cache: 1024K +L3 cache: 33792K +NUMA node0 CPU(s): 0-63 +Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 + +df -h +Filesystem Size Used Avail Use% Mounted on +/dev/vda1 197G 4.2G 183G 3% / +devtmpfs 252G 0 252G 0% /dev +tmpfs 252G 8.5M 252G 1% /dev/shm +tmpfs 252G 556K 252G 1% /run +tmpfs 252G 0 252G 0% /sys/fs/cgroup +/dev/mapper/vgdata01-lv03 4.0T 441G 3.6T 11% /data03 +/dev/mapper/vgdata01-lv02 4.0T 339G 3.7T 9% /data02 +/dev/mapper/vgdata01-lv01 4.0T 660G 3.4T 17% /data01 +tmpfs 51G 0 51G 0% /run/user/0 + +# result +./tpcc.lua --pgsql-host=/tmp --pgsql-port=1921 --pgsql-user=postgres --pgsql-db=postgres --time=600 --threads=64 --report-interval=3 --tables=10 --scale=100 --trx_level=RC --db-driver=pgsql run +sysbench 1.0.15 (using bundled LuaJIT 2.1.0-beta2) + +Running the test with following options: +Number of threads: 64 +Report intermediate results every 3 second(s) +Initializing random number generator from current time + + +Initializing worker threads... + +Threads started! + +[ 3s ] thds: 64 tps: 12685.36 qps: 371763.65 (r/w/o: 164762.15/170932.67/36068.83) lat (ms,95%): 12.75 err/s 53.94 reconn/s: 0.00 +[ 6s ] thds: 64 tps: 15308.11 qps: 435366.55 (r/w/o: 198545.22/206205.11/30616.22) lat (ms,95%): 10.27 err/s 65.03 reconn/s: 0.00 +[ 9s ] thds: 64 tps: 15472.80 qps: 440416.11 (r/w/o: 200906.46/208564.37/30945.27) lat (ms,95%): 10.27 err/s 67.66 reconn/s: 0.00 +[ 12s ] thds: 64 tps: 15752.04 qps: 444756.08 (r/w/o: 202714.00/210537.68/31504.41) lat (ms,95%): 10.27 err/s 64.34 reconn/s: 0.00 +[ 15s ] thds: 64 tps: 15960.39 qps: 452761.93 (r/w/o: 206430.73/214410.76/31920.45) lat (ms,95%): 9.91 err/s 66.00 reconn/s: 0.00 +[ 18s ] thds: 64 tps: 15399.04 qps: 439089.37 (r/w/o: 200194.14/208096.83/30798.41) lat (ms,95%): 10.09 err/s 62.67 reconn/s: 0.00 +[ 21s ] thds: 64 tps: 16144.29 qps: 458680.78 (r/w/o: 209193.78/217198.76/32288.24) lat (ms,95%): 9.91 err/s 70.00 reconn/s: 0.00 +[ 24s ] thds: 64 tps: 16385.94 qps: 469205.27 (r/w/o: 214064.13/222368.93/32772.20) lat (ms,95%): 9.73 err/s 74.66 reconn/s: 0.00 +[ 27s ] thds: 64 tps: 15977.57 qps: 455018.46 (r/w/o: 207678.35/215385.31/31954.80) lat (ms,95%): 9.73 err/s 64.00 reconn/s: 0.00 +[ 30s ] thds: 64 tps: 16394.12 qps: 462351.06 (r/w/o: 210802.72/218759.76/32788.58) lat (ms,95%): 9.73 err/s 67.01 reconn/s: 0.00 +[ 33s ] thds: 64 tps: 16761.76 qps: 478247.29 (r/w/o: 218173.95/226550.16/33523.18) lat (ms,95%): 9.22 err/s 76.27 reconn/s: 0.00 +[ 36s ] thds: 64 tps: 15733.39 qps: 447029.24 (r/w/o: 203907.19/211654.95/31467.10) lat (ms,95%): 9.22 err/s 66.72 reconn/s: 0.00 +[ 39s ] thds: 64 tps: 16862.89 qps: 475272.32 (r/w/o: 216736.63/224810.92/33724.77) lat (ms,95%): 9.39 err/s 72.66 reconn/s: 0.00 +[ 42s ] thds: 64 tps: 16424.74 qps: 468518.57 (r/w/o: 213843.28/221825.81/32849.48) lat (ms,95%): 9.56 err/s 72.34 reconn/s: 0.00 +[ 45s ] thds: 64 tps: 16679.21 qps: 473711.48 (r/w/o: 216142.13/224209.92/33359.42) lat (ms,95%): 9.56 err/s 76.33 reconn/s: 0.00 +[ 48s ] thds: 64 tps: 16492.65 qps: 467785.55 (r/w/o: 213398.98/221401.28/32985.29) lat (ms,95%): 9.73 err/s 65.34 reconn/s: 0.00 +[ 51s ] thds: 64 tps: 15617.14 qps: 443160.43 (r/w/o: 202139.87/209786.95/31233.62) lat (ms,95%): 9.73 err/s 67.33 reconn/s: 0.00 +[ 54s ] thds: 64 tps: 16237.84 qps: 463967.24 (r/w/o: 211760.90/219730.99/32475.34) lat (ms,95%): 9.73 err/s 77.00 reconn/s: 0.00 +[ 57s ] thds: 64 tps: 16861.01 qps: 480092.45 (r/w/o: 218968.13/227401.30/33723.02) lat (ms,95%): 9.39 err/s 76.33 reconn/s: 0.00 +[ 60s ] thds: 64 tps: 16474.08 qps: 468649.83 (r/w/o: 213752.06/221949.94/32947.83) lat (ms,95%): 9.73 err/s 63.33 reconn/s: 0.00 +[ 63s ] thds: 64 tps: 16404.26 qps: 464777.90 (r/w/o: 211904.63/220064.43/32808.84) lat (ms,95%): 9.73 err/s 66.00 reconn/s: 0.00 +[ 66s ] thds: 64 tps: 16781.41 qps: 476743.72 (r/w/o: 217408.01/225773.55/33562.15) lat (ms,95%): 9.39 err/s 66.67 reconn/s: 0.00 +[ 69s ] thds: 64 tps: 16230.69 qps: 461251.50 (r/w/o: 210451.05/218338.40/32462.06) lat (ms,95%): 9.56 err/s 69.33 reconn/s: 0.00 +[ 72s ] thds: 64 tps: 16249.77 qps: 460457.17 (r/w/o: 209964.29/217993.67/32499.21) lat (ms,95%): 9.91 err/s 71.34 reconn/s: 0.00 +[ 75s ] thds: 64 tps: 15680.47 qps: 446166.40 (r/w/o: 203648.50/211157.29/31360.61) lat (ms,95%): 9.73 err/s 66.32 reconn/s: 0.00 +[ 78s ] thds: 64 tps: 16596.98 qps: 474419.12 (r/w/o: 216545.18/224679.65/33194.29) lat (ms,95%): 9.39 err/s 72.01 reconn/s: 0.00 +[ 81s ] thds: 64 tps: 16517.85 qps: 471434.95 (r/w/o: 215084.74/223314.50/33035.71) lat (ms,95%): 9.56 err/s 70.00 reconn/s: 0.00 +[ 84s ] thds: 64 tps: 16349.85 qps: 464468.50 (r/w/o: 211953.36/219815.44/32699.70) lat (ms,95%): 9.73 err/s 72.34 reconn/s: 0.00 +[ 87s ] thds: 64 tps: 16411.97 qps: 465186.45 (r/w/o: 212106.60/220255.92/32823.94) lat (ms,95%): 9.73 err/s 60.67 reconn/s: 0.00 +[ 90s ] thds: 64 tps: 16549.92 qps: 473098.75 (r/w/o: 215904.23/224094.69/33099.84) lat (ms,95%): 9.73 err/s 83.99 reconn/s: 0.00 +[ 93s ] thds: 64 tps: 15616.52 qps: 443803.98 (r/w/o: 202548.75/210021.52/31233.70) lat (ms,95%): 9.91 err/s 68.33 reconn/s: 0.00 +[ 96s ] thds: 64 tps: 16213.60 qps: 461744.21 (r/w/o: 210738.86/218578.82/32426.54) lat (ms,95%): 9.91 err/s 70.34 reconn/s: 0.00 +[ 99s ] thds: 64 tps: 16576.58 qps: 469367.65 (r/w/o: 214146.26/222067.89/33153.50) lat (ms,95%): 9.73 err/s 65.00 reconn/s: 0.00 +[ 102s ] thds: 64 tps: 16277.77 qps: 462477.20 (r/w/o: 210977.31/218944.36/32555.53) lat (ms,95%): 9.91 err/s 61.00 reconn/s: 0.00 +[ 105s ] thds: 64 tps: 16042.95 qps: 457617.65 (r/w/o: 208733.05/216799.36/32085.24) lat (ms,95%): 10.09 err/s 68.33 reconn/s: 0.00 +[ 108s ] thds: 64 tps: 15939.03 qps: 457439.73 (r/w/o: 208692.10/216868.91/31878.72) lat (ms,95%): 10.09 err/s 66.32 reconn/s: 0.00 +[ 111s ] thds: 64 tps: 16360.02 qps: 465873.98 (r/w/o: 212553.57/220600.37/32720.04) lat (ms,95%): 9.73 err/s 71.02 reconn/s: 0.00 +[ 114s ] thds: 64 tps: 16473.79 qps: 467096.48 (r/w/o: 213058.92/221090.32/32947.24) lat (ms,95%): 9.91 err/s 67.00 reconn/s: 0.00 +[ 117s ] thds: 64 tps: 16383.51 qps: 465041.45 (r/w/o: 212069.00/220205.09/32767.36) lat (ms,95%): 9.91 err/s 85.33 reconn/s: 0.00 +[ 120s ] thds: 64 tps: 16433.19 qps: 468602.32 (r/w/o: 213768.10/221968.19/32866.04) lat (ms,95%): 9.73 err/s 69.00 reconn/s: 0.00 +[ 123s ] thds: 64 tps: 16040.45 qps: 458075.32 (r/w/o: 208970.51/217023.91/32080.90) lat (ms,95%): 10.09 err/s 76.67 reconn/s: 0.00 +[ 126s ] thds: 64 tps: 16700.62 qps: 475440.07 (r/w/o: 216994.09/225044.40/33401.58) lat (ms,95%): 9.56 err/s 78.00 reconn/s: 0.00 +[ 129s ] thds: 64 tps: 16527.35 qps: 467064.56 (r/w/o: 212973.59/221036.61/33054.36) lat (ms,95%): 9.73 err/s 69.00 reconn/s: 0.00 +[ 132s ] thds: 64 tps: 16580.67 qps: 469907.70 (r/w/o: 214293.79/222452.57/33161.35) lat (ms,95%): 9.56 err/s 76.50 reconn/s: 0.00 +[ 135s ] thds: 64 tps: 16655.01 qps: 473220.50 (r/w/o: 215822.72/224087.43/33310.36) lat (ms,95%): 9.56 err/s 73.15 reconn/s: 0.00 +[ 138s ] thds: 64 tps: 16439.44 qps: 467519.79 (r/w/o: 213365.69/221275.55/32878.55) lat (ms,95%): 9.73 err/s 76.01 reconn/s: 0.00 +[ 141s ] thds: 64 tps: 16613.67 qps: 473130.41 (r/w/o: 215752.11/224150.61/33227.68) lat (ms,95%): 9.56 err/s 69.33 reconn/s: 0.00 +[ 144s ] thds: 64 tps: 16475.56 qps: 469145.65 (r/w/o: 214001.29/222193.24/32951.12) lat (ms,95%): 9.73 err/s 74.00 reconn/s: 0.00 +[ 147s ] thds: 64 tps: 16708.69 qps: 477001.94 (r/w/o: 217565.68/226019.20/33417.06) lat (ms,95%): 9.56 err/s 79.67 reconn/s: 0.00 +[ 150s ] thds: 64 tps: 16771.18 qps: 476995.57 (r/w/o: 217498.98/225954.24/33542.36) lat (ms,95%): 9.39 err/s 73.00 reconn/s: 0.00 +[ 153s ] thds: 64 tps: 17128.46 qps: 487748.25 (r/w/o: 222447.38/231043.61/34257.26) lat (ms,95%): 9.39 err/s 84.33 reconn/s: 0.00 +[ 156s ] thds: 64 tps: 17183.34 qps: 488150.56 (r/w/o: 222534.61/231249.59/34366.36) lat (ms,95%): 9.22 err/s 70.32 reconn/s: 0.00 +[ 159s ] thds: 64 tps: 17294.04 qps: 491226.89 (r/w/o: 224136.08/232503.06/34587.75) lat (ms,95%): 9.06 err/s 73.01 reconn/s: 0.00 +[ 162s ] thds: 64 tps: 17085.99 qps: 483986.11 (r/w/o: 220804.90/229008.90/34172.32) lat (ms,95%): 9.22 err/s 79.33 reconn/s: 0.00 +[ 165s ] thds: 64 tps: 16588.05 qps: 469852.45 (r/w/o: 214345.40/222330.93/33176.11) lat (ms,95%): 9.06 err/s 71.67 reconn/s: 0.00 +[ 168s ] thds: 64 tps: 16881.65 qps: 479911.39 (r/w/o: 218936.80/227210.95/33763.64) lat (ms,95%): 9.39 err/s 65.33 reconn/s: 0.00 +[ 171s ] thds: 64 tps: 16976.49 qps: 482543.39 (r/w/o: 220147.34/228443.08/33952.97) lat (ms,95%): 9.39 err/s 66.33 reconn/s: 0.00 +[ 174s ] thds: 64 tps: 16813.80 qps: 478021.19 (r/w/o: 218108.76/226285.16/33627.27) lat (ms,95%): 9.39 err/s 71.00 reconn/s: 0.00 +[ 177s ] thds: 64 tps: 16995.98 qps: 485841.70 (r/w/o: 221552.78/230296.61/33992.30) lat (ms,95%): 9.22 err/s 67.00 reconn/s: 0.00 +[ 180s ] thds: 64 tps: 17008.86 qps: 481399.84 (r/w/o: 219657.18/227724.94/34017.72) lat (ms,95%): 9.39 err/s 67.00 reconn/s: 0.00 +[ 183s ] thds: 64 tps: 16608.30 qps: 468036.04 (r/w/o: 213490.72/221329.39/33215.94) lat (ms,95%): 9.56 err/s 68.00 reconn/s: 0.00 +[ 186s ] thds: 64 tps: 16600.38 qps: 472656.86 (r/w/o: 215556.29/223899.48/33201.09) lat (ms,95%): 9.39 err/s 77.33 reconn/s: 0.00 +[ 189s ] thds: 64 tps: 17049.81 qps: 485303.34 (r/w/o: 221378.83/229824.56/34099.95) lat (ms,95%): 9.22 err/s 75.67 reconn/s: 0.00 +[ 192s ] thds: 64 tps: 17105.49 qps: 483795.39 (r/w/o: 220649.41/228935.33/34210.65) lat (ms,95%): 9.22 err/s 73.00 reconn/s: 0.00 +[ 195s ] thds: 64 tps: 16894.74 qps: 481737.66 (r/w/o: 219958.32/227989.53/33789.82) lat (ms,95%): 9.22 err/s 78.00 reconn/s: 0.00 +[ 198s ] thds: 64 tps: 16897.47 qps: 478789.12 (r/w/o: 218473.39/226520.79/33794.93) lat (ms,95%): 9.39 err/s 74.67 reconn/s: 0.00 +[ 201s ] thds: 64 tps: 16721.40 qps: 477133.37 (r/w/o: 217662.19/226028.72/33442.46) lat (ms,95%): 9.39 err/s 73.34 reconn/s: 0.00 +[ 204s ] thds: 64 tps: 16868.14 qps: 478510.44 (r/w/o: 218265.80/226508.70/33735.94) lat (ms,95%): 9.39 err/s 76.00 reconn/s: 0.00 +[ 207s ] thds: 64 tps: 16916.98 qps: 479656.51 (r/w/o: 218808.44/227013.77/33834.30) lat (ms,95%): 9.39 err/s 68.00 reconn/s: 0.00 +[ 210s ] thds: 64 tps: 16883.93 qps: 480488.21 (r/w/o: 219152.11/227567.91/33768.20) lat (ms,95%): 9.39 err/s 77.00 reconn/s: 0.00 +[ 213s ] thds: 64 tps: 17023.17 qps: 480935.97 (r/w/o: 219422.93/227466.70/34046.34) lat (ms,95%): 9.22 err/s 68.66 reconn/s: 0.00 +[ 216s ] thds: 64 tps: 17059.26 qps: 485355.76 (r/w/o: 221391.05/229846.85/34117.85) lat (ms,95%): 9.06 err/s 80.00 reconn/s: 0.00 +[ 219s ] thds: 64 tps: 17108.51 qps: 487948.98 (r/w/o: 222666.61/231064.69/34217.68) lat (ms,95%): 9.22 err/s 72.00 reconn/s: 0.00 +[ 222s ] thds: 64 tps: 16930.81 qps: 482541.89 (r/w/o: 220176.93/228504.00/33860.96) lat (ms,95%): 9.39 err/s 67.33 reconn/s: 0.00 +[ 225s ] thds: 64 tps: 16957.81 qps: 481596.81 (r/w/o: 219732.15/227948.38/33916.28) lat (ms,95%): 9.22 err/s 68.33 reconn/s: 0.00 +[ 228s ] thds: 64 tps: 17246.05 qps: 488487.58 (r/w/o: 222757.90/231237.59/34492.10) lat (ms,95%): 9.06 err/s 70.00 reconn/s: 0.00 +[ 231s ] thds: 64 tps: 17132.54 qps: 484342.74 (r/w/o: 221023.65/229054.34/34264.75) lat (ms,95%): 9.22 err/s 73.32 reconn/s: 0.00 +[ 234s ] thds: 64 tps: 17107.09 qps: 484879.11 (r/w/o: 221161.96/229503.64/34213.51) lat (ms,95%): 9.22 err/s 77.35 reconn/s: 0.00 +[ 237s ] thds: 64 tps: 17010.66 qps: 486065.15 (r/w/o: 221686.58/230356.58/34021.99) lat (ms,95%): 9.22 err/s 83.00 reconn/s: 0.00 +[ 240s ] thds: 64 tps: 16939.96 qps: 482108.85 (r/w/o: 219885.48/228343.46/33879.92) lat (ms,95%): 9.39 err/s 75.33 reconn/s: 0.00 +[ 243s ] thds: 64 tps: 16742.81 qps: 478657.18 (r/w/o: 218277.24/226893.98/33485.96) lat (ms,95%): 9.56 err/s 64.33 reconn/s: 0.00 +[ 246s ] thds: 64 tps: 16435.43 qps: 470599.11 (r/w/o: 214855.93/222872.32/32870.87) lat (ms,95%): 9.39 err/s 68.66 reconn/s: 0.00 +[ 249s ] thds: 64 tps: 17045.92 qps: 482287.02 (r/w/o: 220069.28/228125.89/34091.85) lat (ms,95%): 9.22 err/s 68.67 reconn/s: 0.00 +[ 252s ] thds: 64 tps: 17070.38 qps: 485935.93 (r/w/o: 221683.57/230111.93/34140.42) lat (ms,95%): 9.22 err/s 80.00 reconn/s: 0.00 +[ 255s ] thds: 64 tps: 16908.57 qps: 484649.81 (r/w/o: 221186.36/229645.98/33817.47) lat (ms,95%): 9.39 err/s 67.00 reconn/s: 0.00 +[ 258s ] thds: 64 tps: 17074.03 qps: 483034.58 (r/w/o: 220418.75/228468.10/34147.73) lat (ms,95%): 9.22 err/s 76.67 reconn/s: 0.00 +[ 261s ] thds: 64 tps: 16955.61 qps: 480106.27 (r/w/o: 218991.54/227203.18/33911.54) lat (ms,95%): 9.39 err/s 71.00 reconn/s: 0.00 +[ 264s ] thds: 64 tps: 16896.89 qps: 480915.13 (r/w/o: 219391.21/227730.82/33793.11) lat (ms,95%): 9.22 err/s 64.67 reconn/s: 0.00 +[ 267s ] thds: 64 tps: 17121.76 qps: 484935.45 (r/w/o: 221236.27/229455.65/34243.53) lat (ms,95%): 9.22 err/s 64.33 reconn/s: 0.00 +[ 270s ] thds: 64 tps: 16993.73 qps: 483434.69 (r/w/o: 220501.77/228944.80/33988.12) lat (ms,95%): 9.22 err/s 68.67 reconn/s: 0.00 +[ 273s ] thds: 64 tps: 17241.68 qps: 489334.34 (r/w/o: 223159.15/231692.16/34483.02) lat (ms,95%): 9.22 err/s 70.67 reconn/s: 0.00 +[ 276s ] thds: 64 tps: 17218.60 qps: 490397.31 (r/w/o: 223680.41/232279.37/34437.52) lat (ms,95%): 9.06 err/s 82.00 reconn/s: 0.00 +[ 279s ] thds: 64 tps: 17051.33 qps: 483003.75 (r/w/o: 220412.56/228488.54/34102.66) lat (ms,95%): 9.39 err/s 71.00 reconn/s: 0.00 +[ 282s ] thds: 64 tps: 17261.78 qps: 489124.09 (r/w/o: 223106.49/231494.38/34523.23) lat (ms,95%): 9.22 err/s 70.33 reconn/s: 0.00 +[ 285s ] thds: 64 tps: 17082.96 qps: 484509.74 (r/w/o: 221029.76/229315.07/34164.91) lat (ms,95%): 9.22 err/s 81.33 reconn/s: 0.00 +[ 288s ] thds: 64 tps: 16836.13 qps: 479662.36 (r/w/o: 218768.69/227220.08/33673.59) lat (ms,95%): 9.39 err/s 69.00 reconn/s: 0.00 +[ 291s ] thds: 64 tps: 16989.32 qps: 484789.51 (r/w/o: 221281.78/229529.10/33978.63) lat (ms,95%): 9.22 err/s 70.67 reconn/s: 0.00 +[ 294s ] thds: 64 tps: 17136.65 qps: 486752.44 (r/w/o: 222002.15/230476.98/34273.31) lat (ms,95%): 9.22 err/s 82.00 reconn/s: 0.00 +[ 297s ] thds: 64 tps: 17178.54 qps: 487178.69 (r/w/o: 222279.67/230542.28/34356.74) lat (ms,95%): 9.22 err/s 73.00 reconn/s: 0.00 +[ 300s ] thds: 64 tps: 16972.59 qps: 484985.30 (r/w/o: 221299.66/229740.13/33945.51) lat (ms,95%): 9.39 err/s 75.66 reconn/s: 0.00 +[ 303s ] thds: 64 tps: 17104.06 qps: 484859.01 (r/w/o: 221185.02/229465.88/34208.11) lat (ms,95%): 9.22 err/s 82.34 reconn/s: 0.00 +[ 306s ] thds: 64 tps: 16758.56 qps: 477539.74 (r/w/o: 217808.66/226213.95/33517.13) lat (ms,95%): 9.56 err/s 72.33 reconn/s: 0.00 +[ 309s ] thds: 64 tps: 16258.91 qps: 463757.36 (r/w/o: 211531.13/219708.42/32517.81) lat (ms,95%): 9.56 err/s 72.33 reconn/s: 0.00 +[ 312s ] thds: 64 tps: 16907.19 qps: 480938.11 (r/w/o: 219455.49/227668.58/33814.05) lat (ms,95%): 9.39 err/s 73.67 reconn/s: 0.00 +[ 315s ] thds: 64 tps: 16611.76 qps: 474246.95 (r/w/o: 216410.53/224612.57/33223.85) lat (ms,95%): 9.73 err/s 74.00 reconn/s: 0.00 +[ 318s ] thds: 64 tps: 16553.80 qps: 471770.68 (r/w/o: 215178.35/223484.74/33107.59) lat (ms,95%): 9.56 err/s 72.33 reconn/s: 0.00 +[ 321s ] thds: 64 tps: 16889.06 qps: 480302.06 (r/w/o: 219071.38/227453.57/33777.11) lat (ms,95%): 9.39 err/s 73.67 reconn/s: 0.00 +[ 324s ] thds: 64 tps: 16788.94 qps: 476175.30 (r/w/o: 217272.63/225325.11/33577.56) lat (ms,95%): 9.56 err/s 72.00 reconn/s: 0.00 +[ 327s ] thds: 64 tps: 16594.65 qps: 468864.25 (r/w/o: 213914.40/221759.22/33190.63) lat (ms,95%): 9.22 err/s 80.00 reconn/s: 0.00 +[ 330s ] thds: 64 tps: 16085.38 qps: 456032.52 (r/w/o: 208105.88/215755.90/32170.75) lat (ms,95%): 9.22 err/s 82.00 reconn/s: 0.00 +[ 333s ] thds: 64 tps: 17091.15 qps: 485507.53 (r/w/o: 221462.58/229862.65/34182.30) lat (ms,95%): 9.22 err/s 72.33 reconn/s: 0.00 +[ 336s ] thds: 64 tps: 16867.06 qps: 480268.18 (r/w/o: 219055.18/227479.88/33733.13) lat (ms,95%): 9.06 err/s 74.00 reconn/s: 0.00 +[ 339s ] thds: 64 tps: 17417.60 qps: 493103.17 (r/w/o: 224889.17/233378.47/34835.54) lat (ms,95%): 8.90 err/s 76.00 reconn/s: 0.00 +[ 342s ] thds: 64 tps: 17130.76 qps: 487127.76 (r/w/o: 222257.59/230607.97/34262.19) lat (ms,95%): 9.22 err/s 70.00 reconn/s: 0.00 +[ 345s ] thds: 64 tps: 17197.15 qps: 488296.03 (r/w/o: 222777.91/231124.16/34393.96) lat (ms,95%): 9.22 err/s 80.33 reconn/s: 0.00 +[ 348s ] thds: 64 tps: 16809.03 qps: 481698.62 (r/w/o: 219807.44/228273.45/33617.73) lat (ms,95%): 9.39 err/s 73.67 reconn/s: 0.00 +[ 351s ] thds: 64 tps: 17140.59 qps: 483906.29 (r/w/o: 220730.99/228893.79/34281.50) lat (ms,95%): 9.22 err/s 74.00 reconn/s: 0.00 +[ 354s ] thds: 64 tps: 17167.90 qps: 486047.61 (r/w/o: 221571.35/230140.13/34336.13) lat (ms,95%): 9.06 err/s 74.33 reconn/s: 0.00 +[ 357s ] thds: 64 tps: 17281.56 qps: 493767.79 (r/w/o: 225408.28/233796.72/34562.78) lat (ms,95%): 9.06 err/s 72.33 reconn/s: 0.00 +[ 360s ] thds: 64 tps: 16630.93 qps: 472919.62 (r/w/o: 215685.73/223971.70/33262.19) lat (ms,95%): 9.22 err/s 63.33 reconn/s: 0.00 +[ 363s ] thds: 64 tps: 17100.91 qps: 488269.14 (r/w/o: 222629.18/231438.13/34201.82) lat (ms,95%): 9.22 err/s 73.67 reconn/s: 0.00 +[ 366s ] thds: 64 tps: 17086.87 qps: 486060.01 (r/w/o: 221694.00/230193.27/34172.74) lat (ms,95%): 9.39 err/s 71.00 reconn/s: 0.00 +[ 369s ] thds: 64 tps: 16290.75 qps: 465298.48 (r/w/o: 212171.72/220544.59/32582.16) lat (ms,95%): 9.56 err/s 64.67 reconn/s: 0.00 +[ 372s ] thds: 64 tps: 16780.93 qps: 477020.14 (r/w/o: 217474.40/225983.54/33562.19) lat (ms,95%): 9.56 err/s 69.67 reconn/s: 0.00 +[ 375s ] thds: 64 tps: 16676.57 qps: 472461.46 (r/w/o: 215520.77/223587.56/33353.14) lat (ms,95%): 9.22 err/s 73.33 reconn/s: 0.00 +[ 378s ] thds: 64 tps: 16736.97 qps: 474330.02 (r/w/o: 216324.55/224531.52/33473.95) lat (ms,95%): 9.56 err/s 82.34 reconn/s: 0.00 +[ 381s ] thds: 64 tps: 16391.51 qps: 466778.48 (r/w/o: 212888.02/221107.44/32783.03) lat (ms,95%): 9.73 err/s 81.00 reconn/s: 0.00 +[ 384s ] thds: 64 tps: 16640.92 qps: 472157.64 (r/w/o: 215382.67/223493.47/33281.51) lat (ms,95%): 9.39 err/s 71.33 reconn/s: 0.00 +[ 387s ] thds: 64 tps: 16723.60 qps: 474601.42 (r/w/o: 216418.13/224736.43/33446.87) lat (ms,95%): 9.56 err/s 76.67 reconn/s: 0.00 +[ 390s ] thds: 64 tps: 16759.33 qps: 476885.50 (r/w/o: 217677.33/225689.51/33518.67) lat (ms,95%): 9.39 err/s 76.33 reconn/s: 0.00 +[ 393s ] thds: 64 tps: 16444.27 qps: 469313.23 (r/w/o: 214109.45/222314.92/32888.87) lat (ms,95%): 9.39 err/s 68.00 reconn/s: 0.00 +[ 396s ] thds: 64 tps: 16474.72 qps: 466475.46 (r/w/o: 212834.67/220691.36/32949.44) lat (ms,95%): 9.39 err/s 66.67 reconn/s: 0.00 +[ 399s ] thds: 64 tps: 16766.69 qps: 477942.64 (r/w/o: 217942.96/226465.97/33533.71) lat (ms,95%): 9.56 err/s 65.67 reconn/s: 0.00 +[ 402s ] thds: 64 tps: 16776.64 qps: 478033.50 (r/w/o: 218041.36/226438.85/33553.29) lat (ms,95%): 9.39 err/s 70.67 reconn/s: 0.00 +[ 405s ] thds: 64 tps: 17035.83 qps: 480716.48 (r/w/o: 219312.12/227333.37/34070.99) lat (ms,95%): 9.39 err/s 79.00 reconn/s: 0.00 +[ 408s ] thds: 64 tps: 16978.36 qps: 483357.82 (r/w/o: 220608.37/228792.39/33957.06) lat (ms,95%): 9.22 err/s 72.33 reconn/s: 0.00 +[ 411s ] thds: 64 tps: 16751.25 qps: 477581.14 (r/w/o: 217834.92/226243.72/33502.50) lat (ms,95%): 9.22 err/s 71.67 reconn/s: 0.00 +[ 414s ] thds: 64 tps: 16818.41 qps: 477492.28 (r/w/o: 217761.38/226093.75/33637.16) lat (ms,95%): 9.39 err/s 70.66 reconn/s: 0.00 +[ 417s ] thds: 64 tps: 16734.59 qps: 476639.00 (r/w/o: 217432.60/225738.23/33468.17) lat (ms,95%): 9.39 err/s 72.00 reconn/s: 0.00 +[ 420s ] thds: 64 tps: 16819.41 qps: 478411.72 (r/w/o: 218290.61/226481.97/33639.14) lat (ms,95%): 9.39 err/s 74.00 reconn/s: 0.00 +[ 423s ] thds: 64 tps: 16684.65 qps: 476768.16 (r/w/o: 217554.43/225844.43/33369.31) lat (ms,95%): 9.56 err/s 79.32 reconn/s: 0.00 +[ 426s ] thds: 64 tps: 16360.93 qps: 468054.61 (r/w/o: 213686.90/221645.84/32721.86) lat (ms,95%): 9.56 err/s 72.01 reconn/s: 0.00 +[ 429s ] thds: 64 tps: 16951.46 qps: 482720.23 (r/w/o: 220194.70/228622.60/33902.93) lat (ms,95%): 9.39 err/s 84.00 reconn/s: 0.00 +[ 432s ] thds: 64 tps: 16664.66 qps: 471740.93 (r/w/o: 215151.64/223259.64/33329.66) lat (ms,95%): 9.73 err/s 78.00 reconn/s: 0.00 +[ 435s ] thds: 64 tps: 16660.85 qps: 473381.45 (r/w/o: 215944.67/224114.76/33322.03) lat (ms,95%): 9.73 err/s 69.00 reconn/s: 0.00 +[ 438s ] thds: 64 tps: 16521.71 qps: 472935.78 (r/w/o: 215720.84/224171.85/33043.08) lat (ms,95%): 9.56 err/s 67.66 reconn/s: 0.00 +[ 441s ] thds: 64 tps: 16348.78 qps: 462400.11 (r/w/o: 210900.83/218801.38/32697.90) lat (ms,95%): 9.39 err/s 73.00 reconn/s: 0.00 +[ 444s ] thds: 64 tps: 16622.13 qps: 473560.92 (r/w/o: 216074.38/224242.28/33244.26) lat (ms,95%): 9.56 err/s 79.67 reconn/s: 0.00 +[ 447s ] thds: 64 tps: 16758.93 qps: 474915.23 (r/w/o: 216502.71/224895.00/33517.52) lat (ms,95%): 9.56 err/s 63.33 reconn/s: 0.00 +[ 450s ] thds: 64 tps: 16524.06 qps: 470065.41 (r/w/o: 214567.05/222449.91/33048.45) lat (ms,95%): 9.73 err/s 67.33 reconn/s: 0.00 +[ 453s ] thds: 64 tps: 16643.17 qps: 471929.82 (r/w/o: 215282.61/223360.86/33286.35) lat (ms,95%): 9.56 err/s 74.00 reconn/s: 0.00 +[ 456s ] thds: 64 tps: 16743.50 qps: 477052.66 (r/w/o: 217578.79/225987.21/33486.66) lat (ms,95%): 9.56 err/s 69.33 reconn/s: 0.00 +[ 459s ] thds: 64 tps: 16828.50 qps: 476405.50 (r/w/o: 217292.20/225456.29/33657.00) lat (ms,95%): 9.39 err/s 75.66 reconn/s: 0.00 +[ 462s ] thds: 64 tps: 16402.34 qps: 468310.80 (r/w/o: 213633.41/221872.38/32805.01) lat (ms,95%): 9.56 err/s 71.27 reconn/s: 0.00 +[ 465s ] thds: 64 tps: 16726.24 qps: 473350.85 (r/w/o: 215918.40/223980.98/33451.48) lat (ms,95%): 9.56 err/s 80.72 reconn/s: 0.00 +[ 468s ] thds: 64 tps: 16692.83 qps: 474738.47 (r/w/o: 216524.04/224828.44/33386.00) lat (ms,95%): 9.56 err/s 64.01 reconn/s: 0.00 +[ 471s ] thds: 64 tps: 16756.56 qps: 476568.41 (r/w/o: 217473.93/225580.70/33513.78) lat (ms,95%): 9.39 err/s 70.33 reconn/s: 0.00 +[ 474s ] thds: 64 tps: 16799.76 qps: 477347.85 (r/w/o: 217730.56/226018.11/33599.18) lat (ms,95%): 9.39 err/s 75.66 reconn/s: 0.00 +[ 477s ] thds: 64 tps: 16821.19 qps: 478079.76 (r/w/o: 218221.74/226215.32/33642.71) lat (ms,95%): 9.39 err/s 64.67 reconn/s: 0.00 +[ 480s ] thds: 64 tps: 16345.23 qps: 467552.83 (r/w/o: 213323.96/221540.08/32688.79) lat (ms,95%): 9.39 err/s 80.33 reconn/s: 0.00 +[ 483s ] thds: 64 tps: 16887.59 qps: 478812.25 (r/w/o: 218384.71/226650.35/33777.19) lat (ms,95%): 9.39 err/s 68.00 reconn/s: 0.00 +[ 486s ] thds: 64 tps: 16694.88 qps: 477973.22 (r/w/o: 218028.10/226555.71/33389.42) lat (ms,95%): 9.39 err/s 82.67 reconn/s: 0.00 +[ 489s ] thds: 64 tps: 16090.99 qps: 457109.33 (r/w/o: 208535.92/216391.75/32181.65) lat (ms,95%): 9.22 err/s 74.67 reconn/s: 0.00 +[ 492s ] thds: 64 tps: 16931.80 qps: 478768.98 (r/w/o: 218345.48/226559.56/33863.94) lat (ms,95%): 9.39 err/s 70.00 reconn/s: 0.00 +[ 495s ] thds: 64 tps: 17098.54 qps: 486299.95 (r/w/o: 221804.38/230298.82/34196.75) lat (ms,95%): 9.22 err/s 68.33 reconn/s: 0.00 +[ 498s ] thds: 64 tps: 16967.20 qps: 482723.47 (r/w/o: 220171.90/228617.50/33934.06) lat (ms,95%): 9.39 err/s 75.67 reconn/s: 0.00 +[ 501s ] thds: 64 tps: 16621.07 qps: 471180.57 (r/w/o: 214901.94/223035.82/33242.81) lat (ms,95%): 9.56 err/s 80.33 reconn/s: 0.00 +[ 504s ] thds: 64 tps: 16628.43 qps: 475307.05 (r/w/o: 216715.84/225335.35/33255.86) lat (ms,95%): 9.56 err/s 82.66 reconn/s: 0.00 +[ 507s ] thds: 64 tps: 17129.87 qps: 487538.08 (r/w/o: 222520.28/230757.07/34260.73) lat (ms,95%): 9.22 err/s 73.66 reconn/s: 0.00 +[ 510s ] thds: 64 tps: 16042.86 qps: 453897.98 (r/w/o: 207032.27/214778.99/32086.72) lat (ms,95%): 9.06 err/s 76.68 reconn/s: 0.00 +[ 513s ] thds: 64 tps: 17115.29 qps: 486388.05 (r/w/o: 221843.75/230314.39/34229.91) lat (ms,95%): 9.22 err/s 72.33 reconn/s: 0.00 +[ 516s ] thds: 64 tps: 16940.83 qps: 485430.22 (r/w/o: 221515.08/230033.49/33881.65) lat (ms,95%): 9.22 err/s 75.33 reconn/s: 0.00 +[ 519s ] thds: 64 tps: 16972.29 qps: 483775.38 (r/w/o: 220769.82/229060.63/33944.92) lat (ms,95%): 9.22 err/s 79.67 reconn/s: 0.00 +[ 522s ] thds: 64 tps: 17157.41 qps: 485485.36 (r/w/o: 221470.12/229700.75/34314.49) lat (ms,95%): 9.22 err/s 80.64 reconn/s: 0.00 +[ 525s ] thds: 64 tps: 17152.85 qps: 489269.06 (r/w/o: 223327.34/231635.68/34306.04) lat (ms,95%): 9.06 err/s 72.31 reconn/s: 0.00 +[ 528s ] thds: 64 tps: 17264.08 qps: 492752.71 (r/w/o: 224823.27/233402.28/34527.16) lat (ms,95%): 9.06 err/s 76.38 reconn/s: 0.00 +[ 531s ] thds: 64 tps: 17409.23 qps: 496030.37 (r/w/o: 226194.98/235016.93/34818.46) lat (ms,95%): 9.06 err/s 80.66 reconn/s: 0.00 +[ 534s ] thds: 64 tps: 17169.11 qps: 489491.85 (r/w/o: 223255.45/231897.18/34339.22) lat (ms,95%): 9.06 err/s 74.34 reconn/s: 0.00 +[ 537s ] thds: 64 tps: 17256.76 qps: 494113.52 (r/w/o: 225516.98/234084.03/34512.51) lat (ms,95%): 9.06 err/s 81.99 reconn/s: 0.00 +[ 540s ] thds: 64 tps: 16969.28 qps: 482495.26 (r/w/o: 220138.02/228418.33/33938.90) lat (ms,95%): 9.06 err/s 80.67 reconn/s: 0.00 +[ 543s ] thds: 64 tps: 17233.69 qps: 492404.68 (r/w/o: 224625.98/233310.99/34467.71) lat (ms,95%): 9.06 err/s 73.34 reconn/s: 0.00 +[ 546s ] thds: 64 tps: 17286.30 qps: 490862.58 (r/w/o: 223954.25/232335.39/34572.94) lat (ms,95%): 9.06 err/s 74.34 reconn/s: 0.00 +[ 549s ] thds: 64 tps: 17507.73 qps: 495822.24 (r/w/o: 226088.79/234718.99/35014.46) lat (ms,95%): 9.06 err/s 73.33 reconn/s: 0.00 +[ 552s ] thds: 64 tps: 17370.26 qps: 492712.68 (r/w/o: 224893.42/233078.40/34740.85) lat (ms,95%): 9.06 err/s 75.00 reconn/s: 0.00 +[ 555s ] thds: 64 tps: 17135.83 qps: 485810.15 (r/w/o: 221501.12/230037.04/34272.00) lat (ms,95%): 9.22 err/s 82.67 reconn/s: 0.00 +[ 558s ] thds: 64 tps: 17016.49 qps: 485013.37 (r/w/o: 221161.74/229817.98/34033.65) lat (ms,95%): 9.39 err/s 77.00 reconn/s: 0.00 +[ 561s ] thds: 64 tps: 17125.99 qps: 486007.80 (r/w/o: 221603.00/230153.49/34251.31) lat (ms,95%): 9.22 err/s 71.66 reconn/s: 0.00 +[ 564s ] thds: 64 tps: 17209.20 qps: 490650.47 (r/w/o: 223859.32/232372.41/34418.74) lat (ms,95%): 9.22 err/s 78.68 reconn/s: 0.00 +[ 567s ] thds: 64 tps: 17080.72 qps: 486607.94 (r/w/o: 222045.32/230401.52/34161.10) lat (ms,95%): 9.22 err/s 72.66 reconn/s: 0.00 +[ 570s ] thds: 64 tps: 17156.06 qps: 486398.05 (r/w/o: 221808.29/230277.31/34312.44) lat (ms,95%): 9.22 err/s 79.67 reconn/s: 0.00 +[ 573s ] thds: 64 tps: 17002.25 qps: 487431.20 (r/w/o: 222482.21/230945.17/34003.83) lat (ms,95%): 9.22 err/s 73.67 reconn/s: 0.00 +[ 576s ] thds: 64 tps: 17153.57 qps: 489076.46 (r/w/o: 223148.35/231620.31/34307.80) lat (ms,95%): 9.06 err/s 79.33 reconn/s: 0.00 +[ 579s ] thds: 64 tps: 16870.56 qps: 481605.98 (r/w/o: 219684.96/228179.91/33741.12) lat (ms,95%): 9.56 err/s 71.67 reconn/s: 0.00 +[ 582s ] thds: 64 tps: 17105.04 qps: 489485.50 (r/w/o: 223259.53/232016.55/34209.42) lat (ms,95%): 9.22 err/s 79.00 reconn/s: 0.00 +[ 585s ] thds: 64 tps: 16681.13 qps: 475035.24 (r/w/o: 216850.97/224822.02/33362.25) lat (ms,95%): 9.06 err/s 75.34 reconn/s: 0.00 +[ 588s ] thds: 64 tps: 17086.77 qps: 484715.93 (r/w/o: 221159.08/229382.97/34173.88) lat (ms,95%): 9.22 err/s 78.33 reconn/s: 0.00 +[ 591s ] thds: 64 tps: 17116.35 qps: 486033.83 (r/w/o: 221697.89/230103.23/34232.70) lat (ms,95%): 9.22 err/s 85.67 reconn/s: 0.00 +[ 594s ] thds: 64 tps: 16968.70 qps: 483163.37 (r/w/o: 220481.06/228744.58/33937.73) lat (ms,95%): 9.39 err/s 71.67 reconn/s: 0.00 +[ 597s ] thds: 64 tps: 16932.42 qps: 482617.22 (r/w/o: 220204.83/228548.21/33864.18) lat (ms,95%): 9.39 err/s 74.00 reconn/s: 0.00 +[ 600s ] thds: 64 tps: 16671.78 qps: 474341.31 (r/w/o: 216275.51/224722.23/33343.57) lat (ms,95%): 9.39 err/s 75.00 reconn/s: 0.00 +SQL statistics: + queries performed: + read: 130202475 + write: 135141530 + other: 20105862 + total: 285449867 + transactions: 10036898 (16722.66 per sec.) + queries: 285449867 (475593.33 per sec.) + ignored errors: 43740 (72.88 per sec.) + reconnects: 0 (0.00 per sec.) + +General statistics: + total time: 600.1949s + total number of events: 10036898 + +Latency (ms): + min: 0.30 + avg: 3.82 + max: 1013.73 + 95th percentile: 9.39 + sum: 38372005.89 + +Threads fairness: + events (avg/stddev): 156826.5312/675.69 + execution time (avg/stddev): 599.5626/0.03 From fe8d36e4fea1a18098d860cf79074012c77e2b4e Mon Sep 17 00:00:00 2001 From: digoal Date: Thu, 20 Sep 2018 23:13:14 +0800 Subject: [PATCH 03/14] improve --- README.md | 15 +++++++++++++++ tpcc_common.lua | 23 ++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3c22dd9..ae2c15a 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,21 @@ dbname=postgres ``` ./tpcc.lua --pgsql-host=/tmp --pgsql-port=1921 --pgsql-user=postgres --pgsql-db=postgres --time=300 --threads=64 --report-interval=1 --tables=10 --scale=100 --trx_level=RC --db-ps-mode=auto --db-driver=pgsql prepare ``` + +or disable foreign key + +``` +./tpcc.lua --pgsql-host=/tmp --pgsql-port=1921 --pgsql-user=postgres --pgsql-db=postgres --time=300 --threads=64 --report-interval=1 --tables=10 --scale=100 --trx_level=RC --db-ps-mode=auto --db-driver=pgsql --use_fk=0 prepare +``` + +or use custom tablespace + +``` +export pgsql_table_options="tablespace tbs1" +export pgsql_index_options="tablespace tbs2" + +./tpcc.lua --pgsql-host=/tmp --pgsql-port=1921 --pgsql-user=postgres --pgsql-db=postgres --time=300 --threads=64 --report-interval=1 --tables=10 --scale=100 --trx_level=RC --db-ps-mode=auto --db-driver=pgsql prepare +``` ## PostgreSQL: Run benchmark ``` diff --git a/tpcc_common.lua b/tpcc_common.lua index 1465dd2..1c8e2db 100644 --- a/tpcc_common.lua +++ b/tpcc_common.lua @@ -119,7 +119,10 @@ sysbench.cmdline.commands = { function create_tables(drv, con, table_num) local id_index_def, id_def local engine_def = "" - local extra_table_options = "" +-- local extra_table_options = "" +-- local extra_index_options = "" + local extra_table_options = os.getenv("pgsql_table_options") or "" + local extra_index_options = os.getenv("pgsql_index_options") or "" local query local tinyint_type="smallint" local datetime_type="timestamp" @@ -330,12 +333,18 @@ function create_tables(drv, con, table_num) con:bulk_insert_done() print(string.format("Adding indexes %d ... \n", i)) - con:query("CREATE INDEX idx_customer"..i.." ON customer"..i.." (c_w_id,c_d_id,c_last,c_first)") - con:query("CREATE INDEX idx_orders"..i.." ON orders"..i.." (o_w_id,o_d_id,o_c_id,o_id)") - con:query("CREATE INDEX fkey_stock_2"..i.." ON stock"..i.." (s_i_id)") - con:query("CREATE INDEX fkey_order_line_2"..i.." ON order_line"..i.." (ol_supply_w_id,ol_i_id)") - con:query("CREATE INDEX fkey_history_1"..i.." ON history"..i.." (h_c_w_id,h_c_d_id,h_c_id)") - con:query("CREATE INDEX fkey_history_2"..i.." ON history"..i.." (h_w_id,h_d_id )") + -- con:query("CREATE INDEX idx_customer"..i.." ON customer"..i.." (c_w_id,c_d_id,c_last,c_first)") + -- con:query("CREATE INDEX idx_orders"..i.." ON orders"..i.." (o_w_id,o_d_id,o_c_id,o_id)") + -- con:query("CREATE INDEX fkey_stock_2"..i.." ON stock"..i.." (s_i_id)") + -- con:query("CREATE INDEX fkey_order_line_2"..i.." ON order_line"..i.." (ol_supply_w_id,ol_i_id)") + -- con:query("CREATE INDEX fkey_history_1"..i.." ON history"..i.." (h_c_w_id,h_c_d_id,h_c_id)") + -- con:query("CREATE INDEX fkey_history_2"..i.." ON history"..i.." (h_w_id,h_d_id )") + con:query("CREATE INDEX idx_customer"..i.." ON customer"..i.." (c_w_id,c_d_id,c_last,c_first) "..extra_index_options) + con:query("CREATE INDEX idx_orders"..i.." ON orders"..i.." (o_w_id,o_d_id,o_c_id,o_id) "..extra_index_options) + con:query("CREATE INDEX fkey_stock_2"..i.." ON stock"..i.." (s_i_id) "..extra_index_options) + con:query("CREATE INDEX fkey_order_line_2"..i.." ON order_line"..i.." (ol_supply_w_id,ol_i_id) "..extra_index_options) + con:query("CREATE INDEX fkey_history_1"..i.." ON history"..i.." (h_c_w_id,h_c_d_id,h_c_id) "..extra_index_options) + con:query("CREATE INDEX fkey_history_2"..i.." ON history"..i.." (h_w_id,h_d_id ) "..extra_index_options) if sysbench.opt.use_fk == 1 then print(string.format("Adding FK %d ... \n", i)) con:query("ALTER TABLE new_orders"..i.." ADD CONSTRAINT fkey_new_orders_1_"..table_num.." FOREIGN KEY(no_w_id,no_d_id,no_o_id) REFERENCES orders"..i.."(o_w_id,o_d_id,o_id)") From 55aa143a4c47bbef1878470aa49b80e1abf560f7 Mon Sep 17 00:00:00 2001 From: digoal Date: Sat, 22 Sep 2018 09:22:57 +0800 Subject: [PATCH 04/14] for custom option for pgsql --- README.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ae2c15a..474975c 100644 --- a/README.md +++ b/README.md @@ -22,13 +22,13 @@ dbname=postgres ## PostgreSQL: prepare data and tables ``` -./tpcc.lua --pgsql-host=/tmp --pgsql-port=1921 --pgsql-user=postgres --pgsql-db=postgres --time=300 --threads=64 --report-interval=1 --tables=10 --scale=100 --trx_level=RC --db-ps-mode=auto --db-driver=pgsql prepare +./tpcc.lua --pgsql-host=/tmp --pgsql-port=1921 --pgsql-user=postgres --pgsql-db=postgres --threads=64 --tables=10 --scale=100 --trx_level=RC --db-ps-mode=auto --db-driver=pgsql prepare ``` or disable foreign key ``` -./tpcc.lua --pgsql-host=/tmp --pgsql-port=1921 --pgsql-user=postgres --pgsql-db=postgres --time=300 --threads=64 --report-interval=1 --tables=10 --scale=100 --trx_level=RC --db-ps-mode=auto --db-driver=pgsql --use_fk=0 prepare +./tpcc.lua --pgsql-host=/tmp --pgsql-port=1921 --pgsql-user=postgres --pgsql-db=postgres --threads=64 --tables=10 --scale=100 --trx_level=RC --db-ps-mode=auto --db-driver=pgsql --use_fk=0 prepare ``` or use custom tablespace @@ -37,17 +37,26 @@ or use custom tablespace export pgsql_table_options="tablespace tbs1" export pgsql_index_options="tablespace tbs2" -./tpcc.lua --pgsql-host=/tmp --pgsql-port=1921 --pgsql-user=postgres --pgsql-db=postgres --time=300 --threads=64 --report-interval=1 --tables=10 --scale=100 --trx_level=RC --db-ps-mode=auto --db-driver=pgsql prepare +./tpcc.lua --pgsql-host=/tmp --pgsql-port=1921 --pgsql-user=postgres --pgsql-db=postgres --threads=64 --tables=10 --scale=100 --trx_level=RC --db-ps-mode=auto --db-driver=pgsql --use_fk=0 prepare ``` + +or use zheap custom storage_engine + +``` +export pgsql_table_options="with (storage_engine='zheap') tablespace tbs1" +export pgsql_index_options="with (storage_engine='zheap') tablespace tbs2" +./tpcc.lua --pgsql-host=/tmp --pgsql-port=4001 --pgsql-user=postgres --pgsql-db=postgres --threads=64 --tables=20 --scale=100 --trx_level=RC --db-ps-mode=auto --db-driver=pgsql --use_fk=0 prepare +``` + ## PostgreSQL: Run benchmark ``` -./tpcc.lua --pgsql-host=/tmp --pgsql-port=1921 --pgsql-user=postgres --pgsql-db=postgres --time=300 --threads=64 --report-interval=1 --tables=10 --scale=100 --trx_level=RC --db-ps-mode=auto --db-driver=pgsql run +./tpcc.lua --pgsql-host=/tmp --pgsql-port=1921 --pgsql-user=postgres --pgsql-db=postgres --time=300 --threads=64 --report-interval=1 --tables=10 --scale=100 --trx_level=RC --db-ps-mode=auto --db-driver=pgsql --use_fk=0 run ``` ## PostgreSQL: Cleanup ``` -./tpcc.lua --pgsql-host=/tmp --pgsql-port=1921 --pgsql-user=postgres --pgsql-db=postgres --time=300 --threads=64 --report-interval=1 --tables=10 --scale=100 --trx_level=RC --db-ps-mode=auto --db-driver=pgsql cleanup +./tpcc.lua --pgsql-host=/tmp --pgsql-port=1921 --pgsql-user=postgres --pgsql-db=postgres --time=300 --threads=64 --report-interval=1 --tables=10 --scale=100 --trx_level=RC --db-ps-mode=auto --db-driver=pgsql --use_fk=0 cleanup ``` # for MySQL From d5edfa8226449ee4f3522febd1072ce77d2adeae Mon Sep 17 00:00:00 2001 From: digoal Date: Sat, 22 Sep 2018 09:24:24 +0800 Subject: [PATCH 05/14] for custom option for pgsql --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 474975c..1604b83 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ or use zheap custom storage_engine ``` export pgsql_table_options="with (storage_engine='zheap') tablespace tbs1" -export pgsql_index_options="with (storage_engine='zheap') tablespace tbs2" +export pgsql_index_options="tablespace tbs2" ./tpcc.lua --pgsql-host=/tmp --pgsql-port=4001 --pgsql-user=postgres --pgsql-db=postgres --threads=64 --tables=20 --scale=100 --trx_level=RC --db-ps-mode=auto --db-driver=pgsql --use_fk=0 prepare ``` From b6f195302f3de46641aacba5d254366d682afe32 Mon Sep 17 00:00:00 2001 From: digoal Date: Tue, 25 Sep 2018 10:51:42 +0800 Subject: [PATCH 06/14] use double instead of decimal --- tpcc_common.lua | 146 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) diff --git a/tpcc_common.lua b/tpcc_common.lua index 1c8e2db..26c506e 100644 --- a/tpcc_common.lua +++ b/tpcc_common.lua @@ -138,6 +138,24 @@ function create_tables(drv, con, table_num) print(string.format("Creating tables: %d\n", table_num)) + + if drv:name() == "pgsql" + then + query = string.format([[ + CREATE TABLE IF NOT EXISTS warehouse%d ( + w_id smallint not null, + w_name varchar(10), + w_street_1 varchar(20), + w_street_2 varchar(20), + w_city varchar(20), + w_state char(2), + w_zip char(9), + w_tax float8, + w_ytd float8, + primary key (w_id) + ) %s %s]], + table_num, engine_def, extra_table_options) + else query = string.format([[ CREATE TABLE IF NOT EXISTS warehouse%d ( w_id smallint not null, @@ -152,9 +170,29 @@ function create_tables(drv, con, table_num) primary key (w_id) ) %s %s]], table_num, engine_def, extra_table_options) + end con:query(query) + if drv:name() == "pgsql" + then + query = string.format([[ + create table IF NOT EXISTS district%d ( + d_id ]] .. tinyint_type .. [[ not null, + d_w_id smallint not null, + d_name varchar(10), + d_street_1 varchar(20), + d_street_2 varchar(20), + d_city varchar(20), + d_state char(2), + d_zip char(9), + d_tax float8, + d_ytd float8, + d_next_o_id int, + primary key (d_w_id, d_id) + ) %s %s]], + table_num, engine_def, extra_table_options) + else query = string.format([[ create table IF NOT EXISTS district%d ( d_id ]] .. tinyint_type .. [[ not null, @@ -171,11 +209,41 @@ function create_tables(drv, con, table_num) primary key (d_w_id, d_id) ) %s %s]], table_num, engine_def, extra_table_options) + end con:query(query) -- CUSTOMER TABLE + if drv:name() == "pgsql" + then + query = string.format([[ + create table IF NOT EXISTS customer%d ( + c_id int not null, + c_d_id ]] .. tinyint_type .. [[ not null, + c_w_id smallint not null, + c_first varchar(16), + c_middle char(2), + c_last varchar(16), + c_street_1 varchar(20), + c_street_2 varchar(20), + c_city varchar(20), + c_state char(2), + c_zip char(9), + c_phone char(16), + c_since ]] .. datetime_type .. [[, + c_credit char(2), + c_credit_lim bigint, + c_discount float8, + c_balance float8, + c_ytd_payment float8, + c_payment_cnt smallint, + c_delivery_cnt smallint, + c_data text, + PRIMARY KEY(c_w_id, c_d_id, c_id) + ) %s %s]], + table_num, engine_def, extra_table_options) + else query = string.format([[ create table IF NOT EXISTS customer%d ( c_id int not null, @@ -202,6 +270,7 @@ function create_tables(drv, con, table_num) PRIMARY KEY(c_w_id, c_d_id, c_id) ) %s %s]], table_num, engine_def, extra_table_options) + end con:query(query) @@ -212,6 +281,23 @@ function create_tables(drv, con, table_num) hist_auto_inc="id int NOT NULL AUTO_INCREMENT," hist_pk=",PRIMARY KEY(id)" end + + if drv:name() == "pgsql" + then + query = string.format([[ + create table IF NOT EXISTS history%d ( + %s + h_c_id int, + h_c_d_id ]] .. tinyint_type .. [[, + h_c_w_id smallint, + h_d_id ]] .. tinyint_type .. [[, + h_w_id smallint, + h_date ]] .. datetime_type .. [[, + h_amount float8, + h_data varchar(24) %s + ) %s %s]], + table_num, hist_auto_inc, hist_pk, engine_def, extra_table_options) + else query = string.format([[ create table IF NOT EXISTS history%d ( %s @@ -225,6 +311,7 @@ function create_tables(drv, con, table_num) h_data varchar(24) %s ) %s %s]], table_num, hist_auto_inc, hist_pk, engine_def, extra_table_options) + end con:query(query) @@ -257,6 +344,24 @@ function create_tables(drv, con, table_num) con:query(query) + if drv:name() == "pgsql" + then + query = string.format([[ + create table IF NOT EXISTS order_line%d ( + ol_o_id int not null, + ol_d_id ]] .. tinyint_type .. [[ not null, + ol_w_id smallint not null, + ol_number ]] .. tinyint_type .. [[ not null, + ol_i_id int, + ol_supply_w_id smallint, + ol_delivery_d ]] .. datetime_type .. [[, + ol_quantity ]] .. tinyint_type .. [[, + ol_amount float8, + ol_dist_info char(24), + PRIMARY KEY(ol_w_id, ol_d_id, ol_o_id, ol_number) + ) %s %s]], + table_num, engine_def, extra_table_options) + else query = string.format([[ create table IF NOT EXISTS order_line%d ( ol_o_id int not null, @@ -272,11 +377,37 @@ function create_tables(drv, con, table_num) PRIMARY KEY(ol_w_id, ol_d_id, ol_o_id, ol_number) ) %s %s]], table_num, engine_def, extra_table_options) + end con:query(query) -- STOCK table + if drv:name() == "pgsql" + then + query = string.format([[ + create table IF NOT EXISTS stock%d ( + s_i_id int not null, + s_w_id smallint not null, + s_quantity smallint, + s_dist_01 char(24), + s_dist_02 char(24), + s_dist_03 char(24), + s_dist_04 char(24), + s_dist_05 char(24), + s_dist_06 char(24), + s_dist_07 char(24), + s_dist_08 char(24), + s_dist_09 char(24), + s_dist_10 char(24), + s_ytd float8, + s_order_cnt smallint, + s_remote_cnt smallint, + s_data varchar(50), + PRIMARY KEY(s_w_id, s_i_id) + ) %s %s]], + table_num, engine_def, extra_table_options) + else query = string.format([[ create table IF NOT EXISTS stock%d ( s_i_id int not null, @@ -299,11 +430,25 @@ function create_tables(drv, con, table_num) PRIMARY KEY(s_w_id, s_i_id) ) %s %s]], table_num, engine_def, extra_table_options) + end con:query(query) local i = table_num + if drv:name() == "pgsql" + then + query = string.format([[ + create table IF NOT EXISTS item%d ( + i_id int not null, + i_im_id int, + i_name varchar(24), + i_price float8, + i_data varchar(50), + PRIMARY KEY(i_id) + ) %s %s]], + i, engine_def, extra_table_options) + else query = string.format([[ create table IF NOT EXISTS item%d ( i_id int not null, @@ -314,6 +459,7 @@ function create_tables(drv, con, table_num) PRIMARY KEY(i_id) ) %s %s]], i, engine_def, extra_table_options) + end con:query(query) From 2c3a4c1f909e01c03cca082e1361f403ad0a953f Mon Sep 17 00:00:00 2001 From: digoal Date: Tue, 25 Sep 2018 15:10:24 +0800 Subject: [PATCH 07/14] improve --- README.md | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1604b83..e84ed40 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ export pgsql_index_options="tablespace tbs2" ## PostgreSQL: Run benchmark ``` -./tpcc.lua --pgsql-host=/tmp --pgsql-port=1921 --pgsql-user=postgres --pgsql-db=postgres --time=300 --threads=64 --report-interval=1 --tables=10 --scale=100 --trx_level=RC --db-ps-mode=auto --db-driver=pgsql --use_fk=0 run +./tpcc.lua --pgsql-host=/tmp --pgsql-port=1921 --pgsql-user=postgres --pgsql-db=postgres --time=300 --threads=64 --report-interval=1 --tables=10 --scale=100 --trx_level=RC --db-ps-mode=auto --db-driver=pgsql --use_fk=0 --enable_purge=yes run ``` ## PostgreSQL: Cleanup @@ -83,3 +83,29 @@ export pgsql_index_options="tablespace tbs2" ` ./tpcc.lua --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-db=sbt --time=300 --threads=64 --report-interval=1 --tables=10 --scale=100 --db-driver=mysql cleanup ` + +# options +``` +-- Command line options +sysbench.cmdline.options = { + scale = + {"Scale factor (warehouses)", 100}, + tables = + {"Number of tables", 1}, + use_fk = + {"Use foreign keys", 1}, + force_pk = + {"Force using auto-inc PK on history table", 0}, + trx_level = + {"Transaction isolation level (RC, RR or SER)", "RC"}, + enable_purge = + {"Use purge transaction (yes, no)", "no"}, + report_csv = + {"Report output in csv (yes, no)", "no"}, + mysql_storage_engine = + {"Storage engine, if MySQL is used", "innodb"}, + mysql_table_options = + {"Extra table options, if MySQL is used. e.g. 'COLLATE latin1_bin'", ""} +} +``` + From a8ef37247c75abb43b910fde3c41c784bb3b1331 Mon Sep 17 00:00:00 2001 From: digoal Date: Tue, 25 Sep 2018 15:15:26 +0800 Subject: [PATCH 08/14] improve --- tpcc.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tpcc.lua b/tpcc.lua index dc1036c..2f759c8 100644 --- a/tpcc.lua +++ b/tpcc.lua @@ -88,13 +88,13 @@ function thread_init() format(table_num, table_num)) - con:query(([[prepare p_new_order9_%d(int4,int2,int2,int2,int4,int2,int2,numeric,text) as INSERT INTO order_line%d + con:query(([[prepare p_new_order9_%d(int4,int2,int2,int2,int4,int2,int2,float8,text) as INSERT INTO order_line%d (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) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)]]): format(table_num, table_num)) - con:query(([[prepare p_payment1_%d(numeric,int2) as UPDATE warehouse%d + con:query(([[prepare p_payment1_%d(float8,int2) as UPDATE warehouse%d SET w_ytd = w_ytd + $1 WHERE w_id = $2]]):format(table_num, table_num)) @@ -102,7 +102,7 @@ function thread_init() FROM warehouse%d WHERE w_id = $1]]):format(table_num, table_num)) - con:query(([[prepare p_payment3_%d(numeric,int2,int2) as UPDATE district%d + con:query(([[prepare p_payment3_%d(float8,int2,int2) as UPDATE district%d SET d_ytd = d_ytd + $1 WHERE d_w_id = $2 AND d_id= $3]]):format(table_num, table_num)) @@ -139,21 +139,21 @@ function thread_init() AND c_id= $3]]): format(table_num, table_num)) - con:query(([[prepare p_payment9_%d(numeric,numeric,text,int2,int2,int4) as UPDATE customer%d + con:query(([[prepare p_payment9_%d(float8,float8,text,int2,int2,int4) as UPDATE customer%d SET c_balance=$1, c_ytd_payment=$2, c_data=$3 WHERE c_w_id = $4 AND c_d_id = $5 AND c_id = $6]]) :format(table_num, table_num )) - con:query(([[prepare p_payment10_%d(numeric,numeric,int2,int2,int4) as UPDATE customer%d + con:query(([[prepare p_payment10_%d(float8,float8,int2,int2,int4) as UPDATE customer%d SET c_balance=$1, c_ytd_payment=$2 WHERE c_w_id = $3 AND c_d_id = $4 AND c_id = $5]]) :format(table_num, table_num )) - con:query(([[prepare p_payment11_%d(int2,int2,int4,int2,int2,numeric,text) as INSERT INTO history%d + con:query(([[prepare p_payment11_%d(int2,int2,int4,int2,int2,float8,text) as INSERT INTO history%d (h_c_d_id, h_c_w_id, h_c_id, h_d_id, h_w_id, h_date, h_amount, h_data) VALUES ($1,$2,$3,$4,$5,NOW(),$6,$7)]]) :format(table_num, table_num)) @@ -236,7 +236,7 @@ function thread_init() :format(table_num, table_num)) - con:query(([[prepare p_delivery7_%d(numeric,int4,int2,int2) as UPDATE customer%d + con:query(([[prepare p_delivery7_%d(float8,int4,int2,int2) as UPDATE customer%d SET c_balance = c_balance + $1, c_delivery_cnt = c_delivery_cnt + 1 WHERE c_id = $2 From d04ad3374fe4bc22ac1101ec137aa243487d7674 Mon Sep 17 00:00:00 2001 From: digoal Date: Tue, 25 Sep 2018 16:57:22 +0800 Subject: [PATCH 09/14] purge fix --- tpcc_run.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tpcc_run.lua b/tpcc_run.lua index 2d066e4..3908ff3 100644 --- a/tpcc_run.lua +++ b/tpcc_run.lua @@ -804,8 +804,10 @@ end -- function purge to remove all orders, this is useful if we want to limit data directory in size function purge() - for i = 1, 10 do - local table_num = sysbench.rand.uniform(1, sysbench.opt.tables) + -- for i = 1, 10 do + -- local table_num = sysbench.rand.uniform(1, sysbench.opt.tables) + for i = 1, sysbench.opt.tables do + local table_num = i local w_id = sysbench.rand.uniform(1, sysbench.opt.scale) local d_id = sysbench.rand.uniform(1, DIST_PER_WARE) From ab100bb31023c6c692fd60b5e11f75d9784ddab1 Mon Sep 17 00:00:00 2001 From: "Digoal.zhou" <1920239+digoal@users.noreply.github.com> Date: Tue, 3 Aug 2021 18:12:44 +0800 Subject: [PATCH 10/14] update rs1 to rs update rs1 to rs --- tpcc_run.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tpcc_run.lua b/tpcc_run.lua index 3908ff3..c354246 100644 --- a/tpcc_run.lua +++ b/tpcc_run.lua @@ -783,15 +783,15 @@ function stocklevel() -- AND s_i_id = :ol_i_id -- AND s_quantity < :level;*/ - rs1 = con:query(([[execute p_stocklevel4_%d(%d,%d,%d)]]):format(table_num, w_id, ol_i_id, level)) --- rs1 = con:query(([[SELECT count(*) FROM stock%d + rs = con:query(([[execute p_stocklevel4_%d(%d,%d,%d)]]):format(table_num, w_id, ol_i_id, level)) +-- rs = con:query(([[SELECT count(*) FROM stock%d -- WHERE s_w_id = %d AND s_i_id = %d -- AND s_quantity < %d]]) -- :format(table_num, w_id, ol_i_id, level ) ) local cnt - for i = 1, rs1.nrows do - cnt = unpack(rs1:fetch_row(), 1, rs1.nfields) + for i = 1, rs.nrows do + cnt = unpack(rs:fetch_row(), 1, rs.nfields) end end From 12fd95fdd2f91ab66520a4660daf02bbcf455396 Mon Sep 17 00:00:00 2001 From: "Digoal.zhou" <1920239+digoal@users.noreply.github.com> Date: Tue, 3 Aug 2021 18:13:20 +0800 Subject: [PATCH 11/14] update rs1 to rs update rs1 to rs --- tpcc_run.lua.old | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tpcc_run.lua.old b/tpcc_run.lua.old index f44b4bb..59add20 100755 --- a/tpcc_run.lua.old +++ b/tpcc_run.lua.old @@ -727,13 +727,13 @@ function stocklevel() -- AND s_i_id = :ol_i_id -- AND s_quantity < :level;*/ - rs1 = con:query(([[SELECT count(*) FROM stock%d + rs = con:query(([[SELECT count(*) FROM stock%d WHERE s_w_id = %d AND s_i_id = %d AND s_quantity < %d]]) :format(table_num, w_id, ol_i_id, level ) ) local cnt - for i = 1, rs1.nrows do - cnt = unpack(rs1:fetch_row(), 1, rs1.nfields) + for i = 1, rs.nrows do + cnt = unpack(rs:fetch_row(), 1, rs.nfields) end end From 542f9732bcc9d1450dfdce620714f12c9988f459 Mon Sep 17 00:00:00 2001 From: "Digoal.zhou" <1920239+digoal@users.noreply.github.com> Date: Tue, 3 Aug 2021 18:34:36 +0800 Subject: [PATCH 12/14] Update tpcc_run.lua --- tpcc_run.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tpcc_run.lua b/tpcc_run.lua index c354246..ea7cda9 100644 --- a/tpcc_run.lua +++ b/tpcc_run.lua @@ -783,15 +783,15 @@ function stocklevel() -- AND s_i_id = :ol_i_id -- AND s_quantity < :level;*/ - rs = con:query(([[execute p_stocklevel4_%d(%d,%d,%d)]]):format(table_num, w_id, ol_i_id, level)) + rs1 = con:query(([[execute p_stocklevel4_%d(%d,%d,%d)]]):format(table_num, w_id, ol_i_id, level)) -- rs = con:query(([[SELECT count(*) FROM stock%d -- WHERE s_w_id = %d AND s_i_id = %d -- AND s_quantity < %d]]) -- :format(table_num, w_id, ol_i_id, level ) ) local cnt - for i = 1, rs.nrows do - cnt = unpack(rs:fetch_row(), 1, rs.nfields) + for i = 1, rs1.nrows do + cnt = unpack(rs1:fetch_row(), 1, rs1.nfields) end end From 222fbdc4b51ca748177978e8913897ec6a409b72 Mon Sep 17 00:00:00 2001 From: "Digoal.zhou" <1920239+digoal@users.noreply.github.com> Date: Tue, 3 Aug 2021 18:43:11 +0800 Subject: [PATCH 13/14] Handle inside loop properly Handle inside loop properly --- tpcc_run.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tpcc_run.lua b/tpcc_run.lua index ea7cda9..b3808e9 100644 --- a/tpcc_run.lua +++ b/tpcc_run.lua @@ -771,27 +771,27 @@ function stocklevel() -- AND ol_o_id < %d AND ol_o_id >= %d]]) -- :format(table_num, w_id, d_id, d_next_o_id, d_next_o_id - 20 )) - local ol_i_id + local ol_i_id = {} for i = 1, rs.nrows do - ol_i_id = unpack(rs:fetch_row(), 1, rs.nfields) - - + ol_i_id[i] = unpack(rs:fetch_row(), 1, rs.nfields) + end + for i = 1, #ol_i_id do -- SELECT count(*) INTO :i_count -- FROM stock -- WHERE s_w_id = :w_id -- AND s_i_id = :ol_i_id -- AND s_quantity < :level;*/ - rs1 = con:query(([[execute p_stocklevel4_%d(%d,%d,%d)]]):format(table_num, w_id, ol_i_id, level)) + rs = con:query(([[execute p_stocklevel4_%d(%d,%d,%d)]]):format(table_num, w_id, ol_i_id, level)) -- rs = con:query(([[SELECT count(*) FROM stock%d -- WHERE s_w_id = %d AND s_i_id = %d -- AND s_quantity < %d]]) --- :format(table_num, w_id, ol_i_id, level ) ) +-- :format(table_num, w_id, ol_i_id[i], level ) ) local cnt - for i = 1, rs1.nrows do - cnt = unpack(rs1:fetch_row(), 1, rs1.nfields) + for i = 1, rs.nrows do + cnt = unpack(rs:fetch_row(), 1, rs.nfields) end end From cc42e0752b44fc9d07c6b85987106f9bc1a780be Mon Sep 17 00:00:00 2001 From: "Digoal.zhou" <1920239+digoal@users.noreply.github.com> Date: Tue, 3 Aug 2021 18:46:55 +0800 Subject: [PATCH 14/14] Handle inside loop properly Handle inside loop properly --- tpcc_run.lua.old | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tpcc_run.lua.old b/tpcc_run.lua.old index 59add20..d9ad861 100755 --- a/tpcc_run.lua.old +++ b/tpcc_run.lua.old @@ -715,10 +715,12 @@ function stocklevel() AND ol_o_id < %d AND ol_o_id >= %d]]) :format(table_num, w_id, d_id, d_next_o_id, d_next_o_id - 20 )) - local ol_i_id + local ol_i_id = {} for i = 1, rs.nrows do - ol_i_id = unpack(rs:fetch_row(), 1, rs.nfields) + ol_i_id[i] = unpack(rs:fetch_row(), 1, rs.nfields) + end + for i = 1, #ol_i_id do -- SELECT count(*) INTO :i_count @@ -726,11 +728,11 @@ function stocklevel() -- WHERE s_w_id = :w_id -- AND s_i_id = :ol_i_id -- AND s_quantity < :level;*/ - + rs = con:query(([[SELECT count(*) FROM stock%d WHERE s_w_id = %d AND s_i_id = %d AND s_quantity < %d]]) - :format(table_num, w_id, ol_i_id, level ) ) + :format(table_num, w_id, ol_i_id[i], level ) ) local cnt for i = 1, rs.nrows do cnt = unpack(rs:fetch_row(), 1, rs.nfields)