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 73a3bed
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 18 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 @@ -218,10 +218,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
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 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 @@ -349,10 +349,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
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ SELECT id, strip_volatile(descriptor) FROM crdb_internal.kv_catalog_descriptor
4294967272 {"table": {"columns": [{"id": 1, "name": "database_id", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 2, "name": "database_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "schema_id", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 4, "name": "schema_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 5, "name": "function_id", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 6, "name": "function_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 7, "name": "create_statement", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967272, "name": "create_function_statements", "nextColumnId": 8, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1"}}
4294967273 {"table": {"columns": [{"id": 1, "name": "aggregated_ts", "type": {"family": "TimestampTZFamily", "oid": 1184}}, {"id": 2, "name": "fingerprint_id", "type": {"family": "BytesFamily", "oid": 17}}, {"id": 3, "name": "app_name", "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "metadata", "type": {"family": "JsonFamily", "oid": 3802}}, {"id": 5, "name": "statistics", "type": {"family": "JsonFamily", "oid": 3802}}, {"id": 6, "name": "aggregation_interval", "type": {"family": "IntervalFamily", "intervalDurationField": {}, "oid": 1186}}], "formatVersion": 3, "id": 4294967273, "name": "cluster_transaction_statistics", "nextColumnId": 7, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1"}}
4294967274 {"table": {"columns": [{"id": 1, "name": "aggregated_ts", "type": {"family": "TimestampTZFamily", "oid": 1184}}, {"id": 2, "name": "fingerprint_id", "type": {"family": "BytesFamily", "oid": 17}}, {"id": 3, "name": "transaction_fingerprint_id", "type": {"family": "BytesFamily", "oid": 17}}, {"id": 4, "name": "plan_hash", "type": {"family": "BytesFamily", "oid": 17}}, {"id": 5, "name": "app_name", "type": {"family": "StringFamily", "oid": 25}}, {"id": 6, "name": "metadata", "type": {"family": "JsonFamily", "oid": 3802}}, {"id": 7, "name": "statistics", "type": {"family": "JsonFamily", "oid": 3802}}, {"id": 8, "name": "sampled_plan", "type": {"family": "JsonFamily", "oid": 3802}}, {"id": 9, "name": "aggregation_interval", "type": {"family": "IntervalFamily", "intervalDurationField": {}, "oid": 1186}}, {"id": 10, "name": "index_recommendations", "type": {"arrayContents": {"family": "StringFamily", "oid": 25}, "arrayElemType": "StringFamily", "family": "ArrayFamily", "oid": 1009}}], "formatVersion": 3, "id": 4294967274, "name": "cluster_statement_statistics", "nextColumnId": 11, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1"}}
4294967275 {"table": {"columns": [{"id": 1, "name": "variable", "type": {"family": "StringFamily", "oid": 25}}, {"id": 2, "name": "value", "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "type", "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "public", "type": {"oid": 16}}, {"id": 5, "name": "description", "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967275, "name": "cluster_settings", "nextColumnId": 6, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1"}}
4294967275 {"table": {"columns": [{"id": 1, "name": "variable", "type": {"family": "StringFamily", "oid": 25}}, {"id": 2, "name": "value", "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "type", "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "public", "type": {"oid": 16}}, {"id": 5, "name": "description", "type": {"family": "StringFamily", "oid": 25}}, {"id": 6, "name": "default_value", "type": {"family": "StringFamily", "oid": 25}}, {"id": 7, "name": "origin", "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967275, "name": "cluster_settings", "nextColumnId": 8, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1"}}
4294967276 {"table": {"columns": [{"id": 1, "name": "node_id", "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 2, "name": "session_id", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "user_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "client_address", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 5, "name": "application_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 6, "name": "active_queries", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 7, "name": "last_active_query", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 8, "name": "num_txns_executed", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 9, "name": "session_start", "nullable": true, "type": {"family": "TimestampFamily", "oid": 1114}}, {"id": 10, "name": "active_query_start", "nullable": true, "type": {"family": "TimestampFamily", "oid": 1114}}, {"id": 11, "name": "kv_txn", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 12, "name": "alloc_bytes", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 13, "name": "max_alloc_bytes", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 14, "name": "status", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 15, "name": "session_end", "nullable": true, "type": {"family": "TimestampFamily", "oid": 1114}}], "formatVersion": 3, "id": 4294967276, "name": "cluster_sessions", "nextColumnId": 16, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1"}}
4294967277 {"table": {"columns": [{"id": 1, "name": "id", "nullable": true, "type": {"family": "UuidFamily", "oid": 2950}}, {"id": 2, "name": "node_id", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 3, "name": "session_id", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "start", "nullable": true, "type": {"family": "TimestampFamily", "oid": 1114}}, {"id": 5, "name": "txn_string", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 6, "name": "application_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 7, "name": "num_stmts", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 8, "name": "num_retries", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 9, "name": "num_auto_retries", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 10, "name": "last_auto_retry_reason", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967277, "name": "cluster_transactions", "nextColumnId": 11, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1"}}
4294967278 {"table": {"columns": [{"id": 1, "name": "query_id", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 2, "name": "txn_id", "nullable": true, "type": {"family": "UuidFamily", "oid": 2950}}, {"id": 3, "name": "node_id", "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 4, "name": "session_id", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 5, "name": "user_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 6, "name": "start", "nullable": true, "type": {"family": "TimestampFamily", "oid": 1114}}, {"id": 7, "name": "query", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 8, "name": "client_address", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 9, "name": "application_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 10, "name": "distributed", "nullable": true, "type": {"oid": 16}}, {"id": 11, "name": "phase", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 12, "name": "full_scan", "nullable": true, "type": {"oid": 16}}, {"id": 13, "name": "plan_gist", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 14, "name": "database", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967278, "name": "cluster_queries", "nextColumnId": 15, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1"}}
Expand Down
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 @@ -179,23 +179,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 73a3bed

Please sign in to comment.