From cd2b7380221fd609ffe5b51586d8f5267763a6f9 Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Tue, 12 Sep 2017 10:08:59 +0300 Subject: [PATCH] Avoid PK conflicts in oltp_insert.lua by creating empty tables on 'prepare'. --- src/lua/oltp_common.lua | 6 ++++-- src/lua/oltp_insert.lua | 14 ++++++++++++++ tests/t/script_oltp_insert_mysql.t | 1 - tests/t/script_oltp_insert_pgsql.t | 1 - 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/lua/oltp_common.lua b/src/lua/oltp_common.lua index 24485d9..a964222 100644 --- a/src/lua/oltp_common.lua +++ b/src/lua/oltp_common.lua @@ -196,8 +196,10 @@ CREATE TABLE sbtest%d( con:query(query) - print(string.format("Inserting %d records into 'sbtest%d'", - sysbench.opt.table_size, table_num)) + if (sysbench.opt.table_size > 0) then + print(string.format("Inserting %d records into 'sbtest%d'", + sysbench.opt.table_size, table_num)) + end if sysbench.opt.auto_inc then query = "INSERT INTO sbtest" .. table_num .. "(k, c, pad) VALUES" diff --git a/src/lua/oltp_insert.lua b/src/lua/oltp_insert.lua index 62a5573..5cddf8c 100755 --- a/src/lua/oltp_insert.lua +++ b/src/lua/oltp_insert.lua @@ -21,6 +21,20 @@ require("oltp_common") +sysbench.cmdline.commands.prepare = { + function () + if (not sysbench.opt.auto_inc) then + -- Create empty tables on prepare when --auto-inc is off, since IDs + -- generated on prepare may collide later with values generated by + -- sysbench.rand.unique() + sysbench.opt.table_size=0 + end + + cmd_prepare() + end, + sysbench.cmdline.PARALLEL_PREPARE +} + function prepare_statements() -- We do not use prepared statements here, but oltp_common.sh expects this -- function to be defined diff --git a/tests/t/script_oltp_insert_mysql.t b/tests/t/script_oltp_insert_mysql.t index 629b98b..b5c4acd 100644 --- a/tests/t/script_oltp_insert_mysql.t +++ b/tests/t/script_oltp_insert_mysql.t @@ -196,6 +196,5 @@ oltp_insert.lua + MySQL tests Dropping table 'sbtest1'... # Test --auto-inc=off Creating table 'sbtest1'... - Inserting 10000 records into 'sbtest1' Creating a secondary index on 'sbtest1'... Dropping table 'sbtest1'... diff --git a/tests/t/script_oltp_insert_pgsql.t b/tests/t/script_oltp_insert_pgsql.t index ec7406e..6290aa7 100644 --- a/tests/t/script_oltp_insert_pgsql.t +++ b/tests/t/script_oltp_insert_pgsql.t @@ -198,6 +198,5 @@ oltp_insert.lua + PostgreSQL tests Dropping table 'sbtest1'... # Test --auto-inc=off Creating table 'sbtest1'... - Inserting 10000 records into 'sbtest1' Creating a secondary index on 'sbtest1'... Dropping table 'sbtest1'...