Skip to content

Commit

Permalink
Merge pull request #98 from sm-shaw/39
Browse files Browse the repository at this point in the history
39 MySQL prepared statements
  • Loading branch information
abondvt89 committed Feb 19, 2020
2 parents a4dac31 + e583975 commit fe1e0d6
Show file tree
Hide file tree
Showing 8 changed files with 720 additions and 276 deletions.
2 changes: 2 additions & 0 deletions config/mysql.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<connection>
<mysql_host>127.0.0.1</mysql_host>
<mysql_port>3306</mysql_port>
<mysql_socket>/tmp/mysql.sock</mysql_socket>
</connection>
<tpcc>
<schema>
Expand All @@ -13,6 +14,7 @@
<mysql_dbase>tpcc</mysql_dbase>
<mysql_storage_engine>innodb</mysql_storage_engine>
<mysql_partition>false</mysql_partition>
<mysql_prepared>false</mysql_prepared>
</schema>
<driver>
<mysql_total_iterations>1000000</mysql_total_iterations>
Expand Down
4 changes: 4 additions & 0 deletions src/db2/db2opt.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ grid $Name -column 1 -row 12 -sticky w
bind .tpc.f1.r1 <ButtonPress-1> {
set db2_allwarehouse "false"
set db2_timeprofile "false"
set db2_async_scale "false"
set db2_async_verbose "false"
.tpc.f1.e17 configure -state disabled
.tpc.f1.e18 configure -state disabled
.tpc.f1.e19 configure -state disabled
Expand All @@ -281,9 +283,11 @@ bind .tpc.f1.r2 <ButtonPress-1> {
.tpc.f1.e20 configure -state normal
.tpc.f1.e21 configure -state normal
.tpc.f1.e22 configure -state normal
if { $db2_async_scale eq "true" } {
.tpc.f1.e23 configure -state normal
.tpc.f1.e24 configure -state normal
.tpc.f1.e25 configure -state normal
}
if {$db2_monreport >= $db2_duration} {
set db2_monreport 0
}
Expand Down
165 changes: 131 additions & 34 deletions src/mysql/mysqlolap.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ if {[dict exists $dbdict mysql library ]} {
upvar #0 configmysql configmysql
#set variables to values in dict
setlocaltpchvars $configmysql
if {[ tk_messageBox -title "Create Schema" -icon question -message "Ready to create a Scale Factor $mysql_scale_fact TPC-H schema\n in host [string toupper $mysql_host:$mysql_port] 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 { ![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 TPC-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 {
Expand Down Expand Up @@ -36,6 +37,14 @@ 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 CreateDatabase { mysql_handler db } {
puts "CREATING DATABASE $db"
set sql(1) "SET FOREIGN_KEY_CHECKS = 0"
Expand Down Expand Up @@ -401,7 +410,7 @@ puts "ORDERS and LINEITEM Done Rows $start_rows..$end_rows"
return
}

proc do_tpch { host port scale_fact user password db mysql_tpch_storage_engine num_vu } {
proc do_tpch { host port socket scale_fact user password db mysql_tpch_storage_engine num_vu } {
global mysqlstatus
global dist_names dist_weights weights dists weights
###############################################
Expand Down Expand Up @@ -453,15 +462,30 @@ set num_vu 1
}
if { $threaded eq "SINGLE-THREADED" || $threaded eq "MULTI-THREADED" && $myposition eq 1 } {
puts "CREATING [ string toupper $user ] SCHEMA"
if { [ chk_socket $host $socket ] eq "TRUE" } {
if [catch {mysqlconnect -socket $socket -user $user -password $password} mysql_handler] {
puts "the local socket connection to $socket could not be established"
set connected "FALSE"
} else {
set connected "TRUE"
}
} else {
if [catch {mysqlconnect -host $host -port $port -user $user -password $password} mysql_handler] {
puts "the database connection to $host could not be established"
error $mysqlstatus(message)
puts "the tcp connection to $host:$port could not be established"
set connected "FALSE"
} else {
set connected "TRUE"
}
}
if {$connected} {
CreateDatabase $mysql_handler $db
mysqluse $mysql_handler $db
mysql::autocommit $mysql_handler 0
CreateTables $mysql_handler $mysql_tpch_storage_engine
}
} else {
error $mysqlstatus(message)
return
}
if { $threaded eq "MULTI-THREADED" } {
tsv::set application load "READY"
puts "Loading REGION..."
Expand Down Expand Up @@ -510,13 +534,28 @@ return
}
after 5000
}
if { [ chk_socket $host $socket ] eq "TRUE" } {
if [catch {mysqlconnect -socket $socket -user $user -password $password} mysql_handler] {
puts "the local socket connection to $socket could not be established"
set connected "FALSE"
} else {
set connected "TRUE"
}
} else {
if [catch {mysqlconnect -host $host -port $port -user $user -password $password} mysql_handler] {
puts "the database connection to $host could not be established"
error $mysqlstatus(message)
puts "the tcp connection to $host:$port could not be established"
set connected "FALSE"
} else {
set connected "TRUE"
}
}
if {$connected} {
mysqluse $mysql_handler $db
mysql::autocommit $mysql_handler 0
mysqlexec $mysql_handler "SET FOREIGN_KEY_CHECKS = 0"
} else {
error $mysqlstatus(message)
return
}
if { [ expr $myposition - 1 ] > $max_threads } { puts "No Data to Create"; return }
if { [ expr $num_vu + 1 ] > $max_threads } { set num_vu $max_threads }
Expand Down Expand Up @@ -553,7 +592,7 @@ return
}
}
}
.ed_mainFrame.mainwin.textFrame.left.text fastinsert end "do_tpch $mysql_host $mysql_port $mysql_scale_fact $mysql_tpch_user $mysql_tpch_pass $mysql_tpch_dbase $mysql_tpch_storage_engine $mysql_num_tpch_threads"
.ed_mainFrame.mainwin.textFrame.left.text fastinsert end "do_tpch $mysql_host $mysql_port $mysql_socket $mysql_scale_fact $mysql_tpch_user $mysql_tpch_pass $mysql_tpch_dbase $mysql_tpch_storage_engine $mysql_num_tpch_threads"
} else { return }
}

Expand All @@ -578,6 +617,7 @@ 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 user \"$mysql_tpch_user\" ;# MySQL user
set password \"$mysql_tpch_pass\" ;# Password for the MySQL user
set db \"$mysql_tpch_dbase\" ;# Database containing the TPC Schema
Expand All @@ -603,6 +643,14 @@ error "Query Error : $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"
}
}
#########################
#TPCH REFRESH PROCEDURE
proc mk_order_ref { mysql_handler upd_num scale_factor trickle_refresh REFRESH_VERBOSE } {
Expand Down Expand Up @@ -727,14 +775,29 @@ mysql::commit $mysql_handler
mysql::commit $mysql_handler
}

proc do_refresh { host port user password db scale_factor update_sets trickle_refresh REFRESH_VERBOSE RF_SET } {
proc do_refresh { host port socket user password db scale_factor update_sets trickle_refresh REFRESH_VERBOSE RF_SET } {
if { [ chk_socket $host $socket ] eq "TRUE" } {
if [catch {mysqlconnect -socket $socket -user $user -password $password} mysql_handler] {
puts "the local socket connection to $socket could not be established"
set connected "FALSE"
} else {
set connected "TRUE"
}
} else {
if [catch {mysqlconnect -host $host -port $port -user $user -password $password} mysql_handler] {
puts "the database connection to $host could not be established"
error $mysqlstatus(message)
puts "the tcp connection to $host:$port could not be established"
set connected "FALSE"
} else {
set connected "TRUE"
}
}
if {$connected} {
mysqluse $mysql_handler $db
mysql::autocommit $mysql_handler 0
}
} else {
error $mysqlstatus(message)
return
}
set upd_num 1
for { set set_counter 1 } {$set_counter <= $update_sets } {incr set_counter} {
if { [ tsv::get application abort ] } { break }
Expand Down Expand Up @@ -984,18 +1047,32 @@ return $q2sub
}
#########################
#TPCH QUERY SETS PROCEDURE
proc do_tpch { host port user password db scale_factor RAISEERROR VERBOSE total_querysets myposition } {
proc do_tpch { host port socket user password db scale_factor RAISEERROR VERBOSE total_querysets myposition } {
global mysqlstatus
if { [ chk_socket $host $socket ] eq "TRUE" } {
if [catch {mysqlconnect -socket $socket -user $user -password $password} mysql_handler] {
puts "the local socket connection to $socket could not be established"
set connected "FALSE"
} else {
set connected "TRUE"
}
} else {
if [catch {mysqlconnect -host $host -port $port -user $user -password $password} mysql_handler] {
puts "the database connection to $host could not be established"
error $mysqlstatus(message)
puts "the tcp connection to $host:$port could not be established"
set connected "FALSE"
} else {
set connected "TRUE"
}
}
if {$connected} {
mysqluse $mysql_handler $db
mysql::autocommit $mysql_handler 0
} else {
error $mysqlstatus(message)
return
}
for {set it 0} {$it < $total_querysets} {incr it} {
if { [ tsv::get application abort ] } { break }
unset -nocomplain qlist
set start [ clock seconds ]
for { set q 1 } { $q <= 22 } { incr q } {
set dssquery($q) [sub_query $q $scale_factor $myposition ]
Expand Down Expand Up @@ -1023,7 +1100,6 @@ set oput [ standsql $mysql_handler $dssquery($qos) $RAISEERROR ]
set t1 [clock clicks -millisec]
set value [expr {double($t1-$t0)/1000}]
if {$VERBOSE} { printlist $oput }
if { [ llength $oput ] > 0 } { lappend qlist $value }
puts "query $qos completed in $value seconds"
} else {
set q15c 0
Expand Down Expand Up @@ -1051,7 +1127,6 @@ error "Query Error : $mysqlstatus(message)"
set t1 [clock clicks -millisec]
set value [expr {double($t1-$t0)/1000}]
if {$VERBOSE} { printlist $oput }
if { [ llength $oput ] > 0 } { lappend qlist $value }
puts "query $qos completed in $value seconds"
}
incr q15c
Expand All @@ -1062,7 +1137,6 @@ set end [ clock seconds ]
set wall [ expr $end - $start ]
set qsets [ expr $it + 1 ]
puts "Completed $qsets query set(s) in $wall seconds"
puts "Geometric mean of query times returning rows ([llength $qlist]) is [ format \"%.5f\" [ gmean $qlist ]]"
}
mysqlclose $mysql_handler
}
Expand All @@ -1080,21 +1154,21 @@ if { $power_test } {
set trickle_refresh 0
set update_sets 1
set REFRESH_VERBOSE "false"
do_refresh $host $port $user $password $db $scale_factor $update_sets $trickle_refresh $REFRESH_VERBOSE RF1
do_tpch $host $port $user $password $db $scale_factor $RAISEERROR $VERBOSE $total_querysets 0
do_refresh $host $port $user $password $db $scale_factor $update_sets $trickle_refresh $REFRESH_VERBOSE RF2
do_refresh $host $port $socket $user $password $db $scale_factor $update_sets $trickle_refresh $REFRESH_VERBOSE RF1
do_tpch $host $port $socket $user $password $db $scale_factor $RAISEERROR $VERBOSE $total_querysets 0
do_refresh $host $port $socket $user $password $db $scale_factor $update_sets $trickle_refresh $REFRESH_VERBOSE RF2
} else {
switch $myposition {
1 {
do_refresh $host $port $user $password $db $scale_factor $update_sets $trickle_refresh $REFRESH_VERBOSE BOTH
do_refresh $host $port $socket $user $password $db $scale_factor $update_sets $trickle_refresh $REFRESH_VERBOSE BOTH
}
default {
do_tpch $host $port $user $password $db $scale_factor $RAISEERROR $VERBOSE $total_querysets [ expr $myposition - 1 ]
do_tpch $host $port $socket $user $password $db $scale_factor $RAISEERROR $VERBOSE $total_querysets [ expr $myposition - 1 ]
}
}
}
} else {
do_tpch $host $port $user $password $db $scale_factor $RAISEERROR $VERBOSE $total_querysets $myposition
do_tpch $host $port $socket $user $password $db $scale_factor $RAISEERROR $VERBOSE $total_querysets $myposition
}}
}

Expand All @@ -1117,6 +1191,7 @@ set RAISEERROR \"$mysql_raise_query_error\" ;# Exit script on MySQL query error
set VERBOSE \"$mysql_verbose\" ;# Show query text and output
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 user \"$mysql_tpch_user\" ;# MySQL user
set password \"$mysql_tpch_pass\" ;# Password for the MySQL user
set db \"$mysql_tpch_dbase\" ;# Database containing the TPC Schema
Expand All @@ -1139,6 +1214,14 @@ error "Query Error : $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"
}
}
#########################
#CLOUD ANALYTIC TPCH QUERY GENERATION
proc set_query { } {
Expand Down Expand Up @@ -1167,17 +1250,31 @@ return $sql($query_no)
}
#########################
#CLOUD ANALYTIC TPCH QUERY SETS PROCEDURE
proc do_cloud { host port user password db RAISEERROR VERBOSE } {
proc do_cloud { host port socket user password db RAISEERROR VERBOSE } {
global mysqlstatus
if { [ chk_socket $host $socket ] eq "TRUE" } {
if [catch {mysqlconnect -socket $socket -user $user -password $password} mysql_handler] {
puts "the local socket connection to $socket could not be established"
set connected "FALSE"
} else {
set connected "TRUE"
}
} else {
if [catch {mysqlconnect -host $host -port $port -user $user -password $password} mysql_handler] {
puts stderr "error, the database connection to $host could not be established"
puts stderr $mysqlstatus(message)
return
puts "the tcp connection to $host:$port could not be established"
set connected "FALSE"
} else {
mysqluse $mysql_handler $db
mysql::autocommit $mysql_handler 0
mysqlexec $mysql_handler "set session group_concat_max_len = 18446744073709551615"
}
set connected "TRUE"
}
}
if {$connected} {
mysqluse $mysql_handler $db
mysql::autocommit $mysql_handler 0
mysqlexec $mysql_handler "set session group_concat_max_len = 18446744073709551615"
} else {
error $mysqlstatus(message)
return
}
unset -nocomplain qlist
set start [ clock seconds ]
for { set q 1 } { $q <= 13 } { incr q } {
Expand All @@ -1203,5 +1300,5 @@ mysqlclose $mysql_handler
}
#########################
#RUN CLOUD ANALYTIC TPC-H
do_cloud $host $port $user $password $db $RAISEERROR $VERBOSE}
do_cloud $host $port $socket $user $password $db $RAISEERROR $VERBOSE}
}
Loading

0 comments on commit fe1e0d6

Please sign in to comment.