-
Notifications
You must be signed in to change notification settings - Fork 119
/
mysqlolap.tcl
executable file
·2013 lines (1941 loc) · 113 KB
/
mysqlolap.tcl
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
proc build_mysqltpch {} {
global maxvuser suppo ntimes threadscreated _ED mysql_ssl_options
upvar #0 dbdict dbdict
if {[dict exists $dbdict mysql library ]} {
set library [ dict get $dbdict mysql library ]
} else { set library "mysqltcl" }
upvar #0 configmysql configmysql
#set variables to values in dict
setlocaltpchvars $configmysql
#If the options menu has been run under the GUI mysql_ssl_options is set
#If build is run under the GUI, CLI or WS mysql_ssl_options is not set
#Set it now if it doesn't exist
if ![ info exists mysql_ssl_options ] { check_mysql_ssl $configmysql }
if { ![string match windows $::tcl_platform(platform)] && ($mysql_host eq "127.0.0.1" || [ string tolower $mysql_host ] eq "localhost") && [ string tolower $mysql_socket ] != "null" } { set mysql_connector "$mysql_host:$mysql_socket" } else { set mysql_connector "$mysql_host:$mysql_port" }
if {[ tk_messageBox -title "Create Schema" -icon question -message "Ready to create a Scale Factor $mysql_scale_fact TPROC-H schema\n in host [string toupper $mysql_connector] under user [ string toupper $mysql_tpch_user ] in database [ string toupper $mysql_tpch_dbase ] with storage engine [ string toupper $mysql_tpch_storage_engine ]?" -type yesno ] == yes} {
if { $mysql_num_tpch_threads eq 1 } {
set maxvuser 1
} else {
set maxvuser [ expr $mysql_num_tpch_threads + 1 ]
}
set suppo 1
set ntimes 1
ed_edit_clear
set _ED(packagekeyname) "MySQL TPROC-H creation"
if { [catch {load_virtual} message]} {
puts "Failed to create threads for schema creation: $message"
return
}
.ed_mainFrame.mainwin.textFrame.left.text fastinsert end "#!/usr/local/bin/tclsh8.6
#LOAD LIBRARIES AND MODULES
set library $library
"
.ed_mainFrame.mainwin.textFrame.left.text fastinsert end {if [catch {package require $library} message] { error "Failed to load $library - $message" }
if [catch {::tcl::tm::path add modules} ] { error "Failed to find modules directory" }
if [catch {package require tpchcommon} ] { error "Failed to load tpch common functions" } else { namespace import tpchcommon::* }
proc GatherStatistics { mysql_handler is_oceanbase partition_num} {
puts "GATHERING SCHEMA STATISTICS"
if { $is_oceanbase == "true" } {
set sql(1) "set _force_parallel_query_dop = $partition_num;"
set sql(2) "set GLOBAL ob_query_timeout = 20000000000;"
set sql(3) "analyze table LINEITEM partition(LINEITEM) compute statistics for all columns size auto;"
set sql(4) "analyze table orders partition(orders) compute statistics for all columns size auto;"
set sql(5) "analyze table partsupp partition(partsupp) compute statistics for all columns size auto;"
set sql(6) "analyze table part partition(part) compute statistics for all columns size auto;"
set sql(7) "analyze table customer partition(customer) compute statistics for all columns size auto;"
set sql(8) "analyze table supplier partition(supplier) compute statistics for all columns size auto;"
set sql(9) "analyze table nation compute statistics for all columns size auto;"
set sql(10) "analyze table region compute statistics for all columns size auto;"
for { set i 1 } { $i <= 8 } { incr i } {
puts "$sql($i).."
mysqlexec $mysql_handler $sql($i)
}
} else {
set sql(1) "analyze table ORDERS, PARTSUPP, CUSTOMER, PART, SUPPLIER, NATION, REGION, LINEITEM"
mysqlexec $mysql_handler $sql(1)
}
return
}
proc chk_socket { host socket } {
if { ![string match windows $::tcl_platform(platform)] && ($host eq "127.0.0.1" || [ string tolower $host ] eq "localhost") && [ string tolower $socket ] != "null" } {
return "TRUE"
} else {
return "FALSE"
}
}
proc PrepareOceanbase { host port socket ssl_options user password ob_tenant_name} {
puts "Prepare Oceanbase"
global mysqlstatus
#ssl_options is variable length so build a connectstring
set use_socket "false"
append connectstring " -host $host -port $port"
foreach key [ dict keys $ssl_options ] {
append connectstring " $key [ dict get $ssl_options $key ] "
}
append connectstring " -user $user@sys -password $password"
set login_command "mysqlconnect [ dict get $connectstring ]"
puts "login_command: $login_command"
#eval the login command
if [catch {set ob_handler [eval $login_command]}] {
if $use_socket {
puts "the local socket connection to $socket could not be established"
} else {
puts "the tcp connection to $host:$port could not be established"
}
set connected "false"
} else {
set connected "true"
}
if {$connected} {
mysql::autocommit $ob_handler 0
catch {set ssl_status [ mysql::sel $ob_handler "show session status like 'ssl_cipher'" -list ]}
if { [ info exists ssl_status ] } {
puts [ join $ssl_status ]
}
set sql(1) "alter system set enable_sql_extension=True tenant=$ob_tenant_name;"
set sql(2) "alter system set enable_perf_event=True;"
for { set i 1 } { $i <= 2 } { incr i } {
puts "$sql($i)"
mysqlexec $ob_handler $sql($i)
}
puts "Oceanbase system parameters is ready"
return $ob_handler
} else {
error $mysqlstatus(message)
return
}
}
proc ConnectToMySQL { host port socket ssl_options user password is_oceanbase ob_tenant_name} {
global mysqlstatus
#ssl_options is variable length so build a connectstring
if { ($is_oceanbase == "false" ) && ([ chk_socket $host $socket ] eq "TRUE")} {
set use_socket "true"
append connectstring " -socket $socket"
} else {
set use_socket "false"
append connectstring " -host $host -port $port"
#if is_oceanbase is false and chk_socket is false we don't want to change the username
if { $is_oceanbase == "true" } {
set user "$user@$ob_tenant_name"
}
}
foreach key [ dict keys $ssl_options ] {
append connectstring " $key [ dict get $ssl_options $key ] "
}
append connectstring " -user $user -password $password"
set login_command "mysqlconnect [ dict get $connectstring ]"
#eval the login command
if [catch {set mysql_handler [eval $login_command]}] {
if $use_socket {
puts "the local socket connection to $socket could not be established"
} else {
puts "the tcp connection to $host:$port could not be established"
}
set connected "false"
} else {
set connected "true"
}
if {$connected} {
mysql::autocommit $mysql_handler 0
catch {set ssl_status [ mysql::sel $mysql_handler "show session status like 'ssl_cipher'" -list ]}
if { [ info exists ssl_status ] } {
puts [ join $ssl_status ]
}
return $mysql_handler
} else {
error $mysqlstatus(message)
return
}
}
proc CreateDatabase { mysql_handler db } {
puts "CHECKING IF DATABASE $db EXISTS"
set db_exists [ mysql::sel $mysql_handler "SELECT COUNT(*) FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '$db'" -flatlist ]
if { $db_exists } {
set table_count [ mysql::sel $mysql_handler "SELECT COUNT(DISTINCT TABLE_NAME) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '$db'" -flatlist ]
if { $table_count == 0 } {
puts "Empty database $db exists"
puts "Using existing empty Database $db for Schema build"
} else {
puts "Database $db exists but is not empty, specify a new or empty database name"
return false
}
} else {
puts "CREATING DATABASE $db"
set sql(1) "SET FOREIGN_KEY_CHECKS = 0"
set sql(2) "CREATE DATABASE IF NOT EXISTS `$db` CHARACTER SET latin1 COLLATE latin1_swedish_ci"
for { set i 1 } { $i <= 2 } { incr i } {
mysqlexec $mysql_handler $sql($i)
}
}
return true
}
proc CreateTables { mysql_handler mysql_tpch_storage_engine } {
puts "CREATING TPCH TABLES"
set sql(1) "CREATE TABLE `ORDERS` (
`O_ORDERDATE` DATE NULL,
`O_ORDERKEY` BIGINT NOT NULL,
`O_CUSTKEY` INT NOT NULL,
`O_ORDERPRIORITY` CHAR(15) BINARY NULL,
`O_SHIPPRIORITY` INT NULL,
`O_CLERK` CHAR(15) BINARY NULL,
`O_ORDERSTATUS` CHAR(1) BINARY NULL,
`O_TOTALPRICE` DECIMAL(10,2) NULL,
`O_COMMENT` VARCHAR(79) BINARY NULL,
PRIMARY KEY (`O_ORDERKEY`),
FOREIGN KEY ORDERS_FK1(`O_CUSTKEY`) REFERENCES CUSTOMER(`C_CUSTKEY`)
)
ENGINE = $mysql_tpch_storage_engine"
set sql(2) "CREATE TABLE `PARTSUPP` (
PS_PARTKEY INT NOT NULL,
PS_SUPPKEY INT NOT NULL,
PS_SUPPLYCOST INT NOT NULL,
PS_AVAILQTY INT NULL,
PS_COMMENT VARCHAR(199) BINARY NULL,
PRIMARY KEY (`PS_PARTKEY`,`PS_SUPPKEY`),
INDEX PARTSUPP_PART_FKIDX (`PS_PARTKEY`),
INDEX PARTSUPP_SUPPLIER_FKIDX (`PS_SUPPKEY`),
FOREIGN KEY PARTSUPP_FK1(`PS_PARTKEY`) REFERENCES PART(`P_PARTKEY`),
FOREIGN KEY PARTSUPP_FK2(`PS_SUPPKEY`) REFERENCES SUPPLIER(`S_SUPPKEY`)
)
ENGINE = $mysql_tpch_storage_engine"
set sql(3) "CREATE TABLE `CUSTOMER` (
C_CUSTKEY INT NOT NULL,
C_MKTSEGMENT CHAR(10) BINARY NULL,
C_NATIONKEY INT NULL,
C_NAME VARCHAR(25) BINARY NULL,
C_ADDRESS VARCHAR(40) BINARY NULL,
C_PHONE CHAR(15) BINARY NULL,
C_ACCTBAL DECIMAL(10,2) NULL,
C_COMMENT VARCHAR(118) BINARY NULL,
PRIMARY KEY (`C_CUSTKEY`),
INDEX CUSTOMER_NATION_FKIDX (`C_NATIONKEY`),
FOREIGN KEY CUSTOMER_FK1(`C_NATIONKEY`) REFERENCES NATION(`N_NATIONKEY`)
)
ENGINE = $mysql_tpch_storage_engine"
set sql(4) "CREATE TABLE `PART` (
P_PARTKEY INT NOT NULL,
P_TYPE VARCHAR(25) BINARY NULL,
P_SIZE INT NULL,
P_BRAND CHAR(10) BINARY NULL,
P_NAME VARCHAR(55) BINARY NULL,
P_CONTAINER CHAR(10) BINARY NULL,
P_MFGR CHAR(25) BINARY NULL,
P_RETAILPRICE DECIMAL(10,2) NULL,
P_COMMENT VARCHAR(23) BINARY NULL,
PRIMARY KEY (`P_PARTKEY`)
)
ENGINE = $mysql_tpch_storage_engine"
set sql(5) "CREATE TABLE `SUPPLIER` (
S_SUPPKEY INT NOT NULL,
S_NATIONKEY INT NULL,
S_COMMENT VARCHAR(102) BINARY NULL,
S_NAME CHAR(25) BINARY NULL,
S_ADDRESS VARCHAR(40) BINARY NULL,
S_PHONE CHAR(15) BINARY NULL,
S_ACCTBAL DECIMAL(10,2) NULL,
PRIMARY KEY (`S_SUPPKEY`),
FOREIGN KEY SUPPLIER_FK1(`S_NATIONKEY`) REFERENCES NATION(`N_NATIONKEY`)
)
ENGINE = $mysql_tpch_storage_engine"
set sql(6) "CREATE TABLE `NATION` (
N_NATIONKEY INT NOT NULL,
N_NAME CHAR(25) BINARY NULL,
N_REGIONKEY INT NULL,
N_COMMENT VARCHAR(152) BINARY NULL,
PRIMARY KEY (`N_NATIONKEY`),
INDEX NATION_REGIONKEY_FKIDX (`N_REGIONKEY`),
FOREIGN KEY NATION_FK1(`N_REGIONKEY`) REFERENCES REGION(`R_REGIONKEY`)
)
ENGINE = $mysql_tpch_storage_engine"
set sql(7) "CREATE TABLE `REGION` (
R_REGIONKEY INT NOT NULL,
R_NAME CHAR(25) BINARY NULL,
R_COMMENT VARCHAR(152) BINARY NULL,
PRIMARY KEY (`R_REGIONKEY`)
)
ENGINE = $mysql_tpch_storage_engine"
set sql(8) "CREATE TABLE `LINEITEM` (
L_SHIPDATE DATE NULL,
L_ORDERKEY BIGINT NOT NULL,
L_DISCOUNT DECIMAL(10,2) NOT NULL,
L_EXTENDEDPRICE DECIMAL(10,2) NOT NULL,
L_SUPPKEY INT NOT NULL,
L_QUANTITY INT NOT NULL,
L_RETURNFLAG CHAR(1) BINARY NULL,
L_PARTKEY INT NOT NULL,
L_LINESTATUS CHAR(1) BINARY NULL,
L_TAX DECIMAL(10,2) NOT NULL,
L_COMMITDATE DATE NULL,
L_RECEIPTDATE DATE NULL,
L_SHIPMODE CHAR(10) BINARY NULL,
L_LINENUMBER INT NOT NULL,
L_SHIPINSTRUCT CHAR(25) BINARY NULL,
L_COMMENT VARCHAR(44) BINARY NULL,
PRIMARY KEY (`L_ORDERKEY`, `L_LINENUMBER`),
INDEX LINEITEM_PART_SUPP_FKIDX (`L_PARTKEY`,`L_SUPPKEY`),
INDEX IDX_LINEITEM_ORDERKEY_FKIDX (`L_ORDERKEY`),
FOREIGN KEY LINEITEM_FK1(`L_ORDERKEY`) REFERENCES ORDERS(`O_ORDERKEY`),
FOREIGN KEY LINEITEM_FK2(`L_PARTKEY`, `L_SUPPKEY`) REFERENCES PARTSUPP(`PS_PARTKEY`, `PS_SUPPKEY`)
)
ENGINE = $mysql_tpch_storage_engine"
for { set i 1 } { $i <= 8 } { incr i } {
mysqlexec $mysql_handler $sql($i)
}
return
}
proc CreateOBTables { mysql_handler partitions_num } {
puts "CREATING OceanBase TPCH TABLES"
set sql(1) "CREATE TABLE IF NOT EXISTS `ORDERS` (
`O_ORDERDATE` DATE NULL,
`O_ORDERKEY` INT NOT NULL,
`O_CUSTKEY` INT NOT NULL,
`O_ORDERPRIORITY` CHAR(15) BINARY NULL,
`O_SHIPPRIORITY` INT NULL,
`O_CLERK` CHAR(15) BINARY NULL,
`O_ORDERSTATUS` CHAR(1) BINARY NULL,
`O_TOTALPRICE` DECIMAL(10,2) NULL,
`O_COMMENT` VARCHAR(79) BINARY NULL,
PRIMARY KEY (`O_ORDERKEY`))
partition by key(O_ORDERKEY) partitions $partitions_num;
create index I_O_ORDERDATE on orders(O_ORDERDATE) local;"
set sql(2) "CREATE TABLE IF NOT EXISTS `CUSTOMER` (
C_CUSTKEY INT NOT NULL,
C_MKTSEGMENT CHAR(10) BINARY NULL,
C_NATIONKEY INT NULL,
C_NAME VARCHAR(25) BINARY NULL,
C_ADDRESS VARCHAR(40) BINARY NULL,
C_PHONE CHAR(15) BINARY NULL,
C_ACCTBAL DECIMAL(10,2) NULL,
C_COMMENT VARCHAR(118) BINARY NULL,
PRIMARY KEY (`C_CUSTKEY`))
partition by key(C_CUSTKEY) partitions $partitions_num;"
set sql(3) "CREATE TABLE IF NOT EXISTS `PART` (
P_PARTKEY INT NOT NULL,
P_TYPE VARCHAR(25) BINARY NULL,
P_SIZE INT NULL,
P_BRAND CHAR(10) BINARY NULL,
P_NAME VARCHAR(55) BINARY NULL,
P_CONTAINER CHAR(10) BINARY NULL,
P_MFGR CHAR(25) BINARY NULL,
P_RETAILPRICE DECIMAL(10,2) NULL,
P_COMMENT VARCHAR(23) BINARY NULL,
PRIMARY KEY (`P_PARTKEY`))
partition by key(P_PARTKEY) partitions $partitions_num;"
set sql(4) "CREATE TABLE IF NOT EXISTS `SUPPLIER` (
S_SUPPKEY INT NOT NULL,
S_NATIONKEY INT NULL,
S_COMMENT VARCHAR(102) BINARY NULL,
S_NAME CHAR(25) BINARY NULL,
S_ADDRESS VARCHAR(40) BINARY NULL,
S_PHONE CHAR(15) BINARY NULL,
S_ACCTBAL DECIMAL(10,2) NULL,
PRIMARY KEY (`S_SUPPKEY`))
partition by key(S_SUPPKEY) partitions $partitions_num;"
set sql(5) "CREATE TABLE IF NOT EXISTS `PARTSUPP` (
PS_PARTKEY INT NOT NULL,
PS_SUPPKEY INT NOT NULL,
PS_SUPPLYCOST INT NOT NULL,
PS_AVAILQTY INT NULL,
PS_COMMENT VARCHAR(199) BINARY NULL,
PRIMARY KEY (`PS_PARTKEY`,`PS_SUPPKEY`),
INDEX PARTSUPP_PART_FKIDX (`PS_PARTKEY`),
INDEX PARTSUPP_SUPPLIER_FKIDX (`PS_SUPPKEY`),
FOREIGN KEY (PS_PARTKEY) REFERENCES PART(`P_PARTKEY`),
FOREIGN KEY (PS_SUPPKEY) REFERENCES SUPPLIER(`S_SUPPKEY`))
partition by key(PS_PARTKEY) partitions $partitions_num;"
set sql(6) "CREATE TABLE IF NOT EXISTS `NATION` (
N_NATIONKEY INT NOT NULL,
N_NAME CHAR(25) BINARY NULL,
N_REGIONKEY INT NULL,
N_COMMENT VARCHAR(152) BINARY NULL,
PRIMARY KEY (`N_NATIONKEY`));"
set sql(7) "CREATE TABLE IF NOT EXISTS `REGION` (
R_REGIONKEY INT NOT NULL,
R_NAME CHAR(25) BINARY NULL,
R_COMMENT VARCHAR(152) BINARY NULL,
PRIMARY KEY (`R_REGIONKEY`));"
set sql(8) "CREATE TABLE IF NOT EXISTS `LINEITEM` (
L_SHIPDATE DATE NULL,
L_ORDERKEY BIGINT NOT NULL,
L_DISCOUNT DECIMAL(10,2) NOT NULL,
L_EXTENDEDPRICE DECIMAL(10,2) NOT NULL,
L_SUPPKEY INT NOT NULL,
L_QUANTITY INT NOT NULL,
L_RETURNFLAG CHAR(1) BINARY NULL,
L_PARTKEY INT NOT NULL,
L_LINESTATUS CHAR(1) BINARY NULL,
L_TAX DECIMAL(10,2) NOT NULL,
L_COMMITDATE DATE NULL,
L_RECEIPTDATE DATE NULL,
L_SHIPMODE CHAR(10) BINARY NULL,
L_LINENUMBER INT NOT NULL,
L_SHIPINSTRUCT CHAR(25) BINARY NULL,
L_COMMENT VARCHAR(44) BINARY NULL,
PRIMARY KEY (`L_ORDERKEY`, `L_LINENUMBER`))
partition by key (L_ORDERKEY) partitions $partitions_num;
create index I_L_ORDERKEY on LINEITEM(L_ORDERKEY) local;
create index I_L_SHIPDATE on LINEITEM(L_SHIPDATE) local;"
for { set i 1 } { $i <= 8 } { incr i } {
set regex_pattern {^CREATE TABLE IF NOT EXISTS `([^`]*)`}
if {[regexp $regex_pattern $sql($i) match submatch]} {
puts "CREATE TABLE $submatch"
} else {
puts "can not find table for $sql($i)"
}
mysqlexec $mysql_handler $sql($i)
puts "TABLE $submatch is created"
}
return
}
proc UpdateHeatwaveSchema { mysql_handler } {
puts "MySQL UpdateHeatwaveSchema"
# https://github.com/oracle/heatwave-tpch/blob/0e4ad91b3f17b5a8fd9f099c94b223d861c09846/HeatWave/secondary_load.sql
# With updated varchar values to be compatible with HammerDB schema
set sql(1) "
alter table NATION secondary_engine NULL;
alter table REGION secondary_engine NULL;
alter table LINEITEM secondary_engine NULL;
alter table SUPPLIER secondary_engine NULL;
alter table ORDERS secondary_engine NULL;
alter table CUSTOMER secondary_engine NULL;
alter table PART secondary_engine NULL;
alter table PARTSUPP secondary_engine NULL;
"
set sql(2) "
alter table NATION change N_NAME N_NAME CHAR(25) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table NATION change N_COMMENT N_COMMENT VARCHAR(152) COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table REGION change R_NAME R_NAME CHAR(25) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table REGION change R_COMMENT R_COMMENT VARCHAR(152) COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table PART change P_NAME P_NAME VARCHAR(55) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table PART change P_MFGR P_MFGR CHAR(25) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table PART change P_BRAND P_BRAND CHAR(10) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table PART change P_TYPE P_TYPE VARCHAR(25) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table PART change P_CONTAINER P_CONTAINER CHAR(10) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table PART change P_COMMENT P_COMMENT VARCHAR(23) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table SUPPLIER change S_NAME S_NAME CHAR(25) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table SUPPLIER change S_ADDRESS S_ADDRESS VARCHAR(40) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table SUPPLIER change S_PHONE S_PHONE CHAR(15) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table SUPPLIER change S_COMMENT S_COMMENT VARCHAR(102) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table PARTSUPP change PS_COMMENT PS_COMMENT VARCHAR(199) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table CUSTOMER change C_NAME C_NAME VARCHAR(25) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table CUSTOMER change C_ADDRESS C_ADDRESS VARCHAR(40) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table CUSTOMER change C_PHONE C_PHONE CHAR(15) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table CUSTOMER change C_MKTSEGMENT C_MKTSEGMENT CHAR(10) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table CUSTOMER change C_COMMENT C_COMMENT VARCHAR(118) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table ORDERS change O_ORDERSTATUS O_ORDERSTATUS CHAR(1) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table ORDERS change O_ORDERPRIORITY O_ORDERPRIORITY CHAR(15) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table ORDERS change O_CLERK O_CLERK CHAR(15) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table ORDERS change O_COMMENT O_COMMENT VARCHAR(79) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table LINEITEM change L_RETURNFLAG L_RETURNFLAG CHAR(1) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table LINEITEM change L_LINESTATUS L_LINESTATUS CHAR(1) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table LINEITEM change L_SHIPINSTRUCT L_SHIPINSTRUCT CHAR(25) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table LINEITEM change L_COMMENT L_COMMENT VARCHAR(44) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table LINEITEM change L_SHIPMODE L_SHIPMODE CHAR(10) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
alter table CUSTOMER change C_PHONE C_PHONE CHAR(15) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=VARLEN';
alter table ORDERS change O_COMMENT O_COMMENT VARCHAR(79) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=VARLEN';
alter table PART change P_NAME P_NAME VARCHAR(55) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=VARLEN';
alter table PART change P_TYPE P_TYPE VARCHAR(25) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=VARLEN';
alter table SUPPLIER change S_COMMENT S_COMMENT VARCHAR(102) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=VARLEN';
"
set sql(3) "
alter table LINEITEM change L_ORDERKEY L_ORDERKEY INT NOT NULL COMMENT 'RAPID_COLUMN=DATA_PLACEMENT_KEY=1';
"
set sql(4) "
alter table NATION secondary_engine RAPID;
alter table REGION secondary_engine RAPID;
alter table LINEITEM secondary_engine RAPID;
alter table SUPPLIER secondary_engine RAPID;
alter table ORDERS secondary_engine RAPID;
alter table CUSTOMER secondary_engine RAPID;
alter table PART secondary_engine RAPID;
alter table PARTSUPP secondary_engine RAPID;
"
set sql(5) "
ALTER TABLE LINEITEM SECONDARY_LOAD;
ALTER TABLE ORDERS SECONDARY_LOAD;
ALTER TABLE CUSTOMER SECONDARY_LOAD;
ALTER TABLE SUPPLIER SECONDARY_LOAD;
ALTER TABLE NATION SECONDARY_LOAD;
ALTER TABLE REGION SECONDARY_LOAD;
ALTER TABLE PART SECONDARY_LOAD;
ALTER TABLE PARTSUPP SECONDARY_LOAD;
"
for { set i 1 } { $i <= 5 } { incr i } {
set separate [split $sql($i) ";"]
foreach query $separate {
if { [string trim $query] eq "" } { continue }
mysql::exec $mysql_handler $query
}
}
return
}
proc mk_region { mysql_handler } {
for { set i 1 } { $i <= 5 } {incr i} {
set code [ expr {$i - 1} ]
set text [ lindex [ lindex [ get_dists regions ] [ expr {$i - 1} ] ] 0 ]
set comment [ TEXT_1 72 ]
mysql::exec $mysql_handler "INSERT INTO REGION (`R_REGIONKEY`,`R_NAME`,`R_COMMENT`) VALUES ('$code' , '$text' , '$comment')"
}
mysql::commit $mysql_handler
}
proc mk_nation { mysql_handler } {
for { set i 1 } { $i <= 25 } {incr i} {
set code [ expr {$i - 1} ]
set text [ lindex [ lindex [ get_dists nations ] [ expr {$i - 1} ] ] 0 ]
set nind [ lsearch -glob [ get_dists nations ] \*$text\* ]
switch $nind {
0 - 4 - 5 - 14 - 15 - 16 { set join 0 }
1 - 2 - 3 - 17 - 24 { set join 1 }
8 - 9 - 12 - 18 - 21 { set join 2 }
6 - 7 - 19 - 22 - 23 { set join 3 }
10 - 11 - 13 - 20 { set join 4 }
}
set comment [ TEXT_1 72 ]
mysql::exec $mysql_handler "INSERT INTO NATION (`N_NATIONKEY`, `N_NAME`, `N_REGIONKEY`, `N_COMMENT`) VALUES ('$code' , '$text' , '$join' , '$comment')"
}
mysql::commit $mysql_handler
}
proc mk_supp { mysql_handler start_rows end_rows } {
set BBB_COMMEND "Recommends"
set BBB_COMPLAIN "Complaints"
for { set i $start_rows } { $i <= $end_rows } { incr i } {
set suppkey $i
set name [ concat Supplier#[format %1.9d $i]]
set address [ V_STR 25 ]
set nation_code [ RandomNumber 0 24 ]
set phone [ gen_phone ]
#random format to 2 floating point places 1681.00
set acctbal [format %4.2f [ expr {[ expr {double([ RandomNumber -99999 999999 ])} ] / 100} ] ]
set comment [ TEXT_1 63 ]
set bad_press [ RandomNumber 1 10000 ]
set type [ RandomNumber 0 100 ]
set noise [ RandomNumber 0 19 ]
set offset [ RandomNumber 0 [ expr {19 + $noise} ] ]
if { $bad_press <= 10 } {
set st [ expr {9 + $offset + $noise} ]
set fi [ expr {$st + 10} ]
if { $type < 50 } {
set comment [ string replace $comment $st $fi $BBB_COMPLAIN ]
} else {
set comment [ string replace $comment $st $fi $BBB_COMMEND ]
}
}
append supp_val_list ('$suppkey', '$nation_code', '$comment', '$name', '$address', '$phone', '$acctbal')
if { ![ expr {$i % 1000} ] || $i eq $end_rows } {
mysql::exec $mysql_handler "INSERT INTO SUPPLIER (`S_SUPPKEY`, `S_NATIONKEY`, `S_COMMENT`, `S_NAME`, `S_ADDRESS`, `S_PHONE`, `S_ACCTBAL`) VALUES $supp_val_list"
mysql::commit $mysql_handler
unset supp_val_list
} else {
append supp_val_list ,
}
if { ![ expr {$i % 10000} ] } {
puts "Loading SUPPLIER...$i"
}
}
mysql::commit $mysql_handler
puts "SUPPLIER Done Rows $start_rows..$end_rows"
return
}
proc mk_cust { mysql_handler start_rows end_rows } {
for { set i $start_rows } { $i <= $end_rows } { incr i } {
set custkey $i
set name [ concat Customer#[format %1.9d $i]]
set address [ V_STR 25 ]
set nation_code [ RandomNumber 0 24 ]
set phone [ gen_phone ]
set acctbal [format %4.2f [ expr {[ expr {double([ RandomNumber -99999 999999 ])} ] / 100} ] ]
set mktsegment [ pick_str_1 msegmnt ]
set comment [ TEXT_1 73 ]
append cust_val_list ('$custkey', '$mktsegment', '$nation_code', '$name', '$address', '$phone', '$acctbal', '$comment')
if { ![ expr {$i % 1000} ] || $i eq $end_rows } {
mysql::exec $mysql_handler "INSERT INTO CUSTOMER (`C_CUSTKEY`, `C_MKTSEGMENT`, `C_NATIONKEY`, `C_NAME`, `C_ADDRESS`, `C_PHONE`, `C_ACCTBAL`, `C_COMMENT`) values $cust_val_list"
mysql::commit $mysql_handler
unset cust_val_list
} else {
append cust_val_list ,
}
if { ![ expr {$i % 10000} ] } {
puts "Loading CUSTOMER...$i"
}
}
mysql::commit $mysql_handler
puts "Customer Done Rows $start_rows..$end_rows"
return
}
proc mk_part { mysql_handler start_rows end_rows scale_factor } {
for { set i $start_rows } { $i <= $end_rows } { incr i } {
set partkey $i
unset -nocomplain name
for {set j 0} {$j < [ expr {5 - 1} ] } {incr j } {
append name [ pick_str_1 colors ] " "
}
append name [ pick_str_1 colors ]
set mf [ RandomNumber 1 5 ]
set mfgr [ concat Manufacturer#$mf ]
set brand [ concat Brand#[ expr {$mf * 10 + [ RandomNumber 1 5 ]} ] ]
set type [ pick_str_1 p_types ]
set size [ RandomNumber 1 50 ]
set container [ pick_str_1 p_cntr ]
set price [ rpb_routine $i ]
set comment [ TEXT_1 14 ]
append part_val_list ('$partkey', '$type', '$size', '$brand', '$name', '$container', '$mfgr', '$price', '$comment')
#Part Supp Loop
for {set k 0} {$k < 4 } {incr k } {
set psupp_pkey $partkey
set psupp_suppkey [ PART_SUPP_BRIDGE $i $k $scale_factor ]
set psupp_qty [ RandomNumber 1 9999 ]
set psupp_scost [format %4.2f [ expr {double([ RandomNumber 100 100000 ]) / 100} ] ]
set psupp_comment [ TEXT_1 124 ]
append psupp_val_list ('$psupp_pkey', '$psupp_suppkey', '$psupp_scost', '$psupp_qty', '$psupp_comment')
if { $k<=2 } {
append psupp_val_list ,
}
}
# end of psupp loop
if { ![ expr {$i % 1000} ] || $i eq $end_rows } {
mysql::exec $mysql_handler "INSERT INTO PART (`P_PARTKEY`, `P_TYPE`, `P_SIZE`, `P_BRAND`, `P_NAME`, `P_CONTAINER`, `P_MFGR`, `P_RETAILPRICE`, `P_COMMENT`) VALUES $part_val_list"
mysql::exec $mysql_handler "INSERT INTO PARTSUPP (`PS_PARTKEY`, `PS_SUPPKEY`, `PS_SUPPLYCOST`, `PS_AVAILQTY`, `PS_COMMENT`) VALUES $psupp_val_list"
mysql::commit $mysql_handler
unset part_val_list
unset psupp_val_list
} else {
append part_val_list ,
append psupp_val_list ,
}
if { ![ expr {$i % 10000} ] } {
puts "Loading PART/PARTSUPP...$i"
}
}
mysql::commit $mysql_handler
puts "PART and PARTSUPP Done Rows $start_rows..$end_rows"
return
}
proc mk_order { mysql_handler start_rows end_rows upd_num scale_factor oceanbase_db} {
set refresh 100
set delta 1
set L_PKEY_MAX [ expr {200000 * $scale_factor} ]
set O_CKEY_MAX [ expr {150000 * $scale_factor} ]
set O_ODATE_MAX [ expr {(92001 + 2557 - (121 + 30) - 1)} ]
for { set i $start_rows } { $i <= $end_rows } { incr i } {
if { $upd_num == 0 } {
set okey [ mk_sparse $i $upd_num ]
} else {
set okey [ mk_sparse $i [ expr {1 + $upd_num / (10000 / $refresh)} ] ]
}
set custkey [ RandomNumber 1 $O_CKEY_MAX ]
while { $custkey % 3 == 0 } {
set custkey [ expr {$custkey + $delta} ]
if { $custkey < $O_CKEY_MAX } { set min $custkey } else { set min $O_CKEY_MAX }
set custkey $min
set delta [ expr {$delta * -1} ]
}
if { ![ array exists ascdate ] } {
for { set d 1 } { $d <= 2557 } {incr d} {
set ascdate($d) [ mk_time $d ]
}
}
set tmp_date [ RandomNumber 92002 $O_ODATE_MAX ]
set date $ascdate([ expr {$tmp_date - 92001} ])
set opriority [ pick_str_1 o_oprio ]
set clk_num [ RandomNumber 1 [ expr {$scale_factor * 1000} ] ]
set clerk [ concat Clerk#[format %1.9d $clk_num]]
set comment [ TEXT_1 49 ]
set spriority 0
set totalprice 0
set orderstatus "O"
set ocnt 0
set lcnt [ RandomNumber 1 7 ]
#Lineitem Loop
for { set l 0 } { $l < $lcnt } {incr l} {
set lokey $okey
set llcnt [ expr {$l + 1} ]
set lquantity [ RandomNumber 1 50 ]
set ldiscount [format %1.2f [ expr [ RandomNumber 0 10 ] / 100.00 ]]
set ltax [format %1.2f [ expr [ RandomNumber 0 8 ] / 100.00 ]]
set linstruct [ pick_str_1 instruct ]
set lsmode [ pick_str_1 smode ]
set lcomment [ TEXT_1 27 ]
set lpartkey [ RandomNumber 1 $L_PKEY_MAX ]
set rprice [ rpb_routine $lpartkey ]
set supp_num [ RandomNumber 0 3 ]
set lsuppkey [ PART_SUPP_BRIDGE $lpartkey $supp_num $scale_factor ]
set leprice [format %4.2f [ expr {$rprice * $lquantity} ]]
foreach price { ldiscount ltax leprice } intprice { ldiscountint ltaxint lepriceint } { set $intprice [ expr { int(round([ set $price ] * 100)) } ]}
set totalprice [ expr {$totalprice + (($lepriceint * (100 - $ldiscountint)) / 100) * (100 + $ltaxint) / 100} ]
set s_date [ RandomNumber 1 121 ]
set s_date [ expr {$s_date + $tmp_date} ]
set c_date [ RandomNumber 30 90 ]
set c_date [ expr {$c_date + $tmp_date} ]
set r_date [ RandomNumber 1 30 ]
set r_date [ expr {$r_date + $s_date} ]
set lsdate $ascdate([ expr {$s_date - 92001} ])
set lcdate $ascdate([ expr {$c_date - 92001} ])
set lrdate $ascdate([ expr {$r_date - 92001} ])
if { [ julian $r_date ] <= 95168 } {
set lrflag [ pick_str_1 rflag ]
} else { set lrflag "N" }
if { [ julian $s_date ] <= 95168 } {
incr ocnt
set lstatus "F"
} else { set lstatus "O" }
if { $oceanbase_db eq "true" } {
set scanned [clock scan $lsdate -format "%Y-%b-%d"]
set lsdate [clock format $scanned -format "%Y-%m-%d"]
set scanned [clock scan $lrdate -format "%Y-%b-%d"]
set lrdate [clock format $scanned -format "%Y-%m-%d"]
set scanned [clock scan $lcdate -format "%Y-%b-%d"]
set lcdate [clock format $scanned -format "%Y-%m-%d"]
append lineit_val_list ('$lsdate','$lokey', '$ldiscount', '$leprice', '$lsuppkey', '$lquantity', '$lrflag', '$lpartkey', '$lstatus', '$ltax', '$lcdate', '$lrdate', '$lsmode', '$llcnt', '$linstruct', '$lcomment')
} else {
append lineit_val_list (str_to_date('$lsdate','%Y-%M-%d'),'$lokey', '$ldiscount', '$leprice', '$lsuppkey', '$lquantity', '$lrflag', '$lpartkey', '$lstatus', '$ltax', str_to_date('$lcdate','%Y-%M-%d'), str_to_date('$lrdate','%Y-%M-%d'), '$lsmode', '$llcnt', '$linstruct', '$lcomment')
}
if { $l < [ expr $lcnt - 1 ] } {
append lineit_val_list ,
}
}
set totalprice [ expr double($totalprice) / 100 ]
if { $ocnt > 0} { set orderstatus "P" }
if { $ocnt == $lcnt } { set orderstatus "F" }
if { $oceanbase_db eq "true" } {
set scanned [clock scan $date -format "%Y-%b-%d"]
set date [clock format $scanned -format "%Y-%m-%d"]
append order_val_list ('$date', '$okey', '$custkey', '$opriority', '$spriority', '$clerk', '$orderstatus', '$totalprice', '$comment')
} else {
append order_val_list (str_to_date('$date','%Y-%M-%d'), '$okey', '$custkey', '$opriority', '$spriority', '$clerk', '$orderstatus', '$totalprice', '$comment')
}
if { ![ expr {$i % 1000} ] || $i eq $end_rows } {
mysql::exec $mysql_handler "INSERT INTO LINEITEM (`L_SHIPDATE`, `L_ORDERKEY`, `L_DISCOUNT`, `L_EXTENDEDPRICE`, `L_SUPPKEY`, `L_QUANTITY`, `L_RETURNFLAG`, `L_PARTKEY`, `L_LINESTATUS`, `L_TAX`, `L_COMMITDATE`, `L_RECEIPTDATE`, `L_SHIPMODE`, `L_LINENUMBER`, `L_SHIPINSTRUCT`, `L_COMMENT`) VALUES $lineit_val_list"
mysql::exec $mysql_handler "INSERT INTO ORDERS (`O_ORDERDATE`, `O_ORDERKEY`, `O_CUSTKEY`, `O_ORDERPRIORITY`, `O_SHIPPRIORITY`, `O_CLERK`, `O_ORDERSTATUS`, `O_TOTALPRICE`, `O_COMMENT`) VALUES $order_val_list"
mysql::commit $mysql_handler
unset lineit_val_list
unset order_val_list
} else {
append order_val_list ,
append lineit_val_list ,
}
if { ![ expr {$i % 10000} ] } {
puts "Loading ORDERS/LINEITEM...$i"
}
}
mysql::commit $mysql_handler
puts "ORDERS and LINEITEM Done Rows $start_rows..$end_rows"
return
}
proc do_tpch { host port socket ssl_options scale_fact user password db mysql_tpch_storage_engine num_vu oceanbase_db ob_partition_num ob_tenant_name} {
global mysqlstatus
global dist_names dist_weights weights dists weights
###############################################
#Generating following rows
#5 rows in region table
#25 rows in nation table
#SF * 10K rows in Supplier table
#SF * 150K rows in Customer table
#SF * 200K rows in Part table
#SF * 800K rows in Partsupp table
#SF * 1500K rows in Orders table
#SF * 6000K rows in Lineitem table
###############################################
#update number always zero for first load
set upd_num 0
if { ![ array exists dists ] } { set_dists }
foreach i [ array names dists ] {
set_dist_list $i
}
set sup_rows [ expr {$scale_fact * 10000} ]
set max_threads 256
set sf_mult 1
set cust_mult 15
set part_mult 20
set ord_mult 150
if { $num_vu > $max_threads } { set num_vu $max_threads }
if { $num_vu > 1 && [ chk_thread ] eq "TRUE" } {
set threaded "MULTI-THREADED"
set rema [ lassign [ findvuhposition ] myposition totalvirtualusers ]
switch $myposition {
1 {
puts "Monitor Thread"
if { $threaded eq "MULTI-THREADED" } {
tsv::lappend common thrdlst monitor
for { set th 1 } { $th <= $totalvirtualusers } { incr th } {
tsv::lappend common thrdlst idle
}
tsv::set application load "WAIT"
}
}
default {
puts "Worker Thread"
if { [ expr $myposition - 1 ] > $max_threads } { puts "No Data to Create"; return }
}
}
} else {
set threaded "SINGLE-THREADED"
set num_vu 1
}
if { $threaded eq "SINGLE-THREADED" || $threaded eq "MULTI-THREADED" && $myposition eq 1 } {
puts "CREATING [ string toupper $user ] SCHEMA"
if { $oceanbase_db == "true" } {
PrepareOceanbase $host $port $socket $ssl_options $user $password $ob_tenant_name
}
set mysql_handler [ ConnectToMySQL $host $port $socket $ssl_options $user $password $oceanbase_db $ob_tenant_name]
set db_created [ CreateDatabase $mysql_handler $db ]
if { !$db_created } {
tsv::set application abort 1
error "Database not created"
}
mysqluse $mysql_handler $db
mysql::autocommit $mysql_handler 0
# If storage_engine is set to heatwave, first, create the db schema using InnoDB and migrate it after data generation.
if { $oceanbase_db == "true" } {
CreateOBTables $mysql_handler $ob_partition_num
} else {
if { [string equal -nocase $mysql_tpch_storage_engine "Heatwave" ] } {
CreateTables $mysql_handler "InnoDB"
} else {
CreateTables $mysql_handler $mysql_tpch_storage_engine
}
}
if { $threaded eq "MULTI-THREADED" } {
tsv::set application load "READY"
puts "Loading REGION..."
mk_region $mysql_handler
puts "Loading REGION COMPLETE"
puts "Loading NATION..."
mk_nation $mysql_handler
puts "Loading NATION COMPLETE"
puts "Monitoring Workers..."
after 10000
set prevactive 0
while 1 {
set idlcnt 0; set lvcnt 0; set dncnt 0;
for {set th 2} {$th <= $totalvirtualusers } {incr th} {
switch [tsv::lindex common thrdlst $th] {
idle { incr idlcnt }
active { incr lvcnt }
done { incr dncnt }
}
}
if { $lvcnt != $prevactive } {
puts "Workers: $lvcnt Active $dncnt Done"
}
set prevactive $lvcnt
if { $dncnt eq [expr $totalvirtualusers - 1] } { break }
after 10000
}
} else {
puts "Loading REGION..."
mk_region $mysql_handler
puts "Loading REGION COMPLETE"
puts "Loading NATION..."
mk_nation $mysql_handler
puts "Loading NATION COMPLETE"
}
}
if { $threaded eq "SINGLE-THREADED" || $threaded eq "MULTI-THREADED" && $myposition != 1 } {
if { $threaded eq "MULTI-THREADED" } {
puts "Waiting for Monitor Thread..."
set mtcnt 0
while 1 {
if { [ tsv::get application abort ] } { return }
if { [ tsv::exists application load ] } {
incr mtcnt
if { [ tsv::get application load ] eq "READY" } { break }
if { $mtcnt eq 48 } {
puts "Monitor failed to notify ready state"
return
}
}
after 5000
}
set mysql_handler [ ConnectToMySQL $host $port $socket $ssl_options $user $password $oceanbase_db $ob_tenant_name]
mysqluse $mysql_handler $db
mysqlexec $mysql_handler "SET FOREIGN_KEY_CHECKS = 0"
if { [ expr $myposition - 1 ] > $max_threads } { puts "No Data to Create"; return }
if { [ expr $num_vu + 1 ] > $max_threads } { set num_vu $max_threads }
set sf_chunk [ split [ start_end $sup_rows $myposition $sf_mult $num_vu ] ":" ]
set cust_chunk [ split [ start_end $sup_rows $myposition $cust_mult $num_vu ] ":" ]
set part_chunk [ split [ start_end $sup_rows $myposition $part_mult $num_vu ] ":" ]
set ord_chunk [ split [ start_end $sup_rows $myposition $ord_mult $num_vu ] ":" ]
tsv::lreplace common thrdlst $myposition $myposition active
} else {
set sf_chunk "1 $sup_rows"
set cust_chunk "1 [ expr {$sup_rows * $cust_mult} ]"
set part_chunk "1 [ expr {$sup_rows * $part_mult} ]"
set ord_chunk "1 [ expr {$sup_rows * $ord_mult} ]"
}
puts "Start:[ clock format [ clock seconds ] ]"
puts "Loading SUPPLIER..."
mk_supp $mysql_handler [ lindex $sf_chunk 0 ] [ lindex $sf_chunk 1 ]
puts "Loading CUSTOMER..."
mk_cust $mysql_handler [ lindex $cust_chunk 0 ] [ lindex $cust_chunk 1 ]
puts "Loading PART and PARTSUPP..."
mk_part $mysql_handler [ lindex $part_chunk 0 ] [ lindex $part_chunk 1 ] $scale_fact
puts "Loading ORDERS and LINEITEM..."
mk_order $mysql_handler [ lindex $ord_chunk 0 ] [ lindex $ord_chunk 1 ] [ expr {$upd_num % 10000} ] $scale_fact $oceanbase_db
puts "Loading TPCH TABLES COMPLETE"
puts "End:[ clock format [ clock seconds ] ]"
if { $threaded eq "MULTI-THREADED" } {
tsv::lreplace common thrdlst $myposition $myposition done
}
}
# Update schema and set secondary_engine. Start data migration to Heatwave.
if { [string equal -nocase $mysql_tpch_storage_engine "Heatwave" ] } {
puts "Migrating data to Heatwave..."
UpdateHeatwaveSchema $mysql_handler
puts "Migrating data to Heatwave COMPLETE"
}
if { $threaded eq "SINGLE-THREADED" || $threaded eq "MULTI-THREADED" && $myposition eq 1 } {
GatherStatistics $mysql_handler $oceanbase_db $ob_partition_num
puts "[ string toupper $db ] SCHEMA COMPLETE"
return
}
}
}
.ed_mainFrame.mainwin.textFrame.left.text fastinsert end "do_tpch $mysql_host $mysql_port $mysql_socket {$mysql_ssl_options} $mysql_scale_fact $mysql_tpch_user [ quotemeta $mysql_tpch_pass ] $mysql_tpch_dbase $mysql_tpch_storage_engine $mysql_num_tpch_threads $mysql_tpch_obcompat $mysql_ob_partition_num $mysql_ob_tenant_name"
} else { return }
}
proc loadmysqltpch { } {
global _ED mysql_ssl_options
upvar #0 dbdict dbdict
if {[dict exists $dbdict mysql library ]} {
set library [ dict get $dbdict mysql library ]
} else { set library "mysqltcl" }
upvar #0 configmysql configmysql
#set variables to values in dict
setlocaltpchvars $configmysql
#If the options menu has been run under the GUI mysql_ssl_options is set
#If build is run under the GUI, CLI or WS mysql_ssl_options is not set
#Set it now if it doesn't exist
if ![ info exists mysql_ssl_options ] { check_mysql_ssl $configmysql }
ed_edit_clear
.ed_mainFrame.notebook select .ed_mainFrame.mainwin
set _ED(packagekeyname) "MySQL TPROC-H"
.ed_mainFrame.mainwin.textFrame.left.text fastinsert end "#!/usr/local/bin/tclsh8.6
#EDITABLE OPTIONS##################################################
set library $library ;# MySQL Library
set total_querysets $mysql_total_querysets ;# Number of query sets before logging off
set RAISEERROR \"$mysql_raise_query_error\" ;# Exit script on MySQL query error (true or false)
set VERBOSE \"$mysql_verbose\" ;# Show query text and output
set scale_factor $mysql_scale_fact ;#Scale factor of the tpc-h schema
set host \"$mysql_host\" ;# Address of the server hosting MySQL
set port \"$mysql_port\" ;# Port of the MySQL Server, defaults to 3306
set socket \"$mysql_socket\" ;# MySQL Socket for local connections
set ssl_options {$mysql_ssl_options} ;# MySQL SSL/TLS options
set user \"$mysql_tpch_user\" ;# MySQL user
set password \"[ quotemeta $mysql_tpch_pass ]\" ;# Password for the MySQL user
set db \"$mysql_tpch_dbase\" ;# Database containing the TPC Schema
set refresh_on \"$mysql_refresh_on\" ;#First User does refresh function
set update_sets $mysql_update_sets ;#Number of sets of refresh function to complete
set trickle_refresh $mysql_trickle_refresh ;#time delay (ms) to trickle refresh function
set REFRESH_VERBOSE \"$mysql_refresh_verbose\" ;#report refresh function activity
set tpch_obcompat \"$mysql_tpch_obcompat\" ;# Oceanbase compatible
set ob_tenant_name \"$mysql_ob_tenant_name\" ;# Oceanbase tenant name
#EDITABLE OPTIONS##################################################
"
.ed_mainFrame.mainwin.textFrame.left.text fastinsert end {#LOAD LIBRARIES AND MODULES
if [catch {package require $library} message] { error "Failed to load $library - $message" }
if [catch {::tcl::tm::path add modules} ] { error "Failed to find modules directory" }
if [catch {package require tpchcommon} ] { error "Failed to load tpch common functions" } else { namespace import tpchcommon::* }
proc standsql { mysql_handler sql RAISEERROR } {
global mysqlstatus
set oput ""
catch { set oput [ join [ mysql::sel $mysql_handler "$sql" -list ] ] }
if { $mysqlstatus(code) } {
if { $RAISEERROR } {
error "Query Error : $mysqlstatus(message)"
} else { puts $mysqlstatus(message)
}
}
return $oput
}
proc chk_socket { host socket } {
if { ![string match windows $::tcl_platform(platform)] && ($host eq "127.0.0.1" || [ string tolower $host ] eq "localhost") && [ string tolower $socket ] != "null" } {
return "TRUE"
} else {
return "FALSE"
}
}
proc ConnectToMySQL { host port socket ssl_options user password db is_oceanbase ob_tenant_name} {