You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.3 KiB
50 lines
1.3 KiB
#!/usr/bin/sysbench
|
|
|
|
require("account_common")
|
|
|
|
|
|
local function select_account_cmd(db_index)
|
|
return string.format(
|
|
"select * from %s_%d where accountType=? and accountId=?",
|
|
account_table_name, db_index
|
|
)
|
|
end
|
|
|
|
thread_stmt_map = thread_stmt_map or {}
|
|
function thread_init()
|
|
drv = sysbench.sql.driver()
|
|
con = drv:connect()
|
|
|
|
-- 初始化当前线程的查询
|
|
local one_thread_count = account_table_max / sysbench.opt.threads;
|
|
local db_start = thread_id * one_thread_count;
|
|
for i=1, one_thread_count do
|
|
thread_stmt_map[j] = {
|
|
stmt = con:prepare(select_account_cmd(db_start+i)),
|
|
params = {
|
|
[1] = stmt:bind_create(sysbench.sql.type.INT),
|
|
[2] = stmt:bind_create(sysbench.sql.type.VARCHAR),
|
|
}
|
|
}
|
|
thread_stmt_map[j].stmt:bind_param(unpack(thread_stmt_map[j].params));
|
|
end
|
|
end
|
|
|
|
function thread_done()
|
|
local one_thread_count = account_table_max / sysbench.opt.threads;
|
|
for i=1, one_thread_count do
|
|
thread_stmt_map[j].stmt:close()
|
|
end
|
|
con:disconnect()
|
|
end
|
|
|
|
function select_account()
|
|
local account_id = sysbench.rand.default(1, 5000)
|
|
params[1]:set(accountId_to_type(account_id))
|
|
params[2]:set(get_account_id(account_id))
|
|
stmt:execute()
|
|
end
|
|
|
|
function event()
|
|
select_account()
|
|
end
|
|
|