From 8925dfdc79b2ddd31347f723c18d7cbcd4540548 Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Mon, 16 Jan 2017 16:01:35 +0300 Subject: [PATCH] Re-write select_random*.lua benchmarks to the new SQL API. --- sysbench/drivers/mysql/drv_mysql.c | 24 +++++-- sysbench/lua/select_random_points.lua | 59 ++++++++++++++++++ sysbench/lua/select_random_ranges.lua | 62 +++++++++++++++++++ ....disabled => script_select_random_mysql.t} | 4 +- ....disabled => script_select_random_pgsql.t} | 4 +- 5 files changed, 143 insertions(+), 10 deletions(-) create mode 100644 sysbench/lua/select_random_points.lua create mode 100644 sysbench/lua/select_random_ranges.lua rename tests/t/{script_select_random_mysql.t.disabled => script_select_random_mysql.t} (97%) rename tests/t/{script_select_random_pgsql.t.disabled => script_select_random_pgsql.t} (97%) diff --git a/sysbench/drivers/mysql/drv_mysql.c b/sysbench/drivers/mysql/drv_mysql.c index 42ff085..4967af9 100644 --- a/sysbench/drivers/mysql/drv_mysql.c +++ b/sysbench/drivers/mysql/drv_mysql.c @@ -489,14 +489,15 @@ int mysql_drv_disconnect(db_conn_t *sb_conn) int mysql_drv_prepare(db_stmt_t *stmt, const char *query, size_t len) { - db_mysql_conn_t *db_mysql_con = (db_mysql_conn_t *) stmt->connection->ptr; - MYSQL *con = db_mysql_con->mysql; MYSQL_STMT *mystmt; unsigned int rc; if (args.dry_run) return 0; + db_mysql_conn_t *db_mysql_con = (db_mysql_conn_t *) stmt->connection->ptr; + MYSQL *con = db_mysql_con->mysql; + if (con == NULL) return 1; @@ -557,8 +558,6 @@ int mysql_drv_prepare(db_stmt_t *stmt, const char *query, size_t len) int mysql_drv_bind_param(db_stmt_t *stmt, db_bind_t *params, size_t len) { - db_mysql_conn_t *db_mysql_con = (db_mysql_conn_t *) stmt->connection->ptr; - MYSQL *con = db_mysql_con->mysql; MYSQL_BIND *bind; unsigned int i; my_bool rc; @@ -567,6 +566,9 @@ int mysql_drv_bind_param(db_stmt_t *stmt, db_bind_t *params, size_t len) if (args.dry_run) return 0; + db_mysql_conn_t *db_mysql_con = (db_mysql_conn_t *) stmt->connection->ptr; + MYSQL *con = db_mysql_con->mysql; + if (con == NULL) return 1; @@ -629,12 +631,16 @@ int mysql_drv_bind_param(db_stmt_t *stmt, db_bind_t *params, size_t len) int mysql_drv_bind_result(db_stmt_t *stmt, db_bind_t *params, size_t len) { - db_mysql_conn_t *db_mysql_con =(db_mysql_conn_t *) stmt->connection->ptr; - MYSQL *con = db_mysql_con->mysql; MYSQL_BIND *bind; unsigned int i; my_bool rc; + if (args.dry_run) + return 0; + + db_mysql_conn_t *db_mysql_con =(db_mysql_conn_t *) stmt->connection->ptr; + MYSQL *con = db_mysql_con->mysql; + if (con == NULL || stmt->ptr == NULL) return 1; @@ -924,6 +930,9 @@ int mysql_drv_fetch(db_result_t *rs) /* NYI */ (void)rs; /* unused */ + if (args.dry_run) + return DB_ERROR_NONE; + return 1; } @@ -934,6 +943,9 @@ int mysql_drv_fetch(db_result_t *rs) int mysql_drv_fetch_row(db_result_t *rs, db_row_t *row) { + if (args.dry_run) + return DB_ERROR_NONE; + db_mysql_conn_t *db_mysql_con = (db_mysql_conn_t *) rs->connection->ptr; row->ptr = mysql_fetch_row(rs->ptr); DEBUG("mysql_fetch_row(%p) = %p", rs->ptr, row->ptr); diff --git a/sysbench/lua/select_random_points.lua b/sysbench/lua/select_random_points.lua new file mode 100644 index 0000000..b31746e --- /dev/null +++ b/sysbench/lua/select_random_points.lua @@ -0,0 +1,59 @@ +-- This test is designed for testing MariaDB's key_cache_segments for MyISAM, +-- and should work with other storage engines as well. +-- +-- For details about key_cache_segments please refer to: +-- http://kb.askmonty.org/v/segmented-key-cache +-- + +-- Override oltp_tables_count, this test only supports a single table +oltp_tables_count = 1 + +pathtest = string.match(test, "(.*/)") + +if pathtest then + dofile(pathtest .. "oltp_common.lua") +else + require("oltp_common") +end + +function thread_init() + set_vars_points() + + drv = sysbench.sql.driver() + con = drv:connect() + + local points = string.rep("?, ", random_points - 1) .. "?" + + stmt = con:prepare(string.format([[ + SELECT id, k, c, pad + FROM sbtest1 + WHERE k IN (%s) + ]], points)) + + params = {} + for j = 1,random_points do + params[j] = stmt:bind_create(sysbench.sql.type.INT) + end + + stmt:bind_param(unpack(params)) + + rlen = oltp_table_size / num_threads +end + +function event(thread_id) + -- To prevent overlapping of our range queries we need to partition the whole + -- table into num_threads segments and then make each thread work with its + -- own segment. + for i = 1,random_points do + local rmin = rlen * thread_id + local rmax = rmin + rlen + params[i]:set(sb_rand(rmin, rmax)) + end + + stmt:execute() +end + +function set_vars_points() + set_vars() + random_points = random_points or 10 +end diff --git a/sysbench/lua/select_random_ranges.lua b/sysbench/lua/select_random_ranges.lua new file mode 100644 index 0000000..39e8f31 --- /dev/null +++ b/sysbench/lua/select_random_ranges.lua @@ -0,0 +1,62 @@ +-- This test is designed for testing MariaDB's key_cache_segments for MyISAM, +-- and should work with other storage engines as well. +-- +-- For details about key_cache_segments please refer to: +-- http://kb.askmonty.org/v/segmented-key-cache +-- + +-- Override oltp_tables_count, this test only supports a single table +oltp_tables_count = 1 + +pathtest = string.match(test, "(.*/)") + +if pathtest then + dofile(pathtest .. "oltp_common.lua") +else + require("oltp_common") +end + +function thread_init() + set_vars_ranges() + + drv = sysbench.sql.driver() + con = drv:connect() + + local ranges = string.rep("k BETWEEN ? AND ? OR ", number_of_ranges - 1) .. + "k BETWEEN ? AND ?" + + stmt = con:prepare(string.format([[ + SELECT count(k) + FROM sbtest1 + WHERE %s]], ranges)) + + params = {} + for j = 1, number_of_ranges*2 do + params[j] = stmt:bind_create(sysbench.sql.type.INT) + end + + stmt:bind_param(unpack(params)) + + rlen = oltp_table_size / num_threads +end + +function event(thread_id) + -- To prevent overlapping of our range queries we need to partition the whole + -- table into num_threads segments and then make each thread work with its + -- own segment. + for i = 1, number_of_ranges*2, 2 do + local rmin = rlen * thread_id + local rmax = rmin + rlen + local val = sb_rand(rmin, rmax) + params[i]:set(val) + params[i+1]:set(val + delta) + end + + stmt:execute() +end + +function set_vars_ranges() + set_vars() + number_of_ranges = number_of_ranges or 10 + delta = random_ranges_delta or 5 +end diff --git a/tests/t/script_select_random_mysql.t.disabled b/tests/t/script_select_random_mysql.t similarity index 97% rename from tests/t/script_select_random_mysql.t.disabled rename to tests/t/script_select_random_mysql.t index dbb75d0..b2eb389 100644 --- a/tests/t/script_select_random_mysql.t.disabled +++ b/tests/t/script_select_random_mysql.t @@ -52,7 +52,7 @@ select_random_*.lua + MySQL tests write: 0 other: 0 total: 100 - transactions: 0 (0.00 per sec.) + transactions: 100 (* per sec.) (glob) queries: 100 (* per sec.) (glob) ignored errors: 0 (0.00 per sec.) reconnects: 0 (0.00 per sec.) @@ -122,7 +122,7 @@ select_random_*.lua + MySQL tests write: 0 other: 0 total: 100 - transactions: 0 (0.00 per sec.) + transactions: 100 (* per sec.) (glob) queries: 100 (* per sec.) (glob) ignored errors: 0 (0.00 per sec.) reconnects: 0 (0.00 per sec.) diff --git a/tests/t/script_select_random_pgsql.t.disabled b/tests/t/script_select_random_pgsql.t similarity index 97% rename from tests/t/script_select_random_pgsql.t.disabled rename to tests/t/script_select_random_pgsql.t index 8dcc87f..847f7fc 100644 --- a/tests/t/script_select_random_pgsql.t.disabled +++ b/tests/t/script_select_random_pgsql.t @@ -53,7 +53,7 @@ select_random_*.lua + PostgreSQL tests write: 0 other: 0 total: 100 - transactions: 0 (0.00 per sec.) + transactions: 100 (* per sec.) (glob) queries: 100 (* per sec.) (glob) ignored errors: 0 (0.00 per sec.) reconnects: 0 (0.00 per sec.) @@ -124,7 +124,7 @@ select_random_*.lua + PostgreSQL tests write: 0 other: 0 total: 100 - transactions: 0 (0.00 per sec.) + transactions: 100 (* per sec.) (glob) queries: 100 (* per sec.) (glob) ignored errors: 0 (0.00 per sec.) reconnects: 0 (0.00 per sec.)