Skip to content

Commit

Permalink
tpch: add query tuning configs for tpch (#179)
Browse files Browse the repository at this point in the history
* Add query tuning configs for tpch

* Fix cmd

* Fix

* WIP

* Address comments

* Remove debug code
  • Loading branch information
zanmato1984 authored Aug 20, 2024
1 parent 50e155e commit ccd5fcd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
29 changes: 29 additions & 0 deletions cmd/go-tpc/tpch.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,31 @@ import (

var tpchConfig tpch.Config

var queryTuningVars = []struct {
name string
value string
}{
// For optimal join order, esp. for q9.
{"tidb_default_string_match_selectivity", "0.1"},
// For optimal join order for all queries.
{"tidb_opt_join_reorder_threshold", "60"},
// For optimal join type between broadcast and hash partition join.
{"tidb_prefer_broadcast_join_by_exchange_data_size", "ON"},
}

func appendQueryTuningVarsToConnParams() {
for _, v := range queryTuningVars {
if !strings.Contains(connParams, v.name) {
connParams = fmt.Sprintf("%s&%s=%s", connParams, v.name, v.value)
}
}
}

func executeTpch(action string) {
if action == "run" && driver == "mysql" && tpchConfig.EnableQueryTuning {
appendQueryTuningVarsToConnParams()
}

openDB()
defer closeDB()

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

cmdRun.PersistentFlags().BoolVar(&tpchConfig.EnableQueryTuning,
"enable-query-tuning",
true,
"Tune queries by setting some session variables known effective for tpch")

var cmdCleanup = &cobra.Command{
Use: "cleanup",
Short: "Cleanup data for the workload",
Expand Down
2 changes: 2 additions & 0 deletions tpch/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type Config struct {
PlanReplayerConfig replayer.PlanReplayerConfig
EnablePlanReplayer bool

EnableQueryTuning bool

// for prepare command only
OutputType string
OutputDir string
Expand Down

0 comments on commit ccd5fcd

Please sign in to comment.