Skip to content

Commit 50e4dcb

Browse files
committed
oltp_common.lua: add option start_id for parallel prepare one table
1 parent e9ea09f commit 50e4dcb

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/lua/oltp_common.lua

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ end
3333
sysbench.cmdline.options = {
3434
table_size =
3535
{"Number of rows per table", 10000},
36+
start_id =
37+
{"Start id of rows for prepare insert into table, " ..
38+
"used for parallel prepare data into one table, " ..
39+
"users can run multiple sysbench process with different start_id concurrently. " ..
40+
"in this case, range_size is the number of rows to be inserted, id of inserted " ..
41+
"rows are {start_id, start_id + 1, ..., start_id + range_size - 1}. " ..
42+
"this option should not be used with auto_inc. " ..
43+
"default is 0 to conform origin sysbench", 0},
3644
range_size =
3745
{"Range size for range SELECT queries", 100},
3846
tables =
@@ -198,7 +206,7 @@ function create_table(drv, con, table_num)
198206

199207
if sysbench.opt.use_file then
200208
query = string.format([[
201-
CREATE TABLE sbtest%d(
209+
CREATE TABLE IF NOT EXISTS sbtest%d(
202210
id %s,
203211
k INTEGER DEFAULT '0' NOT NULL,
204212
c VARCHAR(512) DEFAULT '' NOT NULL,
@@ -209,7 +217,7 @@ function create_table(drv, con, table_num)
209217
sysbench.opt.create_table_options)
210218
else
211219
query = string.format([[
212-
CREATE TABLE sbtest%d(
220+
CREATE TABLE IF NOT EXISTS sbtest%d(
213221
id %s,
214222
k INTEGER DEFAULT '0' NOT NULL,
215223
c CHAR(120) DEFAULT '' NOT NULL,
@@ -237,8 +245,18 @@ function create_table(drv, con, table_num)
237245

238246
local c_val
239247
local pad_val
248+
local start_id;
249+
local finish_id;
240250

241-
for i = 1, sysbench.opt.table_size do
251+
if sysbench.opt.start_id == 0 then
252+
start_id = 1;
253+
finish_id = sysbench.opt.table_size;
254+
else
255+
start_id = sysbench.opt.start_id;
256+
finish_id = start_id + sysbench.opt.range_size - 1;
257+
end
258+
259+
for i = start_id, finish_id do
242260

243261
if sysbench.opt.use_file then
244262
c_val, pad_val = get_str_value()

0 commit comments

Comments
 (0)