!51 mot sp for sysbench

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

View File

@ -0,0 +1,6 @@
1. complile sysbench binary by README.md
2. cd tests/include/oltp_mot_sp_legacy
3. you should first run create_mot_jit_sp.sh to create procedure in openGauss
4. then you can run oltp_read_write.lua for test

View File

@ -0,0 +1,190 @@
-- Input parameters
-- oltp-tables-count - number of tables to create
-- oltp-secondary - use secondary key instead PRIMARY key for id column
--
--
function create_insert(table_id)
local index_name
local i
local j
local query
if (oltp_secondary) then
index_name = "KEY xid"
else
index_name = "PRIMARY KEY"
end
if (pgsql_variant == 'redshift') then
auto_inc_type = "INTEGER IDENTITY(1,1)"
else
auto_inc_type = "SERIAL"
end
i = table_id
print("Creating foreign table 'sbtest" .. i .. "'...")
if ((db_driver == "mysql") or (db_driver == "attachsql")) then
query = [[
CREATE FOREIGN TABLE sbtest]] .. i .. [[ (
id INTEGER UNSIGNED NOT NULL ]] ..
((oltp_auto_inc and "AUTO_INCREMENT") or "") .. [[,
k INTEGER UNSIGNED DEFAULT '0' NOT NULL,
c CHAR(120) DEFAULT '' NOT NULL,
pad CHAR(60) DEFAULT '' NOT NULL,
]] .. index_name .. [[ (id)
) /*! ENGINE = ]] .. mysql_table_engine ..
" MAX_ROWS = " .. myisam_max_rows .. " */ " ..
(mysql_table_options or "")
elseif (db_driver == "pgsql") then
query = [[
CREATE FOREIGN TABLE IF NOT EXISTS sbtest]] .. i .. [[ (
id ]] .. auto_inc_type .. [[ NOT NULL,
k INTEGER DEFAULT '0' NOT NULL,
c CHAR(120) DEFAULT '' NOT NULL,
pad CHAR(60) DEFAULT '' NOT NULL,
]] .. index_name .. [[ (id)
) ]]
elseif (db_driver == "drizzle") then
query = [[
CREATE FOREIGN TABLE sbtest (
id INTEGER NOT NULL ]] .. ((oltp_auto_inc and "AUTO_INCREMENT") or "") .. [[,
k INTEGER DEFAULT '0' NOT NULL,
c CHAR(120) DEFAULT '' NOT NULL,
pad CHAR(60) DEFAULT '' NOT NULL,
]] .. index_name .. [[ (id)
) ]]
else
print("Unknown database driver: " .. db_driver)
return 1
end
db_query(query)
print("Inserting " .. oltp_table_size .. " records into 'sbtest" .. i .. "'")
if (oltp_auto_inc) then
db_bulk_insert_init("INSERT INTO sbtest" .. i .. "(k, c, pad) VALUES")
else
db_bulk_insert_init("INSERT INTO sbtest" .. i .. "(id, k, c, pad) VALUES")
end
local c_val
local pad_val
for j = 1,oltp_table_size do
c_val = sb_rand_str([[
###########-###########-###########-###########-###########-###########-###########-###########-###########-###########]])
pad_val = sb_rand_str([[
###########-###########-###########-###########-###########]])
if (oltp_auto_inc) then
db_bulk_insert_next("(" .. sb_rand(1, oltp_table_size) .. ", '".. c_val .."', '" .. pad_val .. "')")
else
db_bulk_insert_next("("..j.."," .. sb_rand(1, oltp_table_size) .. ",'".. c_val .."', '" .. pad_val .. "' )")
end
end
db_bulk_insert_done()
if oltp_create_secondary then
print("Creating secondary indexes on 'sbtest" .. i .. "'...")
db_query("CREATE INDEX k_" .. i .. " on sbtest" .. i .. "(k)")
end
end
function prepare()
local query
local i
local j
set_vars()
db_connect()
for i = 1,oltp_tables_count do
create_insert(i)
end
return 0
end
function cleanup()
local i
set_vars()
for i = 1,oltp_tables_count do
print("Dropping table 'sbtest" .. i .. "'...")
db_query("DROP FOREIGN TABLE IF EXISTS sbtest".. i )
end
end
function set_vars()
oltp_table_size = tonumber(oltp_table_size) or 10000
oltp_range_size = tonumber(oltp_range_size) or 100
oltp_tables_count = tonumber(oltp_tables_count) or 1
oltp_point_selects = tonumber(oltp_point_selects) or 10
oltp_simple_ranges = tonumber(oltp_simple_ranges) or 1
oltp_sum_ranges = tonumber(oltp_sum_ranges) or 1
oltp_order_ranges = tonumber(oltp_order_ranges) or 1
oltp_distinct_ranges = tonumber(oltp_distinct_ranges) or 1
oltp_index_updates = tonumber(oltp_index_updates) or 1
oltp_non_index_updates = tonumber(oltp_non_index_updates) or 1
oltp_delete_inserts = tonumber(oltp_delete_inserts) or 1
if (oltp_range_selects == 'off') then
oltp_range_selects = false
else
oltp_range_selects = true
end
if (oltp_auto_inc == 'off') then
oltp_auto_inc = false
else
oltp_auto_inc = true
end
if (oltp_read_only == 'on') then
oltp_read_only = true
else
oltp_read_only = false
end
if (oltp_write_only == 'on') then
oltp_write_only = true
else
oltp_write_only = false
end
if (oltp_read_only and oltp_write_only) then
error("--oltp-read-only and --oltp-write-only are mutually exclusive")
end
if (oltp_skip_trx == 'on') then
oltp_skip_trx = true
else
oltp_skip_trx = false
end
if (oltp_create_secondary == 'off') then
oltp_create_secondary = false
else
oltp_create_secondary = true
end
if (pgsql_variant == 'redshift') then
oltp_create_secondary = false
oltp_delete_inserts = 0
end
end

View File

@ -0,0 +1,97 @@
#!/bin/bash
for i in {1..24}
do
gsql -d testdb -p 5432 << EOF
CREATE OR REPLACE PROCEDURE select_c_from_sbtest$i(IN id_param INT, OUT out1 TEXT) AS
DECLARE
pad_val TEXT;
i INT := id_param;
i_end INT := i+10;
BEGIN
FOR x IN i..i_end LOOP
SELECT c INTO pad_val FROM sbtest$i WHERE id = x;
END LOOP;
END;
/
CREATE OR REPLACE PROCEDURE select_c_where_sbtest$i(IN a_param INT, IN b_param INT, OUT out1 TEXT) AS
BEGIN
PERFORM c FROM sbtest$i WHERE id BETWEEN a_param AND b_param;
out1 := '0';
END;
/
CREATE OR REPLACE PROCEDURE select_sum_sbtest$i(IN a_param INT, IN b_param INT, OUT out1 TEXT) AS
DECLARE
pad_val INT;
BEGIN
SELECT SUM(K) INTO pad_val FROM sbtest$i WHERE id BETWEEN a_param AND b_param;
out1 := '0';
END;
/
CREATE OR REPLACE PROCEDURE select_c_where_order_sbtest$i(IN a_param INT, IN b_param INT, OUT out1 TEXT) AS
BEGIN
PERFORM c FROM sbtest$i WHERE id BETWEEN a_param AND b_param ORDER BY c;
out1 := '0';
END;
/
CREATE OR REPLACE PROCEDURE insert_into1_sbtest$i(IN k_param INT, IN c_param TEXT, IN pad_param TEXT, OUT out1 TEXT) AS
BEGIN
INSERT INTO sbtest$i (k, c, pad) VALUES (k_param, c_param, pad_param);
out1 := '1';
END;
/
CREATE OR REPLACE PROCEDURE insert_into2_sbtest$i(IN id_param INT, IN k_param INT, IN c_param TEXT, IN pad_param TEXT, OUT out1 TEXT) AS
BEGIN
INSERT INTO sbtest$i (id, k, c, pad) VALUES (id_param, k_param, c_param, pad_param);
out1 := '1';
END;
/
CREATE OR REPLACE PROCEDURE insert_into_sbtest$i(IN id_param INT, IN k_param INT, IN c_param TEXT, IN pad_param TEXT, OUT out1 TEXT) AS
BEGIN
INSERT INTO sbtest$i (id, k, c, pad) VALUES (id_param, k_param, c_param, pad_param);
out1 := '1';
END;
/
CREATE OR REPLACE PROCEDURE update_sbtest$i(IN c_param TEXT, IN id_param INT, OUT out1 TEXT) AS
BEGIN
UPDATE sbtest$i SET c = c_param WHERE id = id_param;
out1 := '1';
END;
/
CREATE OR REPLACE PROCEDURE delete_from_sbtest$i(IN id_param INT, OUT out1 TEXT) AS
BEGIN
DELETE FROM sbtest$i WHERE id = id_param;
out1 := '1';
END;
/
CREATE OR REPLACE PROCEDURE sp_sbtest$i(IN id_param INT, IN k_param INT, IN c_param TEXT, IN pad_param TEXT, OUT out1 TEXT) AS
DECLARE
pad_val TEXT;
i INT := id_param;
i_end INT := i+10;
BEGIN
FOR x IN i..i_end LOOP
SELECT c INTO pad_val FROM sbtest$i WHERE id = x;
END LOOP;
UPDATE sbtest$i SET c = c_param WHERE id = id_param;
DELETE FROM sbtest$i WHERE id = id_param;
INSERT INTO sbtest$i (id, k, c, pad) VALUES (id_param, k_param, c_param, pad_param);
out1 := '0';
EXCEPTION WHEN OTHERS THEN out1 := '0'; END;
END;
/
EOF
# echo $i
done

View File

@ -0,0 +1,76 @@
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_sp_sbtest"..i.."(INT,INT,TEXT,TEXT) AS SELECT * FROM sp_sbtest"..i.."($1,$2,$3,$4);")
rc = db_query("PREPARE ps_select_c_from_sbtest"..i.."(INT) AS SELECT * FROM select_c_from_sbtest"..i.."($1);")
rc = db_query("PREPARE select_c_from_sbtest"..i.."(INT) AS SELECT * FROM sbtest"..i.." WHERE id = " .. "($1);")
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
oltp_skip_trx = true
table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count)
if not oltp_read_only then
id = sb_rand(1, oltp_table_size)
c_val = sb_rand_str([[
###########-###########-###########-###########-###########-###########-###########-###########-###########-###########]])
pad_val = sb_rand_str([[
###########-###########-###########-###########-###########]])
rc = db_query("EXECUTE ps_sp_" .. table_name .. "" .. string.format("(%d, %d, '%s', '%s')",id, sb_rand(1, oltp_table_size) , c_val, pad_val) )
--rc = db_query("EXECUTE ps_select_c_from_" .. table_name .. "" .. string.format("(%d)",id) )
end
if oltp_read_only then
id = sb_rand(1, oltp_table_size)
--rs = db_query("EXECUTE select_c_from_".. table_name .."(" .. sb_rand(1, oltp_table_size) .. ")")
rc = db_query("EXECUTE ps_select_c_from_" .. table_name .. "" .. string.format("(%d)",id) )
end
if not oltp_skip_trx then
db_query(commit_query)
end
end