-
Notifications
You must be signed in to change notification settings - Fork 5
/
oltp_prepared.lua
125 lines (103 loc) · 4.51 KB
/
oltp_prepared.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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
pathtest = string.match(test, "(.*/)") or ""
dofile(pathtest .. "common.lua")
function thread_init(thread_id)
set_vars()
if (((db_driver == "mysql") or (db_driver == "attachsql")) and mysql_table_engine == "myisam") then
begin_query = "LOCK TABLES sbtest WRITE"
commit_query = "UNLOCK TABLES"
else
begin_query = "BEGIN"
commit_query = "COMMIT"
end
table_name = "sbtest".. sb_rand_uniform(1, oltp_tables_count)
point_stmt = db_prepare("SELECT c FROM ".. table_name .." WHERE id = ?")
simple_range_stmt = db_prepare("SELECT c FROM ".. table_name .." WHERE id BETWEEN ? AND ?")
sum_range_stmt = db_prepare("SELECT SUM(K) FROM ".. table_name .." WHERE id BETWEEN ? AND ?")
order_range_stmt = db_prepare("SELECT c FROM ".. table_name .." WHERE id BETWEEN ? AND ? ORDER BY c")
distinct_range_stmt = db_prepare("SELECT DISTINCT c FROM ".. table_name .." WHERE id BETWEEN ? AND ? ORDER BY c")
index_update_stmt = db_prepare("UPDATE " .. table_name .. " SET k = k + 1 WHERE id = ?")
non_index_update_stmt = db_prepare("UPDATE " .. table_name .. " SET c = ? WHERE id = ?")
delete_stmt = db_prepare("DELETE FROM " .. table_name .. " WHERE id = ?")
insert_stmt = db_prepare("INSERT INTO " .. table_name .. " (id, k, c, pad) VALUES (?, ?, ?, ?)")
point_params = {}
point_params[1] = 1
range_params = {1, 1}
non_index_update_params = {"###########-###########-###########-###########-###########-###########-###########-###########-###########-###########", 1}
insert_params = {1, 1, "###########-###########-###########-###########-###########-###########-###########-###########-###########-###########", "###########-###########-###########-###########-###########"}
db_bind_param(point_stmt, point_params)
db_bind_param(simple_range_stmt, range_params)
db_bind_param(sum_range_stmt, range_params)
db_bind_param(order_range_stmt, range_params)
db_bind_param(distinct_range_stmt, range_params)
db_bind_param(index_update_stmt, point_params)
db_bind_param(non_index_update_stmt, non_index_update_params)
db_bind_param(delete_stmt, point_params)
db_bind_param(insert_stmt, insert_params)
end
function event(thread_id)
local rs
local i
local range_start
local c_val
local pad_val
local query
if not oltp_skip_trx then
db_query(begin_query)
end
for i=1, oltp_point_selects do
point_params[1] = sb_rand(1, oltp_table_size)
rs = db_execute(point_stmt)
db_free_results(rs)
end
for i=1, oltp_simple_ranges do
range_params[1] = sb_rand(1, oltp_table_size)
range_params[2] = range_params[1] + oltp_range_size
rs = db_execute(simple_range_stmt)
db_free_results(rs)
end
for i=1, oltp_sum_ranges do
range_params[1] = sb_rand(1, oltp_table_size)
range_params[2] = range_params[1] + oltp_range_size
rs = db_execute(sum_range_stmt)
db_free_results(rs)
end
for i=1, oltp_order_ranges do
range_params[1] = sb_rand(1, oltp_table_size)
range_params[2] = range_params[1] + oltp_range_size
rs = db_execute(order_range_stmt)
db_free_results(rs)
end
for i=1, oltp_distinct_ranges do
range_params[1] = sb_rand(1, oltp_table_size)
range_params[2] = range_params[1] + oltp_range_size
rs = db_execute(distinct_range_stmt)
db_free_results(rs)
end
if not oltp_read_only then
for i=1, oltp_index_updates do
point_params[1] = sb_rand(1, oltp_table_size)
rs = db_execute(index_update_stmt)
end
for i=1, oltp_non_index_updates do
non_index_update_params[1] = sb_rand_str("###########-###########-###########-###########-###########-###########-###########-###########-###########-###########")
non_index_update_params[2] = sb_rand(1, oltp_table_size)
rs = db_execute(non_index_update_stmt)
--prints table: 0x... if enabled
--if rs then
--print(non_index_update_params)
--end
end
point_params[1] = sb_rand(1, oltp_table_size)
rs = db_execute(delete_stmt)
insert_params[1] = point_params[1]
insert_params[2] = sb_rand(1, oltp_table_size)
insert_params[3] = sb_rand_str([[
###########-###########-###########-###########-###########-###########-###########-###########-###########-###########]])
insert_params[4] = sb_rand_str([[
###########-###########-###########-###########-###########]])
rs = db_execute(insert_stmt)
end -- oltp_read_only
if not oltp_skip_trx then
db_query(commit_query)
end
end