Skip to content

Commit

Permalink
sql: add default_value and is_overridden to cluster settings
Browse files Browse the repository at this point in the history
Fixes https://cockroachlabs.atlassian.net/browse/CRDB-28519

Previously, there was no easy way to see default values for
cluster settings. This commit add the column for `default_value`
and `origin` to `crdb_internal.cluster_settings` and
the `show cluster settings` command.

Release note (sql change): Add columns `default_value` and
`origin` (default, override, external-override) to the
`show cluster settings` command.
  • Loading branch information
maryliag committed Jun 7, 2023
1 parent 4f05bc6 commit a04e1f5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
16 changes: 15 additions & 1 deletion pkg/sql/crdb_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2063,7 +2063,9 @@ CREATE TABLE crdb_internal.cluster_settings (
value STRING NOT NULL,
type STRING NOT NULL,
public BOOL NOT NULL, -- whether the setting is documented, which implies the user can expect support.
description STRING NOT NULL
description STRING NOT NULL,
default_value STRING NOT NULL,
origin STRING NOT NULL -- the origin of the value: 'default' , 'override' or 'external-override'
)`,
populate: func(ctx context.Context, p *planner, _ catalog.DatabaseDescriptor, addRow func(...tree.Datum) error) error {
if hasPriv, err := func() (bool, error) {
Expand Down Expand Up @@ -2110,12 +2112,24 @@ CREATE TABLE crdb_internal.cluster_settings (
strVal := setting.String(&p.ExecCfg().Settings.SV)
isPublic := setting.Visibility() == settings.Public
desc := setting.Description()
defaultVal, err := setting.DecodeToString(setting.EncodedDefault())
if err != nil {
return err
}

origin := "default"
// TODO(dt): make this reflect overrides for tenants
if strVal != defaultVal {
origin = "override"
}
if err := addRow(
tree.NewDString(k),
tree.NewDString(strVal),
tree.NewDString(setting.Typ()),
tree.MakeDBool(tree.DBool(isPublic)),
tree.NewDString(desc),
tree.NewDString(defaultVal),
tree.NewDString(origin),
); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/delegate/show_all_cluster_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ func (d *delegator) delegateShowClusterSettingList(

if stmt.All {
return d.parse(
`SELECT variable, value, type AS setting_type, public, description
`SELECT variable, value, type AS setting_type, public, description, default_value, origin
FROM crdb_internal.cluster_settings`,
)
}
return d.parse(
`SELECT variable, value, type AS setting_type, description
`SELECT variable, value, type AS setting_type, description, default_value, origin
FROM crdb_internal.cluster_settings
WHERE public IS TRUE`,
)
Expand Down
15 changes: 15 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/cluster_settings
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ WHERE variable IN ('sql.defaults.default_int_size')
----
sql.defaults.default_int_size 4

query TTTT
SELECT variable, value, default_value, origin FROM [SHOW ALL CLUSTER SETTINGS]
WHERE variable IN ('sql.index_recommendation.drop_unused_duration')
----
sql.index_recommendation.drop_unused_duration 168h0m0s 168h0m0s no-override

statement ok
SET CLUSTER SETTING sql.index_recommendation.drop_unused_duration = '10s'

query TTTT
SELECT variable, value, default_value, origin FROM [SHOW ALL CLUSTER SETTINGS]
WHERE variable IN ('sql.index_recommendation.drop_unused_duration')
----
sql.index_recommendation.drop_unused_duration 10s 168h0m0s override

user root

statement ok
Expand Down

0 comments on commit a04e1f5

Please sign in to comment.