From 2060b92634a766e6c4d568efac12d2e9bb92b2ba Mon Sep 17 00:00:00 2001 From: maryliag Date: Tue, 6 Jun 2023 17:16:59 -0400 Subject: [PATCH] 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. --- .../testdata/logic_test/crdb_internal_tenant | 4 ++-- pkg/server/settings_test.go | 2 +- pkg/settings/setting.go | 4 ++++ pkg/sql/crdb_internal.go | 11 ++++++++++- pkg/sql/delegate/show_all_cluster_settings.go | 4 ++-- .../testdata/logic_test/cluster_settings | 15 +++++++++++++++ .../testdata/logic_test/crdb_internal | 4 ++-- .../testdata/logic_test/crdb_internal_catalog | 2 +- .../logictest/testdata/logic_test/show_source | 18 +++++++++--------- 9 files changed, 46 insertions(+), 18 deletions(-) diff --git a/pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant b/pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant index 89b67b8132c6..c3084bcdb05e 100644 --- a/pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant +++ b/pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant @@ -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 = '' diff --git a/pkg/server/settings_test.go b/pkg/server/settings_test.go index 567accfd7b9c..95e3ed18bb86 100644 --- a/pkg/server/settings_test.go +++ b/pkg/server/settings_test.go @@ -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])) } diff --git a/pkg/settings/setting.go b/pkg/settings/setting.go index 72455441c783..16900d11e3e3 100644 --- a/pkg/settings/setting.go +++ b/pkg/settings/setting.go @@ -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] +} diff --git a/pkg/sql/crdb_internal.go b/pkg/sql/crdb_internal.go index e718c6538329..bef5f135953e 100644 --- a/pkg/sql/crdb_internal.go +++ b/pkg/sql/crdb_internal.go @@ -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()) @@ -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 } diff --git a/pkg/sql/delegate/show_all_cluster_settings.go b/pkg/sql/delegate/show_all_cluster_settings.go index 7aa0169f9c4b..6024648c9dc0 100644 --- a/pkg/sql/delegate/show_all_cluster_settings.go +++ b/pkg/sql/delegate/show_all_cluster_settings.go @@ -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`, ) diff --git a/pkg/sql/logictest/testdata/logic_test/cluster_settings b/pkg/sql/logictest/testdata/logic_test/cluster_settings index 1437710777c7..b701633f54a5 100644 --- a/pkg/sql/logictest/testdata/logic_test/cluster_settings +++ b/pkg/sql/logictest/testdata/logic_test/cluster_settings @@ -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 diff --git a/pkg/sql/logictest/testdata/logic_test/crdb_internal b/pkg/sql/logictest/testdata/logic_test/crdb_internal index d3468e5e9818..b8360caa78d4 100644 --- a/pkg/sql/logictest/testdata/logic_test/crdb_internal +++ b/pkg/sql/logictest/testdata/logic_test/crdb_internal @@ -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 = '' diff --git a/pkg/sql/logictest/testdata/logic_test/crdb_internal_catalog b/pkg/sql/logictest/testdata/logic_test/crdb_internal_catalog index a0a4fa1bdc6a..f961c89fd51b 100644 --- a/pkg/sql/logictest/testdata/logic_test/crdb_internal_catalog +++ b/pkg/sql/logictest/testdata/logic_test/crdb_internal_catalog @@ -466,7 +466,7 @@ SELECT id, strip_volatile(descriptor) FROM crdb_internal.kv_catalog_descriptor O 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"}} 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"}} 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"}} -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"}} +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"}} 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"}} 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"}} 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"}} diff --git a/pkg/sql/logictest/testdata/logic_test/show_source b/pkg/sql/logictest/testdata/logic_test/show_source index 1f11222da883..a4abe7975efd 100644 --- a/pkg/sql/logictest/testdata/logic_test/show_source +++ b/pkg/sql/logictest/testdata/logic_test/show_source @@ -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]