-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfull_table_postgres.lua
54 lines (41 loc) · 1.25 KB
/
full_table_postgres.lua
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
sysbench.cmdline.options = {
table_size = {"Number of rows per table", 10000},
create_table_options = {"Extra CREATE TABLE options", ""},
}
function prepare()
local drv = sysbench.sql.driver()
local con = drv:connect()
print("Creating table 'sbtest1'")
local create_query = string.format( [[
CREATE TABLE sbtest1 (
id INT NOT NULL,
col int not null,
PRIMARY KEY(id)
); ]] .. sysbench.opt.create_table_options)
con:query(create_query)
if (sysbench.opt.table_size > 0) then
print(string.format("Inserting %d records into 'sbtest1'", sysbench.opt.table_size))
end
local query = [[INSERT INTO sbtest1 (id, col) VALUES ]]
local str_vals = {"val0", "val1", "val2"}
math.randomseed(0)
con:bulk_insert_init(query)
for i = 1, sysbench.opt.table_size do
local row_values = "(" .. i .. "," .. -- id
math.random(-2147483648, 2147483647) .. ")" -- col
con:bulk_insert_next(row_values)
end
con:bulk_insert_done()
end
function thread_init()
drv = sysbench.sql.driver()
con = drv:connect()
stmt = con:prepare('SELECT * FROM sbtest1')
end
function thread_done()
stmt:close()
con:disconnect()
end
function event()
stmt:execute()
end