!50 first commit for oltp_mot_sp_legacy

Merge pull request !50 from 熊小军/master2
This commit is contained in:
opengauss-bot 2023-05-30 09:12:15 +00:00 committed by Gitee
commit eb75538259
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
12 changed files with 635 additions and 0 deletions

View File

@ -0,0 +1,61 @@
-- -------------------------------------------------------------------------- --
-- Bulk insert tests --
-- -------------------------------------------------------------------------- --
cursize=0
function prepare()
local i
db_connect()
for i = 0,num_threads-1 do
if (db_driver == "pgsql") then
db_query([[
CREATE TABLE IF NOT EXISTS sbtest]] .. i .. [[ (
id INTEGER NOT NULL,
k INTEGER DEFAULT '0' NOT NULL,
PRIMARY KEY (id)
)]])
else
db_query([[
CREATE TABLE IF NOT EXISTS sbtest]] .. i .. [[ (
id INTEGER UNSIGNED NOT NULL,
k INTEGER UNSIGNED DEFAULT '0' NOT NULL,
PRIMARY KEY (id)
) ENGINE = InnoDB
]])
end
end --for
end
function event()
local i
if (cursize == 0) then
db_bulk_insert_init("INSERT INTO sbtest" .. thread_id .. " VALUES")
end
cursize = cursize + 1
db_bulk_insert_next("(" .. cursize .. "," .. cursize .. ")")
end
function thread_done(thread_9d)
db_bulk_insert_done()
end
function cleanup()
local i
for i = 0,num_threads-1 do
print("Dropping table 'sbtest" .. i .. "'...")
db_query("DROP TABLE IF EXISTS sbtest".. i )
end
end

View File

@ -0,0 +1,17 @@
pathtest = string.match(test, "(.*/)")
if pathtest then
dofile(pathtest .. "common_mot.lua")
else
require("common")
end
function thread_init()
set_vars()
end
function event()
local table_name
table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count)
rs = db_query("DELETE FROM " .. table_name .. " WHERE id=" .. sb_rand(1, oltp_table_size))
end

View File

@ -0,0 +1,56 @@
-- pathtest = string.match(test, "(.*/)")
pathtest = "/home/gauss/mot_tests/tools/sysbench-master/tests/include/oltp_mot_sp_legacy/"
-- print(pathtest)
if pathtest then
dofile(pathtest .. "common_mot.lua")
else
require("common")
end
function prepare_statements()
for i=1, oltp_tables_count do
rc = db_query("PREPARE ps1_insert_into_sbtest"..i.."(INT,TEXT,TEXT) AS SELECT * FROM insert_into1_sbtest"..i.."($1,$2,$3);")
rc = db_query("PREPARE ps2_insert_into_sbtest"..i.."(INT,INT,TEXT,TEXT) AS SELECT * FROM insert_into2_sbtest"..i.."($1,$2,$3,$4);")
end
print("PREPARE STATEMENT FOR STORE PROCEDURE INSERT")
end
function thread_init(thread_id)
set_vars()
prepare_statements()
end
function event()
local table_name
local i
local c_val
local k_val
local pad_val
table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count)
k_val = sb_rand(1, oltp_table_size)
c_val = sb_rand_str([[
###########-###########-###########-###########-###########-###########-###########-###########-###########-###########]])
pad_val = sb_rand_str([[
###########-###########-###########-###########-###########]])
if (db_driver == "pgsql" and oltp_auto_inc) then
-- rs = db_query("INSERT INTO " .. table_name .. " (k, c, pad) VALUES " ..
-- string.format("(%d, '%s', '%s')", k_val, c_val, pad_val))
rc = db_query("EXECUTE ps1_insert_into_" .. table_name .. "" .. string.format("(%d, '%s', '%s')", k_val, c_val, pad_val .. "") )
-- rc = 0
else
if (oltp_auto_inc) then
i = 0
else
i = sb_rand_uniq()
end
-- rs = db_query("INSERT INTO " .. table_name ..
-- " (id, k, c, pad) VALUES " ..
-- string.format("(%d, %d, '%s', '%s')", i, k_val, c_val,
-- pad_val))
rc = db_query("EXECUTE ps2_insert_into_" .. table_name .. "" .. string.format("(%d, %d, '%s', '%s')", i, k_val, c_val, pad_val .. "") )
-- rc = 0
end
end

View File

@ -0,0 +1,114 @@
pathtest = string.match(test, "(.*/)")
if pathtest then
dofile(pathtest .. "common_mot.lua")
else
require("common")
end
function thread_init()
set_vars()
if (((db_driver == "mysql") or (db_driver == "attachsql")) and mysql_table_engine == "myisam") then
local i
local tables = {}
for i=1, oltp_tables_count do
tables[i] = string.format("sbtest%i WRITE", i)
end
begin_query = "LOCK TABLES " .. table.concat(tables, " ,")
commit_query = "UNLOCK TABLES"
else
begin_query = "BEGIN"
commit_query = "COMMIT"
end
end
function get_range_str()
local start = sb_rand(1, oltp_table_size)
return string.format(" WHERE id BETWEEN %u AND %u",
start, start + oltp_range_size - 1)
end
function event()
local rs
local i
local table_name
local c_val
local pad_val
local query
table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count)
if not oltp_skip_trx then
db_query(begin_query)
end
if not oltp_write_only then
for i=1, oltp_point_selects do
rs = db_query("SELECT c FROM ".. table_name .." WHERE id=" ..
sb_rand(1, oltp_table_size))
end
if oltp_range_selects then
for i=1, oltp_simple_ranges do
rs = db_query("SELECT c FROM ".. table_name .. get_range_str())
end
for i=1, oltp_sum_ranges do
rs = db_query("SELECT SUM(K) FROM ".. table_name .. get_range_str())
end
for i=1, oltp_order_ranges do
rs = db_query("SELECT c FROM ".. table_name .. get_range_str() ..
" ORDER BY c")
end
for i=1, oltp_distinct_ranges do
rs = db_query("SELECT DISTINCT c FROM ".. table_name .. get_range_str() ..
" ORDER BY c")
end
end
end
if not oltp_read_only then
for i=1, oltp_index_updates do
rs = db_query("UPDATE " .. table_name .. " SET k=k+1 WHERE id=" .. sb_rand(1, oltp_table_size))
end
for i=1, oltp_non_index_updates do
c_val = sb_rand_str("###########-###########-###########-###########-###########-###########-###########-###########-###########-###########")
query = "UPDATE " .. table_name .. " SET c='" .. c_val .. "' WHERE id=" .. sb_rand(1, oltp_table_size)
rs = db_query(query)
if rs then
print(query)
end
end
for i=1, oltp_delete_inserts do
i = sb_rand(1, oltp_table_size)
rs = db_query("DELETE FROM " .. table_name .. " WHERE id=" .. i)
c_val = sb_rand_str([[
###########-###########-###########-###########-###########-###########-###########-###########-###########-###########]])
pad_val = sb_rand_str([[
###########-###########-###########-###########-###########]])
rs = db_query("INSERT INTO " .. table_name .. " (id, k, c, pad) VALUES " .. string.format("(%d, %d, '%s', '%s')",i, sb_rand(1, oltp_table_size) , c_val, pad_val))
end
end -- oltp_read_only
if not oltp_skip_trx then
db_query(commit_query)
end
end

View File

@ -0,0 +1,148 @@
pathtest = string.match(test, "(.*/)")
if pathtest then
dofile(pathtest .. "common_mot.lua")
else
require("common")
end
function prepare_statements()
for i=1, oltp_tables_count do
rc = db_query("PREPARE ps_select_c_from_sbtest"..i.."(INT) AS SELECT * FROM select_c_from_sbtest"..i.."($1);")
rc = db_query("PREPARE ps_select_c_where_sbtest"..i.."(INT, INT) AS SELECT * FROM select_c_where_sbtest"..i.."($1,$2);")
rc = db_query("PREPARE ps_select_sum_sbtest"..i.."(INT, INT) AS SELECT * FROM select_sum_sbtest"..i.."($1,$2);")
rc = db_query("PREPARE ps_select_c_where_order_sbtest"..i.."(INT, INT) AS SELECT * FROM select_c_where_order_sbtest"..i.."($1,$2);")
rc = db_query("PREPARE ps_select_distinct_c_where_order_sbtest"..i.."(INT, INT) AS SELECT DISTINCT c FROM sbtest" ..i.. " WHERE id BETWEEN $1 AND $2 ORDER BY c;")
rc = db_query("PREPARE ps_update_sbtest"..i.."(TEXT,INT) AS SELECT * FROM update_sbtest"..i.."($1,$2);")
rc = db_query("PREPARE ps_delete_from_sbtest"..i.."(INT) AS SELECT * FROM delete_from_sbtest"..i.."($1);")
rc = db_query("PREPARE ps_insert_into_sbtest"..i.."(INT,INT,TEXT,TEXT) AS SELECT * FROM insert_into_sbtest"..i.."($1,$2,$3,$4);")
end
print("PREPARE STATEMENT FOR STORE PROCEDURE")
end
function thread_init()
set_vars()
if (((db_driver == "mysql") or (db_driver == "attachsql")) and mysql_table_engine == "myisam") then
local i
local tables = {}
for i=1, oltp_tables_count do
tables[i] = string.format("sbtest%i WRITE", i)
end
begin_query = "LOCK TABLES " .. table.concat(tables, " ,")
commit_query = "UNLOCK TABLES"
else
begin_query = "BEGIN"
commit_query = "COMMIT"
end
prepare_statements()
end
function get_range_str()
local start = sb_rand(1, oltp_table_size)
return string.format(" WHERE id BETWEEN %u AND %u",
start, start + oltp_range_size - 1)
end
function event()
local rs
local i
local table_name
local c_val
local pad_val
local query
table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count)
if not oltp_skip_trx then
db_query(begin_query)
end
if not oltp_write_only then
for i=1, oltp_point_selects do
-- rs = db_query("SELECT c FROM ".. table_name .." WHERE id=" ..
-- sb_rand(1, oltp_table_size))
rs = db_query("EXECUTE ps_select_c_from_".. table_name .."(" .. sb_rand(1, oltp_table_size) .. ")")
end
if oltp_range_selects then
for i=1, oltp_simple_ranges do
-- rs = db_query("SELECT c FROM ".. table_name .. get_range_str())
local start = sb_rand(1, oltp_table_size)
rs = db_query("EXECUTE ps_select_c_where_".. table_name .."(" .. string.format("%u, %u", start, start + oltp_range_size - 1) .. ")")
end
for i=1, oltp_sum_ranges do
-- rs = db_query("SELECT SUM(K) FROM ".. table_name .. get_range_str())
local start = sb_rand(1, oltp_table_size)
rs = db_query("EXECUTE ps_select_sum_".. table_name .."(" .. string.format("%u, %u", start, start + oltp_range_size - 1) .. ")")
end
for i=1, oltp_order_ranges do
-- rs = db_query("SELECT c FROM ".. table_name .. get_range_str() ..
-- " ORDER BY c")
local start = sb_rand(1, oltp_table_size)
rs = db_query("EXECUTE ps_select_c_where_order_".. table_name .."(" .. string.format("%u, %u", start, start + oltp_range_size - 1) .. ")")
end
for i=1, oltp_distinct_ranges do
-- rs = db_query("SELECT DISTINCT c FROM ".. table_name .. get_range_str() ..
-- " ORDER BY c")
local start = sb_rand(1, oltp_table_size)
rs = db_query("EXECUTE ps_select_distinct_c_where_order_".. table_name .."(" .. string.format("%u, %u", start, start + oltp_range_size - 1) .. ")")
end
end
end
if not oltp_read_only then
--[[
for i=1, oltp_index_updates do
rs = db_query("UPDATE " .. table_name .. " SET k=k+1 WHERE id=" .. sb_rand(1, oltp_table_size))
end
--]]
local range = oltp_table_size / threads
local start = range * thread_id
local stop = start + range
for i=1, oltp_non_index_updates do
c_val = sb_rand_str("###########-###########-###########-###########-###########-###########-###########-###########-###########-###########")
-- query = "UPDATE " .. table_name .. " SET c='" .. c_val .. "' WHERE id=" .. sb_rand(1, oltp_table_size)
-- rs = db_query(query)
-- rs = db_query("EXECUTE ps_update_".. table_name .."('" .. c_val .."', " .. sb_rand(1, oltp_table_size) .. ")")
rs = db_query("EXECUTE ps_update_".. table_name .."('" .. c_val .."', " .. sb_rand(start, stop) .. ")")
if rs then
print(query)
end
end
for i=1, oltp_delete_inserts do
-- i = sb_rand(1, oltp_table_size)
i = sb_rand(start, stop)
-- rs = db_query("DELETE FROM " .. table_name .. " WHERE id=" .. i)
rs = db_query("EXECUTE ps_delete_from_".. table_name .."(" .. i .. ")")
c_val = sb_rand_str([[
###########-###########-###########-###########-###########-###########-###########-###########-###########-###########]])
pad_val = sb_rand_str([[
###########-###########-###########-###########-###########]])
-- rs = db_query("INSERT INTO " .. table_name .. " (id, k, c, pad) VALUES " .. string.format("(%d, %d, '%s', '%s')",i, sb_rand(1, oltp_table_size) , c_val, pad_val))
rc = db_query("EXECUTE ps_insert_into_" .. table_name .. "" .. string.format("(%d, %d, '%s', '%s')",i, sb_rand(1, oltp_table_size) , c_val, pad_val) )
end
end -- oltp_read_only
if not oltp_skip_trx then
db_query(commit_query)
end
end

View File

@ -0,0 +1,19 @@
pathtest = string.match(test, "(.*/)")
if pathtest then
dofile(pathtest .. "common_mot.lua")
else
require("common")
end
function thread_init()
set_vars()
end
function event()
local table_name
table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count)
rs = db_query("SELECT c FROM ".. table_name .." WHERE id=" .. sb_rand(1, oltp_table_size))
end

View File

@ -0,0 +1,30 @@
-- for proper initialization use --max-requests = N, where N is --num-threads
--
pathtest = string.match(test, "(.*/)")
if pathtest then
dofile(pathtest .. "common_mot.lua")
else
require("common")
end
function thread_init()
set_vars()
end
function event()
local index_name
local i
print("thread prepare"..thread_id)
if (oltp_secondary) then
index_name = "KEY xid"
else
index_name = "PRIMARY KEY"
end
for i=thread_id+1, oltp_tables_count, num_threads do
create_insert(i)
end
end

View File

@ -0,0 +1,27 @@
pathtest = string.match(test, "(.*/)")
if pathtest then
dofile(pathtest .. "common_mot.lua")
else
require("common")
end
function prepare_statements()
for i=1, oltp_tables_count do
rc = db_query("PREPARE ps_select_from_sbtest"..i.."(INT) AS SELECT * FROM select_c_from_sbtest"..i.."($1);")
end
print("PREPARE STATEMENT FOR STORE PROCEDURE SELECT")
end
function thread_init()
set_vars()
prepare_statements()
end
function event()
local table_name
table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count)
rs = db_query("EXECUTE ps_select_from_".. table_name .."(" .. sb_rand(1, oltp_table_size) .. ")")
end

View File

@ -0,0 +1,61 @@
-- 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 .. "common_mot.lua")
else
require("common")
end
function thread_init()
set_vars_points()
points = ""
for i = 1,random_points do
points = points .. "?, "
end
-- Get rid of last comma and space.
points = string.sub(points, 1, string.len(points) - 2)
stmt = db_prepare([[
SELECT id, k, c, pad
FROM sbtest1
WHERE k IN (]] .. points .. [[)
]])
params = {}
for j = 1,random_points do
params[j] = 1
end
db_bind_param(stmt, params)
end
function event()
local rs
-- 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
params[i] = sb_rand(oltp_table_size / num_threads * thread_id, oltp_table_size / num_threads * (thread_id + 1))
end
rs = db_execute(stmt)
db_store_results(rs)
db_free_results(rs)
end
function set_vars_points()
set_vars()
random_points = random_points or 10
end

View File

@ -0,0 +1,64 @@
-- 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
--
pathtest = string.match(test, "(.*/)")
if pathtest then
dofile(pathtest .. "common_mot.lua")
else
require("common")
end
-- Override oltp_tables_count, this test only supports a single table
oltp_tables_count = 1
function thread_init()
set_vars_ranges()
ranges = ""
for i = 1,number_of_ranges do
ranges = ranges .. "k BETWEEN ? AND ? OR "
end
-- Get rid of last OR and space.
ranges = string.sub(ranges, 1, string.len(ranges) - 3)
stmt = db_prepare([[
SELECT count(k)
FROM sbtest1
WHERE ]] .. ranges .. [[
]])
params = {}
for j = 1,number_of_ranges * 2 do
params[j] = 1
end
db_bind_param(stmt, params)
end
function event()
local rs
-- 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
params[i] = sb_rand(oltp_table_size / num_threads * thread_id, oltp_table_size / num_threads * (thread_id + 1))
params[i + 1] = params[i] + delta
end
rs = db_execute(stmt)
db_store_results(rs)
db_free_results(rs)
end
function set_vars_ranges()
set_vars()
number_of_ranges = number_of_ranges or 10
delta = random_ranges_delta or 5
end

View File

@ -0,0 +1,17 @@
pathtest = string.match(test, "(.*/)")
if pathtest then
dofile(pathtest .. "common_mot.lua")
else
require("common")
end
function thread_init()
set_vars()
end
function event()
local table_name
table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count)
rs = db_query("UPDATE ".. table_name .." SET k=k+1 WHERE id=" .. sb_rand(1, oltp_table_size))
end

View File

@ -0,0 +1,21 @@
pathtest = string.match(test, "(.*/)")
if pathtest then
dofile(pathtest .. "common_mot.lua")
else
require("common")
end
function thread_init()
set_vars()
end
function event()
local table_name
local c_val
local query
table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count)
c_val = sb_rand_str("###########-###########-###########-###########-###########-###########-###########-###########-###########-###########")
query = "UPDATE " .. table_name .. " SET c='" .. c_val .. "' WHERE id=" .. sb_rand(1, oltp_table_size)
rs = db_query(query)
end