Skip to content

Commit ccd5fcd

Browse files
authored
tpch: add query tuning configs for tpch (pingcap#179)
* Add query tuning configs for tpch * Fix cmd * Fix * WIP * Address comments * Remove debug code
1 parent 50e155e commit ccd5fcd

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

cmd/go-tpc/tpch.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,31 @@ import (
1414

1515
var tpchConfig tpch.Config
1616

17+
var queryTuningVars = []struct {
18+
name string
19+
value string
20+
}{
21+
// For optimal join order, esp. for q9.
22+
{"tidb_default_string_match_selectivity", "0.1"},
23+
// For optimal join order for all queries.
24+
{"tidb_opt_join_reorder_threshold", "60"},
25+
// For optimal join type between broadcast and hash partition join.
26+
{"tidb_prefer_broadcast_join_by_exchange_data_size", "ON"},
27+
}
28+
29+
func appendQueryTuningVarsToConnParams() {
30+
for _, v := range queryTuningVars {
31+
if !strings.Contains(connParams, v.name) {
32+
connParams = fmt.Sprintf("%s&%s=%s", connParams, v.name, v.value)
33+
}
34+
}
35+
}
36+
1737
func executeTpch(action string) {
38+
if action == "run" && driver == "mysql" && tpchConfig.EnableQueryTuning {
39+
appendQueryTuningVarsToConnParams()
40+
}
41+
1842
openDB()
1943
defer closeDB()
2044

@@ -130,6 +154,11 @@ func registerTpch(root *cobra.Command) {
130154
"",
131155
"Name of plan Replayer file dumps")
132156

157+
cmdRun.PersistentFlags().BoolVar(&tpchConfig.EnableQueryTuning,
158+
"enable-query-tuning",
159+
true,
160+
"Tune queries by setting some session variables known effective for tpch")
161+
133162
var cmdCleanup = &cobra.Command{
134163
Use: "cleanup",
135164
Short: "Cleanup data for the workload",

tpch/workload.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ type Config struct {
4545
PlanReplayerConfig replayer.PlanReplayerConfig
4646
EnablePlanReplayer bool
4747

48+
EnableQueryTuning bool
49+
4850
// for prepare command only
4951
OutputType string
5052
OutputDir string

0 commit comments

Comments
 (0)