Skip to content

Commit

Permalink
sql: Add information_schema.session_variables table
Browse files Browse the repository at this point in the history
The `session_variables` table exposes the session variables.
Related to: #8675

Release note (sql change): Added session_variables table to the information_schema.
  • Loading branch information
mneverov committed Dec 11, 2020
1 parent 2b897f3 commit c66de92
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 130 deletions.
1 change: 1 addition & 0 deletions pkg/sql/catalog/catconstants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const (
InformationSchemaRoutineTableID
InformationSchemaSchemataTableID
InformationSchemaSchemataTablePrivilegesID
InformationSchemaSessionVariables
InformationSchemaSequencesID
InformationSchemaStatisticsTableID
InformationSchemaTableConstraintTableID
Expand Down
19 changes: 19 additions & 0 deletions pkg/sql/information_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ var informationSchema = virtualSchema{
catconstants.InformationSchemaRoutineTableID: informationSchemaRoutineTable,
catconstants.InformationSchemaSchemataTableID: informationSchemaSchemataTable,
catconstants.InformationSchemaSchemataTablePrivilegesID: informationSchemaSchemataTablePrivileges,
catconstants.InformationSchemaSessionVariables: informationSchemaSessionVariables,
catconstants.InformationSchemaSequencesID: informationSchemaSequences,
catconstants.InformationSchemaStatisticsTableID: informationSchemaStatisticsTable,
catconstants.InformationSchemaTableConstraintTableID: informationSchemaTableConstraintTable,
Expand Down Expand Up @@ -1669,6 +1670,24 @@ https://www.postgresql.org/docs/current/infoschema-collation-character-set-appli
},
}

var informationSchemaSessionVariables = virtualSchemaTable{
comment: `exposes the session variables.`,
schema: vtable.InformationSchemaSessionVariables,
populate: func(ctx context.Context, p *planner, _ *dbdesc.Immutable, addRow func(...tree.Datum) error) error {
for _, vName := range varNames {
gen := varGen[vName]
value := gen.Get(&p.extendedEvalCtx)
if err := addRow(
tree.NewDString(vName),
tree.NewDString(value),
); err != nil {
return err
}
}
return nil
},
}

// forEachSchema iterates over the physical and virtual schemas.
func forEachSchema(
ctx context.Context, p *planner, db *dbdesc.Immutable, fn func(sc catalog.ResolvedSchema) error,
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/logictest/testdata/logic_test/grant_table
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ test information_schema routines public
test information_schema schema_privileges public SELECT
test information_schema schemata public SELECT
test information_schema sequences public SELECT
test information_schema session_variables public SELECT
test information_schema statistics public SELECT
test information_schema table_constraints public SELECT
test information_schema table_privileges public SELECT
Expand Down
100 changes: 100 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/information_schema
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ information_schema routines table NULL NULL NU
information_schema schema_privileges table NULL NULL NULL
information_schema schemata table NULL NULL NULL
information_schema sequences table NULL NULL NULL
information_schema session_variables table NULL NULL NULL
information_schema statistics table NULL NULL NULL
information_schema table_constraints table NULL NULL NULL
information_schema table_privileges table NULL NULL NULL
Expand Down Expand Up @@ -105,6 +106,8 @@ GRANT CREATE ON information_schema.tables TO root
statement error tables is a virtual object and cannot be modified
REVOKE CREATE ON information_schema.tables FROM root

statement error session_variables is a virtual object and cannot be modified
ALTER TABLE information_schema.session_variables ALTER x DROP NOT NULL

# Verify information_schema tables handles read-only property correctly.

Expand Down Expand Up @@ -148,6 +151,20 @@ UPDATE information_schema.collations SET a = 'abc'
statement error collations is a virtual object and cannot be modified
TRUNCATE TABLE information_schema.collations

# Verify information_schema session_variables handles read-only property correctly.

query error user root does not have DELETE privilege on relation session_variables
DELETE FROM information_schema.session_variables

query error user root does not have INSERT privilege on relation session_variables
INSERT INTO information_schema.session_variables VALUES ('abc')

statement error user root does not have UPDATE privilege on relation session_variables
UPDATE information_schema.session_variables SET a = 'abc'

statement error session_variables is a virtual object and cannot be modified
TRUNCATE TABLE information_schema.session_variables

# Verify information_schema handles reflection correctly.

query TTTTT
Expand Down Expand Up @@ -180,6 +197,7 @@ information_schema routines table NULL NULL NU
information_schema schema_privileges table NULL NULL NULL
information_schema schemata table NULL NULL NULL
information_schema sequences table NULL NULL NULL
information_schema session_variables table NULL NULL NULL
information_schema statistics table NULL NULL NULL
information_schema table_constraints table NULL NULL NULL
information_schema table_privileges table NULL NULL NULL
Expand Down Expand Up @@ -321,6 +339,7 @@ information_schema routines
information_schema schema_privileges
information_schema schemata
information_schema sequences
information_schema session_variables
information_schema statistics
information_schema table_constraints
information_schema table_privileges
Expand Down Expand Up @@ -479,6 +498,7 @@ routines
schema_privileges
schemata
sequences
session_variables
statistics
table_constraints
table_privileges
Expand Down Expand Up @@ -656,6 +676,7 @@ system information_schema routines SYSTEM
system information_schema schema_privileges SYSTEM VIEW NO 1
system information_schema schemata SYSTEM VIEW NO 1
system information_schema sequences SYSTEM VIEW NO 1
system information_schema session_variables SYSTEM VIEW NO 1
system information_schema statistics SYSTEM VIEW NO 1
system information_schema table_constraints SYSTEM VIEW NO 1
system information_schema table_privileges SYSTEM VIEW NO 1
Expand Down Expand Up @@ -1781,6 +1802,7 @@ NULL public system information_schema routines
NULL public system information_schema schema_privileges SELECT NULL YES
NULL public system information_schema schemata SELECT NULL YES
NULL public system information_schema sequences SELECT NULL YES
NULL public system information_schema session_variables SELECT NULL YES
NULL public system information_schema statistics SELECT NULL YES
NULL public system information_schema table_constraints SELECT NULL YES
NULL public system information_schema table_privileges SELECT NULL YES
Expand Down Expand Up @@ -2164,6 +2186,7 @@ NULL public system information_schema routines
NULL public system information_schema schema_privileges SELECT NULL YES
NULL public system information_schema schemata SELECT NULL YES
NULL public system information_schema sequences SELECT NULL YES
NULL public system information_schema session_variables SELECT NULL YES
NULL public system information_schema statistics SELECT NULL YES
NULL public system information_schema table_constraints SELECT NULL YES
NULL public system information_schema table_privileges SELECT NULL YES
Expand Down Expand Up @@ -3226,3 +3249,80 @@ test pg_catalog zh NULL
test pg_catalog zh-u-co-stroke NULL NULL UTF8
test pg_catalog zh-Hant-u-co-pinyin NULL NULL UTF8
test pg_catalog zh-Hant NULL NULL UTF8


## information_schema.session_variables

query TT colnames
SELECT * FROM information_schema.session_variables
variable value
allow_prepare_as_opt_plan off
application_name ·
bytea_output hex
client_encoding UTF8
client_min_messages notice
crdb_version CockroachDB OSS v21.1.0-alpha.1-272-g63d74f0eb9-dirty (x86_64-linux-gnu, built , go1.15.5)
database test
datestyle ISO, MDY
default_int_size 8
default_tablespace ·
default_transaction_isolation serializable
default_transaction_priority normal
default_transaction_read_only off
disable_partially_distributed_plans off
disallow_full_table_scans off
distsql off
enable_experimental_alter_column_type_general off
enable_implicit_select_for_update on
enable_insert_fast_path on
enable_seqscan on
enable_zigzag_join on
experimental_distsql_planning off
experimental_enable_hash_sharded_indexes off
experimental_enable_multi_column_inverted_indexes off
experimental_enable_temp_tables off
experimental_enable_unique_without_index_constraints off
extra_float_digits 0
force_savepoint_restart off
foreign_key_cascades_limit 10000
idle_in_session_timeout 0
idle_in_transaction_session_timeout 0
integer_datetimes on
intervalstyle postgres
locality region=test,dc=dc1
lock_timeout 0
max_identifier_length 128
max_index_keys 32
node_id 1
optimizer on
optimizer_use_histograms on
optimizer_use_multicol_stats on
prefer_lookup_joins_for_fks off
reorder_joins_limit 8
require_explicit_primary_keys off
results_buffer_size 16384
row_security off
save_tables_prefix ·
search_path $user,public
serial_normalization rowid
server_encoding UTF8
server_version 9.5.0
server_version_num 90500
session_authorization root
session_id 164fbf75300562960000000000000001
session_user root
sql_safe_updates off
ssl_renegotiation_limit 0
standard_conforming_strings on
statement_timeout 0
synchronize_seqscans on
synchronous_commit on
testing_vectorize_inject_panics off
timezone UTC
tracing off
transaction_isolation serializable
transaction_priority normal
transaction_read_only off
transaction_status NoTxn
vectorize on
vectorize_row_count_threshold 0
Loading

0 comments on commit c66de92

Please sign in to comment.