-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_common.lua
85 lines (74 loc) · 1.82 KB
/
test_common.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
function thread_init(thread_id)
set_vars()
end
function set_vars()
branches_size = branches_size or 1
tellers_size = tellers_size or 10
accounts_size = accounts_size or 100000
scale = scale or 1
mysql_table_engine = mysql_table_engine or "innodb"
end
function prepare()
set_vars()
db_connect()
db_query([[
create table accounts(
aid int not null primary key,
bid int,
abalance int,
filler char(84)
)
/*! ENGINE = ]] .. mysql_table_engine ..
[[ default character set=latin1 */
]])
db_query([[
create table branches(
bid int not null primary key,
bbalance int,
filler char(88)
)
/*! ENGINE = ]] .. mysql_table_engine ..
[[ default character set=latin1 */
]])
db_query([[
create table history(
tid int,
bid int,
aid int,
delta int,
mtime timestamp,
filler char(22)
)
/*! ENGINE = ]] .. mysql_table_engine ..
[[ default character set=latin1 */
]])
db_query([[
create table tellers(
tid int primary key,
bid int,
tbalance int,
filler char(84)
)
/*! ENGINE = ]] .. mysql_table_engine ..
[[ default character set=latin1 */
]])
db_bulk_insert_init("insert into branches (bid, bbalance, filler) values")
for i=1,(branches_size * scale) do
db_bulk_insert_next("(" .. i .. ", 0, '')")
end
db_bulk_insert_done()
db_bulk_insert_init("insert into tellers (tid, bid, tbalance, filler) values")
for i=1,(tellers_size * scale) do
db_bulk_insert_next("(" .. i .. ", " .. ((i % (branches_size * scale)) + 1) .. ", 0, '')")
end
db_bulk_insert_done()
db_bulk_insert_init("insert into accounts (aid, bid, abalance, filler) values")
for i=1,(accounts_size * scale) do
db_bulk_insert_next("(" .. i .. ", " .. ((i % (branches_size * scale)) + 1) .. ", 0, '')")
end
db_bulk_insert_done()
end
function cleanup()
print("Dropping tables accounts, branches, history, tellers");
db_query("drop table accounts, branches, history, tellers")
end