diff --git a/cmd/go-tpc/tpch.go b/cmd/go-tpc/tpch.go index 8fb51b1..6547d98 100644 --- a/cmd/go-tpc/tpch.go +++ b/cmd/go-tpc/tpch.go @@ -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() @@ -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", diff --git a/tpch/workload.go b/tpch/workload.go index 904ef57..6dd0926 100644 --- a/tpch/workload.go +++ b/tpch/workload.go @@ -45,6 +45,8 @@ type Config struct { PlanReplayerConfig replayer.PlanReplayerConfig EnablePlanReplayer bool + EnableQueryTuning bool + // for prepare command only OutputType string OutputDir string