From c0e4fc3b96561348f19a399892349f9d345f21d2 Mon Sep 17 00:00:00 2001 From: Rebecca Taft Date: Wed, 8 Mar 2023 15:21:46 -0600 Subject: [PATCH] opt: enable optimizer_always_use_histograms by default This commit enables the new session setting, optimizer_always_use_histograms, by default. This ensures that the optimizer always uses histograms when available to calculate the statistics of every plan that it explores. Enabling this setting can prevent the optimizer from choosing a suboptimal index when statistics for a table are stale. Informs #64570 Release note: None --- pkg/sql/logictest/testdata/logic_test/information_schema | 2 +- pkg/sql/logictest/testdata/logic_test/pg_catalog | 4 ++-- pkg/sql/logictest/testdata/logic_test/show_source | 2 +- pkg/sql/vars.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/information_schema b/pkg/sql/logictest/testdata/logic_test/information_schema index 1bb09ce63b60..bc066c4221e7 100644 --- a/pkg/sql/logictest/testdata/logic_test/information_schema +++ b/pkg/sql/logictest/testdata/logic_test/information_schema @@ -5016,7 +5016,7 @@ null_ordered_last off on_update_rehome_row_enabled on opt_split_scan_limit 2048 optimizer on -optimizer_always_use_histograms off +optimizer_always_use_histograms on optimizer_use_forecasts on optimizer_use_histograms on optimizer_use_improved_disjunction_stats on diff --git a/pkg/sql/logictest/testdata/logic_test/pg_catalog b/pkg/sql/logictest/testdata/logic_test/pg_catalog index 1a4714bf4763..014c7d272b75 100644 --- a/pkg/sql/logictest/testdata/logic_test/pg_catalog +++ b/pkg/sql/logictest/testdata/logic_test/pg_catalog @@ -2647,7 +2647,7 @@ node_id 1 NULL null_ordered_last off NULL NULL NULL string on_update_rehome_row_enabled on NULL NULL NULL string opt_split_scan_limit 2048 NULL NULL NULL string -optimizer_always_use_histograms off NULL NULL NULL string +optimizer_always_use_histograms on NULL NULL NULL string optimizer_use_forecasts on NULL NULL NULL string optimizer_use_histograms on NULL NULL NULL string optimizer_use_improved_disjunction_stats on NULL NULL NULL string @@ -2795,7 +2795,7 @@ node_id 1 NULL null_ordered_last off NULL user NULL off off on_update_rehome_row_enabled on NULL user NULL on on opt_split_scan_limit 2048 NULL user NULL 2048 2048 -optimizer_always_use_histograms off NULL user NULL off off +optimizer_always_use_histograms on NULL user NULL on on optimizer_use_forecasts on NULL user NULL on on optimizer_use_histograms on NULL user NULL on on optimizer_use_improved_disjunction_stats on NULL user NULL on on diff --git a/pkg/sql/logictest/testdata/logic_test/show_source b/pkg/sql/logictest/testdata/logic_test/show_source index 96b76a3cff2f..b5b3861d5aa4 100644 --- a/pkg/sql/logictest/testdata/logic_test/show_source +++ b/pkg/sql/logictest/testdata/logic_test/show_source @@ -109,7 +109,7 @@ node_id 1 null_ordered_last off on_update_rehome_row_enabled on opt_split_scan_limit 2048 -optimizer_always_use_histograms off +optimizer_always_use_histograms on optimizer_use_forecasts on optimizer_use_histograms on optimizer_use_improved_disjunction_stats on diff --git a/pkg/sql/vars.go b/pkg/sql/vars.go index fb20594ffdcd..7ca1bac29541 100644 --- a/pkg/sql/vars.go +++ b/pkg/sql/vars.go @@ -2530,7 +2530,7 @@ var varGen = map[string]sessionVar{ Get: func(evalCtx *extendedEvalContext, _ *kv.Txn) (string, error) { return formatBoolAsPostgresSetting(evalCtx.SessionData().OptimizerAlwaysUseHistograms), nil }, - GlobalDefault: globalFalse, + GlobalDefault: globalTrue, }, }