-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathselect_random_points.lua
More file actions
79 lines (65 loc) · 2.22 KB
/
Copy pathselect_random_points.lua
File metadata and controls
79 lines (65 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env sysbench
-- 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
--
require("oltp_common")
-- Add random_points to the list of standard OLTP options
sysbench.cmdline.options.random_points =
{"Number of random points in the IN() clause in generated SELECTs", 10}
-- Override standard prepare/cleanup OLTP functions, as this benchmark does not
-- support multiple tables
oltp_prepare = prepare
oltp_cleanup = cleanup
function prepare()
assert(sysbench.opt.tables == 1, "this benchmark does not support " ..
"--tables > 1")
oltp_prepare()
end
function cleanup()
assert(sysbench.opt.tables == 1, "this benchmark does not support " ..
"--tables > 1")
oltp_cleanup()
end
function thread_init()
drv = sysbench.sql.driver()
con = drv:connect()
local rs = con:query("select connection_id()")
for i = 1, rs.nrows do
print(string.format("open connection id: %s\n", unpack(rs:fetch_row(), 1, rs.nfields)))
end
local points = string.rep("?, ", sysbench.opt.random_points - 1) .. "?"
stmt = con:prepare(string.format([[
SELECT id, k, c, pad
FROM sbtest1
WHERE k IN (%s)
]], points))
params = {}
for j = 1, sysbench.opt.random_points do
params[j] = stmt:bind_create(sysbench.sql.type.INT)
end
stmt:bind_param(unpack(params))
rlen = sysbench.opt.table_size / sysbench.opt.threads
thread_id = sysbench.tid % sysbench.opt.threads
end
function thread_done()
stmt:close()
local rs = con:query("select connection_id()")
for i = 1, rs.nrows do
print(string.format("close connection id: %s\n", unpack(rs:fetch_row(), 1, rs.nfields)))
end
con:disconnect()
end
function event()
-- To prevent overlapping of our range queries we need to partition the whole
-- table into 'threads' segments and then make each thread work with its
-- own segment.
for i = 1, sysbench.opt.random_points do
local rmin = rlen * thread_id
local rmax = rmin + rlen
params[i]:set(sb_rand(rmin, rmax))
end
stmt:execute()
end