Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/ccl/backupccl/testdata/backup-restore/metadata
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ exec-sql
SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false;
----

exec-sql
SET enable_create_stats_using_extremes = true;
----

exec-sql
CREATE DATABASE db1;
USE db1;
Expand Down
12 changes: 12 additions & 0 deletions pkg/sql/create_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,18 @@ func (n *createStatsNode) makeJobRecord(ctx context.Context) (*jobs.Record, erro
)
}

if n.Options.UsingExtremes && !n.p.SessionData().EnableCreateStatsUsingExtremes {
return nil, pgerror.New(pgcode.FeatureNotSupported,
"creating partial statistics at extremes is not yet supported",
)
}

if n.Options.Where != nil {
return nil, pgerror.New(pgcode.FeatureNotSupported,
"creating partial statistics with a WHERE clause is not yet supported",
)
}

if err := n.p.CheckPrivilege(ctx, tableDesc, privilege.SELECT); err != nil {
return nil, err
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/sql/exec_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3470,6 +3470,10 @@ func (m *sessionDataMutator) SetOptimizerAlwaysUseHistograms(val bool) {
m.data.OptimizerAlwaysUseHistograms = val
}

func (m *sessionDataMutator) SetEnableCreateStatsUsingExtremes(val bool) {
m.data.EnableCreateStatsUsingExtremes = val
}

// Utility functions related to scrubbing sensitive information on SQL Stats.

// quantizeCounts ensures that the Count field in the
Expand Down
9 changes: 9 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/distsql_stats
Original file line number Diff line number Diff line change
Expand Up @@ -1998,6 +1998,15 @@ INSERT INTO abcd VALUES
statement ok
INSERT INTO xy VALUES (-1, 9), (-2, 8), (5, 15), (6, 16)

statement error pgcode 0A000 creating partial statistics with a WHERE clause is not yet supported
CREATE STATISTICS abcd_a_partial ON a FROM abcd WHERE a > 1;

statement error pgcode 0A000 creating partial statistics at extremes is not yet supported
CREATE STATISTICS abcd_a_partial ON a FROM abcd USING EXTREMES;

statement ok
SET enable_create_stats_using_extremes = on

statement ok
CREATE STATISTICS abcd_a_partial ON a FROM abcd USING EXTREMES;

Expand Down
1 change: 1 addition & 0 deletions pkg/sql/logictest/testdata/logic_test/information_schema
Original file line number Diff line number Diff line change
Expand Up @@ -4961,6 +4961,7 @@ disable_partially_distributed_plans off
disable_plan_gists off
disallow_full_table_scans off
enable_auto_rehoming off
enable_create_stats_using_extremes off
enable_drop_enum_value on
enable_experimental_alter_column_type_general off
enable_implicit_select_for_update on
Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/pg_catalog
Original file line number Diff line number Diff line change
Expand Up @@ -2595,6 +2595,7 @@ disable_plan_gists off NULL
disallow_full_table_scans off NULL NULL NULL string
distsql off NULL NULL NULL string
enable_auto_rehoming off NULL NULL NULL string
enable_create_stats_using_extremes off NULL NULL NULL string
enable_experimental_alter_column_type_general off NULL NULL NULL string
enable_implicit_select_for_update on NULL NULL NULL string
enable_implicit_transaction_for_batch_statements on NULL NULL NULL string
Expand Down Expand Up @@ -2743,6 +2744,7 @@ disable_plan_gists off NULL
disallow_full_table_scans off NULL user NULL off off
distsql off NULL user NULL off off
enable_auto_rehoming off NULL user NULL off off
enable_create_stats_using_extremes off NULL user NULL off off
enable_experimental_alter_column_type_general off NULL user NULL off off
enable_implicit_select_for_update on NULL user NULL on on
enable_implicit_transaction_for_batch_statements on NULL user NULL on on
Expand Down Expand Up @@ -2889,6 +2891,7 @@ disallow_full_table_scans NULL NULL NULL
distsql NULL NULL NULL NULL NULL
distsql_workmem NULL NULL NULL NULL NULL
enable_auto_rehoming NULL NULL NULL NULL NULL
enable_create_stats_using_extremes NULL NULL NULL NULL NULL
enable_experimental_alter_column_type_general NULL NULL NULL NULL NULL
enable_implicit_select_for_update NULL NULL NULL NULL NULL
enable_implicit_transaction_for_batch_statements NULL NULL NULL NULL NULL
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/logictest/testdata/logic_test/show_source
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ disable_plan_gists off
disallow_full_table_scans off
distsql off
enable_auto_rehoming off
enable_create_stats_using_extremes off
enable_experimental_alter_column_type_general off
enable_implicit_select_for_update on
enable_implicit_transaction_for_batch_statements on
Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/sessiondatapb/local_only_session_data.proto
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ message LocalOnlySessionData {
// OptimizerAlwaysUseHistograms, when true, ensures that the optimizer
// always uses histograms to calculate statistics if available.
bool optimizer_always_use_histograms = 94;
// EnableCreateStatsUsingExtremes, when true, allows the use of CREATE
// STATISTICS .. USING EXTREMES.
bool enable_create_stats_using_extremes = 95;

///////////////////////////////////////////////////////////////////////////
// WARNING: consider whether a session parameter you're adding needs to //
Expand Down
17 changes: 17 additions & 0 deletions pkg/sql/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -2532,6 +2532,23 @@ var varGen = map[string]sessionVar{
},
GlobalDefault: globalTrue,
},

// CockroachDB extension.
`enable_create_stats_using_extremes`: {
GetStringVal: makePostgresBoolGetStringValFn(`enable_create_stats_using_extremes`),
Set: func(_ context.Context, m sessionDataMutator, s string) error {
b, err := paramparse.ParseBoolVar("enable_create_stats_using_extremes", s)
if err != nil {
return err
}
m.SetEnableCreateStatsUsingExtremes(b)
return nil
},
Get: func(evalCtx *extendedEvalContext, _ *kv.Txn) (string, error) {
return formatBoolAsPostgresSetting(evalCtx.SessionData().EnableCreateStatsUsingExtremes), nil
},
GlobalDefault: globalFalse,
},
}

// We want test coverage for this on and off so make it metamorphic.
Expand Down