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

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

Release note (sql change): Add columns `default_value` and
`is_overridden` to `crdb_internal.cluster_settings` and
`show cluster settings` command..
  • Loading branch information
maryliag committed Jun 6, 2023
1 parent 4f05bc6 commit 706e0a9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
11 changes: 10 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,
is_overridden BOOL NOT NULL
)`,
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,19 @@ 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 {
defaultVal = setting.EncodedDefault()
}
isOverridden := strVal != defaultVal
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.MakeDBool(tree.DBool(isOverridden)),
); 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, is_overridden
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, is_overridden
FROM crdb_internal.cluster_settings
WHERE public IS TRUE`,
)
Expand Down
6 changes: 6 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,12 @@ WHERE variable IN ('sql.defaults.default_int_size')
----
sql.defaults.default_int_size 4

query TTTB
SELECT variable, value, default_value, is_overridden FROM [SHOW ALL CLUSTER SETTINGS]
WHERE variable IN ('sql.defaults.default_int_size')
----
sql.defaults.default_int_size 4 4 f

user root

statement ok
Expand Down

0 comments on commit 706e0a9

Please sign in to comment.