Skip to content

Commit

Permalink
sql: added setting for enable/disable queries against unimplemented
Browse files Browse the repository at this point in the history
virtual tables

Previously, Unimplemented virtual tables where tables
listed in the virtual schema which do not have a definition
This was inadequate because:
- A lot of tables where added for compatibility reasons
which are not longer considered umimplemented
- A tool hung because was expecting an unimplemented table
return rows
To address this, this patch:
- Adds a new field to the virtualSchemaTable to set a virtual
table as unimplemented
- Added a setting for enable / disable queries against
virtual tables

Release note (sql change): setting for enable/disable queries against
unimplemented virtual tables

Fixes cockroachdb#61866 cockroachdb#61801
  • Loading branch information
MiguelNovelo committed Mar 16, 2021
1 parent f5ed0e2 commit c07b85b
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 262 deletions.
3 changes: 3 additions & 0 deletions pkg/sql/exec_factory_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ func constructVirtualScan(
if err != nil {
return nil, err
}
if !virtual.QueriesEnabled(p.EvalContext()) {
return nil, errors.Errorf("queries are disabled for unimplemented tables: %s", tn.Table())
}
indexDesc := index.(*optVirtualIndex).desc
columns, constructor := virtual.getPlanInfo(
table.(*optVirtualTable).desc,
Expand Down
10 changes: 10 additions & 0 deletions pkg/sql/exec_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ var experimentalStreamReplicationEnabled = settings.RegisterBoolSetting(
false,
)

var unimplementedVirtualTableQueriesEnabledClusterValue = settings.RegisterBoolSetting(
`sql.defaults.unimplemented_virtual_table_queries.enabled`,
`setting to allow queries against unimplemented tables`,
true,
)

// ExperimentalDistSQLPlanningClusterSettingName is the name for the cluster
// setting that controls experimentalDistSQLPlanningClusterMode below.
const ExperimentalDistSQLPlanningClusterSettingName = "sql.defaults.experimental_distsql_planning"
Expand Down Expand Up @@ -2371,6 +2377,10 @@ func (m *sessionDataMutator) initSequenceCache() {
m.data.SequenceCache = sessiondata.SequenceCache{}
}

func (m *sessionDataMutator) SetUnimplementedVirtualTableQueriesEnabled(enabled bool) {
m.data.UnimplementedVirtualTableQueriesEnabled = enabled
}

type sqlStatsCollector struct {
// sqlStats tracks per-application statistics for all applications on each
// node.
Expand Down
83 changes: 2 additions & 81 deletions pkg/sql/information_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,79 +50,6 @@ var pgCatalogNameDString = tree.NewDString(pgCatalogName)
// information_schema.
var informationSchema = virtualSchema{
name: sessiondata.InformationSchemaName,
allTableNames: buildStringSet(
// Generated with:
// select distinct '"'||table_name||'",' from information_schema.tables
// where table_schema='information_schema' order by table_name;
"_pg_foreign_data_wrappers",
"_pg_foreign_servers",
"_pg_foreign_table_columns",
"_pg_foreign_tables",
"_pg_user_mappings",
"administrable_role_authorizations",
"applicable_roles",
"attributes",
"character_sets",
"check_constraint_routine_usage",
"check_constraints",
"collation_character_set_applicability",
"collations",
"column_domain_usage",
"column_options",
"column_privileges",
"column_udt_usage",
"columns",
"constraint_column_usage",
"constraint_table_usage",
"data_type_privileges",
"domain_constraints",
"domain_udt_usage",
"domains",
"element_types",
"enabled_roles",
"foreign_data_wrapper_options",
"foreign_data_wrappers",
"foreign_server_options",
"foreign_servers",
"foreign_table_options",
"foreign_tables",
"information_schema_catalog_name",
"key_column_usage",
"parameters",
"referential_constraints",
"role_column_grants",
"role_routine_grants",
"role_table_grants",
"role_udt_grants",
"role_usage_grants",
"routine_privileges",
"routines",
"schemata",
"sequences",
"sql_features",
"sql_implementation_info",
"sql_languages",
"sql_packages",
"sql_parts",
"sql_sizing",
"sql_sizing_profiles",
"table_constraints",
"table_privileges",
"tables",
"transforms",
"triggered_update_columns",
"triggers",
"type_privileges",
"udt_privileges",
"usage_privileges",
"user_defined_types",
"user_mapping_options",
"user_mappings",
"view_column_usage",
"view_routine_usage",
"view_table_usage",
"views",
),
tableDefs: map[descpb.ID]virtualSchemaDef{
catconstants.InformationSchemaAdministrableRoleAuthorizationsID: informationSchemaAdministrableRoleAuthorizations,
catconstants.InformationSchemaApplicableRolesID: informationSchemaApplicableRoles,
Expand Down Expand Up @@ -156,14 +83,6 @@ var informationSchema = virtualSchema{
validWithNoDatabaseContext: true,
}

func buildStringSet(ss ...string) map[string]struct{} {
m := map[string]struct{}{}
for _, s := range ss {
m[s] = struct{}{}
}
return m
}

var (
emptyString = tree.NewDString("")
// information_schema was defined before the BOOLEAN data type was added to
Expand Down Expand Up @@ -869,6 +788,7 @@ CREATE TABLE information_schema.parameters (
populate: func(ctx context.Context, p *planner, dbContext *dbdesc.Immutable, addRow func(...tree.Datum) error) error {
return nil
},
unimplemented: true,
}

var (
Expand Down Expand Up @@ -1081,6 +1001,7 @@ CREATE TABLE information_schema.routines (
populate: func(ctx context.Context, p *planner, dbContext *dbdesc.Immutable, addRow func(...tree.Datum) error) error {
return nil
},
unimplemented: true,
}

// MySQL: https://dev.mysql.com/doc/refman/5.7/en/schemata-table.html
Expand Down
5 changes: 5 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/cluster_settings
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,8 @@ WHERE variable IN ('cloudstorage.gs.default.key', 'sql.defaults.default_int_size
----
cloudstorage.gs.default.key foo
sql.defaults.default_int_size 4

query B
SHOW CLUSTER SETTING sql.defaults.unimplemented_virtual_table_queries.enabled
----
true
1 change: 1 addition & 0 deletions pkg/sql/logictest/testdata/logic_test/information_schema
Original file line number Diff line number Diff line change
Expand Up @@ -3668,6 +3668,7 @@ transaction_isolation serializable
transaction_priority normal
transaction_read_only off
transaction_status NoTxn
unimplemented_virtual_table_queries_enabled on
vectorize_row_count_threshold 0

# information_schema can be used with the anonymous database.
Expand Down
18 changes: 18 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/pg_catalog
Original file line number Diff line number Diff line change
Expand Up @@ -2157,6 +2157,7 @@ transaction_isolation serializable NULL
transaction_priority normal NULL NULL NULL string
transaction_read_only off NULL NULL NULL string
transaction_status NoTxn NULL NULL NULL string
unimplemented_virtual_table_queries_enabled on NULL NULL NULL string
vectorize on NULL NULL NULL string
vectorize_row_count_threshold 0 NULL NULL NULL string

Expand Down Expand Up @@ -2237,6 +2238,7 @@ transaction_isolation serializable NULL
transaction_priority normal NULL user NULL normal normal
transaction_read_only off NULL user NULL off off
transaction_status NoTxn NULL user NULL NoTxn NoTxn
unimplemented_virtual_table_queries_enabled on NULL user NULL on on
vectorize on NULL user NULL on on
vectorize_row_count_threshold 0 NULL user NULL 0 0

Expand Down Expand Up @@ -2315,6 +2317,7 @@ transaction_isolation NULL NULL NULL
transaction_priority NULL NULL NULL NULL NULL
transaction_read_only NULL NULL NULL NULL NULL
transaction_status NULL NULL NULL NULL NULL
unimplemented_virtual_table_queries_enabled NULL NULL NULL NULL NULL
vectorize NULL NULL NULL NULL NULL
vectorize_row_count_threshold NULL NULL NULL NULL NULL

Expand Down Expand Up @@ -3260,3 +3263,18 @@ GROUP BY indexname, indisunique, indisprimary, amname, exprdef, attoptions
indexname array_agg indisunique indisprimary array_agg amname exprdef attoptions
indexes_include_idx {a,c,d} false false {ASC,ASC,ASC} prefix NULL NULL
primary {id} true true {ASC} prefix NULL NULL

statement ok
SET unimplemented_virtual_table_queries_enabled=false

statement error queries are disabled for unimplemented tables: pg_seclabel
SELECT * FROM pg_seclabel

statement ok
SELECT count(*) FROM pg_depend

statement ok
SET unimplemented_virtual_table_queries_enabled=true

statement ok
SELECT * FROM pg_seclabel
1 change: 1 addition & 0 deletions pkg/sql/logictest/testdata/logic_test/show_source
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ transaction_isolation serializable
transaction_priority normal
transaction_read_only off
transaction_status NoTxn
unimplemented_virtual_table_queries_enabled on
vectorize on
vectorize_row_count_threshold 0

Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/opt_exec_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,9 @@ func (ef *execFactory) constructVirtualTableLookupJoin(
if err != nil {
return nil, err
}
if !virtual.QueriesEnabled(ef.planner.EvalContext()) {
return nil, errors.Errorf("queries are disabled for unimplemented tables: %s", tn.Table())
}
if len(eqCols) > 1 {
return nil, errors.AssertionFailedf("vtable indexes with more than one column aren't supported yet")
}
Expand Down
Loading

0 comments on commit c07b85b

Please sign in to comment.