Skip to content

Commit e64b6a4

Browse files
committed
sql: add default_value and is_overridden to cluster settings
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.
1 parent f13f008 commit e64b6a4

File tree

9 files changed

+76
-19
lines changed

9 files changed

+76
-19
lines changed

pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ SELECT * FROM crdb_internal.session_trace WHERE span_idx < 0
224224
----
225225
span_idx message_idx timestamp duration operation loc tag message age
226226

227-
query TTTBT colnames
227+
query TTTBTTT colnames
228228
SELECT * FROM crdb_internal.cluster_settings WHERE variable = ''
229229
----
230-
variable value type public description
230+
variable value type public description default_value origin
231231

232232
query TI colnames
233233
SELECT * FROM crdb_internal.feature_usage WHERE feature_name = ''

pkg/server/settings_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func TestSettingsShowAll(t *testing.T) {
276276
if len(rows) < 2 {
277277
t.Fatalf("show all returned too few rows (%d)", len(rows))
278278
}
279-
const expColumns = 5
279+
const expColumns = 7
280280
if len(rows[0]) != expColumns {
281281
t.Fatalf("show all must return %d columns, found %d", expColumns, len(rows[0]))
282282
}

pkg/settings/setting.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010

1111
package settings
1212

13-
import "context"
13+
import (
14+
"context"
15+
"fmt"
16+
)
1417

1518
// Setting is the interface exposing the metadata for a cluster setting.
1619
//
@@ -159,3 +162,10 @@ const (
159162
// via a host-cluster override for this or all tenant(s).
160163
OriginExternallySet
161164
)
165+
166+
func (v ValueOrigin) String() string {
167+
if v > OriginExternallySet {
168+
return fmt.Sprintf("invalid (%d)", v)
169+
}
170+
return [...]string{"default", "override", "external-override"}[v]
171+
}

pkg/sql/crdb_internal.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2054,7 +2054,9 @@ CREATE TABLE crdb_internal.cluster_settings (
20542054
value STRING NOT NULL,
20552055
type STRING NOT NULL,
20562056
public BOOL NOT NULL, -- whether the setting is documented, which implies the user can expect support.
2057-
description STRING NOT NULL
2057+
description STRING NOT NULL,
2058+
default_value STRING NOT NULL,
2059+
origin STRING NOT NULL -- the origin of the value: 'default' , 'override' or 'external-override'
20582060
)`,
20592061
populate: func(ctx context.Context, p *planner, _ catalog.DatabaseDescriptor, addRow func(...tree.Datum) error) error {
20602062
hasSqlModify, err := p.HasPrivilege(ctx, syntheticprivilege.GlobalPrivilegeObject, privilege.MODIFYSQLCLUSTERSETTING, p.User())
@@ -2093,12 +2095,19 @@ CREATE TABLE crdb_internal.cluster_settings (
20932095
strVal := setting.String(&p.ExecCfg().Settings.SV)
20942096
isPublic := setting.Visibility() == settings.Public
20952097
desc := setting.Description()
2098+
defaultVal, err := setting.DecodeToString(setting.EncodedDefault())
2099+
if err != nil {
2100+
return err
2101+
}
2102+
origin := setting.ValueOrigin(ctx, &p.ExecCfg().Settings.SV).String()
20962103
if err := addRow(
20972104
tree.NewDString(k),
20982105
tree.NewDString(strVal),
20992106
tree.NewDString(setting.Typ()),
21002107
tree.MakeDBool(tree.DBool(isPublic)),
21012108
tree.NewDString(desc),
2109+
tree.NewDString(defaultVal),
2110+
tree.NewDString(origin),
21022111
); err != nil {
21032112
return err
21042113
}

pkg/sql/delegate/show_all_cluster_settings.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ func (d *delegator) delegateShowClusterSettingList(
7777

7878
if stmt.All {
7979
return d.parse(
80-
`SELECT variable, value, type AS setting_type, public, description
80+
`SELECT variable, value, type AS setting_type, public, description, default_value, origin
8181
FROM crdb_internal.cluster_settings`,
8282
)
8383
}
8484
return d.parse(
85-
`SELECT variable, value, type AS setting_type, description
85+
`SELECT variable, value, type AS setting_type, description, default_value, origin
8686
FROM crdb_internal.cluster_settings
8787
WHERE public IS TRUE`,
8888
)

pkg/sql/logictest/testdata/logic_test/cluster_settings

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,44 @@ WHERE variable IN ('sql.defaults.default_int_size')
7878
----
7979
sql.defaults.default_int_size 4
8080

81+
query TTTT
82+
SELECT variable, value, default_value, origin FROM [SHOW ALL CLUSTER SETTINGS]
83+
WHERE variable IN ('sql.index_recommendation.drop_unused_duration')
84+
----
85+
sql.index_recommendation.drop_unused_duration 168h0m0s 168h0m0s default
86+
87+
statement ok
88+
SET CLUSTER SETTING sql.index_recommendation.drop_unused_duration = '10s'
89+
90+
query TTTT
91+
SELECT variable, value, default_value, origin FROM [SHOW ALL CLUSTER SETTINGS]
92+
WHERE variable IN ('sql.index_recommendation.drop_unused_duration')
93+
----
94+
sql.index_recommendation.drop_unused_duration 10s 168h0m0s override
95+
96+
statement ok
97+
RESET CLUSTER SETTING sql.index_recommendation.drop_unused_duration
98+
99+
query TTTT
100+
SELECT variable, value, default_value, origin FROM [SHOW ALL CLUSTER SETTINGS]
101+
WHERE variable IN ('sql.index_recommendation.drop_unused_duration')
102+
----
103+
sql.index_recommendation.drop_unused_duration 168h0m0s 168h0m0s default
104+
105+
user host-cluster-root
106+
107+
statement ok
108+
ALTER TENANT ALL SET CLUSTER SETTING sql.index_recommendation.drop_unused_duration = '50s'
109+
110+
user root
111+
112+
onlyif config 3node-tenant-default-configs
113+
query TTTT
114+
SELECT variable, value, default_value, origin FROM [SHOW ALL CLUSTER SETTINGS]
115+
WHERE variable IN ('sql.index_recommendation.drop_unused_duration')
116+
----
117+
sql.index_recommendation.drop_unused_duration 50s 168h0m0s external-override
118+
81119
user root
82120

83121
statement ok

pkg/sql/logictest/testdata/logic_test/crdb_internal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,10 @@ SELECT * FROM crdb_internal.session_trace WHERE span_idx < 0
355355
----
356356
span_idx message_idx timestamp duration operation loc tag message age
357357

358-
query TTTBT colnames
358+
query TTTBTTT colnames
359359
SELECT * FROM crdb_internal.cluster_settings WHERE variable = ''
360360
----
361-
variable value type public description
361+
variable value type public description default_value origin
362362

363363
query TI colnames
364364
SELECT * FROM crdb_internal.feature_usage WHERE feature_name = ''

pkg/sql/logictest/testdata/logic_test/crdb_internal_catalog

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ SELECT id, strip_volatile(descriptor) FROM crdb_internal.kv_catalog_descriptor O
466466
4294967271 {"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": 4294967271, "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"}}
467467
4294967272 {"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": 4294967272, "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"}}
468468
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": "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": 4294967273, "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"}}
469-
4294967274 {"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": 4294967274, "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"}}
469+
4294967274 {"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": 4294967274, "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"}}
470470
4294967275 {"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": 4294967275, "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"}}
471471
4294967276 {"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}}, {"id": 11, "name": "isolation_level", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 12, "name": "priority", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 13, "name": "quality_of_service", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967276, "name": "cluster_transactions", "nextColumnId": 14, "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"}}
472472
4294967277 {"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": 4294967277, "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"}}

pkg/sql/logictest/testdata/logic_test/show_source

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,23 +180,23 @@ SELECT * FROM [SHOW CLUSTER SETTING sql.defaults.distsql]
180180
sql.defaults.distsql
181181
off
182182

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

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

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

201201
query T colnames
202202
SELECT * FROM [SHOW SESSION_USER]

0 commit comments

Comments
 (0)