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 22, 2023
1 parent f13f008 commit d2a807f
Show file tree
Hide file tree
Showing 9 changed files with 353 additions and 331 deletions.
4 changes: 2 additions & 2 deletions pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ SELECT * FROM crdb_internal.session_trace WHERE span_idx < 0
----
span_idx message_idx timestamp duration operation loc tag message age

query TTTBT colnames
query TTTBTTT colnames
SELECT * FROM crdb_internal.cluster_settings WHERE variable = ''
----
variable value type public description
variable value type public description default_value origin

query TI colnames
SELECT * FROM crdb_internal.feature_usage WHERE feature_name = ''
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func TestSettingsShowAll(t *testing.T) {
if len(rows) < 2 {
t.Fatalf("show all returned too few rows (%d)", len(rows))
}
const expColumns = 5
const expColumns = 7
if len(rows[0]) != expColumns {
t.Fatalf("show all must return %d columns, found %d", expColumns, len(rows[0]))
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/settings/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,7 @@ const (
// via a host-cluster override for this or all tenant(s).
OriginExternallySet
)

func (v ValueOrigin) String() string {
return [...]string{"default", "override", "external-override"}[v]
}
11 changes: 10 additions & 1 deletion pkg/sql/crdb_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2054,7 +2054,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 {
hasSqlModify, err := p.HasPrivilege(ctx, syntheticprivilege.GlobalPrivilegeObject, privilege.MODIFYSQLCLUSTERSETTING, p.User())
Expand Down Expand Up @@ -2093,12 +2095,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 {
return err
}
origin := setting.ValueOrigin(ctx, &p.ExecCfg().Settings.SV).String()
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 default

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
4 changes: 2 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/crdb_internal
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,10 @@ SELECT * FROM crdb_internal.session_trace WHERE span_idx < 0
----
span_idx message_idx timestamp duration operation loc tag message age

query TTTBT colnames
query TTTBTTT colnames
SELECT * FROM crdb_internal.cluster_settings WHERE variable = ''
----
variable value type public description
variable value type public description default_value origin

query TI colnames
SELECT * FROM crdb_internal.feature_usage WHERE feature_name = ''
Expand Down
622 changes: 308 additions & 314 deletions pkg/sql/logictest/testdata/logic_test/crdb_internal_catalog

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions pkg/sql/logictest/testdata/logic_test/show_source
Original file line number Diff line number Diff line change
Expand Up @@ -180,23 +180,23 @@ SELECT * FROM [SHOW CLUSTER SETTING sql.defaults.distsql]
sql.defaults.distsql
off

query TTTBT colnames
query TTTBTTT colnames
SELECT * FROM [SHOW ALL CLUSTER SETTINGS] WHERE variable LIKE '%organization'
----
variable value setting_type public description
cluster.organization · s true organization name
variable value setting_type public description default_value origin
cluster.organization · s true organization name · default

query TTTT colnames
query TTTTTT colnames
SELECT * FROM [SHOW CLUSTER SETTINGS] WHERE variable LIKE '%organization'
----
variable value setting_type description
cluster.organization · s organization name
variable value setting_type description default_value origin
cluster.organization · s organization name · default

query TTTT colnames
query TTTTTT colnames
SELECT * FROM [SHOW PUBLIC CLUSTER SETTINGS] WHERE variable LIKE '%organization'
----
variable value setting_type description
cluster.organization · s organization name
variable value setting_type description default_value origin
cluster.organization · s organization name · default

query T colnames
SELECT * FROM [SHOW SESSION_USER]
Expand Down

0 comments on commit d2a807f

Please sign in to comment.