diff --git a/docs/generated/sql/bnf/alter_index_stmt.bnf b/docs/generated/sql/bnf/alter_index_stmt.bnf index 56fedf088399..0c2827a3ac8e 100644 --- a/docs/generated/sql/bnf/alter_index_stmt.bnf +++ b/docs/generated/sql/bnf/alter_index_stmt.bnf @@ -5,3 +5,4 @@ alter_index_stmt ::= | alter_scatter_index_stmt | alter_rename_index_stmt | alter_zone_index_stmt + | alter_index_visible_stmt diff --git a/docs/generated/sql/bnf/create_index_stmt.bnf b/docs/generated/sql/bnf/create_index_stmt.bnf index 1032956af07c..1fbd24e21e76 100644 --- a/docs/generated/sql/bnf/create_index_stmt.bnf +++ b/docs/generated/sql/bnf/create_index_stmt.bnf @@ -1,5 +1,5 @@ create_index_stmt ::= - 'CREATE' ( 'UNIQUE' | ) 'INDEX' ( 'CONCURRENTLY' | ) opt_index_name 'ON' table_name ( 'USING' name | ) '(' ( ( ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) ( ( ',' ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) )* ) ')' ( 'USING' 'HASH' | ) ( ( 'COVERING' | 'STORING' | 'INCLUDE' ) '(' name_list ')' | ) ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) ( 'WITH' '(' ( ( storage_parameter ) ( ( ',' storage_parameter ) )* ) ')' ) opt_where_clause - | 'CREATE' ( 'UNIQUE' | ) 'INDEX' ( 'CONCURRENTLY' | ) 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name ( 'USING' name | ) '(' ( ( ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) ( ( ',' ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) )* ) ')' ( 'USING' 'HASH' | ) ( ( 'COVERING' | 'STORING' | 'INCLUDE' ) '(' name_list ')' | ) ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) ( 'WITH' '(' ( ( storage_parameter ) ( ( ',' storage_parameter ) )* ) ')' ) opt_where_clause + 'CREATE' ( 'UNIQUE' | ) 'INDEX' ( 'CONCURRENTLY' | ) opt_index_name 'ON' table_name ( 'USING' name | ) '(' ( ( ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) ( ( ',' ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) )* ) ')' ( 'USING' 'HASH' | ) ( ( 'COVERING' | 'STORING' | 'INCLUDE' ) '(' name_list ')' | ) ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) ( 'WITH' '(' ( ( storage_parameter ) ( ( ',' storage_parameter ) )* ) ')' ) opt_where_clause opt_index_hidden + | 'CREATE' ( 'UNIQUE' | ) 'INDEX' ( 'CONCURRENTLY' | ) 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name ( 'USING' name | ) '(' ( ( ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) ( ( ',' ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) )* ) ')' ( 'USING' 'HASH' | ) ( ( 'COVERING' | 'STORING' | 'INCLUDE' ) '(' name_list ')' | ) ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) ( 'WITH' '(' ( ( storage_parameter ) ( ( ',' storage_parameter ) )* ) ')' ) opt_where_clause opt_index_hidden diff --git a/docs/generated/sql/bnf/create_inverted_index_stmt.bnf b/docs/generated/sql/bnf/create_inverted_index_stmt.bnf index aeebf9a9335a..19a7e8c72752 100644 --- a/docs/generated/sql/bnf/create_inverted_index_stmt.bnf +++ b/docs/generated/sql/bnf/create_inverted_index_stmt.bnf @@ -1,5 +1,5 @@ create_index_stmt ::= - 'CREATE' ( 'UNIQUE' | ) 'INDEX' ( 'CONCURRENTLY' | ) opt_index_name 'ON' table_name opt_index_access_method '(' ( ( ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) ( ( ',' ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) )* ) ')' opt_hash_sharded ( ( 'COVERING' | 'STORING' | 'INCLUDE' ) '(' name_list ')' | ) ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) ( 'WITH' '(' ( ( storage_parameter ) ( ( ',' storage_parameter ) )* ) ')' ) opt_where_clause - | 'CREATE' ( 'UNIQUE' | ) 'INDEX' ( 'CONCURRENTLY' | ) 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name opt_index_access_method '(' ( ( ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) ( ( ',' ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) )* ) ')' opt_hash_sharded ( ( 'COVERING' | 'STORING' | 'INCLUDE' ) '(' name_list ')' | ) ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) ( 'WITH' '(' ( ( storage_parameter ) ( ( ',' storage_parameter ) )* ) ')' ) opt_where_clause - | 'CREATE' ( 'UNIQUE' | ) 'INVERTED' 'INDEX' ( 'CONCURRENTLY' | ) opt_index_name 'ON' table_name '(' ( ( ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) ( ( ',' ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) )* ) ')' ( ( 'COVERING' | 'STORING' | 'INCLUDE' ) '(' name_list ')' | ) ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) ( 'WITH' '(' ( ( storage_parameter ) ( ( ',' storage_parameter ) )* ) ')' ) opt_where_clause - | 'CREATE' ( 'UNIQUE' | ) 'INVERTED' 'INDEX' ( 'CONCURRENTLY' | ) 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' ( ( ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) ( ( ',' ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) )* ) ')' ( ( 'COVERING' | 'STORING' | 'INCLUDE' ) '(' name_list ')' | ) ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) ( 'WITH' '(' ( ( storage_parameter ) ( ( ',' storage_parameter ) )* ) ')' ) opt_where_clause + 'CREATE' ( 'UNIQUE' | ) 'INDEX' ( 'CONCURRENTLY' | ) opt_index_name 'ON' table_name opt_index_access_method '(' ( ( ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) ( ( ',' ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) )* ) ')' opt_hash_sharded ( ( 'COVERING' | 'STORING' | 'INCLUDE' ) '(' name_list ')' | ) ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) ( 'WITH' '(' ( ( storage_parameter ) ( ( ',' storage_parameter ) )* ) ')' ) opt_where_clause opt_index_hidden + | 'CREATE' ( 'UNIQUE' | ) 'INDEX' ( 'CONCURRENTLY' | ) 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name opt_index_access_method '(' ( ( ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) ( ( ',' ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) )* ) ')' opt_hash_sharded ( ( 'COVERING' | 'STORING' | 'INCLUDE' ) '(' name_list ')' | ) ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) ( 'WITH' '(' ( ( storage_parameter ) ( ( ',' storage_parameter ) )* ) ')' ) opt_where_clause opt_index_hidden + | 'CREATE' ( 'UNIQUE' | ) 'INVERTED' 'INDEX' ( 'CONCURRENTLY' | ) opt_index_name 'ON' table_name '(' ( ( ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) ( ( ',' ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) )* ) ')' ( ( 'COVERING' | 'STORING' | 'INCLUDE' ) '(' name_list ')' | ) ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) ( 'WITH' '(' ( ( storage_parameter ) ( ( ',' storage_parameter ) )* ) ')' ) opt_where_clause opt_index_hidden + | 'CREATE' ( 'UNIQUE' | ) 'INVERTED' 'INDEX' ( 'CONCURRENTLY' | ) 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' ( ( ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) ( ( ',' ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) )* ) ')' ( ( 'COVERING' | 'STORING' | 'INCLUDE' ) '(' name_list ')' | ) ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) ( 'WITH' '(' ( ( storage_parameter ) ( ( ',' storage_parameter ) )* ) ')' ) opt_where_clause opt_index_hidden diff --git a/docs/generated/sql/bnf/index_def.bnf b/docs/generated/sql/bnf/index_def.bnf index 02bf12633574..c84850a41a7b 100644 --- a/docs/generated/sql/bnf/index_def.bnf +++ b/docs/generated/sql/bnf/index_def.bnf @@ -1,19 +1,19 @@ index_def ::= - 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'COVERING' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause - | 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'STORING' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause - | 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'INCLUDE' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause - | 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause - | 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'COVERING' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause - | 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'STORING' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause - | 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'INCLUDE' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause - | 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause - | 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'COVERING' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause - | 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'STORING' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause - | 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'INCLUDE' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause - | 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause - | 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'COVERING' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause - | 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'STORING' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause - | 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'INCLUDE' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause - | 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause - | 'INVERTED' 'INDEX' name '(' index_elem ( ( ',' index_elem ) )* ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause - | 'INVERTED' 'INDEX' '(' index_elem ( ( ',' index_elem ) )* ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause + 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'COVERING' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'STORING' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'INCLUDE' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'COVERING' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'STORING' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'INCLUDE' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'COVERING' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'STORING' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'INCLUDE' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'COVERING' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'STORING' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'INCLUDE' '(' name_list ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'INVERTED' 'INDEX' name '(' index_elem ( ( ',' index_elem ) )* ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'INVERTED' 'INDEX' '(' index_elem ( ( ',' index_elem ) )* ')' ( 'PARTITION' ( 'ALL' | ) 'BY' partition_by_inner | ) opt_with_storage_parameter_list opt_where_clause opt_index_hidden diff --git a/docs/generated/sql/bnf/stmt_block.bnf b/docs/generated/sql/bnf/stmt_block.bnf index 6841b2ea7e01..226083fda971 100644 --- a/docs/generated/sql/bnf/stmt_block.bnf +++ b/docs/generated/sql/bnf/stmt_block.bnf @@ -1451,6 +1451,7 @@ alter_index_stmt ::= | alter_scatter_index_stmt | alter_rename_index_stmt | alter_zone_index_stmt + | alter_index_visible_stmt alter_view_stmt ::= alter_rename_view_stmt @@ -1573,10 +1574,10 @@ create_database_stmt ::= | 'CREATE' 'DATABASE' 'IF' 'NOT' 'EXISTS' database_name opt_with opt_template_clause opt_encoding_clause opt_lc_collate_clause opt_lc_ctype_clause opt_connection_limit opt_primary_region_clause opt_regions_list opt_survival_goal_clause create_index_stmt ::= - 'CREATE' opt_unique 'INDEX' opt_concurrently opt_index_name 'ON' table_name opt_index_access_method '(' index_params ')' opt_hash_sharded opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause - | 'CREATE' opt_unique 'INDEX' opt_concurrently 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name opt_index_access_method '(' index_params ')' opt_hash_sharded opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause - | 'CREATE' opt_unique 'INVERTED' 'INDEX' opt_concurrently opt_index_name 'ON' table_name '(' index_params ')' opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause - | 'CREATE' opt_unique 'INVERTED' 'INDEX' opt_concurrently 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' index_params ')' opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause + 'CREATE' opt_unique 'INDEX' opt_concurrently opt_index_name 'ON' table_name opt_index_access_method '(' index_params ')' opt_hash_sharded opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'CREATE' opt_unique 'INDEX' opt_concurrently 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name opt_index_access_method '(' index_params ')' opt_hash_sharded opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'CREATE' opt_unique 'INVERTED' 'INDEX' opt_concurrently opt_index_name 'ON' table_name '(' index_params ')' opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'CREATE' opt_unique 'INVERTED' 'INDEX' opt_concurrently 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name '(' index_params ')' opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause opt_index_hidden create_schema_stmt ::= 'CREATE' 'SCHEMA' qualifiable_schema_name @@ -1959,6 +1960,10 @@ alter_rename_index_stmt ::= alter_zone_index_stmt ::= 'ALTER' 'INDEX' table_index_name set_zone_config +alter_index_visible_stmt ::= + 'ALTER' 'INDEX' table_index_name alter_index_visible + | 'ALTER' 'INDEX' 'IF' 'EXISTS' table_index_name alter_index_visible + alter_rename_view_stmt ::= 'ALTER' 'VIEW' relation_expr 'RENAME' 'TO' view_name | 'ALTER' 'MATERIALIZED' 'VIEW' relation_expr 'RENAME' 'TO' view_name @@ -2212,6 +2217,11 @@ opt_partition_by_index ::= opt_with_storage_parameter_list ::= 'WITH' '(' storage_parameter_list ')' +opt_index_hidden ::= + 'NOT' 'VISIBLE' + | 'VISIBLE' + | + opt_schema_name ::= qualifiable_schema_name | @@ -2551,6 +2561,10 @@ locality ::= alter_index_cmds ::= ( alter_index_cmd ) ( ( ',' alter_index_cmd ) )* +alter_index_visible ::= + 'NOT' 'VISIBLE' + | 'VISIBLE' + sequence_option_list ::= ( sequence_option_elem ) ( ( sequence_option_elem ) )* @@ -3407,9 +3421,9 @@ storage_parameter_key ::= | 'SCONST' index_def ::= - 'INDEX' opt_index_name '(' index_params ')' opt_hash_sharded opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause - | 'UNIQUE' 'INDEX' opt_index_name '(' index_params ')' opt_hash_sharded opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause - | 'INVERTED' 'INDEX' opt_name '(' index_params ')' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause + 'INDEX' opt_index_name '(' index_params ')' opt_hash_sharded opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'UNIQUE' 'INDEX' opt_index_name '(' index_params ')' opt_hash_sharded opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause opt_index_hidden + | 'INVERTED' 'INDEX' opt_name '(' index_params ')' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause opt_index_hidden like_table_option_list ::= ( ) ( ( 'INCLUDING' like_table_option | 'EXCLUDING' like_table_option ) )* diff --git a/pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant b/pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant index fc0ac5d08c22..26cda9b81574 100644 --- a/pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant +++ b/pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant @@ -280,10 +280,10 @@ SELECT * FROM crdb_internal.table_columns WHERE descriptor_name = '' ---- descriptor_id descriptor_name column_id column_name column_type nullable default_expr hidden -query ITITTBBBIT colnames +query ITITTBBBBIT colnames SELECT * FROM crdb_internal.table_indexes WHERE descriptor_name = '' ---- -descriptor_id descriptor_name index_id index_name index_type is_unique is_inverted is_sharded shard_bucket_count created_at +descriptor_id descriptor_name index_id index_name index_type is_unique is_inverted is_sharded is_hidden shard_bucket_count created_at query ITITTITTB colnames SELECT * FROM crdb_internal.index_columns WHERE descriptor_name = '' diff --git a/pkg/ccl/schemachangerccl/testdata/decomp/multiregion b/pkg/ccl/schemachangerccl/testdata/decomp/multiregion index 8052cd38b1e8..2826f3642757 100644 --- a/pkg/ccl/schemachangerccl/testdata/decomp/multiregion +++ b/pkg/ccl/schemachangerccl/testdata/decomp/multiregion @@ -121,6 +121,7 @@ ElementState: indexId: 1 isConcurrently: false isCreatedExplicitly: false + isHidden: false isInverted: false isUnique: true sharding: null @@ -373,6 +374,7 @@ ElementState: indexId: 1 isConcurrently: false isCreatedExplicitly: false + isHidden: false isInverted: false isUnique: true sharding: null @@ -637,6 +639,7 @@ ElementState: indexId: 1 isConcurrently: false isCreatedExplicitly: false + isHidden: false isInverted: false isUnique: true sharding: null diff --git a/pkg/ccl/schemachangerccl/testdata/decomp/partitioning b/pkg/ccl/schemachangerccl/testdata/decomp/partitioning index 1a01255106a8..a98ae095f62e 100644 --- a/pkg/ccl/schemachangerccl/testdata/decomp/partitioning +++ b/pkg/ccl/schemachangerccl/testdata/decomp/partitioning @@ -94,6 +94,7 @@ ElementState: indexId: 1 isConcurrently: false isCreatedExplicitly: false + isHidden: false isInverted: false isUnique: true sharding: null @@ -107,6 +108,7 @@ ElementState: indexId: 2 isConcurrently: false isCreatedExplicitly: false + isHidden: false isInverted: true isUnique: false sharding: null @@ -466,6 +468,7 @@ ElementState: indexId: 1 isConcurrently: false isCreatedExplicitly: false + isHidden: false isInverted: false isUnique: true sharding: null @@ -479,6 +482,7 @@ ElementState: indexId: 2 isConcurrently: false isCreatedExplicitly: false + isHidden: false isInverted: false isUnique: true sharding: null diff --git a/pkg/cli/testdata/doctor/test_recreate_zipdir b/pkg/cli/testdata/doctor/test_recreate_zipdir index d7d0a2403ee9..9a3181c944d6 100644 --- a/pkg/cli/testdata/doctor/test_recreate_zipdir +++ b/pkg/cli/testdata/doctor/test_recreate_zipdir @@ -12,16 +12,16 @@ SELECT crdb_internal.unsafe_upsert_descriptor(50, decode('12380a0964656661756c74 SELECT crdb_internal.unsafe_upsert_namespace_entry(0, 0, 'defaultdb', 50, true); SELECT crdb_internal.unsafe_upsert_descriptor(51, decode('12370a08706f73746772657310331a210a0b0a0561646d696e100218000a0a0a04726f6f74100218001204726f6f7418012200280140004a00', 'hex'), true); SELECT crdb_internal.unsafe_upsert_namespace_entry(0, 0, 'postgres', 51, true); -SELECT crdb_internal.unsafe_upsert_descriptor(53, decode('0afa040a0575736572731835203428013a0042280a02696410011a0d080e100018003000508617600020003000680070007800800100880100980100422a0a046369747910021a0d0807100018003007509308600020003000680070007800800100880100980100422a0a046e616d6510031a0d0807100018003007509308600020013000680070007800800100880100980100422d0a076164647265737310041a0d080710001800300750930860002001300068007000780080010088010098010042310a0b6372656469745f6361726410051a0d0807100018003007509308600020013000680070007800800100880100980100480652600a077072696d617279100118012204636974792202696430023001400040004a10080010001a00200028003000380040005a007a0408002000800100880100900101980100a20106080012001800a80100b20100ba0100c00100c80100d0010060026a210a0b0a0561646d696e100218000a0a0a04726f6f74100218001204726f6f741801800101880103980100b2013d0a077072696d61727910001a0269641a04636974791a046e616d651a07616464726573731a0b6372656469745f63617264200120022003200420052800b80101c20100e80100f2010408001200f801008002009202009a0200aa02290836100210041802180120352a11666b5f636974795f7265665f757365727330023800400048007000aa02290837100210041802180120352a11666b5f636974795f7265665f757365727330023800400048007000aa0229083a100110021802180120352a11666b5f636974795f7265665f757365727330023800400048007000b20200b80200c0021dc80200e00200800300880300', 'hex'), true); +SELECT crdb_internal.unsafe_upsert_descriptor(53, decode('0afd040a0575736572731835203428013a0042280a02696410011a0d080e100018003000508617600020003000680070007800800100880100980100422a0a046369747910021a0d0807100018003007509308600020003000680070007800800100880100980100422a0a046e616d6510031a0d0807100018003007509308600020013000680070007800800100880100980100422d0a076164647265737310041a0d080710001800300750930860002001300068007000780080010088010098010042310a0b6372656469745f6361726410051a0d0807100018003007509308600020013000680070007800800100880100980100480652630a077072696d617279100118012204636974792202696430023001400040004a10080010001a00200028003000380040005a007a0408002000800100880100900101980100a20106080012001800a80100b20100ba0100c00100c80100d00100e0010060026a210a0b0a0561646d696e100218000a0a0a04726f6f74100218001204726f6f741801800101880103980100b2013d0a077072696d61727910001a0269641a04636974791a046e616d651a07616464726573731a0b6372656469745f63617264200120022003200420052800b80101c20100e80100f2010408001200f801008002009202009a0200aa02290836100210041802180120352a11666b5f636974795f7265665f757365727330023800400048007000aa02290837100210041802180120352a11666b5f636974795f7265665f757365727330023800400048007000aa0229083a100110021802180120352a11666b5f636974795f7265665f757365727330023800400048007000b20200b80200c0021dc80200e00200800300880300', 'hex'), true); SELECT crdb_internal.unsafe_upsert_namespace_entry(52, 29, 'users', 53, true); -SELECT crdb_internal.unsafe_upsert_descriptor(54, decode('0aa1070a0876656869636c65731836203428013a0042280a02696410011a0d080e100018003000508617600020003000680070007800800100880100980100422a0a046369747910021a0d0807100018003007509308600020003000680070007800800100880100980100422a0a047479706510031a0d0807100018003007509308600020013000680070007800800100880100980100422e0a086f776e65725f696410041a0d080e10001800300050861760002001300068007000780080010088010098010042330a0d6372656174696f6e5f74696d6510051a0d080510001800300050da08600020013000680070007800800100880100980100422c0a0673746174757310061a0d080710001800300750930860002001300068007000780080010088010098010042360a1063757272656e745f6c6f636174696f6e10071a0d080710001800300750930860002001300068007000780080010088010098010042290a0365787410081a0d081210001800300050da1d600020013000680070007800800100880100980100480952600a077072696d617279100118012204636974792202696430023001400040004a10080010001a00200028003000380040005a007a0408002000800100880100900101980100a20106080012001800a80100b20100ba0100c00100c80100d001005a86010a2576656869636c65735f6175746f5f696e6465785f666b5f636974795f7265665f75736572731002180022046369747922086f776e65725f6964300230043801400040004a10080010001a00200028003000380040005a007a0408002000800100880100900101980100a20106080012001800a80100b20100ba0100c00100c80100d0010060036a210a0b0a0561646d696e100218000a0a0a04726f6f74100218001204726f6f741801800102880103980100b201650a077072696d61727910001a0269641a04636974791a04747970651a086f776e65725f69641a0d6372656174696f6e5f74696d651a067374617475731a1063757272656e745f6c6f636174696f6e1a03657874200120022003200420052006200720082800b80101c20100e80100f2010408001200f801008002009202009a0200a202290836100210041802180120352a11666b5f636974795f7265665f757365727330003800400048007000aa02340837100310051802180120362a1c666b5f76656869636c655f636974795f7265665f76656869636c657330023800400048007000b20200b80200c0021dc80200e00200800300880300', 'hex'), true); +SELECT crdb_internal.unsafe_upsert_descriptor(54, decode('0aa7070a0876656869636c65731836203428013a0042280a02696410011a0d080e100018003000508617600020003000680070007800800100880100980100422a0a046369747910021a0d0807100018003007509308600020003000680070007800800100880100980100422a0a047479706510031a0d0807100018003007509308600020013000680070007800800100880100980100422e0a086f776e65725f696410041a0d080e10001800300050861760002001300068007000780080010088010098010042330a0d6372656174696f6e5f74696d6510051a0d080510001800300050da08600020013000680070007800800100880100980100422c0a0673746174757310061a0d080710001800300750930860002001300068007000780080010088010098010042360a1063757272656e745f6c6f636174696f6e10071a0d080710001800300750930860002001300068007000780080010088010098010042290a0365787410081a0d081210001800300050da1d600020013000680070007800800100880100980100480952630a077072696d617279100118012204636974792202696430023001400040004a10080010001a00200028003000380040005a007a0408002000800100880100900101980100a20106080012001800a80100b20100ba0100c00100c80100d00100e001005a89010a2576656869636c65735f6175746f5f696e6465785f666b5f636974795f7265665f75736572731002180022046369747922086f776e65725f6964300230043801400040004a10080010001a00200028003000380040005a007a0408002000800100880100900101980100a20106080012001800a80100b20100ba0100c00100c80100d00100e0010060036a210a0b0a0561646d696e100218000a0a0a04726f6f74100218001204726f6f741801800102880103980100b201650a077072696d61727910001a0269641a04636974791a04747970651a086f776e65725f69641a0d6372656174696f6e5f74696d651a067374617475731a1063757272656e745f6c6f636174696f6e1a03657874200120022003200420052006200720082800b80101c20100e80100f2010408001200f801008002009202009a0200a202290836100210041802180120352a11666b5f636974795f7265665f757365727330003800400048007000aa02340837100310051802180120362a1c666b5f76656869636c655f636974795f7265665f76656869636c657330023800400048007000b20200b80200c0021dc80200e00200800300880300', 'hex'), true); SELECT crdb_internal.unsafe_upsert_namespace_entry(52, 29, 'vehicles', 54, true); -SELECT crdb_internal.unsafe_upsert_descriptor(55, decode('0ab40a0a0572696465731837203428013a0042280a02696410011a0d080e100018003000508617600020003000680070007800800100880100980100422a0a046369747910021a0d080710001800300750930860002000300068007000780080010088010098010042320a0c76656869636c655f6369747910031a0d0807100018003007509308600020013000680070007800800100880100980100422e0a0872696465725f696410041a0d080e10001800300050861760002001300068007000780080010088010098010042300a0a76656869636c655f696410051a0d080e10001800300050861760002001300068007000780080010088010098010042330a0d73746172745f6164647265737310061a0d080710001800300750930860002001300068007000780080010088010098010042310a0b656e645f6164647265737310071a0d080710001800300750930860002001300068007000780080010088010098010042300a0a73746172745f74696d6510081a0d080510001800300050da08600020013000680070007800800100880100980100422e0a08656e645f74696d6510091a0d080510001800300050da08600020013000680070007800800100880100980100422d0a07726576656e7565100a1a0d08031002180a300050a40d600020013000680070007800800100880100980100480b52600a077072696d617279100118012204636974792202696430023001400040004a10080010001a00200028003000380040005a007a0408002000800100880100900101980100a20106080012001800a80100b20100ba0100c00100c80100d001005a83010a2272696465735f6175746f5f696e6465785f666b5f636974795f7265665f757365727310021800220463697479220872696465725f6964300230043801400040004a10080010001a00200028003000380040005a007a0408002000800100880100900101980100a20106080012001800a80100b20100ba0100c00100c80100d001005a9a010a2d72696465735f6175746f5f696e6465785f666b5f76656869636c655f636974795f7265665f76656869636c657310031800220c76656869636c655f63697479220a76656869636c655f69643003300538023801400040004a10080010001a00200028003000380040005a007a0408002000800100880100900101980100a20106080012001800a80100b20100ba0100c00100c80100d0010060046a210a0b0a0561646d696e100218000a0a0a04726f6f74100218001204726f6f741801800103880103980100a2013a0a1376656869636c655f63697479203d20636974791217636865636b5f76656869636c655f636974795f63697479180028022803300038004000b2018a010a077072696d61727910001a0269641a04636974791a0c76656869636c655f636974791a0872696465725f69641a0a76656869636c655f69641a0d73746172745f616464726573731a0b656e645f616464726573731a0a73746172745f74696d651a08656e645f74696d651a07726576656e7565200120022003200420052006200720082009200a2800b80101c20100e80100f2010408001200f801008002009202009a0200a202290837100210041802180120352a11666b5f636974795f7265665f757365727330003800400048007000a202340837100310051802180120362a1c666b5f76656869636c655f636974795f7265665f76656869636c657330003800400048007000aa02290838100110021802180120372a11666b5f636974795f7265665f726964657330023800400048007000b20200b80200c0021dc80200e00200800300880300', 'hex'), true); +SELECT crdb_internal.unsafe_upsert_descriptor(55, decode('0abd0a0a0572696465731837203428013a0042280a02696410011a0d080e100018003000508617600020003000680070007800800100880100980100422a0a046369747910021a0d080710001800300750930860002000300068007000780080010088010098010042320a0c76656869636c655f6369747910031a0d0807100018003007509308600020013000680070007800800100880100980100422e0a0872696465725f696410041a0d080e10001800300050861760002001300068007000780080010088010098010042300a0a76656869636c655f696410051a0d080e10001800300050861760002001300068007000780080010088010098010042330a0d73746172745f6164647265737310061a0d080710001800300750930860002001300068007000780080010088010098010042310a0b656e645f6164647265737310071a0d080710001800300750930860002001300068007000780080010088010098010042300a0a73746172745f74696d6510081a0d080510001800300050da08600020013000680070007800800100880100980100422e0a08656e645f74696d6510091a0d080510001800300050da08600020013000680070007800800100880100980100422d0a07726576656e7565100a1a0d08031002180a300050a40d600020013000680070007800800100880100980100480b52630a077072696d617279100118012204636974792202696430023001400040004a10080010001a00200028003000380040005a007a0408002000800100880100900101980100a20106080012001800a80100b20100ba0100c00100c80100d00100e001005a86010a2272696465735f6175746f5f696e6465785f666b5f636974795f7265665f757365727310021800220463697479220872696465725f6964300230043801400040004a10080010001a00200028003000380040005a007a0408002000800100880100900101980100a20106080012001800a80100b20100ba0100c00100c80100d00100e001005a9d010a2d72696465735f6175746f5f696e6465785f666b5f76656869636c655f636974795f7265665f76656869636c657310031800220c76656869636c655f63697479220a76656869636c655f69643003300538023801400040004a10080010001a00200028003000380040005a007a0408002000800100880100900101980100a20106080012001800a80100b20100ba0100c00100c80100d00100e0010060046a210a0b0a0561646d696e100218000a0a0a04726f6f74100218001204726f6f741801800103880103980100a2013a0a1376656869636c655f63697479203d20636974791217636865636b5f76656869636c655f636974795f63697479180028022803300038004000b2018a010a077072696d61727910001a0269641a04636974791a0c76656869636c655f636974791a0872696465725f69641a0a76656869636c655f69641a0d73746172745f616464726573731a0b656e645f616464726573731a0a73746172745f74696d651a08656e645f74696d651a07726576656e7565200120022003200420052006200720082009200a2800b80101c20100e80100f2010408001200f801008002009202009a0200a202290837100210041802180120352a11666b5f636974795f7265665f757365727330003800400048007000a202340837100310051802180120362a1c666b5f76656869636c655f636974795f7265665f76656869636c657330003800400048007000aa02290838100110021802180120372a11666b5f636974795f7265665f726964657330023800400048007000b20200b80200c0021dc80200e00200800300880300', 'hex'), true); SELECT crdb_internal.unsafe_upsert_namespace_entry(52, 29, 'rides', 55, true); -SELECT crdb_internal.unsafe_upsert_descriptor(56, decode('0ac9040a1a76656869636c655f6c6f636174696f6e5f686973746f726965731838203428013a00422a0a046369747910011a0d0807100018003007509308600020003000680070007800800100880100980100422d0a07726964655f696410021a0d080e100018003000508617600020003000680070007800800100880100980100422f0a0974696d657374616d7010031a0d080510001800300050da0860002000300068007000780080010088010098010042290a036c617410041a0d080210401800300050bd05600020013000680070007800800100880100980100422a0a046c6f6e6710051a0d080210401800300050bd05600020013000680070007800800100880100980100480652740a077072696d617279100118012204636974792207726964655f6964220974696d657374616d703001300230034000400040004a10080010001a00200028003000380040005a007a0408002000800100880100900101980100a20106080012001800a80100b20100ba0100c00100c80100d0010060026a210a0b0a0561646d696e100218000a0a0a04726f6f74100218001204726f6f741801800102880103980100b2013c0a077072696d61727910001a04636974791a07726964655f69641a0974696d657374616d701a036c61741a046c6f6e67200120022003200420052800b80101c20100e80100f2010408001200f801008002009202009a0200a202290838100110021802180120372a11666b5f636974795f7265665f726964657330003800400048007000b20200b80200c0021dc80200e00200800300880300', 'hex'), true); +SELECT crdb_internal.unsafe_upsert_descriptor(56, decode('0acc040a1a76656869636c655f6c6f636174696f6e5f686973746f726965731838203428013a00422a0a046369747910011a0d0807100018003007509308600020003000680070007800800100880100980100422d0a07726964655f696410021a0d080e100018003000508617600020003000680070007800800100880100980100422f0a0974696d657374616d7010031a0d080510001800300050da0860002000300068007000780080010088010098010042290a036c617410041a0d080210401800300050bd05600020013000680070007800800100880100980100422a0a046c6f6e6710051a0d080210401800300050bd05600020013000680070007800800100880100980100480652770a077072696d617279100118012204636974792207726964655f6964220974696d657374616d703001300230034000400040004a10080010001a00200028003000380040005a007a0408002000800100880100900101980100a20106080012001800a80100b20100ba0100c00100c80100d00100e0010060026a210a0b0a0561646d696e100218000a0a0a04726f6f74100218001204726f6f741801800102880103980100b2013c0a077072696d61727910001a04636974791a07726964655f69641a0974696d657374616d701a036c61741a046c6f6e67200120022003200420052800b80101c20100e80100f2010408001200f801008002009202009a0200a202290838100110021802180120372a11666b5f636974795f7265665f726964657330003800400048007000b20200b80200c0021dc80200e00200800300880300', 'hex'), true); SELECT crdb_internal.unsafe_upsert_namespace_entry(52, 29, 'vehicle_location_histories', 56, true); -SELECT crdb_internal.unsafe_upsert_descriptor(57, decode('0a9c040a0b70726f6d6f5f636f6465731839203428013a00422a0a04636f646510011a0d080710001800300750930860002000300068007000780080010088010098010042310a0b6465736372697074696f6e10021a0d080710001800300750930860002001300068007000780080010088010098010042330a0d6372656174696f6e5f74696d6510031a0d080510001800300050da0860002001300068007000780080010088010098010042350a0f65787069726174696f6e5f74696d6510041a0d080510001800300050da08600020013000680070007800800100880100980100422b0a0572756c657310051a0d081210001800300050da1d600020013000680070007800800100880100980100480652580a077072696d617279100118012204636f6465300140004a10080010001a00200028003000380040005a007a0408002000800100880100900101980100a20106080012001800a80100b20100ba0100c00100c80100d0010060026a210a0b0a0561646d696e100218000a0a0a04726f6f74100218001204726f6f741801800101880103980100b201510a077072696d61727910001a04636f64651a0b6465736372697074696f6e1a0d6372656174696f6e5f74696d651a0f65787069726174696f6e5f74696d651a0572756c6573200120022003200420052800b80101c20100e80100f2010408001200f801008002009202009a0200b20200b80200c0021dc80200e00200800300880300', 'hex'), true); +SELECT crdb_internal.unsafe_upsert_descriptor(57, decode('0a9f040a0b70726f6d6f5f636f6465731839203428013a00422a0a04636f646510011a0d080710001800300750930860002000300068007000780080010088010098010042310a0b6465736372697074696f6e10021a0d080710001800300750930860002001300068007000780080010088010098010042330a0d6372656174696f6e5f74696d6510031a0d080510001800300050da0860002001300068007000780080010088010098010042350a0f65787069726174696f6e5f74696d6510041a0d080510001800300050da08600020013000680070007800800100880100980100422b0a0572756c657310051a0d081210001800300050da1d6000200130006800700078008001008801009801004806525b0a077072696d617279100118012204636f6465300140004a10080010001a00200028003000380040005a007a0408002000800100880100900101980100a20106080012001800a80100b20100ba0100c00100c80100d00100e0010060026a210a0b0a0561646d696e100218000a0a0a04726f6f74100218001204726f6f741801800101880103980100b201510a077072696d61727910001a04636f64651a0b6465736372697074696f6e1a0d6372656174696f6e5f74696d651a0f65787069726174696f6e5f74696d651a0572756c6573200120022003200420052800b80101c20100e80100f2010408001200f801008002009202009a0200b20200b80200c0021dc80200e00200800300880300', 'hex'), true); SELECT crdb_internal.unsafe_upsert_namespace_entry(52, 29, 'promo_codes', 57, true); -SELECT crdb_internal.unsafe_upsert_descriptor(58, decode('0ac9040a10757365725f70726f6d6f5f636f646573183a203428013a00422a0a046369747910011a0d0807100018003007509308600020003000680070007800800100880100980100422d0a07757365725f696410021a0d080e100018003000508617600020003000680070007800800100880100980100422a0a04636f646510031a0d0807100018003007509308600020003000680070007800800100880100980100422f0a0974696d657374616d7010041a0d080510001800300050da0860002001300068007000780080010088010098010042300a0b75736167655f636f756e7410051a0c080110401800300050146000200130006800700078008001008801009801004806526f0a077072696d617279100118012204636974792207757365725f69642204636f64653001300230034000400040004a10080010001a00200028003000380040005a007a0408002000800100880100900101980100a20106080012001800a80100b20100ba0100c00100c80100d0010060026a210a0b0a0561646d696e100218000a0a0a04726f6f74100218001204726f6f741801800102880103980100b201440a077072696d61727910001a04636974791a07757365725f69641a04636f64651a0974696d657374616d701a0b75736167655f636f756e74200120022003200420052800b80101c20100e80100f2010408001200f801008002009202009a0200a20229083a100110021802180120352a11666b5f636974795f7265665f757365727330003800400048007000b20200b80200c0021dc80200e00200800300880300', 'hex'), true); +SELECT crdb_internal.unsafe_upsert_descriptor(58, decode('0acc040a10757365725f70726f6d6f5f636f646573183a203428013a00422a0a046369747910011a0d0807100018003007509308600020003000680070007800800100880100980100422d0a07757365725f696410021a0d080e100018003000508617600020003000680070007800800100880100980100422a0a04636f646510031a0d0807100018003007509308600020003000680070007800800100880100980100422f0a0974696d657374616d7010041a0d080510001800300050da0860002001300068007000780080010088010098010042300a0b75736167655f636f756e7410051a0c08011040180030005014600020013000680070007800800100880100980100480652720a077072696d617279100118012204636974792207757365725f69642204636f64653001300230034000400040004a10080010001a00200028003000380040005a007a0408002000800100880100900101980100a20106080012001800a80100b20100ba0100c00100c80100d00100e0010060026a210a0b0a0561646d696e100218000a0a0a04726f6f74100218001204726f6f741801800102880103980100b201440a077072696d61727910001a04636974791a07757365725f69641a04636f64651a0974696d657374616d701a0b75736167655f636f756e74200120022003200420052800b80101c20100e80100f2010408001200f801008002009202009a0200a20229083a100110021802180120352a11666b5f636974795f7265665f757365727330003800400048007000b20200b80200c0021dc80200e00200800300880300', 'hex'), true); SELECT crdb_internal.unsafe_upsert_namespace_entry(52, 29, 'user_promo_codes', 58, true); COMMIT; diff --git a/pkg/sql/BUILD.bazel b/pkg/sql/BUILD.bazel index e4d7c0569347..3cad06eb091d 100644 --- a/pkg/sql/BUILD.bazel +++ b/pkg/sql/BUILD.bazel @@ -11,6 +11,7 @@ go_library( "alter_database.go", "alter_default_privileges.go", "alter_index.go", + "alter_index_visible.go", "alter_primary_key.go", "alter_role.go", "alter_schema.go", diff --git a/pkg/sql/alter_index_visible.go b/pkg/sql/alter_index_visible.go new file mode 100644 index 000000000000..4962b6340ed2 --- /dev/null +++ b/pkg/sql/alter_index_visible.go @@ -0,0 +1,113 @@ +// Copyright 2017 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package sql + +import ( + "context" + + "github.com/cockroachdb/cockroach/pkg/sql/catalog" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc" + "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" + "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" + "github.com/cockroachdb/cockroach/pkg/sql/privilege" + "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" +) + +type alterIndexVisibleNode struct { + n *tree.AlterIndexVisible + tableDesc *tabledesc.Mutable + idx catalog.Index +} + +// ALTER INDEX ... [NOT VISIBLE | VISIBLE] alters the visibility of the index. +// TODO (wenyihu6): check comments here +// Privileges: CREATE on table. +// notes: postgres requires CREATE on the table. +// mysql requires ALTER, CREATE, INSERT on the table. +func (p *planner) AlterIndexVisible(ctx context.Context, n *tree.AlterIndexVisible) (planNode, error) { + if err := checkSchemaChangeEnabled( + ctx, + p.ExecCfg(), + "ALTER INDEX VISBILITY", + ); err != nil { + return nil, err + } + + // Find the underlying table. + _, tableDesc, err := expandMutableIndexName(ctx, p, n.Index, !n.IfExists /* requireTable */) + + if err != nil { + // Error if no table exists and IfExists is not specified. + return nil, err + } + + if tableDesc == nil { + // Nothing needed if no table exists and IfExists is specified. + return newZeroNode(nil /* columns */), nil + } + + // Now we know this table exists, find the index in the table. + idx, err := tableDesc.FindIndexWithName(string(n.Index.Index)) + if err != nil { + if n.IfExists { + // Nothing needed if no index exists and IfExists is specified. + return newZeroNode(nil /* columns */), nil + } + // Error if no index exists and IfExists is not specified. + return nil, pgerror.WithCandidateCode(err, pgcode.UndefinedObject) + } + + // TODO(wenyihu6): check which privilege should be checked here for alter index invisible + if err := p.CheckPrivilege(ctx, tableDesc, privilege.CREATE); err != nil { + return nil, err + } + + if idx.IsHidden() == n.Hidden { + // Nothing needed if the visibility of the index is already what they want. + // TODO (wenyihu6): give hint that it is already not visible or already visible + return newZeroNode(nil /* columns */), nil + } + + return &alterIndexVisibleNode{n: n, tableDesc: tableDesc, idx: idx}, nil +} + +func (n *alterIndexVisibleNode) startExec(params runParams) error { + p := params.p + ctx := params.ctx + tableDesc := n.tableDesc + idx := n.idx + + // TODO(wenyihu6): do we need to check if any view depends on it? the select query saved in view will have different + // output after index is changed to invisible -> add test case for this + + // TODO (wenyihu6): add more check for edge cases here + if n.n.Hidden { + if n.idx.Primary() { + return pgerror.New(pgcode.FeatureNotSupported, "a primary index cannot be invisible.") + } else if n.idx.IsUnique() { + return pgerror.New(pgcode.FeatureNotSupported, "invisible unique index is currently not supported.") + } + } + + idx.IndexDesc().Hidden = n.n.Hidden + + if err := validateDescriptor(ctx, p, tableDesc); err != nil { + return err + } + + return p.writeSchemaChange( + ctx, tableDesc, descpb.InvalidMutationID, tree.AsStringWithFQNames(n.n, params.Ann())) +} + +func (n *alterIndexVisibleNode) Next(runParams) (bool, error) { return false, nil } +func (n *alterIndexVisibleNode) Values() tree.Datums { return tree.Datums{} } +func (n *alterIndexVisibleNode) Close(context.Context) {} diff --git a/pkg/sql/alter_primary_key.go b/pkg/sql/alter_primary_key.go index ef13ed2c2306..f458b727a472 100644 --- a/pkg/sql/alter_primary_key.go +++ b/pkg/sql/alter_primary_key.go @@ -193,6 +193,7 @@ func (p *planner) AlterPrimaryKey( Version: descpb.StrictIndexColumnIDGuaranteesVersion, ConstraintID: tableDesc.GetNextConstraintID(), CreatedAtNanos: p.EvalContext().GetTxnTimestamp(time.Microsecond).UnixNano(), + Hidden: false, } tableDesc.NextConstraintID++ diff --git a/pkg/sql/alter_table.go b/pkg/sql/alter_table.go index 5a443dc1ef3b..fafb59632cb5 100644 --- a/pkg/sql/alter_table.go +++ b/pkg/sql/alter_table.go @@ -280,6 +280,7 @@ func (n *alterTableNode) startExec(params runParams) error { idx := descpb.IndexDescriptor{ Name: string(d.Name), Unique: true, + Hidden: d.Hidden, StoreColumnNames: d.Storing.ToStrings(), CreatedAtNanos: params.EvalContext().GetTxnTimestamp(time.Microsecond).UnixNano(), } diff --git a/pkg/sql/catalog/catformat/index.go b/pkg/sql/catalog/catformat/index.go index acd8929830c8..138e23a1cea5 100644 --- a/pkg/sql/catalog/catformat/index.go +++ b/pkg/sql/catalog/catformat/index.go @@ -174,6 +174,10 @@ func indexForDisplay( } } + if index.Hidden { + f.WriteString(" NOT VISIBLE") + } + return f.CloseAndGetString(), nil } diff --git a/pkg/sql/catalog/descpb/index.go b/pkg/sql/catalog/descpb/index.go index 63ed04b26f86..a48217f3efa1 100644 --- a/pkg/sql/catalog/descpb/index.go +++ b/pkg/sql/catalog/descpb/index.go @@ -29,6 +29,11 @@ func (desc *IndexDescriptor) IsPartial() bool { return desc.Predicate != "" } +// IsHidden returns whether the index is hidden from the optimizer or not. +func (desc *IndexDescriptor) IsHidden() bool { + return desc.Hidden +} + // ExplicitColumnStartIdx returns the start index of any explicit columns. func (desc *IndexDescriptor) ExplicitColumnStartIdx() int { start := int(desc.Partitioning.NumImplicitColumns) diff --git a/pkg/sql/catalog/descpb/structured.proto b/pkg/sql/catalog/descpb/structured.proto index d7165f47d0bf..0b5cff7dacc7 100644 --- a/pkg/sql/catalog/descpb/structured.proto +++ b/pkg/sql/catalog/descpb/structured.proto @@ -302,6 +302,7 @@ message InterleaveDescriptor { // key_column_names: k1, k2 // key_column_directions: ASC, ASC // key_column_ids: 1, 2 // k1, k2 +// hidden: false // // [old STORING encoding] Index k1v (k1, v) STORING (w): // name: k1v @@ -312,6 +313,7 @@ message InterleaveDescriptor { // store_column_names: w // key_column_ids: 1, 4 // k1, v // key_suffix_column_ids: 2, 5 // k2, w +// hidden: false // // [new STORING encoding] Index k1v (k1, v) STORING (w): // name: k1v @@ -323,6 +325,7 @@ message InterleaveDescriptor { // key_column_ids: 1, 4 // k1, v // key_suffix_column_ids: 2 // k2 // store_column_ids: 5 // w +// hidden: false message IndexDescriptor { option (gogoproto.equal) = true; @@ -491,7 +494,12 @@ message IndexDescriptor { optional uint32 constraint_id = 26 [(gogoproto.customname) = "ConstraintID", (gogoproto.casttype) = "ConstraintID", (gogoproto.nullable) = false]; - // Next ID: 28 + // Hidden specifies whether the index is invisible. An invisible index is + // ignored by the optimizer unless it is explicitly selected with index + // hinting (force index). + optional bool hidden = 28 [(gogoproto.nullable) = false]; + + // Next ID: 29 } // ConstraintToUpdate represents a constraint to be added to the table and diff --git a/pkg/sql/catalog/systemschema/system.go b/pkg/sql/catalog/systemschema/system.go index 850bff19392c..a3c3810c2ce7 100644 --- a/pkg/sql/catalog/systemschema/system.go +++ b/pkg/sql/catalog/systemschema/system.go @@ -674,6 +674,7 @@ func pk(name string) descpb.IndexDescriptor { KeyColumnNames: []string{name}, KeyColumnDirections: singleASC, KeyColumnIDs: singleID1, + Hidden: false, } } diff --git a/pkg/sql/catalog/table_elements.go b/pkg/sql/catalog/table_elements.go index 2856549c6662..ee8b71f25b02 100644 --- a/pkg/sql/catalog/table_elements.go +++ b/pkg/sql/catalog/table_elements.go @@ -139,6 +139,7 @@ type Index interface { IsUnique() bool IsDisabled() bool IsSharded() bool + IsHidden() bool IsCreatedExplicitly() bool GetPredicate() string GetType() descpb.IndexDescriptor_Type diff --git a/pkg/sql/catalog/tabledesc/index.go b/pkg/sql/catalog/tabledesc/index.go index d81703468d4b..63db3bbe1f0a 100644 --- a/pkg/sql/catalog/tabledesc/index.go +++ b/pkg/sql/catalog/tabledesc/index.go @@ -102,6 +102,11 @@ func (w index) IsSharded() bool { return w.desc.IsSharded() } +// IsHidden returns true iff the index is invisible. +func (w index) IsHidden() bool { + return w.desc.Hidden +} + // IsCreatedExplicitly returns true iff this index was created explicitly, i.e. // via 'CREATE INDEX' statement. func (w index) IsCreatedExplicitly() bool { diff --git a/pkg/sql/catalog/tabledesc/structured.go b/pkg/sql/catalog/tabledesc/structured.go index 0189ba93bfef..a2b3a60b3da6 100644 --- a/pkg/sql/catalog/tabledesc/structured.go +++ b/pkg/sql/catalog/tabledesc/structured.go @@ -669,6 +669,7 @@ func (desc *Mutable) ensurePrimaryKey() error { Unique: true, KeyColumnNames: []string{col.Name}, KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, + Hidden: false, } if err := desc.AddPrimaryIndex(idx); err != nil { return err diff --git a/pkg/sql/catalog/tabledesc/table.go b/pkg/sql/catalog/tabledesc/table.go index bfa1cc659aa3..89262cf31f47 100644 --- a/pkg/sql/catalog/tabledesc/table.go +++ b/pkg/sql/catalog/tabledesc/table.go @@ -202,12 +202,14 @@ func MakeColumnDefDescs( col.ComputeExpr = &s } + // TODO (wenyihu6): check to make sure unique constraint index can be invisible but primary constraint index cannot if d.PrimaryKey.IsPrimaryKey || (d.Unique.IsUnique && !d.Unique.WithoutIndex) { if !d.PrimaryKey.Sharded { ret.PrimaryKeyOrUniqueIndexDescriptor = &descpb.IndexDescriptor{ Unique: true, KeyColumnNames: []string{string(d.Name)}, KeyColumnDirections: []catpb.IndexColumn_Direction{catpb.IndexColumn_ASC}, + Hidden: false, } } else { buckets, err := EvalShardBucketCount(ctx, semaCtx, evalCtx, d.PrimaryKey.ShardBuckets, d.PrimaryKey.StorageParams) @@ -225,6 +227,7 @@ func MakeColumnDefDescs( ShardBuckets: buckets, ColumnNames: []string{string(d.Name)}, }, + Hidden: false, } } if d.Unique.ConstraintName != "" { diff --git a/pkg/sql/catalog/tabledesc/validate.go b/pkg/sql/catalog/tabledesc/validate.go index 8e76250c3335..dbe7c14b29f6 100644 --- a/pkg/sql/catalog/tabledesc/validate.go +++ b/pkg/sql/catalog/tabledesc/validate.go @@ -1292,6 +1292,18 @@ func (desc *wrapper) validateTableIndexes( idx.GetName(), idx.IndexDesc().EncodingType, descpb.PrimaryIndexEncoding) } } + if idx.IsHidden() { + // If an index is invisible, it cannot be a primary index or a unique + // index. + if idx.Primary() { + return errors.Newf("a primary index %q cannot be hidden.", + idx.GetName()) + } + if idx.IsUnique() { + return errors.Newf("a unique index %q cannot be hidden.", + idx.GetName()) + } + } // Ensure that index column ID subsets are well formed. if idx.GetVersion() < descpb.StrictIndexColumnIDGuaranteesVersion { continue diff --git a/pkg/sql/catalog/tabledesc/validate_test.go b/pkg/sql/catalog/tabledesc/validate_test.go index 3e64ca360076..9e984459a8ae 100644 --- a/pkg/sql/catalog/tabledesc/validate_test.go +++ b/pkg/sql/catalog/tabledesc/validate_test.go @@ -140,6 +140,7 @@ var validationMap = []struct { "ID": {status: thisFieldReferencesNoObjects}, "Unique": {status: thisFieldReferencesNoObjects}, "Version": {status: thisFieldReferencesNoObjects}, + "Hidden": {status: thisFieldReferencesNoObjects}, "KeyColumnNames": {status: iSolemnlySwearThisFieldIsValidated}, "KeyColumnDirections": {status: iSolemnlySwearThisFieldIsValidated}, "StoreColumnNames": { @@ -652,6 +653,73 @@ func TestValidateTableDesc(t *testing.T) { NextColumnID: 2, NextFamilyID: 1, }}, + {`a primary index "primary" cannot be hidden.`, + descpb.TableDescriptor{ + ID: 2, + ParentID: 1, + Name: "foo", + FormatVersion: descpb.InterleavedFormatVersion, + Columns: []descpb.ColumnDescriptor{ + {ID: 1, Name: "bar", Type: types.Int}, + }, + PrimaryIndex: descpb.IndexDescriptor{ + ID: 1, + Name: "primary", + KeyColumnIDs: []descpb.ColumnID{1}, + KeyColumnNames: []string{"bar"}, + KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + Version: descpb.PrimaryIndexWithStoredColumnsVersion, + EncodingType: descpb.PrimaryIndexEncoding, + ConstraintID: 1, + Hidden: true, + }, + Families: []descpb.ColumnFamilyDescriptor{ + {ID: 0, Name: "primary", + ColumnIDs: []descpb.ColumnID{1}, + ColumnNames: []string{"bar"}, + }, + }, + NextColumnID: 2, + NextFamilyID: 1, + NextIndexID: 2, + }}, + {`a unique index "idx" cannot be hidden.`, + descpb.TableDescriptor{ + ID: 2, + ParentID: 1, + Name: "foo", + FormatVersion: descpb.InterleavedFormatVersion, + Columns: []descpb.ColumnDescriptor{ + {ID: 1, Name: "bar", Type: types.Int}, + }, + PrimaryIndex: descpb.IndexDescriptor{ + ID: 1, + Name: "primary", + KeyColumnIDs: []descpb.ColumnID{1}, + KeyColumnNames: []string{"bar"}, + KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + Version: descpb.PrimaryIndexWithStoredColumnsVersion, + EncodingType: descpb.PrimaryIndexEncoding, + ConstraintID: 1, + Hidden: false, + }, + Families: []descpb.ColumnFamilyDescriptor{ + {ID: 0, Name: "primary", + ColumnIDs: []descpb.ColumnID{1}, + ColumnNames: []string{"bar"}, + }, + }, + Indexes: []descpb.IndexDescriptor{ + {ID: 2, Name: "idx", Unique: true, Hidden: true, + KeyColumnIDs: []descpb.ColumnID{1}, + KeyColumnNames: []string{"bar"}, + KeyColumnDirections: []descpb.IndexDescriptor_Direction{descpb.IndexDescriptor_ASC}, + }, + }, + NextColumnID: 2, + NextFamilyID: 1, + NextIndexID: 3, + }}, {`invalid index ID 0`, descpb.TableDescriptor{ ID: 2, diff --git a/pkg/sql/crdb_internal.go b/pkg/sql/crdb_internal.go index 91d44d1b7949..7dc9392ce124 100644 --- a/pkg/sql/crdb_internal.go +++ b/pkg/sql/crdb_internal.go @@ -2780,6 +2780,7 @@ CREATE TABLE crdb_internal.table_indexes ( is_unique BOOL NOT NULL, is_inverted BOOL NOT NULL, is_sharded BOOL NOT NULL, + is_hidden BOOL NOT NULL, shard_bucket_count INT, created_at TIMESTAMP ) @@ -2825,6 +2826,7 @@ CREATE TABLE crdb_internal.table_indexes ( tree.MakeDBool(tree.DBool(idx.IsUnique())), tree.MakeDBool(idx.GetType() == descpb.IndexDescriptor_INVERTED), tree.MakeDBool(tree.DBool(idx.IsSharded())), + tree.MakeDBool(tree.DBool(idx.IsHidden())), shardBucketCnt, createdAt, ) diff --git a/pkg/sql/create_index.go b/pkg/sql/create_index.go index fd3013a45ead..e8c626026823 100644 --- a/pkg/sql/create_index.go +++ b/pkg/sql/create_index.go @@ -203,6 +203,7 @@ func makeIndexDescriptor( StoreColumnNames: n.Storing.ToStrings(), CreatedExplicitly: true, CreatedAtNanos: params.EvalContext().GetTxnTimestamp(time.Microsecond).UnixNano(), + Hidden: n.Hidden, } columnsToCheckForOpclass := columns @@ -735,6 +736,11 @@ func (n *createIndexNode) startExec(params runParams) error { ) } + // TODO(wenyihu6): check to see if this pgcode error is correct. + if n.n.Unique && n.n.Hidden { + return pgerror.Newf(pgcode.FeatureNotSupported, "invisible unique index is currently not supported.") + } + // Warn against creating a non-partitioned index on a partitioned table, // which is undesirable in most cases. // Avoid the warning if we have PARTITION ALL BY as all indexes will implicitly diff --git a/pkg/sql/create_sequence.go b/pkg/sql/create_sequence.go index 8db6f5f27cd6..41e35485be5f 100644 --- a/pkg/sql/create_sequence.go +++ b/pkg/sql/create_sequence.go @@ -297,6 +297,7 @@ func NewSequenceTableDesc( EncodingType: descpb.PrimaryIndexEncoding, Version: descpb.PrimaryIndexWithStoredColumnsVersion, CreatedAtNanos: creationTime.WallTime, + Hidden: false, }) desc.Families = []descpb.ColumnFamilyDescriptor{ { diff --git a/pkg/sql/create_table.go b/pkg/sql/create_table.go index 77b84683d86e..75bc2de04b1a 100644 --- a/pkg/sql/create_table.go +++ b/pkg/sql/create_table.go @@ -708,6 +708,11 @@ func addUniqueWithoutIndexTableDef( "partitioned unique constraints without an index are not supported", ) } + if d.Hidden { + return pgerror.New(pgcode.FeatureNotSupported, + "invisible unique constraint is currently not supported", + ) + } // If there is a predicate, validate it. var predicate string @@ -1801,6 +1806,7 @@ func NewTableDesc( if d.Inverted { idx.Type = descpb.IndexDescriptor_INVERTED } + idx.Hidden = d.Hidden columns := d.Columns if d.Sharded != nil { var err error @@ -1906,6 +1912,7 @@ func NewTableDesc( Unique: true, StoreColumnNames: d.Storing.ToStrings(), Version: indexEncodingVersion, + Hidden: false, } columns := d.Columns if d.Sharded != nil { @@ -2632,6 +2639,7 @@ func replaceLikeTableOpts(n *tree.CreateTable, params runParams) (tree.TableDefs indexDef := tree.IndexTableDef{ Name: tree.Name(idx.GetName()), Inverted: idx.GetType() == descpb.IndexDescriptor_INVERTED, + Hidden: idx.IsHidden(), Storing: make(tree.NameList, 0, idx.NumSecondaryStoredColumns()), Columns: make(tree.IndexElemList, 0, idx.NumKeyColumns()), } diff --git a/pkg/sql/delegate/show_database_indexes.go b/pkg/sql/delegate/show_database_indexes.go index cefae31a2625..2da7727ad866 100644 --- a/pkg/sql/delegate/show_database_indexes.go +++ b/pkg/sql/delegate/show_database_indexes.go @@ -16,19 +16,28 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" ) +// delegateShowDatabaseIndexes implements SHOW INDEX FROM DATABASE, SHOW INDEXES +// FROM DATABASE, SHOW KEYS FROM DATABASE which returns all the indexes in the +// given or current database. func (d *delegator) delegateShowDatabaseIndexes( n *tree.ShowDatabaseIndexes, ) (tree.Statement, error) { + name, err := d.getSpecifiedOrCurrentDatabase(n.Database) + if err != nil { + return nil, err + } + getAllIndexesQuery := ` SELECT table_name, - index_name, + info.index_name, non_unique::BOOL, seq_in_index, column_name, direction, storing::BOOL, - implicit::BOOL` + implicit::BOOL, + idx.is_hidden::BOOL` if n.WithComment { getAllIndexesQuery += `, @@ -36,8 +45,8 @@ SELECT } getAllIndexesQuery += ` -FROM - %s.information_schema.statistics` + FROM + %[1]s.information_schema.statistics AS info` if n.WithComment { getAllIndexesQuery += ` @@ -45,5 +54,10 @@ FROM statistics.index_name = pg_class.relname` } - return parse(fmt.Sprintf(getAllIndexesQuery, n.Database.String())) + getAllIndexesQuery += ` + LEFT JOIN %[1]s.crdb_internal.table_indexes AS idx ON + idx.index_name = info.index_name AND + idx.descriptor_name = info.table_name` + + return parse(fmt.Sprintf(getAllIndexesQuery, name.String())) } diff --git a/pkg/sql/delegate/show_table.go b/pkg/sql/delegate/show_table.go index 01e989ba58a8..a4a1515a7ec1 100644 --- a/pkg/sql/delegate/show_table.go +++ b/pkg/sql/delegate/show_table.go @@ -100,6 +100,8 @@ ORDER BY return d.showTableDetails(n.Name, showCreateQuery) } +// delegateShowIndexes implements SHOW INDEX FROM, SHOW INDEXES FROM, SHOW KEYS +// FROM which returns all the indexes in the given table. func (d *delegator) delegateShowIndexes(n *tree.ShowIndexes) (tree.Statement, error) { sqltelemetry.IncrementShowCounter(sqltelemetry.Indexes) getIndexesQuery := ` @@ -111,7 +113,8 @@ SELECT column_name, direction, storing::BOOL, - implicit::BOOL` + implicit::BOOL, + idx.is_hidden::BOOL` if n.WithComment { getIndexesQuery += `, @@ -129,13 +132,18 @@ FROM pg_indexes.indexname = s.index_name` } + getIndexesQuery += ` + LEFT JOIN %[4]s.crdb_internal.table_indexes AS idx ON + idx.index_name = s.index_name AND + idx.descriptor_name = s.table_name` + getIndexesQuery += ` WHERE table_catalog=%[1]s AND table_schema=%[5]s AND table_name=%[2]s ORDER BY - 1, 2, 3, 4, 5, 6, 7, 8;` + 1, 2, 3, 4, 5, 6, 7, 8, 9;` return d.showTableDetails(n.Table, getIndexesQuery) } diff --git a/pkg/sql/descriptor_mutation_test.go b/pkg/sql/descriptor_mutation_test.go index f888369ef079..724859814017 100644 --- a/pkg/sql/descriptor_mutation_test.go +++ b/pkg/sql/descriptor_mutation_test.go @@ -1051,11 +1051,11 @@ CREATE TABLE t.test (a STRING PRIMARY KEY, b STRING, c STRING, INDEX foo (c)); mt.CheckQueryResults(t, "SHOW INDEXES FROM t.test", [][]string{ - {"test", "test_pkey", "false", "1", "a", "ASC", "false", "false"}, - {"test", "test_pkey", "false", "2", "b", "N/A", "true", "false"}, - {"test", "test_pkey", "false", "3", "d", "N/A", "true", "false"}, - {"test", "ufo", "true", "1", "d", "ASC", "false", "false"}, - {"test", "ufo", "true", "2", "a", "ASC", "false", "true"}, + {"test", "test_pkey", "false", "1", "a", "ASC", "false", "false", "false"}, + {"test", "test_pkey", "false", "2", "b", "N/A", "true", "false", "false"}, + {"test", "test_pkey", "false", "3", "d", "N/A", "true", "false", "false"}, + {"test", "ufo", "true", "1", "d", "ASC", "false", "false", "false"}, + {"test", "ufo", "true", "2", "a", "ASC", "false", "true", "false"}, }, ) diff --git a/pkg/sql/importer/read_import_pgdump.go b/pkg/sql/importer/read_import_pgdump.go index bcb7dedd4af7..871ded23c55b 100644 --- a/pkg/sql/importer/read_import_pgdump.go +++ b/pkg/sql/importer/read_import_pgdump.go @@ -650,6 +650,7 @@ func readPostgresStmt( Columns: stmt.Columns, Storing: stmt.Storing, Inverted: stmt.Inverted, + Hidden: stmt.Hidden, PartitionByIndex: stmt.PartitionByIndex, StorageParams: stmt.StorageParams, } diff --git a/pkg/sql/logictest/testdata/logic_test/alter_index_visible b/pkg/sql/logictest/testdata/logic_test/alter_index_visible new file mode 100644 index 000000000000..d0037161b767 --- /dev/null +++ b/pkg/sql/logictest/testdata/logic_test/alter_index_visible @@ -0,0 +1,27 @@ +statement ok +CREATE TABLE t (a INT, b INT, c INT, INDEX idx(b)); + +statement ok +ALTER INDEX t@idx NOT VISIBLE + + +query TTBITTBBB colnames +SHOW INDEXES FROM t +---- +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +t idx true 1 b ASC false false true +t idx true 2 rowid ASC false true true +t t_pkey false 1 rowid ASC false false false +t t_pkey false 2 a N/A true false false +t t_pkey false 3 b N/A true false false +t t_pkey false 4 c N/A true false false + + +statement error pgcode 0A000 a primary index cannot be invisible. +ALTER INDEX t@t_pkey NOT VISIBLE + +statement ok +CREATE UNIQUE INDEX unique_idx ON t (b) USING HASH WITH BUCKET_COUNT = 5; + +statement error pgcode 0A000 invisible unique index is currently not supported. +ALTER INDEX t@unique_idx NOT VISIBLE diff --git a/pkg/sql/logictest/testdata/logic_test/alter_primary_key b/pkg/sql/logictest/testdata/logic_test/alter_primary_key index ffc5aa3cdfe5..fc39d262dc87 100644 --- a/pkg/sql/logictest/testdata/logic_test/alter_primary_key +++ b/pkg/sql/logictest/testdata/logic_test/alter_primary_key @@ -1142,7 +1142,8 @@ statement ok create table t1(id integer not null, id2 integer not null, name varchar(32)); query TTT -select index_name,column_name,direction from [show indexes from t1] where index_name like 'primary%'; +select index_name,column_name,direction from [show indexes from t1] where index_name like 'primary%' +ORDER BY index_name, seq_in_index ---- statement ok @@ -1150,7 +1151,8 @@ alter table t1 alter primary key using columns(id, id2); query TTT -select index_name,column_name,direction from [show indexes from t1]; +select index_name,column_name,direction from [show indexes from t1] +ORDER BY index_name, seq_in_index ---- t1_pkey id ASC t1_pkey id2 ASC @@ -1163,7 +1165,8 @@ alter table t1 alter primary key using columns(id, id2); query TTT -select index_name,column_name,direction from [show indexes from t1]; +select index_name,column_name,direction from [show indexes from t1] +ORDER BY index_name, seq_in_index ---- t1_pkey id ASC t1_pkey id2 ASC @@ -1175,7 +1178,8 @@ statement ok alter table t1 drop constraint t1_pkey, alter primary key using columns(id, id2); query TTT -select index_name,column_name,direction from [show indexes from t1]; +select index_name,column_name,direction from [show indexes from t1] +ORDER BY index_name, seq_in_index ---- t1_pkey id ASC t1_pkey id2 ASC @@ -1187,77 +1191,82 @@ alter table t1 alter primary key using columns(id); query TTT -select index_name,column_name,direction from [show indexes from t1]; +select index_name,column_name,direction from [show indexes from t1] +ORDER BY index_name, seq_in_index ---- +t1_id_id2_key id ASC +t1_id_id2_key id2 ASC t1_pkey id ASC t1_pkey id2 N/A t1_pkey name N/A t1_pkey rowid N/A -t1_id_id2_key id ASC -t1_id_id2_key id2 ASC statement ok alter table t1 alter primary key using columns(id desc); query TTT -select index_name,column_name,direction from [show indexes from t1]; +select index_name,column_name,direction from [show indexes from t1] +ORDER BY index_name, seq_in_index ---- +t1_id_id2_key id ASC +t1_id_id2_key id2 ASC +t1_id_key id ASC t1_pkey id DESC t1_pkey id2 N/A t1_pkey name N/A t1_pkey rowid N/A -t1_id_id2_key id ASC -t1_id_id2_key id2 ASC -t1_id_key id ASC statement ok alter table t1 alter primary key using columns(id desc); query TTT -select index_name,column_name,direction from [show indexes from t1]; +select index_name,column_name,direction from [show indexes from t1] +ORDER BY index_name, seq_in_index ---- +t1_id_id2_key id ASC +t1_id_id2_key id2 ASC +t1_id_key id ASC t1_pkey id DESC t1_pkey id2 N/A t1_pkey name N/A t1_pkey rowid N/A -t1_id_id2_key id ASC -t1_id_id2_key id2 ASC -t1_id_key id ASC statement ok alter table t1 alter primary key using columns(id desc); query TTT -select index_name,column_name,direction from [show indexes from t1]; +select index_name,column_name,direction from [show indexes from t1] +ORDER BY index_name, seq_in_index ---- +t1_id_id2_key id ASC +t1_id_id2_key id2 ASC +t1_id_key id ASC t1_pkey id DESC t1_pkey id2 N/A t1_pkey name N/A t1_pkey rowid N/A -t1_id_id2_key id ASC -t1_id_id2_key id2 ASC -t1_id_key id ASC statement ok alter table t1 alter primary key using columns(id) USING HASH WITH (bucket_count=10) query TTT -select index_name,column_name,direction from [show indexes from t1]; +select index_name,column_name,direction from [show indexes from t1] +ORDER BY index_name, seq_in_index ---- -t1_pkey crdb_internal_id_shard_10 ASC -t1_pkey id ASC -t1_pkey id2 N/A -t1_pkey name N/A -t1_pkey rowid N/A -t1_id_key1 id DESC -t1_id_key1 crdb_internal_id_shard_10 ASC t1_id_id2_key id ASC t1_id_id2_key id2 ASC t1_id_id2_key crdb_internal_id_shard_10 ASC t1_id_key id ASC t1_id_key crdb_internal_id_shard_10 ASC +t1_id_key1 id DESC +t1_id_key1 crdb_internal_id_shard_10 ASC +t1_pkey crdb_internal_id_shard_10 ASC +t1_pkey id ASC +t1_pkey id2 N/A +t1_pkey name N/A +t1_pkey rowid N/A statement ok CREATE TABLE table_with_virtual_cols ( @@ -1292,6 +1301,7 @@ CREATE TABLE t (i INT PRIMARY KEY) query TTT SELECT index_name,column_name,direction FROM [SHOW INDEXES FROM t] +ORDER BY index_name, seq_in_index ---- t_pkey i ASC @@ -1300,6 +1310,7 @@ ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (i) USING HASH WITH (bucket_count= query TTT SELECT index_name,column_name,direction FROM [SHOW INDEXES FROM t] +ORDER BY index_name, seq_in_index ---- t_pkey crdb_internal_i_shard_2 ASC t_pkey i ASC @@ -1309,6 +1320,7 @@ ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (i); query TTT SELECT index_name,column_name,direction FROM [SHOW INDEXES FROM t] +ORDER BY index_name, seq_in_index ---- t_pkey i ASC @@ -1606,11 +1618,12 @@ ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (b); query TTT SELECT index_name, column_name, direction FROM [SHOW INDEXES FROM t] +ORDER BY index_name, seq_in_index ---- -t_pkey b ASC -t_pkey a N/A t_a_key a ASC t_a_key b ASC +t_pkey b ASC +t_pkey a N/A # But if the existing index is not strictly equal to the (old) primary key # (even if, for example, the (old) primary key is a strict prefix of an @@ -1630,10 +1643,11 @@ ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (b); # on only (a) but the other on (a, b). query TTTB SELECT index_name, column_name, direction, storing FROM [SHOW INDEXES FROM t] +ORDER BY index_name, seq_in_index ---- -t_pkey b ASC false -t_pkey a N/A true t_a_b_key a ASC false t_a_b_key b ASC false t_a_key a ASC false t_a_key b ASC true +t_pkey b ASC false +t_pkey a N/A true diff --git a/pkg/sql/logictest/testdata/logic_test/alter_table b/pkg/sql/logictest/testdata/logic_test/alter_table index c3b14e73927e..4ac71c6a4b1a 100644 --- a/pkg/sql/logictest/testdata/logic_test/alter_table +++ b/pkg/sql/logictest/testdata/logic_test/alter_table @@ -49,17 +49,17 @@ ALTER TABLE t ADD CONSTRAINT foo UNIQUE (b) statement error pq: multiple primary keys for table "t" are not allowed ALTER TABLE t ADD CONSTRAINT bar PRIMARY KEY (b) -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM t ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -t foo false 1 b ASC false false -t foo false 2 a ASC true true -t t_f_idx true 1 f ASC false false -t t_f_idx true 2 a ASC false true -t t_pkey false 1 a ASC false false -t t_pkey false 2 f N/A true false -t t_pkey false 3 b N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +t foo false 1 b ASC false false false +t foo false 2 a ASC true true false +t t_f_idx true 1 f ASC false false false +t t_f_idx true 2 a ASC false true false +t t_pkey false 1 a ASC false false false +t t_pkey false 2 f N/A true false false +t t_pkey false 3 b N/A true false false query III SELECT * FROM t @@ -226,16 +226,16 @@ LIMIT 2 SCHEMA CHANGE GC GC for DROP INDEX test.public.t@foo CASCADE root running waiting for GC TTL 0 · SCHEMA CHANGE DROP INDEX test.public.t@foo CASCADE root succeeded NULL 1 · -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM t ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -t t_f_idx true 1 f ASC false false -t t_f_idx true 2 a ASC false true -t t_pkey false 1 a ASC false false -t t_pkey false 2 f N/A true false -t t_pkey false 3 b N/A true false -t t_pkey false 4 c N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +t t_f_idx true 1 f ASC false false false +t t_f_idx true 2 a ASC false true false +t t_pkey false 1 a ASC false false false +t t_pkey false 2 f N/A true false false +t t_pkey false 3 b N/A true false false +t t_pkey false 4 c N/A true false false statement ok ALTER TABLE t DROP b, DROP c @@ -382,15 +382,15 @@ ALTER TABLE t DROP COLUMN g CASCADE statement ok ALTER TABLE o DROP COLUMN h -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM o ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -o o_pkey false 1 rowid ASC false false -o o_pkey false 2 gf N/A true false -o o_pkey false 3 i N/A true false -o oi true 1 i ASC false false -o oi true 2 rowid ASC false true +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +o o_pkey false 1 rowid ASC false false false +o o_pkey false 2 gf N/A true false false +o o_pkey false 3 i N/A true false false +o oi true 1 i ASC false false false +o oi true 2 rowid ASC false true false statement ok ALTER TABLE t ADD f INT CHECK (f > 1) diff --git a/pkg/sql/logictest/testdata/logic_test/crdb_internal b/pkg/sql/logictest/testdata/logic_test/crdb_internal index 0e8d86da3d5c..839c7c9fdb33 100644 --- a/pkg/sql/logictest/testdata/logic_test/crdb_internal +++ b/pkg/sql/logictest/testdata/logic_test/crdb_internal @@ -400,10 +400,10 @@ SELECT * FROM crdb_internal.table_columns WHERE descriptor_name = '' ---- descriptor_id descriptor_name column_id column_name column_type nullable default_expr hidden -query ITITTBBBIT colnames +query ITITTBBBBIT colnames SELECT * FROM crdb_internal.table_indexes WHERE descriptor_name = '' ---- -descriptor_id descriptor_name index_id index_name index_type is_unique is_inverted is_sharded shard_bucket_count created_at +descriptor_id descriptor_name index_id index_name index_type is_unique is_inverted is_sharded is_hidden shard_bucket_count created_at query ITITTITTB colnames SELECT * FROM crdb_internal.index_columns WHERE descriptor_name = '' diff --git a/pkg/sql/logictest/testdata/logic_test/create_index b/pkg/sql/logictest/testdata/logic_test/create_index index d034f743438b..5ae90b006c64 100644 --- a/pkg/sql/logictest/testdata/logic_test/create_index +++ b/pkg/sql/logictest/testdata/logic_test/create_index @@ -23,14 +23,14 @@ CREATE INDEX bar ON t (c) statement error index \"bar\" contains duplicate column \"b\" CREATE INDEX bar ON t (b, b); -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM t ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -t foo true 1 b ASC false false -t foo true 2 a ASC false true -t t_pkey false 1 a ASC false false -t t_pkey false 2 b N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +t foo true 1 b ASC false false false +t foo true 2 a ASC false true false +t t_pkey false 1 a ASC false false false +t t_pkey false 2 b N/A true false false statement ok INSERT INTO t VALUES (2,1) @@ -38,14 +38,14 @@ INSERT INTO t VALUES (2,1) statement error pgcode 23505 violates unique constraint "bar" CREATE UNIQUE INDEX bar ON t (b) -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM t ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -t foo true 1 b ASC false false -t foo true 2 a ASC false true -t t_pkey false 1 a ASC false false -t t_pkey false 2 b N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +t foo true 1 b ASC false false false +t foo true 2 a ASC false true false +t t_pkey false 1 a ASC false false false +t t_pkey false 2 b N/A true false false # test for DESC index @@ -68,18 +68,18 @@ CREATE INDEX b_desc ON t (b DESC) statement ok CREATE INDEX b_asc ON t (b ASC, c DESC) -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM t ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -t b_asc true 1 b ASC false false -t b_asc true 2 c DESC false false -t b_asc true 3 a ASC false true -t b_desc true 1 b DESC false false -t b_desc true 2 a ASC false true -t t_pkey false 1 a ASC false false -t t_pkey false 2 b N/A true false -t t_pkey false 3 c N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +t b_asc true 1 b ASC false false false +t b_asc true 2 c DESC false false false +t b_asc true 3 a ASC false true false +t b_desc true 1 b DESC false false false +t b_desc true 2 a ASC false true false +t t_pkey false 1 a ASC false false false +t t_pkey false 2 b N/A true false false +t t_pkey false 3 c N/A true false false statement error pgcode 42P01 relation "foo" does not exist CREATE INDEX fail ON foo (b DESC) @@ -100,12 +100,12 @@ CREATE INDEX foo ON privs (b) user root -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM privs ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -privs privs_pkey false 1 a ASC false false -privs privs_pkey false 2 b N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +privs privs_pkey false 1 a ASC false false false +privs privs_pkey false 2 b N/A true false false statement ok GRANT CREATE ON privs TO testuser @@ -115,14 +115,14 @@ user testuser statement ok CREATE INDEX foo ON privs (b) -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM privs ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -privs foo true 1 b ASC false false -privs foo true 2 a ASC false true -privs privs_pkey false 1 a ASC false false -privs privs_pkey false 2 b N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +privs foo true 1 b ASC false false false +privs foo true 2 a ASC false true false +privs privs_pkey false 1 a ASC false false false +privs privs_pkey false 2 b N/A true false false user root @@ -403,3 +403,22 @@ CREATE INDEX ON opclasses(b blah_ops) # inverted, even if the type is invertible. statement error operator class "blah_ops" does not exist CREATE INDEX ON opclasses(c blah_ops) + +# The following test cases check for invisible index feature. +statement ok +CREATE TABLE b (c INT PRIMARY KEY, d INT, geom1 GEOMETRY) + +statement ok +CREATE INDEX a1 ON b (d) VISIBLE + +statement ok +CREATE INDEX a3 ON b (c) WITH (fillfactor = 100) NOT VISIBLE + +statement ok +CREATE INVERTED INDEX IF NOT EXISTS a4 ON b (geom1) WHERE d > 3 VISIBLE + +statement error pgcode 0A000 invisible unique index is currently not supported. +CREATE UNIQUE INDEX idx ON b (((lower(c) || ' ') || lower(d))) NOT VISIBLE + +statement error pgcode 0A000 invisible unique index is currently not supported. +CREATE UNIQUE INDEX IF NOT EXISTS idx ON b (c) WHERE d > 3 NOT VISIBLE diff --git a/pkg/sql/logictest/testdata/logic_test/create_statements b/pkg/sql/logictest/testdata/logic_test/create_statements index 96a07d1759ec..156f34e47392 100644 --- a/pkg/sql/logictest/testdata/logic_test/create_statements +++ b/pkg/sql/logictest/testdata/logic_test/create_statements @@ -1540,6 +1540,7 @@ CREATE TABLE crdb_internal.table_indexes ( is_unique BOOL NOT NULL, is_inverted BOOL NOT NULL, is_sharded BOOL NOT NULL, + is_hidden BOOL NOT NULL, shard_bucket_count INT8 NULL, created_at TIMESTAMP NULL ) CREATE TABLE crdb_internal.table_indexes ( @@ -1551,6 +1552,7 @@ CREATE TABLE crdb_internal.table_indexes ( is_unique BOOL NOT NULL, is_inverted BOOL NOT NULL, is_sharded BOOL NOT NULL, + is_hidden BOOL NOT NULL, shard_bucket_count INT8 NULL, created_at TIMESTAMP NULL ) {} {} diff --git a/pkg/sql/logictest/testdata/logic_test/create_table b/pkg/sql/logictest/testdata/logic_test/create_table index 1607f7b83cd2..a51f58d749b1 100644 --- a/pkg/sql/logictest/testdata/logic_test/create_table +++ b/pkg/sql/logictest/testdata/logic_test/create_table @@ -59,10 +59,11 @@ rowid_2 query TT SELECT index_name, column_name FROM [SHOW INDEXES FROM t] +ORDER BY index_name, column_name ---- -t_pkey rowid_2 t_pkey rowid t_pkey rowid_1 +t_pkey rowid_2 query TT SHOW CREATE t @@ -986,3 +987,13 @@ tbl CREATE TABLE public.tbl ( CONSTRAINT tbl_pkey PRIMARY KEY (i ASC), FAMILY f1 (i, j) ) + +statement ok +CREATE TABLE t_invisible1 (b INT8, c STRING, d INT, INDEX (b ASC, c DESC) STORING (d) NOT VISIBLE) + +statement ok +CREATE TABLE t_invisible2 (b INT, c GEOGRAPHY, INVERTED INDEX (b ASC, c DESC) WHERE b > 3 NOT VISIBLE) + +# TODO(wenyihu6): need to support this case after changing +#statement error pgcode 0A000 invisible unique index is currently not supported. +#CREATE TABLE t_invisible3 (b INT, c STRING, UNIQUE INDEX foo (b) WHERE c = 'HELLO' NOT VISIBLE) diff --git a/pkg/sql/logictest/testdata/logic_test/drop_index b/pkg/sql/logictest/testdata/logic_test/drop_index index ca9399fc9c18..b0a5e902954a 100644 --- a/pkg/sql/logictest/testdata/logic_test/drop_index +++ b/pkg/sql/logictest/testdata/logic_test/drop_index @@ -52,17 +52,17 @@ DROP INDEX baw statement ok INSERT INTO users VALUES (1, 'tom', 'cat'),(2, 'jerry', 'rat') -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM users ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -users bar false 1 id ASC false false -users bar false 2 name ASC false false -users foo true 1 name ASC false false -users foo true 2 id ASC false true -users users_pkey false 1 id ASC false false -users users_pkey false 2 name N/A true false -users users_pkey false 3 title N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +users bar false 1 id ASC false false false +users bar false 2 name ASC false false false +users foo true 1 name ASC false false false +users foo true 2 id ASC false true false +users users_pkey false 1 id ASC false false false +users users_pkey false 2 name N/A true false false +users users_pkey false 3 title N/A true false false statement error index "zap" does not exist DROP INDEX users@zap @@ -70,32 +70,32 @@ DROP INDEX users@zap statement ok DROP INDEX IF EXISTS users@zap -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM users ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -users bar false 1 id ASC false false -users bar false 2 name ASC false false -users foo true 1 name ASC false false -users foo true 2 id ASC false true -users users_pkey false 1 id ASC false false -users users_pkey false 2 name N/A true false -users users_pkey false 3 title N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +users bar false 1 id ASC false false false +users bar false 2 name ASC false false false +users foo true 1 name ASC false false false +users foo true 2 id ASC false true false +users users_pkey false 1 id ASC false false false +users users_pkey false 2 name N/A true false false +users users_pkey false 3 title N/A true false false # Also test that dropping with a non-existing index still drops 'foo'. statement ok DROP INDEX IF EXISTS users@foo, users@zap -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM users ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -users bar false 1 id ASC false false -users bar false 2 name ASC false false -users users_pkey false 1 id ASC false false -users users_pkey false 2 name N/A true false -users users_pkey false 3 title N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +users bar false 1 id ASC false false false +users bar false 2 name ASC false false false +users users_pkey false 1 id ASC false false false +users users_pkey false 2 name N/A true false false +users users_pkey false 3 title N/A true false false user testuser @@ -118,13 +118,13 @@ DROP INDEX users@bar RESTRICT statement ok DROP INDEX users@bar CASCADE -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM users ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -users users_pkey false 1 id ASC false false -users users_pkey false 2 name N/A true false -users users_pkey false 3 title N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +users users_pkey false 1 id ASC false false false +users users_pkey false 2 name N/A true false false +users users_pkey false 3 title N/A true false false user root @@ -146,17 +146,17 @@ CREATE INDEX baz ON users (name, title) statement ok DROP INDEX IF EXISTS users@invalid, users@baz -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM users ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -users bar true 1 title ASC false false -users bar true 2 id ASC false true -users foo true 1 name ASC false false -users foo true 2 id ASC false true -users users_pkey false 1 id ASC false false -users users_pkey false 2 name N/A true false -users users_pkey false 3 title N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +users bar true 1 title ASC false false false +users bar true 2 id ASC false true false +users foo true 1 name ASC false false false +users foo true 2 id ASC false true false +users users_pkey false 1 id ASC false false false +users users_pkey false 2 name N/A true false false +users users_pkey false 3 title N/A true false false statement ok CREATE VIEW v AS SELECT name FROM users@{FORCE_INDEX=foo} @@ -167,15 +167,15 @@ DROP INDEX users@foo statement ok DROP INDEX users@bar -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM users ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -users foo true 1 name ASC false false -users foo true 2 id ASC false true -users users_pkey false 1 id ASC false false -users users_pkey false 2 name N/A true false -users users_pkey false 3 title N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +users foo true 1 name ASC false false false +users foo true 2 id ASC false true false +users users_pkey false 1 id ASC false false false +users users_pkey false 2 name N/A true false false +users users_pkey false 3 title N/A true false false statement ok CREATE VIEW v2 AS SELECT name FROM v @@ -203,13 +203,13 @@ user root statement ok DROP INDEX users@foo CASCADE -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM users ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -users users_pkey false 1 id ASC false false -users users_pkey false 2 name N/A true false -users users_pkey false 3 title N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +users users_pkey false 1 id ASC false false false +users users_pkey false 2 name N/A true false false +users users_pkey false 3 title N/A true false false query TTTTIT SHOW TABLES @@ -243,13 +243,13 @@ CREATE INDEX baz ON users (name) statement ok DROP INDEX IF EXISTS baz, zap -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM users ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -users users_pkey false 1 id ASC false false -users users_pkey false 2 name N/A true false -users users_pkey false 3 title N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +users users_pkey false 1 id ASC false false false +users users_pkey false 2 name N/A true false false +users users_pkey false 3 title N/A true false false # Test that it still succeeds when an index does not exist. diff --git a/pkg/sql/logictest/testdata/logic_test/fk b/pkg/sql/logictest/testdata/logic_test/fk index 5b37b37078a7..9e52358b19ab 100644 --- a/pkg/sql/logictest/testdata/logic_test/fk +++ b/pkg/sql/logictest/testdata/logic_test/fk @@ -295,12 +295,12 @@ CREATE TABLE missing_col (customer INT REFERENCES customers (idz)) statement ok CREATE TABLE unindexed (customer INT REFERENCES customers) -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM unindexed ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -unindexed unindexed_pkey false 1 rowid ASC false false -unindexed unindexed_pkey false 2 customer N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +unindexed unindexed_pkey false 1 rowid ASC false false false +unindexed unindexed_pkey false 2 customer N/A true false false statement error there is no unique constraint matching given keys for referenced table products CREATE TABLE non_unique (product STRING REFERENCES products (vendor)) @@ -783,32 +783,32 @@ CREATE TABLE refpairs_wrong_order ( INDEX (b, a) ) -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM refpairs_wrong_order ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -refpairs_wrong_order refpairs_wrong_order_b_a_idx true 1 b ASC false false -refpairs_wrong_order refpairs_wrong_order_b_a_idx true 2 a ASC false false -refpairs_wrong_order refpairs_wrong_order_b_a_idx true 3 rowid ASC false true -refpairs_wrong_order refpairs_wrong_order_pkey false 1 rowid ASC false false -refpairs_wrong_order refpairs_wrong_order_pkey false 2 a N/A true false -refpairs_wrong_order refpairs_wrong_order_pkey false 3 b N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +refpairs_wrong_order refpairs_wrong_order_b_a_idx true 1 b ASC false false false +refpairs_wrong_order refpairs_wrong_order_b_a_idx true 2 a ASC false false false +refpairs_wrong_order refpairs_wrong_order_b_a_idx true 3 rowid ASC false true false +refpairs_wrong_order refpairs_wrong_order_pkey false 1 rowid ASC false false false +refpairs_wrong_order refpairs_wrong_order_pkey false 2 a N/A true false false +refpairs_wrong_order refpairs_wrong_order_pkey false 3 b N/A true false false statement ok CREATE TABLE refpairs_c_between (a INT, b STRING, c INT, FOREIGN KEY (a, b) REFERENCES pairs (src, dest), INDEX (a, c, b)) -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM refpairs_c_between ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -refpairs_c_between refpairs_c_between_a_c_b_idx true 1 a ASC false false -refpairs_c_between refpairs_c_between_a_c_b_idx true 2 c ASC false false -refpairs_c_between refpairs_c_between_a_c_b_idx true 3 b ASC false false -refpairs_c_between refpairs_c_between_a_c_b_idx true 4 rowid ASC false true -refpairs_c_between refpairs_c_between_pkey false 1 rowid ASC false false -refpairs_c_between refpairs_c_between_pkey false 2 a N/A true false -refpairs_c_between refpairs_c_between_pkey false 3 b N/A true false -refpairs_c_between refpairs_c_between_pkey false 4 c N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +refpairs_c_between refpairs_c_between_a_c_b_idx true 1 a ASC false false false +refpairs_c_between refpairs_c_between_a_c_b_idx true 2 c ASC false false false +refpairs_c_between refpairs_c_between_a_c_b_idx true 3 b ASC false false false +refpairs_c_between refpairs_c_between_a_c_b_idx true 4 rowid ASC false true false +refpairs_c_between refpairs_c_between_pkey false 1 rowid ASC false false false +refpairs_c_between refpairs_c_between_pkey false 2 a N/A true false false +refpairs_c_between refpairs_c_between_pkey false 3 b N/A true false false +refpairs_c_between refpairs_c_between_pkey false 4 c N/A true false false statement ok CREATE TABLE refpairs ( @@ -820,18 +820,18 @@ CREATE TABLE refpairs ( FAMILY "primary" (a, b, c, rowid) ) -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM refpairs ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -refpairs refpairs_a_b_c_idx true 1 a ASC false false -refpairs refpairs_a_b_c_idx true 2 b ASC false false -refpairs refpairs_a_b_c_idx true 3 c ASC false false -refpairs refpairs_a_b_c_idx true 4 rowid ASC false true -refpairs refpairs_pkey false 1 rowid ASC false false -refpairs refpairs_pkey false 2 a N/A true false -refpairs refpairs_pkey false 3 b N/A true false -refpairs refpairs_pkey false 4 c N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +refpairs refpairs_a_b_c_idx true 1 a ASC false false false +refpairs refpairs_a_b_c_idx true 2 b ASC false false false +refpairs refpairs_a_b_c_idx true 3 c ASC false false false +refpairs refpairs_a_b_c_idx true 4 rowid ASC false true false +refpairs refpairs_pkey false 1 rowid ASC false false false +refpairs refpairs_pkey false 2 a N/A true false false +refpairs refpairs_pkey false 3 b N/A true false false +refpairs refpairs_pkey false 4 c N/A true false false query TT SHOW CREATE TABLE refpairs diff --git a/pkg/sql/logictest/testdata/logic_test/information_schema b/pkg/sql/logictest/testdata/logic_test/information_schema index 234310929302..74f3380b4d8f 100644 --- a/pkg/sql/logictest/testdata/logic_test/information_schema +++ b/pkg/sql/logictest/testdata/logic_test/information_schema @@ -350,10 +350,10 @@ table_type STRING false NULL · is_insertable_into STRING false NULL · {} false version INT8 true NULL · {} false -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM information_schema.tables ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden query TTTTB colnames SHOW CONSTRAINTS FROM information_schema.tables diff --git a/pkg/sql/logictest/testdata/logic_test/new_schema_changer b/pkg/sql/logictest/testdata/logic_test/new_schema_changer index 12c74137eb79..79314146532b 100644 --- a/pkg/sql/logictest/testdata/logic_test/new_schema_changer +++ b/pkg/sql/logictest/testdata/logic_test/new_schema_changer @@ -1338,22 +1338,22 @@ CREATE TABLE tIndx2 (a INT PRIMARY KEY, b INT, INDEX ((a+b))) statement ok CREATE TABLE tIndx3 (a INT PRIMARY KEY, b INT, INVERTED INDEX ((ARRAY[a,b]))) -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM tIndex ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -tindex bar true 1 crdb_internal_idx_expr ASC false false -tindex bar true 2 a ASC false true -tindex bar2 true 1 crdb_internal_idx_expr_1 ASC false false -tindex bar2 true 2 a ASC false true -tindex bar3 false 1 crdb_internal_idx_expr_2 ASC false false -tindex bar3 false 2 a ASC true true -tindex bar4 true 1 crdb_internal_idx_expr_3 ASC false false -tindex bar4 true 2 a ASC false true -tindex foo true 1 b ASC false false -tindex foo true 2 a ASC false true -tindex tindex_pkey false 1 a ASC false false -tindex tindex_pkey false 2 b N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +tindex bar true 1 crdb_internal_idx_expr ASC false false false +tindex bar true 2 a ASC false true false +tindex bar2 true 1 crdb_internal_idx_expr_1 ASC false false false +tindex bar2 true 2 a ASC false true false +tindex bar3 false 1 crdb_internal_idx_expr_2 ASC false false false +tindex bar3 false 2 a ASC true true false +tindex bar4 true 1 crdb_internal_idx_expr_3 ASC false false false +tindex bar4 true 2 a ASC false true false +tindex foo true 1 b ASC false false false +tindex foo true 2 a ASC false true false +tindex tindex_pkey false 1 a ASC false false false +tindex tindex_pkey false 2 b N/A true false false statement error duplicate key value violates unique constraint "bar3" INSERT INTO tIndex VALUES (2,1) @@ -1365,22 +1365,22 @@ INSERT INTO tIndex VALUES (20000,10000) #statement error pgcode 23505 violates unique constraint "bar" #CREATE UNIQUE INDEX bar ON tIndex (b) -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM tIndex ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -tindex bar true 1 crdb_internal_idx_expr ASC false false -tindex bar true 2 a ASC false true -tindex bar2 true 1 crdb_internal_idx_expr_1 ASC false false -tindex bar2 true 2 a ASC false true -tindex bar3 false 1 crdb_internal_idx_expr_2 ASC false false -tindex bar3 false 2 a ASC true true -tindex bar4 true 1 crdb_internal_idx_expr_3 ASC false false -tindex bar4 true 2 a ASC false true -tindex foo true 1 b ASC false false -tindex foo true 2 a ASC false true -tindex tindex_pkey false 1 a ASC false false -tindex tindex_pkey false 2 b N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +tindex bar true 1 crdb_internal_idx_expr ASC false false false +tindex bar true 2 a ASC false true false +tindex bar2 true 1 crdb_internal_idx_expr_1 ASC false false false +tindex bar2 true 2 a ASC false true false +tindex bar3 false 1 crdb_internal_idx_expr_2 ASC false false false +tindex bar3 false 2 a ASC true true false +tindex bar4 true 1 crdb_internal_idx_expr_3 ASC false false false +tindex bar4 true 2 a ASC false true false +tindex foo true 1 b ASC false false false +tindex foo true 2 a ASC false true false +tindex tindex_pkey false 1 a ASC false false false +tindex tindex_pkey false 2 b N/A true false false # test for DESC index @@ -1403,18 +1403,18 @@ CREATE INDEX b_desc ON tIndx (b DESC) statement ok CREATE INDEX b_asc ON tIndx (b ASC, c DESC) -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM tIndx ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -tindx b_asc true 1 b ASC false false -tindx b_asc true 2 c DESC false false -tindx b_asc true 3 a ASC false true -tindx b_desc true 1 b DESC false false -tindx b_desc true 2 a ASC false true -tindx tindx_pkey false 1 a ASC false false -tindx tindx_pkey false 2 b N/A true false -tindx tindx_pkey false 3 c N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +tindx b_asc true 1 b ASC false false false +tindx b_asc true 2 c DESC false false false +tindx b_asc true 3 a ASC false true false +tindx b_desc true 1 b DESC false false false +tindx b_desc true 2 a ASC false true false +tindx tindx_pkey false 1 a ASC false false false +tindx tindx_pkey false 2 b N/A true false false +tindx tindx_pkey false 3 c N/A true false false statement error pgcode 42P01 relation "foo" does not exist CREATE INDEX fail ON foo (b DESC) @@ -1435,12 +1435,12 @@ CREATE INDEX foo ON privs (b) user root -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM privs ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -privs privs_pkey false 1 a ASC false false -privs privs_pkey false 2 b N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +privs privs_pkey false 1 a ASC false false false +privs privs_pkey false 2 b N/A true false false statement ok GRANT CREATE ON privs TO testuser @@ -1450,14 +1450,14 @@ user testuser statement ok CREATE INDEX foo ON privs (b) -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM privs ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -privs foo true 1 b ASC false false -privs foo true 2 a ASC false true -privs privs_pkey false 1 a ASC false false -privs privs_pkey false 2 b N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +privs foo true 1 b ASC false false false +privs foo true 2 a ASC false true false +privs privs_pkey false 1 a ASC false false false +privs privs_pkey false 2 b N/A true false false user root diff --git a/pkg/sql/logictest/testdata/logic_test/pg_catalog b/pkg/sql/logictest/testdata/logic_test/pg_catalog index a8cd5c37fd6d..b5912af82c53 100644 --- a/pkg/sql/logictest/testdata/logic_test/pg_catalog +++ b/pkg/sql/logictest/testdata/logic_test/pg_catalog @@ -324,10 +324,10 @@ nspname NAME false NULL · {} nspowner OID true NULL · {} false nspacl STRING[] true NULL · {} false -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM pg_catalog.pg_namespace ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden query TTTTB colnames SHOW CONSTRAINTS FROM pg_catalog.pg_namespace diff --git a/pkg/sql/logictest/testdata/logic_test/rename_column b/pkg/sql/logictest/testdata/logic_test/rename_column index 71566faed42b..bdb34edd6b9c 100644 --- a/pkg/sql/logictest/testdata/logic_test/rename_column +++ b/pkg/sql/logictest/testdata/logic_test/rename_column @@ -70,18 +70,18 @@ id username species 2 jerry rat # Renaming a column updates the column names in an index. -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM users ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -users bar false 1 id ASC false false -users bar false 2 username ASC false false -users foo true 1 username ASC false false -users foo true 2 species N/A true false -users foo true 3 id ASC false true -users users_pkey false 1 id ASC false false -users users_pkey false 2 username N/A true false -users users_pkey false 3 species N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +users bar false 1 id ASC false false false +users bar false 2 username ASC false false false +users foo true 1 username ASC false false false +users foo true 2 species N/A true false false +users foo true 3 id ASC false true false +users users_pkey false 1 id ASC false false false +users users_pkey false 2 username N/A true false false +users users_pkey false 3 species N/A true false false statement ok CREATE VIEW v1 AS SELECT id FROM users WHERE username = 'tom' diff --git a/pkg/sql/logictest/testdata/logic_test/rename_index b/pkg/sql/logictest/testdata/logic_test/rename_index index 9c78ec52f925..8526d40b5510 100644 --- a/pkg/sql/logictest/testdata/logic_test/rename_index +++ b/pkg/sql/logictest/testdata/logic_test/rename_index @@ -22,29 +22,29 @@ INSERT INTO users VALUES (1, 'tom', 'cat'),(2, 'jerry', 'rat') statement ok INSERT INTO users_dupe VALUES (1, 'tom', 'cat'),(2, 'jerry', 'rat') -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM users ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -users bar false 1 id ASC false false -users bar false 2 name ASC false false -users foo true 1 name ASC false false -users foo true 2 id ASC false true -users users_pkey false 1 id ASC false false -users users_pkey false 2 name N/A true false -users users_pkey false 3 title N/A true false - -query TTBITTBB colnames +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +users bar false 1 id ASC false false false +users bar false 2 name ASC false false false +users foo true 1 name ASC false false false +users foo true 2 id ASC false true false +users users_pkey false 1 id ASC false false false +users users_pkey false 2 name N/A true false false +users users_pkey false 3 title N/A true false false + +query TTBITTBBB colnames SHOW INDEXES FROM users_dupe ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -users_dupe bar false 1 id ASC false false -users_dupe bar false 2 name ASC false false -users_dupe foo true 1 name ASC false false -users_dupe foo true 2 id ASC false true -users_dupe users_dupe_pkey false 1 id ASC false false -users_dupe users_dupe_pkey false 2 name N/A true false -users_dupe users_dupe_pkey false 3 title N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +users_dupe bar false 1 id ASC false false false +users_dupe bar false 2 name ASC false false false +users_dupe foo true 1 name ASC false false false +users_dupe foo true 2 id ASC false true false +users_dupe users_dupe_pkey false 1 id ASC false false false +users_dupe users_dupe_pkey false 2 name N/A true false false +users_dupe users_dupe_pkey false 3 title N/A true false false statement error pgcode 42P07 index name "bar" already exists ALTER INDEX users@foo RENAME TO bar @@ -80,17 +80,17 @@ ALTER INDEX IF EXISTS ufooo RENAME TO ufoo statement ok ALTER INDEX ufoo RENAME TO ufo -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM users ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -users bar false 1 id ASC false false -users bar false 2 name ASC false false -users ufo true 1 name ASC false false -users ufo true 2 id ASC false true -users users_pkey false 1 id ASC false false -users users_pkey false 2 name N/A true false -users users_pkey false 3 title N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +users bar false 1 id ASC false false false +users bar false 2 name ASC false false false +users ufo true 1 name ASC false false false +users ufo true 2 id ASC false true false +users users_pkey false 1 id ASC false false false +users users_pkey false 2 name N/A true false false +users users_pkey false 3 title N/A true false false user testuser @@ -107,17 +107,17 @@ user testuser statement ok ALTER INDEX users@bar RENAME TO rar -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM users ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -users rar false 1 id ASC false false -users rar false 2 name ASC false false -users ufo true 1 name ASC false false -users ufo true 2 id ASC false true -users users_pkey false 1 id ASC false false -users users_pkey false 2 name N/A true false -users users_pkey false 3 title N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +users rar false 1 id ASC false false false +users rar false 2 name ASC false false false +users ufo true 1 name ASC false false false +users ufo true 2 id ASC false true false +users users_pkey false 1 id ASC false false false +users users_pkey false 2 name N/A true false false +users users_pkey false 3 title N/A true false false user root diff --git a/pkg/sql/logictest/testdata/logic_test/show_indexes b/pkg/sql/logictest/testdata/logic_test/show_indexes index fda3d134b85c..f9742e41281e 100644 --- a/pkg/sql/logictest/testdata/logic_test/show_indexes +++ b/pkg/sql/logictest/testdata/logic_test/show_indexes @@ -9,20 +9,20 @@ CREATE TABLE t1 ( UNIQUE INDEX d_b_idx (d ASC, b ASC) ) -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES from t1 ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -t1 c_idx true 1 c ASC false false -t1 c_idx true 2 a ASC false true -t1 c_idx true 3 b ASC false true -t1 d_b_idx false 1 d ASC false false -t1 d_b_idx false 2 b ASC false false -t1 d_b_idx false 3 a ASC true true -t1 t1_pkey false 1 a ASC false false -t1 t1_pkey false 2 b ASC false false -t1 t1_pkey false 3 c N/A true false -t1 t1_pkey false 4 d N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +t1 c_idx true 1 c ASC false false false +t1 c_idx true 2 a ASC false true false +t1 c_idx true 3 b ASC false true false +t1 d_b_idx false 1 d ASC false false false +t1 d_b_idx false 2 b ASC false false false +t1 d_b_idx false 3 a ASC true true false +t1 t1_pkey false 1 a ASC false false false +t1 t1_pkey false 2 b ASC false false false +t1 t1_pkey false 3 c N/A true false false +t1 t1_pkey false 4 d N/A true false false statement ok CREATE TABLE t2 ( @@ -38,29 +38,29 @@ CREATE TABLE t2 ( INDEX d_idx (d ASC) ) -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES from t2 ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -t2 a_e_c_idx true 1 a ASC false false -t2 a_e_c_idx true 2 e ASC false false -t2 a_e_c_idx true 3 c ASC false false -t2 a_e_c_idx true 4 b ASC false true -t2 b_d_idx false 1 b ASC false false -t2 b_d_idx false 2 d ASC false false -t2 b_d_idx false 3 c ASC true true -t2 b_d_idx false 4 a ASC true true -t2 c_e_d_a_idx false 1 c ASC false false -t2 c_e_d_a_idx false 2 e ASC false false -t2 c_e_d_a_idx false 3 d ASC false false -t2 c_e_d_a_idx false 4 a ASC false false -t2 c_e_d_a_idx false 5 b ASC true true -t2 d_idx true 1 d ASC false false -t2 d_idx true 2 c ASC false true -t2 d_idx true 3 b ASC false true -t2 d_idx true 4 a ASC false true -t2 t2_pkey false 1 c ASC false false -t2 t2_pkey false 2 b ASC false false -t2 t2_pkey false 3 a ASC false false -t2 t2_pkey false 4 d N/A true false -t2 t2_pkey false 5 e N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +t2 a_e_c_idx true 1 a ASC false false false +t2 a_e_c_idx true 2 e ASC false false false +t2 a_e_c_idx true 3 c ASC false false false +t2 a_e_c_idx true 4 b ASC false true false +t2 b_d_idx false 1 b ASC false false false +t2 b_d_idx false 2 d ASC false false false +t2 b_d_idx false 3 c ASC true true false +t2 b_d_idx false 4 a ASC true true false +t2 c_e_d_a_idx false 1 c ASC false false false +t2 c_e_d_a_idx false 2 e ASC false false false +t2 c_e_d_a_idx false 3 d ASC false false false +t2 c_e_d_a_idx false 4 a ASC false false false +t2 c_e_d_a_idx false 5 b ASC true true false +t2 d_idx true 1 d ASC false false false +t2 d_idx true 2 c ASC false true false +t2 d_idx true 3 b ASC false true false +t2 d_idx true 4 a ASC false true false +t2 t2_pkey false 1 c ASC false false false +t2 t2_pkey false 2 b ASC false false false +t2 t2_pkey false 3 a ASC false false false +t2 t2_pkey false 4 d N/A true false false +t2 t2_pkey false 5 e N/A true false false diff --git a/pkg/sql/logictest/testdata/logic_test/show_source b/pkg/sql/logictest/testdata/logic_test/show_source index 9fd11d1270e9..5c25b9851a3e 100644 --- a/pkg/sql/logictest/testdata/logic_test/show_source +++ b/pkg/sql/logictest/testdata/logic_test/show_source @@ -202,12 +202,12 @@ database_name schema_name table_name grantee privilege_type is_grantable system public descriptor admin SELECT true system public descriptor root SELECT true -query TTBITTBB colnames +query TTBITTBBB colnames SELECT * FROM [SHOW INDEX FROM system.descriptor] ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -descriptor primary false 1 id ASC false false -descriptor primary false 2 descriptor N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +descriptor primary false 1 id ASC false false false +descriptor primary false 2 descriptor N/A true false false query TTTTB colnames SELECT * FROM [SHOW CONSTRAINT FROM system.descriptor] @@ -215,12 +215,12 @@ SELECT * FROM [SHOW CONSTRAINT FROM system.descriptor] table_name constraint_name constraint_type details validated descriptor primary PRIMARY KEY PRIMARY KEY (id ASC) true -query TTBITTBB colnames +query TTBITTBBB colnames SELECT * FROM [SHOW KEYS FROM system.descriptor] ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -descriptor primary false 1 id ASC false false -descriptor primary false 2 descriptor N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +descriptor primary false 1 id ASC false false false +descriptor primary false 2 descriptor N/A true false false query TT colnames,rowsort SELECT * FROM [SHOW SCHEMAS FROM system] @@ -491,11 +491,11 @@ CREATE TABLE showdbindexestest.table1 (key1 INT PRIMARY KEY); statement ok CREATE TABLE showdbindexestest.table2 (key2 INT PRIMARY KEY); -query TTBITTBB +query TTBITTBBB SHOW INDEXES FROM DATABASE showdbindexestest; ---- -table1 table1_pkey false 1 key1 ASC false false -table2 table2_pkey false 1 key2 ASC false false +table1 table1_pkey false 1 key1 ASC false false false +table2 table2_pkey false 1 key2 ASC false false false statement ok CREATE DATABASE "$peci@l"; @@ -506,11 +506,11 @@ CREATE TABLE "$peci@l".table1 (key1 INT PRIMARY KEY); statement ok CREATE TABLE "$peci@l".table2 (key2 INT PRIMARY KEY); -query TTBITTBB +query TTBITTBBB SHOW INDEXES FROM DATABASE "$peci@l"; ---- -table1 table1_pkey false 1 key1 ASC false false -table2 table2_pkey false 1 key2 ASC false false +table1 table1_pkey false 1 key1 ASC false false false +table2 table2_pkey false 1 key2 ASC false false false # Test SHOW LOCALITY telemetry. query T @@ -582,30 +582,30 @@ CREATE TABLE t ( COMMENT ON COLUMN t.z IS 'comm"en"t2'; COMMENT ON INDEX t@i2 IS 'comm''ent3' -query TTBITTBBT +query TTBITTBBBT SHOW INDEXES FROM t WITH COMMENT ---- -t i1 true 1 x ASC false false NULL -t i1 true 2 rowid ASC false true NULL -t i2 true 1 y ASC false false comm'ent3 -t i2 true 2 rowid ASC false true comm'ent3 -t i3 true 1 z ASC false false NULL -t i3 true 2 rowid ASC false true NULL -t t_pkey false 1 rowid ASC false false NULL -t t_pkey false 2 x N/A true false NULL -t t_pkey false 3 y N/A true false NULL -t t_pkey false 4 z N/A true false NULL - -query TTBITTBBT +t i1 true 1 x ASC false false false NULL +t i1 true 2 rowid ASC false true false NULL +t i2 true 1 y ASC false false false comm'ent3 +t i2 true 2 rowid ASC false true false comm'ent3 +t i3 true 1 z ASC false false false NULL +t i3 true 2 rowid ASC false true false NULL +t t_pkey false 1 rowid ASC false false false NULL +t t_pkey false 2 x N/A true false false NULL +t t_pkey false 3 y N/A true false false NULL +t t_pkey false 4 z N/A true false false NULL + +query TTBITTBBBT SHOW INDEXES FROM t2 WITH COMMENT ---- -t2 i1 true 1 x ASC false false NULL -t2 i1 true 2 rowid ASC false true NULL -t2 i2 true 1 y ASC false false NULL -t2 i2 true 2 rowid ASC false true NULL -t2 i3 true 1 z ASC false false NULL -t2 i3 true 2 rowid ASC false true NULL -t2 t2_pkey false 1 rowid ASC false false NULL -t2 t2_pkey false 2 x N/A true false NULL -t2 t2_pkey false 3 y N/A true false NULL -t2 t2_pkey false 4 z N/A true false NULL +t2 i1 true 1 x ASC false false false NULL +t2 i1 true 2 rowid ASC false true false NULL +t2 i2 true 1 y ASC false false false NULL +t2 i2 true 2 rowid ASC false true false NULL +t2 i3 true 1 z ASC false false false NULL +t2 i3 true 2 rowid ASC false true false NULL +t2 t2_pkey false 1 rowid ASC false false false NULL +t2 t2_pkey false 2 x N/A true false false NULL +t2 t2_pkey false 3 y N/A true false false NULL +t2 t2_pkey false 4 z N/A true false false NULL diff --git a/pkg/sql/logictest/testdata/logic_test/storing b/pkg/sql/logictest/testdata/logic_test/storing index e027a1624354..a9cced5f23a8 100644 --- a/pkg/sql/logictest/testdata/logic_test/storing +++ b/pkg/sql/logictest/testdata/logic_test/storing @@ -8,22 +8,22 @@ CREATE TABLE t ( UNIQUE INDEX c_idx (c) STORING (b, d) ) -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM t ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -t b_idx true 1 b ASC false false -t b_idx true 2 c N/A true false -t b_idx true 3 d N/A true false -t b_idx true 4 a ASC false true -t c_idx false 1 c ASC false false -t c_idx false 2 b N/A true false -t c_idx false 3 d N/A true false -t c_idx false 4 a ASC true true -t t_pkey false 1 a ASC false false -t t_pkey false 2 b N/A true false -t t_pkey false 3 c N/A true false -t t_pkey false 4 d N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +t b_idx true 1 b ASC false false false +t b_idx true 2 c N/A true false false +t b_idx true 3 d N/A true false false +t b_idx true 4 a ASC false true false +t c_idx false 1 c ASC false false false +t c_idx false 2 b N/A true false false +t c_idx false 3 d N/A true false false +t c_idx false 4 a ASC true true false +t t_pkey false 1 a ASC false false false +t t_pkey false 2 b N/A true false false +t t_pkey false 3 c N/A true false false +t t_pkey false 4 d N/A true false false statement ok INSERT INTO t VALUES (1, 2, 3, 4) diff --git a/pkg/sql/logictest/testdata/logic_test/table b/pkg/sql/logictest/testdata/logic_test/table index 95b9151387ea..945afa79c06e 100644 --- a/pkg/sql/logictest/testdata/logic_test/table +++ b/pkg/sql/logictest/testdata/logic_test/table @@ -63,39 +63,39 @@ CREATE TABLE c ( statement ok COMMENT ON INDEX c_foo_idx IS 'index_comment' -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM c ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -c c_bar_key false 1 bar ASC false false -c c_bar_key false 2 id ASC true true -c c_foo_bar_idx true 1 foo ASC false false -c c_foo_bar_idx true 2 bar DESC false false -c c_foo_bar_idx true 3 id ASC false true -c c_foo_idx true 1 foo ASC false false -c c_foo_idx true 2 id ASC false true -c c_foo_idx1 true 1 foo ASC false false -c c_foo_idx1 true 2 id ASC false true -c c_pkey false 1 id ASC false false -c c_pkey false 2 foo N/A true false -c c_pkey false 3 bar N/A true false - -query TTBITTBBT colnames +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +c c_bar_key false 1 bar ASC false false false +c c_bar_key false 2 id ASC true true false +c c_foo_bar_idx true 1 foo ASC false false false +c c_foo_bar_idx true 2 bar DESC false false false +c c_foo_bar_idx true 3 id ASC false true false +c c_foo_idx true 1 foo ASC false false false +c c_foo_idx true 2 id ASC false true false +c c_foo_idx1 true 1 foo ASC false false false +c c_foo_idx1 true 2 id ASC false true false +c c_pkey false 1 id ASC false false false +c c_pkey false 2 foo N/A true false false +c c_pkey false 3 bar N/A true false false + +query TTBITTBBBT colnames SHOW INDEXES FROM c WITH COMMENT ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit comment -c c_bar_key false 1 bar ASC false false NULL -c c_bar_key false 2 id ASC true true NULL -c c_foo_bar_idx true 1 foo ASC false false NULL -c c_foo_bar_idx true 2 bar DESC false false NULL -c c_foo_bar_idx true 3 id ASC false true NULL -c c_foo_idx true 1 foo ASC false false index_comment -c c_foo_idx true 2 id ASC false true index_comment -c c_foo_idx1 true 1 foo ASC false false NULL -c c_foo_idx1 true 2 id ASC false true NULL -c c_pkey false 1 id ASC false false NULL -c c_pkey false 2 foo N/A true false NULL -c c_pkey false 3 bar N/A true false NULL +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden comment +c c_bar_key false 1 bar ASC false false false NULL +c c_bar_key false 2 id ASC true true false NULL +c c_foo_bar_idx true 1 foo ASC false false false NULL +c c_foo_bar_idx true 2 bar DESC false false false NULL +c c_foo_bar_idx true 3 id ASC false true false NULL +c c_foo_idx true 1 foo ASC false false false index_comment +c c_foo_idx true 2 id ASC false true false index_comment +c c_foo_idx1 true 1 foo ASC false false false NULL +c c_foo_idx1 true 2 id ASC false true false NULL +c c_pkey false 1 id ASC false false false NULL +c c_pkey false 2 foo N/A true false false NULL +c c_pkey false 3 bar N/A true false false NULL # primary keys can never be null @@ -199,20 +199,20 @@ nickname STRING true NULL · username STRING(10) true NULL · {users_pkey} false email VARCHAR(100) true NULL · {users_pkey} false -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM test.users ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -users bar false 1 id ASC false false -users bar false 2 name ASC false false -users foo true 1 name ASC false false -users foo true 2 id ASC false true -users users_pkey false 1 id ASC false false -users users_pkey false 2 name N/A true false -users users_pkey false 3 title N/A true false -users users_pkey false 4 nickname N/A true false -users users_pkey false 5 username N/A true false -users users_pkey false 6 email N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +users bar false 1 id ASC false false false +users bar false 2 name ASC false false false +users foo true 1 name ASC false false false +users foo true 2 id ASC false true false +users users_pkey false 1 id ASC false false false +users users_pkey false 2 name N/A true false false +users users_pkey false 3 title N/A true false false +users users_pkey false 4 nickname N/A true false false +users users_pkey false 5 username N/A true false false +users users_pkey false 6 email N/A true false false statement error precision for type float must be at least 1 bit CREATE TABLE test.precision (x FLOAT(0)) diff --git a/pkg/sql/opaque.go b/pkg/sql/opaque.go index 632af6543018..0e71a3d45ab1 100644 --- a/pkg/sql/opaque.go +++ b/pkg/sql/opaque.go @@ -106,6 +106,8 @@ func planOpaque(ctx context.Context, p *planner, stmt tree.Statement) (planNode, return p.alterDefaultPrivileges(ctx, n) case *tree.AlterIndex: return p.AlterIndex(ctx, n) + case *tree.AlterIndexVisible: + return p.AlterIndexVisible(ctx, n) case *tree.AlterSchema: return p.AlterSchema(ctx, n) case *tree.AlterTable: @@ -266,6 +268,7 @@ func init() { &tree.AlterDatabaseAlterSuperRegion{}, &tree.AlterDefaultPrivileges{}, &tree.AlterIndex{}, + &tree.AlterIndexVisible{}, &tree.AlterSchema{}, &tree.AlterTable{}, &tree.AlterTableLocality{}, diff --git a/pkg/sql/opt/cat/index.go b/pkg/sql/opt/cat/index.go index 12ebaa585263..431428adc793 100644 --- a/pkg/sql/opt/cat/index.go +++ b/pkg/sql/opt/cat/index.go @@ -56,6 +56,9 @@ type Index interface { // IsInverted returns true if this is an inverted index. IsInverted() bool + // IsHidden returns true if this index is invisible. + IsHidden() bool + // ColumnCount returns the number of columns in the index. This includes // columns that were part of the index definition (including the STORING // clause), as well as implicitly added primary key columns. It also contains diff --git a/pkg/sql/opt/cat/utils.go b/pkg/sql/opt/cat/utils.go index 8f0a0d005617..77e3802ea0b3 100644 --- a/pkg/sql/opt/cat/utils.go +++ b/pkg/sql/opt/cat/utils.go @@ -129,7 +129,13 @@ func formatCatalogIndex(tab Table, ord int, tp treeprinter.Node) { if IsMutationIndex(tab, ord) { mutation = " (mutation)" } - child := tp.Childf("%sINDEX %s%s", idxType, idx.Name(), mutation) + + isHidden := "" + if idx.IsHidden() { + isHidden = " NOT VISIBLE" + } + + child := tp.Childf("%sINDEX %s%s%s", idxType, idx.Name(), mutation, isHidden) var buf bytes.Buffer colCount := idx.ColumnCount() diff --git a/pkg/sql/opt/exec/execbuilder/testdata/explain b/pkg/sql/opt/exec/execbuilder/testdata/explain index 17fdb50280f7..d184c27b2b97 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/explain +++ b/pkg/sql/opt/exec/execbuilder/testdata/explain @@ -613,15 +613,24 @@ distribution: local vectorized: true · • sort -│ order: +index_name,+non_unique,+seq_in_index,+column_name,+direction,+storing,+implicit +│ order: +index_name,+non_unique,+seq_in_index,+column_name,+direction,+storing,+implicit,+is_hidden │ └── • render │ - └── • filter - │ filter: ((table_catalog = 'test') AND (table_schema = 'public')) AND (table_name = 'foo') + └── • hash join (right outer) + │ equality: (index_name, descriptor_name) = (index_name, table_name) │ - └── • virtual table - table: statistics@primary + ├── • filter + │ │ filter: descriptor_name = 'foo' + │ │ + │ └── • virtual table + │ table: table_indexes@primary + │ + └── • filter + │ filter: ((table_name = 'foo') AND (table_catalog = 'test')) AND (table_schema = 'public') + │ + └── • virtual table + table: statistics@primary query T EXPLAIN SHOW CONSTRAINTS FROM foo diff --git a/pkg/sql/opt/exec/execbuilder/testdata/select b/pkg/sql/opt/exec/execbuilder/testdata/select index 033e4d1b0e3f..021d54ef86ec 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/select +++ b/pkg/sql/opt/exec/execbuilder/testdata/select @@ -531,22 +531,22 @@ CREATE TABLE t ( FAMILY (a, b, c, d) ) -query TTBITTBB colnames +query TTBITTBBB colnames SHOW INDEXES FROM t ---- -table_name index_name non_unique seq_in_index column_name direction storing implicit -t b_idx true 1 b ASC false false -t b_idx true 2 c N/A true false -t b_idx true 3 d N/A true false -t b_idx true 4 a ASC false true -t c_idx false 1 c ASC false false -t c_idx false 2 b N/A true false -t c_idx false 3 d N/A true false -t c_idx false 4 a ASC true true -t t_pkey false 1 a ASC false false -t t_pkey false 2 b N/A true false -t t_pkey false 3 c N/A true false -t t_pkey false 4 d N/A true false +table_name index_name non_unique seq_in_index column_name direction storing implicit is_hidden +t b_idx true 1 b ASC false false false +t b_idx true 2 c N/A true false false +t b_idx true 3 d N/A true false false +t b_idx true 4 a ASC false true false +t c_idx false 1 c ASC false false false +t c_idx false 2 b N/A true false false +t c_idx false 3 d N/A true false false +t c_idx false 4 a ASC true true false +t t_pkey false 1 a ASC false false false +t t_pkey false 2 b N/A true false false +t t_pkey false 3 c N/A true false false +t t_pkey false 4 d N/A true false false statement ok INSERT INTO t VALUES (1, 2, 3, 4) diff --git a/pkg/sql/opt/exec/execbuilder/testdata/select_index b/pkg/sql/opt/exec/execbuilder/testdata/select_index index ef7380398c45..3e9e4b47b769 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/select_index +++ b/pkg/sql/opt/exec/execbuilder/testdata/select_index @@ -766,15 +766,15 @@ vectorized: true # Check that primary key definitions can indicate index ordering, # and this information is subsequently used during index selection # and span generation. #13882 -query TTBITTBB +query TTBITTBBB CREATE TABLE abz(a INT, b INT, c INT, PRIMARY KEY (a DESC, b ASC), UNIQUE(c DESC, b ASC)); SHOW INDEX FROM abz ---- -abz abz_c_b_key false 1 c DESC false false -abz abz_c_b_key false 2 b ASC false false -abz abz_c_b_key false 3 a ASC true true -abz abz_pkey false 1 a DESC false false -abz abz_pkey false 2 b ASC false false -abz abz_pkey false 3 c N/A true false +abz abz_c_b_key false 1 c DESC false false false +abz abz_c_b_key false 2 b ASC false false false +abz abz_c_b_key false 3 a ASC true true false +abz abz_pkey false 1 a DESC false false false +abz abz_pkey false 2 b ASC false false false +abz abz_pkey false 3 c N/A true false false query T EXPLAIN (VERBOSE) SELECT a FROM abz ORDER BY a DESC LIMIT 1 diff --git a/pkg/sql/opt/exec/execbuilder/testdata/show_trace b/pkg/sql/opt/exec/execbuilder/testdata/show_trace index 4fa93b9abf31..357ae0090b6b 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/show_trace +++ b/pkg/sql/opt/exec/execbuilder/testdata/show_trace @@ -64,7 +64,7 @@ query TT $trace_query ---- batch flow coordinator CPut /NamespaceTable/30/1/106/107/"kv"/4/1 -> 108 -batch flow coordinator CPut /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 > next_index_id:2 privileges: users: owner_proto:"root" version:2 > next_mutation_id:1 format_version:3 state:PUBLIC offline_reason:"" view_query:"" is_materialized_view:false drop_time:0 replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:2 > +batch flow coordinator CPut /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 hidden:false > next_index_id:2 privileges: users: owner_proto:"root" version:2 > next_mutation_id:1 format_version:3 state:PUBLIC offline_reason:"" view_query:"" is_materialized_view:false drop_time:0 replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:2 > sql query rows affected: 0 # We avoid using the full trace output, because that would make the @@ -79,7 +79,7 @@ SET tracing = on,kv,results; CREATE UNIQUE INDEX woo ON t.kv(v); SET tracing = o query TT $trace_query ---- -batch flow coordinator Put /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 > next_index_id:4 privileges: users: owner_proto:"root" version:2 > mutations: interleave:<> partitioning: type:FORWARD created_explicitly:true encoding_type:0 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:2 > state:BACKFILLING direction:ADD mutation_id:1 rollback:false > mutations: interleave:<> partitioning: type:FORWARD created_explicitly:true encoding_type:0 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:true created_at_nanos:... constraint_id:3 > state:DELETE_ONLY direction:ADD mutation_id:1 rollback:false > next_mutation_id:2 format_version:3 state:PUBLIC offline_reason:"" view_query:"" is_materialized_view:false mutationJobs:<...> drop_time:0 replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 > +batch flow coordinator Put /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 hidden:false > next_index_id:4 privileges: users: owner_proto:"root" version:2 > mutations: interleave:<> partitioning: type:FORWARD created_explicitly:true encoding_type:0 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:2 hidden:false > state:BACKFILLING direction:ADD mutation_id:1 rollback:false > mutations: interleave:<> partitioning: type:FORWARD created_explicitly:true encoding_type:0 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:true created_at_nanos:... constraint_id:3 hidden:false > state:DELETE_ONLY direction:ADD mutation_id:1 rollback:false > next_mutation_id:2 format_version:3 state:PUBLIC offline_reason:"" view_query:"" is_materialized_view:false mutationJobs:<...> drop_time:0 replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 > sql query rows affected: 0 statement ok @@ -126,7 +126,7 @@ query TT $trace_query ---- batch flow coordinator CPut /NamespaceTable/30/1/106/107/"kv2"/4/1 -> 109 -batch flow coordinator CPut /Table/3/1/109/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:false default_expr:"unique_rowid()" hidden:true inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:4 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 > next_index_id:2 privileges: users: owner_proto:"root" version:2 > next_mutation_id:1 format_version:3 state:ADD offline_reason:"" view_query:"" is_materialized_view:false drop_time:0 replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"TABLE t.public.kv" create_as_of_time:<> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:2 > +batch flow coordinator CPut /Table/3/1/109/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:false default_expr:"unique_rowid()" hidden:true inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:4 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 hidden:false > next_index_id:2 privileges: users: owner_proto:"root" version:2 > next_mutation_id:1 format_version:3 state:ADD offline_reason:"" view_query:"" is_materialized_view:false drop_time:0 replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"TABLE t.public.kv" create_as_of_time:<> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:2 > sql query rows affected: 0 statement ok @@ -163,7 +163,7 @@ SET tracing = off query TT $trace_query ---- -batch flow coordinator Put /Table/3/1/109/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:false default_expr:"unique_rowid()" hidden:true inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:4 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 > next_index_id:2 privileges: users: owner_proto:"root" version:2 > next_mutation_id:1 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"TABLE t.public.kv" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:2 > +batch flow coordinator Put /Table/3/1/109/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:false default_expr:"unique_rowid()" hidden:true inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:4 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 hidden:false > next_index_id:2 privileges: users: owner_proto:"root" version:2 > next_mutation_id:1 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"TABLE t.public.kv" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:2 > batch flow coordinator Del /NamespaceTable/30/1/106/107/"kv2"/4/1 sql query rows affected: 0 commit sql txn Put /Table/3/1/109/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:false default_expr:"unique_rowid()" hidden:true inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:4 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 > next_index_id:2 privileges: users: owner_proto:"root" version:2 > next_mutation_id:1 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false declarative_schema_changer_state:<...> > metadata:<...> target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:DROPPED current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:VALIDATED current_statuses:ABSENT target_ranks:0 target_ranks:1 target_ranks:2 target_ranks:3 target_ranks:4 target_ranks:5 target_ranks:6 target_ranks:7 target_ranks:8 target_ranks:9 target_ranks:10 target_ranks:11 target_ranks:12 target_ranks:13 target_ranks:14 target_ranks:15 target_ranks:16 target_ranks:17 target_ranks:18 target_ranks:19 target_ranks:20 target_ranks:21 target_ranks:22 target_ranks:23 target_ranks:24 target_ranks:25 target_ranks:26 target_ranks:27 relevant_statements: > authorization: > drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"TABLE t.public.kv" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:2 > @@ -193,7 +193,7 @@ SET tracing = off query TT $trace_query ---- -batch flow coordinator Put /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 > next_index_id:4 privileges: users: owner_proto:"root" version:2 > mutations: interleave:<> partitioning: type:FORWARD created_explicitly:true encoding_type:0 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:2 > state:DELETE_AND_WRITE_ONLY direction:DROP mutation_id:2 rollback:false > next_mutation_id:3 format_version:3 state:PUBLIC offline_reason:"" view_query:"" is_materialized_view:false mutationJobs:<...> drop_time:0 replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 > +batch flow coordinator Put /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 hidden:false > next_index_id:4 privileges: users: owner_proto:"root" version:2 > mutations: interleave:<> partitioning: type:FORWARD created_explicitly:true encoding_type:0 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:2 hidden:false > state:DELETE_AND_WRITE_ONLY direction:DROP mutation_id:2 rollback:false > next_mutation_id:3 format_version:3 state:PUBLIC offline_reason:"" view_query:"" is_materialized_view:false mutationJobs:<...> drop_time:0 replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 > sql query rows affected: 0 statement ok @@ -205,7 +205,7 @@ SET tracing = off query TT $trace_query ---- -batch flow coordinator Put /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 > next_index_id:4 privileges: users: owner_proto:"root" version:2 > next_mutation_id:3 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 > +batch flow coordinator Put /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 hidden:false > next_index_id:4 privileges: users: owner_proto:"root" version:2 > next_mutation_id:3 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 > batch flow coordinator Del /NamespaceTable/30/1/106/107/"kv"/4/1 sql query rows affected: 0 commit sql txn Put /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 > next_index_id:4 privileges: users: owner_proto:"root" version:2 > next_mutation_id:3 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false declarative_schema_changer_state:<...> > metadata:<...> target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:DROPPED current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:VALIDATED current_statuses:ABSENT target_ranks:0 target_ranks:1 target_ranks:2 target_ranks:3 target_ranks:4 target_ranks:5 target_ranks:6 target_ranks:7 target_ranks:8 target_ranks:9 target_ranks:10 target_ranks:11 target_ranks:12 target_ranks:13 target_ranks:14 target_ranks:15 target_ranks:16 target_ranks:17 target_ranks:18 target_ranks:19 target_ranks:20 target_ranks:21 target_ranks:22 relevant_statements: > authorization: > drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 > diff --git a/pkg/sql/opt/exec/explain/plan_gist_factory.go b/pkg/sql/opt/exec/explain/plan_gist_factory.go index ba37a30316bb..1efe0af25bc1 100644 --- a/pkg/sql/opt/exec/explain/plan_gist_factory.go +++ b/pkg/sql/opt/exec/explain/plan_gist_factory.go @@ -579,6 +579,10 @@ func (u *unknownIndex) IsUnique() bool { return false } +func (u *unknownIndex) IsHidden() bool { + return false +} + func (u *unknownIndex) IsInverted() bool { return false } diff --git a/pkg/sql/opt/indexrec/hypothetical_index.go b/pkg/sql/opt/indexrec/hypothetical_index.go index 57ce9d9c8f1d..091aaaa96c84 100644 --- a/pkg/sql/opt/indexrec/hypothetical_index.go +++ b/pkg/sql/opt/indexrec/hypothetical_index.go @@ -47,6 +47,9 @@ type hypotheticalIndex struct { // inverted indicates if an index is inverted. inverted bool + + // hidden indicates if an index is invisible. + hidden bool } var _ cat.Index = &hypotheticalIndex{} @@ -111,6 +114,11 @@ func (hi *hypotheticalIndex) IsInverted() bool { return hi.inverted } +// IsHidden is part of the cat.Index interface. +func (hi *hypotheticalIndex) IsHidden() bool { + return hi.hidden +} + // ColumnCount is part of the cat.Index interface. func (hi *hypotheticalIndex) ColumnCount() int { return len(hi.cols) + len(hi.suffixKeyColsOrdList) + hi.storedColsOrdSet.Len() diff --git a/pkg/sql/opt/testutils/opttester/testdata/invisible-index b/pkg/sql/opt/testutils/opttester/testdata/invisible-index new file mode 100644 index 000000000000..458319d843cc --- /dev/null +++ b/pkg/sql/opt/testutils/opttester/testdata/invisible-index @@ -0,0 +1,406 @@ +# This file tests for invisible index feature. Invisible index should be ignored +# by the optimizer unless explicitly selected with index hinting. + +exec-ddl +CREATE TABLE t1 (k INT PRIMARY KEY, v INT, i INT, p INT, INDEX idx_v_invisible (v) NOT VISIBLE) +---- + +# Index idx_v_invisible should be invisible. +exec-ddl +SHOW CREATE t1 +---- +TABLE t1 + ├── k int not null + ├── v int + ├── i int + ├── p int + ├── crdb_internal_mvcc_timestamp decimal [hidden] [system] + ├── tableoid oid [hidden] [system] + ├── PRIMARY INDEX t1_pkey + │ └── k int not null + └── INDEX idx_v_invisible NOT VISIBLE + ├── v int + └── k int not null + +# Optimal plan did not choose a scan of the index +# idx_v_invisible because idx_v_invisible was invisible. +opt +SELECT * FROM t1 WHERE v = 2 +---- +select + ├── columns: k:1(int!null) v:2(int!null) i:3(int) p:4(int) + ├── key: (1) + ├── fd: ()-->(2), (1)-->(3,4) + ├── scan t1 + │ ├── columns: k:1(int!null) v:2(int) i:3(int) p:4(int) + │ ├── key: (1) + │ └── fd: (1)-->(2-4) + └── filters + └── eq [type=bool, outer=(2), constraints=(/2: [/2 - /2]; tight), fd=()-->(2)] + ├── variable: v:2 [type=int] + └── const: 2 [type=int] + +# Optimal plan for the following query chose a scan of the index idx_v_invisible +# because idx_v_invisible was explicitly selected with index hinting. +opt +SELECT * FROM t1@idx_v_invisible WHERE v = 2 +---- +index-join t1 + ├── columns: k:1(int!null) v:2(int!null) i:3(int) p:4(int) + ├── key: (1) + ├── fd: ()-->(2), (1)-->(3,4) + └── scan t1@idx_v_invisible + ├── columns: k:1(int!null) v:2(int!null) + ├── constraint: /2/1: [/2 - /2] + ├── flags: force-index=idx_v_invisible + ├── key: (1) + └── fd: ()-->(2) + +# Index idx_i_visible should be visible. +exec-ddl +CREATE INDEX idx_i_visible ON t1(i) VISIBLE +---- + +# Optimal plan for the following query choose a scan of the index idx_i_visible +# because idx_i_visible is visible. +opt +SELECT * FROM t1 WHERE i = 2 +---- +index-join t1 + ├── columns: k:1(int!null) v:2(int) i:3(int!null) p:4(int) + ├── key: (1) + ├── fd: ()-->(3), (1)-->(2,4) + └── scan t1@idx_i_visible + ├── columns: k:1(int!null) i:3(int!null) + ├── constraint: /3/1: [/2 - /2] + ├── key: (1) + └── fd: ()-->(3) + +exec-ddl +DROP INDEX t1@idx_i_visible +---- + +# Index idx_i_invisible should be invisible. +exec-ddl +CREATE INDEX idx_i_invisible ON t1(i) NOT VISIBLE +---- + +# Optimal plan for the following query did not choose a scan of the index +# idx_i_invisible because idx_i_invisible was invisible. +opt +SELECT * FROM t1 WHERE i = 2 +---- +select + ├── columns: k:1(int!null) v:2(int) i:3(int!null) p:4(int) + ├── key: (1) + ├── fd: ()-->(3), (1)-->(2,4) + ├── scan t1 + │ ├── columns: k:1(int!null) v:2(int) i:3(int) p:4(int) + │ ├── key: (1) + │ └── fd: (1)-->(2-4) + └── filters + └── eq [type=bool, outer=(3), constraints=(/3: [/2 - /2]; tight), fd=()-->(3)] + ├── variable: i:3 [type=int] + └── const: 2 [type=int] + +# Optimal plan for the following query chose a scan of the index idx_i_invisible +# because idx_i_invisible was explicitly selected with index hinting. +opt +SELECT * FROM t1@{FORCE_INDEX=idx_i_invisible, ASC}; +---- +index-join t1 + ├── columns: k:1(int!null) v:2(int) i:3(int) p:4(int) + ├── key: (1) + ├── fd: (1)-->(2-4) + └── scan t1@idx_i_invisible + ├── columns: k:1(int!null) i:3(int) + ├── flags: force-index=idx_i_invisible,fwd + ├── key: (1) + └── fd: (1)-->(3) + +# Optimal plan for the following query chose a scan of the index idx_i_invisible +# because idx_i_invisible was explicitly selected with index hinting. +opt +SELECT * FROM t1@{FORCE_INDEX=idx_i_invisible, DESC} WHERE i > 0; +---- +index-join t1 + ├── columns: k:1(int!null) v:2(int) i:3(int!null) p:4(int) + ├── key: (1) + ├── fd: (1)-->(2-4) + └── scan t1@idx_i_invisible,rev + ├── columns: k:1(int!null) i:3(int!null) + ├── constraint: /3/1: [/1 - ] + ├── flags: force-index=idx_i_invisible,rev + ├── key: (1) + └── fd: (1)-->(3) + +# The following test cases checks for primary index. Primary indexes cannot be +# invisible. + +# TODO (wenyihu3): After introducing ALTER INDEX ... NOT VISIBLE, UNIQUE INDEX, +# ADD CONSTRAINT for UNIQUE new test cases should be added. New test cases +# should also cover ALTER PRIMARY KEY. + +# Note that primary indexes cannot be created with CREATE TABLE or CREATE INDEX. +# Check pkg/sql/parser/testdata/create_table to see how adding invisible with +# primary key constraint caused an error. New indexes created on primary key +# column are secondary and can be made invisible. + +exec-ddl +CREATE INDEX idx_k_invisible ON t1(k) NOT VISIBLE +---- + +opt +SELECT k FROM t1; +---- +scan t1 + ├── columns: k:1(int!null) + └── key: (1) + +# TODO (wenyihu6): More test cases should be added for UNIQUE index and primary key index. +# The following tests check for unique index. +exec-ddl +CREATE TABLE t4 (id INT, INDEX idx_data_invisible(id) WHERE id > 10 NOT VISIBLE); +---- + +exec-ddl +SHOW CREATE t4 +---- +TABLE t4 + ├── id int + ├── rowid int not null default (unique_rowid()) [hidden] + ├── crdb_internal_mvcc_timestamp decimal [hidden] [system] + ├── tableoid oid [hidden] [system] + ├── PRIMARY INDEX t4_pkey + │ └── rowid int not null default (unique_rowid()) [hidden] + └── INDEX idx_data_invisible NOT VISIBLE + ├── id int + ├── rowid int not null default (unique_rowid()) [hidden] + └── WHERE id > 10 + +# The following tests check for invisible partial index. +exec-ddl +CREATE TABLE t2 (a INT, b INT, c INT, INDEX idx_a_partial_visible (a) WHERE a > 0); +---- + +opt +SELECT a FROM t2 WHERE a > 0; +---- +scan t2@idx_a_partial_visible,partial + └── columns: a:1(int!null) + +exec-ddl +DROP INDEX t2@idx_a_partial_visible +---- + +exec-ddl +CREATE INDEX idx_a_partial_invisible ON t2(a) WHERE a > 0 NOT VISIBLE +---- + +opt +SELECT a FROM t2 WHERE a > 0; +---- +select + ├── columns: a:1(int!null) + ├── scan t2 + │ ├── columns: a:1(int) + │ └── partial index predicates + │ └── idx_a_partial_invisible: filters + │ └── gt [type=bool, outer=(1), constraints=(/1: [/1 - ]; tight)] + │ ├── variable: a:1 [type=int] + │ └── const: 0 [type=int] + └── filters + └── gt [type=bool, outer=(1), constraints=(/1: [/1 - ]; tight)] + ├── variable: a:1 [type=int] + └── const: 0 [type=int] + +opt +SELECT * FROM t2@{FORCE_INDEX=idx_a_partial_invisible, DESC} WHERE a > 2; +---- +index-join t2 + ├── columns: a:1(int!null) b:2(int) c:3(int) + └── select + ├── columns: a:1(int!null) rowid:4(int!null) + ├── key: (4) + ├── fd: (4)-->(1) + ├── scan t2@idx_a_partial_invisible,rev,partial + │ ├── columns: a:1(int!null) rowid:4(int!null) + │ ├── flags: force-index=idx_a_partial_invisible,rev + │ ├── key: (4) + │ └── fd: (4)-->(1) + └── filters + └── gt [type=bool, outer=(1), constraints=(/1: [/3 - ]; tight)] + ├── variable: a:1 [type=int] + └── const: 2 [type=int] + +opt +SELECT a FROM t2@{FORCE_INDEX=idx_a_partial_invisible} WHERE a < 0; +---- +select + ├── columns: a:1(int!null) + ├── scan t2 + │ ├── columns: a:1(int) + │ ├── partial index predicates + │ │ └── idx_a_partial_invisible: filters + │ │ └── gt [type=bool, outer=(1), constraints=(/1: [/1 - ]; tight)] + │ │ ├── variable: a:1 [type=int] + │ │ └── const: 0 [type=int] + │ └── flags: force-index=idx_a_partial_invisible + └── filters + └── lt [type=bool, outer=(1), constraints=(/1: (/NULL - /-1]; tight)] + ├── variable: a:1 [type=int] + └── const: 0 [type=int] + +exec-ddl +CREATE INDEX idx_c_partial_invisible ON t2(c) WHERE a >= b AND c = 3 NOT VISIBLE +---- + +opt +SELECT * FROM t2 WHERE a > b AND c = 3; +---- +select + ├── columns: a:1(int!null) b:2(int!null) c:3(int!null) + ├── fd: ()-->(3) + ├── scan t2 + │ ├── columns: a:1(int) b:2(int) c:3(int) + │ └── partial index predicates + │ ├── idx_a_partial_invisible: filters + │ │ └── gt [type=bool, outer=(1), constraints=(/1: [/1 - ]; tight)] + │ │ ├── variable: a:1 [type=int] + │ │ └── const: 0 [type=int] + │ └── idx_c_partial_invisible: filters + │ ├── ge [type=bool, outer=(1,2), constraints=(/1: (/NULL - ]; /2: (/NULL - ])] + │ │ ├── variable: a:1 [type=int] + │ │ └── variable: b:2 [type=int] + │ └── eq [type=bool, outer=(3), constraints=(/3: [/3 - /3]; tight), fd=()-->(3)] + │ ├── variable: c:3 [type=int] + │ └── const: 3 [type=int] + └── filters + ├── gt [type=bool, outer=(1,2), constraints=(/1: (/NULL - ]; /2: (/NULL - ])] + │ ├── variable: a:1 [type=int] + │ └── variable: b:2 [type=int] + └── eq [type=bool, outer=(3), constraints=(/3: [/3 - /3]; tight), fd=()-->(3)] + ├── variable: c:3 [type=int] + └── const: 3 [type=int] + +opt +SELECT * FROM t2@{FORCE_INDEX=idx_c_partial_invisible} WHERE a > b AND c = 3; +---- +select + ├── columns: a:1(int!null) b:2(int!null) c:3(int!null) + ├── fd: ()-->(3) + ├── index-join t2 + │ ├── columns: a:1(int) b:2(int) c:3(int) + │ ├── fd: ()-->(3) + │ └── scan t2@idx_c_partial_invisible,partial + │ ├── columns: c:3(int!null) rowid:4(int!null) + │ ├── flags: force-index=idx_c_partial_invisible + │ ├── key: (4) + │ └── fd: ()-->(3) + └── filters + └── gt [type=bool, outer=(1,2), constraints=(/1: (/NULL - ]; /2: (/NULL - ])] + ├── variable: a:1 [type=int] + └── variable: b:2 [type=int] + +# The following tests check for inverted index and partial inverted index. +exec-ddl +CREATE TABLE t3 (id INT, data JSONB, geom GEOMETRY, INVERTED INDEX idx_data_invisible(data) WHERE id > 10 NOT VISIBLE); +---- + +opt +SELECT * FROM t3 WHERE data @> '{"foo": "1"}' AND id > 10 +---- +select + ├── columns: id:1(int!null) data:2(jsonb!null) geom:3(geometry) + ├── immutable + ├── scan t3 + │ ├── columns: id:1(int) data:2(jsonb) geom:3(geometry) + │ └── partial index predicates + │ └── idx_data_invisible: filters + │ └── gt [type=bool, outer=(1), constraints=(/1: [/11 - ]; tight)] + │ ├── variable: id:1 [type=int] + │ └── const: 10 [type=int] + └── filters + ├── contains [type=bool, outer=(2), immutable, constraints=(/2: (/NULL - ])] + │ ├── variable: data:2 [type=jsonb] + │ └── const: '{"foo": "1"}' [type=jsonb] + └── gt [type=bool, outer=(1), constraints=(/1: [/11 - ]; tight)] + ├── variable: id:1 [type=int] + └── const: 10 [type=int] + +opt +SELECT * FROM t3@idx_data_invisible WHERE data @> '{"foo": "1"}' AND id > 12 +---- +select + ├── columns: id:1(int!null) data:2(jsonb!null) geom:3(geometry) + ├── immutable + ├── index-join t3 + │ ├── columns: id:1(int) data:2(jsonb) geom:3(geometry) + │ └── scan t3@idx_data_invisible,partial + │ ├── columns: rowid:4(int!null) + │ ├── inverted constraint: /7/4 + │ │ └── spans: ["7foo\x00\x01\x121\x00\x01", "7foo\x00\x01\x121\x00\x01"] + │ ├── flags: force-index=idx_data_invisible + │ └── key: (4) + └── filters + └── gt [type=bool, outer=(1), constraints=(/1: [/13 - ]; tight)] + ├── variable: id:1 [type=int] + └── const: 12 [type=int] + +exec-ddl +CREATE INDEX idx_geom_invisible ON t3 USING GIN (geom) NOT VISIBLE +---- + +opt +SELECT * FROM t3 WHERE st_covers(geom, 'LINESTRING ( 0 0, 0 2 )'::geometry) +---- +select + ├── columns: id:1(int) data:2(jsonb) geom:3(geometry!null) + ├── immutable + ├── scan t3 + │ ├── columns: id:1(int) data:2(jsonb) geom:3(geometry) + │ └── partial index predicates + │ └── idx_data_invisible: filters + │ └── gt [type=bool, outer=(1), constraints=(/1: [/11 - ]; tight)] + │ ├── variable: id:1 [type=int] + │ └── const: 10 [type=int] + └── filters + └── function: st_covers [type=bool, outer=(3), immutable, constraints=(/3: (/NULL - ])] + ├── variable: geom:3 [type=geometry] + └── const: '0102000000020000000000000000000000000000000000000000000000000000000000000000000040' [type=geometry] + +opt +SELECT * FROM t3@idx_geom_invisible WHERE st_covers(geom, 'LINESTRING ( 0 0, 0 2 )'::geometry) +---- +select + ├── columns: id:1(int) data:2(jsonb) geom:3(geometry!null) + ├── immutable + ├── index-join t3 + │ ├── columns: id:1(int) data:2(jsonb) geom:3(geometry) + │ └── inverted-filter + │ ├── columns: rowid:4(int!null) + │ ├── inverted expression: /8 + │ │ ├── tight: false, unique: false + │ │ └── union spans + │ │ ├── ["B\xfd\x10\x00\x00\x00\x00\x00\x00\x00", "B\xfd\x10\x00\x00\x00\x00\x00\x00\x00"] + │ │ ├── ["B\xfd\x11\x00\x00\x00\x00\x00\x00\x00", "B\xfd\x11\x00\x00\x00\x00\x00\x00\x00"] + │ │ └── ["B\xfd\x14\x00\x00\x00\x00\x00\x00\x00", "B\xfd\x14\x00\x00\x00\x00\x00\x00\x00"] + │ ├── pre-filterer expression + │ │ └── function: st_coveredby [type=bool] + │ │ ├── const: '0102000000020000000000000000000000000000000000000000000000000000000000000000000040' [type=geometry] + │ │ └── variable: geom:3 [type=geometry] + │ ├── key: (4) + │ └── scan t3@idx_geom_invisible + │ ├── columns: rowid:4(int!null) geom_inverted_key:8(encodedkey!null) + │ ├── inverted constraint: /8/4 + │ │ └── spans + │ │ ├── ["B\xfd\x10\x00\x00\x00\x00\x00\x00\x00", "B\xfd\x10\x00\x00\x00\x00\x00\x00\x00"] + │ │ ├── ["B\xfd\x11\x00\x00\x00\x00\x00\x00\x00", "B\xfd\x11\x00\x00\x00\x00\x00\x00\x00"] + │ │ └── ["B\xfd\x14\x00\x00\x00\x00\x00\x00\x00", "B\xfd\x14\x00\x00\x00\x00\x00\x00\x00"] + │ ├── flags: force-index=idx_geom_invisible + │ ├── key: (4) + │ └── fd: (4)-->(8) + └── filters + └── function: st_covers [type=bool, outer=(3), immutable, constraints=(/3: (/NULL - ])] + ├── variable: geom:3 [type=geometry] + └── const: '0102000000020000000000000000000000000000000000000000000000000000000000000000000040' [type=geometry] diff --git a/pkg/sql/opt/testutils/testcat/create_index.go b/pkg/sql/opt/testutils/testcat/create_index.go index 25c98279b844..a1d3bbfa5d53 100644 --- a/pkg/sql/opt/testutils/testcat/create_index.go +++ b/pkg/sql/opt/testutils/testcat/create_index.go @@ -38,6 +38,7 @@ func (tc *Catalog) CreateIndex(stmt *tree.CreateIndex, version descpb.IndexDescr Sharded: stmt.Sharded, Storing: stmt.Storing, Inverted: stmt.Inverted, + Hidden: stmt.Hidden, PartitionByIndex: stmt.PartitionByIndex, Predicate: stmt.Predicate, } diff --git a/pkg/sql/opt/testutils/testcat/create_table.go b/pkg/sql/opt/testutils/testcat/create_table.go index 820d7067aa6a..3cf72b3e4cce 100644 --- a/pkg/sql/opt/testutils/testcat/create_table.go +++ b/pkg/sql/opt/testutils/testcat/create_table.go @@ -226,6 +226,9 @@ func (tc *Catalog) CreateTable(stmt *tree.CreateTable) *Table { } else if !def.PrimaryKey { tab.addIndex(&def.IndexTableDef, uniqueIndex) } + if def.Hidden { + panic("a unique index cannot be invisible.") + } case *tree.IndexTableDef: tab.addIndex(def, nonUniqueIndex) @@ -699,6 +702,16 @@ func (tt *Table) addIndex(def *tree.IndexTableDef, typ indexType) *Index { func (tt *Table) addIndexWithVersion( def *tree.IndexTableDef, typ indexType, version descpb.IndexDescriptorVersion, ) *Index { + // Primary index cannot be invisible. Theoretically, this case should never + // happen as adding a primary invisible index is not supported syntactically. + if typ == primaryIndex && def.Hidden { + panic("a primary index cannot be invisible.") + } + + if typ == uniqueIndex && def.Hidden { + panic("a unique index cannot be invisible.") + } + // Add a unique constraint if this is a primary or unique index. if typ != nonUniqueIndex { tt.addUniqueConstraint(def.Name, def.Columns, def.Predicate, false /* withoutIndex */) @@ -711,6 +724,7 @@ func (tt *Table) addIndexWithVersion( IdxZone: cat.EmptyZone(), table: tt, version: version, + Hidden: def.Hidden, } // Look for name suffixes indicating this is a mutation index. diff --git a/pkg/sql/opt/testutils/testcat/test_catalog.go b/pkg/sql/opt/testutils/testcat/test_catalog.go index 983e4804d1a6..7b966023d207 100644 --- a/pkg/sql/opt/testutils/testcat/test_catalog.go +++ b/pkg/sql/opt/testutils/testcat/test_catalog.go @@ -917,6 +917,9 @@ type Index struct { // Inverted is true when this index is an inverted index. Inverted bool + // Hidden is true iff this index is invisible. + Hidden bool + Columns []cat.IndexColumn // IdxZone is the zone associated with the index. This may be inherited from @@ -978,6 +981,11 @@ func (ti *Index) IsInverted() bool { return ti.Inverted } +// IsHidden is part of the cat.Index interface. +func (ti *Index) IsHidden() bool { + return ti.Hidden +} + // ColumnCount is part of the cat.Index interface. func (ti *Index) ColumnCount() int { return len(ti.Columns) diff --git a/pkg/sql/opt/testutils/testcat/testdata/index b/pkg/sql/opt/testutils/testcat/testdata/index index 700cbbadad8b..4f412d86ec2c 100644 --- a/pkg/sql/opt/testutils/testcat/testdata/index +++ b/pkg/sql/opt/testutils/testcat/testdata/index @@ -73,6 +73,10 @@ CREATE TABLE g ( ) ---- +exec-ddl +CREATE INDEX geom_idx ON g USING GIST(geog) WITH (s2_max_cells = 20, s2_max_level = 12, s2_level_mod = 3) NOT VISIBLE +---- + exec-ddl SHOW CREATE g ---- @@ -85,15 +89,19 @@ TABLE g ├── tableoid oid [hidden] [system] ├── geog_inverted_key encodedkey not null [inverted] ├── geog_inverted_key encodedkey not null [inverted] + ├── geog_inverted_key encodedkey not null [inverted] ├── PRIMARY INDEX g_pkey │ └── k int not null ├── INVERTED INDEX g_a_geog_idx │ ├── a int │ ├── geog_inverted_key encodedkey not null [inverted] │ └── k int not null - └── INVERTED INDEX g_a_b_geog_idx - ├── a int - ├── b int + ├── INVERTED INDEX g_a_b_geog_idx + │ ├── a int + │ ├── b int + │ ├── geog_inverted_key encodedkey not null [inverted] + │ └── k int not null + └── INVERTED INDEX geom_idx NOT VISIBLE ├── geog_inverted_key encodedkey not null [inverted] └── k int not null diff --git a/pkg/sql/opt/testutils/testcat/testdata/table b/pkg/sql/opt/testutils/testcat/testdata/table index 23fa4eaad7d2..257b7b5867d0 100644 --- a/pkg/sql/opt/testutils/testcat/testdata/table +++ b/pkg/sql/opt/testutils/testcat/testdata/table @@ -415,3 +415,47 @@ TABLE t76994 │ └── WHERE b < 0 └── UNIQUE WITHOUT INDEX (a) └── WHERE b > 0 + +# The following test cases check for invisible index feature. +exec-ddl +CREATE TABLE t1 (b INT8, c STRING, INDEX (b ASC, c DESC) STORING (c) NOT VISIBLE) +---- + +exec-ddl +SHOW CREATE t1 +---- +TABLE t1 + ├── b int + ├── c string + ├── rowid int not null default (unique_rowid()) [hidden] + ├── crdb_internal_mvcc_timestamp decimal [hidden] [system] + ├── tableoid oid [hidden] [system] + ├── PRIMARY INDEX t1_pkey + │ └── rowid int not null default (unique_rowid()) [hidden] + └── INDEX t1_b_c_idx NOT VISIBLE + ├── b int + ├── c string desc + ├── rowid int not null default (unique_rowid()) [hidden] + └── c string (storing) + +exec-ddl +CREATE TABLE t2 (b INT8, c STRING, INVERTED INDEX (b ASC, c DESC) WHERE c > 3 NOT VISIBLE) +---- + +exec-ddl +SHOW CREATE t2 +---- +TABLE t2 + ├── b int + ├── c string + ├── rowid int not null default (unique_rowid()) [hidden] + ├── crdb_internal_mvcc_timestamp decimal [hidden] [system] + ├── tableoid oid [hidden] [system] + ├── c_inverted_key encodedkey not null [inverted] + ├── PRIMARY INDEX t2_pkey + │ └── rowid int not null default (unique_rowid()) [hidden] + └── INVERTED INDEX t2_b_c_idx NOT VISIBLE + ├── b int + ├── c_inverted_key encodedkey not null [inverted] desc + ├── rowid int not null default (unique_rowid()) [hidden] + └── WHERE c > 3 diff --git a/pkg/sql/opt/xform/scan_index_iter.go b/pkg/sql/opt/xform/scan_index_iter.go index b4d8950b97ed..1361e760dba1 100644 --- a/pkg/sql/opt/xform/scan_index_iter.go +++ b/pkg/sql/opt/xform/scan_index_iter.go @@ -219,12 +219,19 @@ func (it *scanIndexIter) ForEachStartingAfter(ord int, f enumerateIndexFunc) { continue } - // If we are forcing a specific index, ignore all other indexes. - if it.scanPrivate.Flags.ForceIndex && ord != it.scanPrivate.Flags.Index { - continue - } - index := it.tabMeta.Table.Index(ord) + if it.scanPrivate.Flags.ForceIndex { + // If we are forcing a specific index, ignore all other indexes. + if ord != it.scanPrivate.Flags.Index { + continue + } + } else { + // If we are not forcing any specific index, ignore invisible indexes + // only. + if index.IsHidden() { + continue + } + } // Skip over inverted indexes if rejectInvertedIndexes is set. if it.hasRejectFlags(rejectInvertedIndexes) && index.IsInverted() { diff --git a/pkg/sql/opt_catalog.go b/pkg/sql/opt_catalog.go index b310252182d6..329c10cde8be 100644 --- a/pkg/sql/opt_catalog.go +++ b/pkg/sql/opt_catalog.go @@ -1444,6 +1444,11 @@ func (oi *optIndex) IsInverted() bool { return oi.idx.GetType() == descpb.IndexDescriptor_INVERTED } +// IsHidden is part of the cat.Index interface. +func (oi *optIndex) IsHidden() bool { + return oi.idx.IsHidden() +} + // ColumnCount is part of the cat.Index interface. func (oi *optIndex) ColumnCount() int { return oi.numCols @@ -2213,6 +2218,11 @@ func (oi *optVirtualIndex) IsInverted() bool { return false } +// IsHidden is part of the cat.Index interface. +func (oi *optVirtualIndex) IsHidden() bool { + return false +} + // ExplicitColumnCount is part of the cat.Index interface. func (oi *optVirtualIndex) ExplicitColumnCount() int { return oi.idx.NumKeyColumns() diff --git a/pkg/sql/parser/sql.y b/pkg/sql/parser/sql.y index 1a139bef888c..4e5b672387ff 100644 --- a/pkg/sql/parser/sql.y +++ b/pkg/sql/parser/sql.y @@ -1004,6 +1004,7 @@ func (u *sqlSymUnion) asTenantClause() tree.TenantID { %type alter_rename_index_stmt %type alter_relocate_index_stmt %type alter_zone_index_stmt +%type alter_index_visible_stmt // ALTER VIEW %type alter_rename_view_stmt @@ -1220,6 +1221,7 @@ func (u *sqlSymUnion) asTenantClause() tree.TenantID { %type alter_table_cmds %type alter_index_cmd %type alter_index_cmds +%type alter_index_visible %type opt_drop_behavior @@ -1331,7 +1333,7 @@ func (u *sqlSymUnion) asTenantClause() tree.TenantID { %type overlay_placing %type opt_unique opt_concurrently opt_cluster opt_without_index -%type opt_index_access_method +%type opt_index_access_method opt_index_hidden %type <*tree.Limit> limit_clause offset_clause opt_limit_clause %type select_fetch_first_value @@ -1959,6 +1961,7 @@ alter_index_stmt: | alter_scatter_index_stmt | alter_rename_index_stmt | alter_zone_index_stmt +| alter_index_visible_stmt // ALTER INDEX has its error help token here because the ALTER INDEX // prefix is spread over multiple non-terminals. | ALTER INDEX error // SHOW HELP: ALTER INDEX @@ -7748,7 +7751,7 @@ generated_by_default_as: GENERATED_BY_DEFAULT BY DEFAULT AS {} index_def: - INDEX opt_index_name '(' index_params ')' opt_hash_sharded opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause + INDEX opt_index_name '(' index_params ')' opt_hash_sharded opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause opt_index_hidden { $$.val = &tree.IndexTableDef{ Name: tree.Name($2), @@ -7758,9 +7761,10 @@ index_def: PartitionByIndex: $8.partitionByIndex(), StorageParams: $9.storageParams(), Predicate: $10.expr(), + Hidden: $11.bool(), } } -| UNIQUE INDEX opt_index_name '(' index_params ')' opt_hash_sharded opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause +| UNIQUE INDEX opt_index_name '(' index_params ')' opt_hash_sharded opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause opt_index_hidden { $$.val = &tree.UniqueConstraintTableDef{ IndexTableDef: tree.IndexTableDef { @@ -7771,10 +7775,11 @@ index_def: PartitionByIndex: $9.partitionByIndex(), StorageParams: $10.storageParams(), Predicate: $11.expr(), + Hidden: $12.bool(), }, } } -| INVERTED INDEX opt_name '(' index_params ')' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause +| INVERTED INDEX opt_name '(' index_params ')' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause opt_index_hidden { $$.val = &tree.IndexTableDef{ Name: tree.Name($3), @@ -7783,6 +7788,7 @@ index_def: PartitionByIndex: $7.partitionByIndex(), StorageParams: $8.storageParams(), Predicate: $9.expr(), + Hidden: $10.bool(), } } @@ -8622,7 +8628,7 @@ enum_val_list: // %SeeAlso: CREATE TABLE, SHOW INDEXES, SHOW CREATE, // WEBDOCS/create-index.html create_index_stmt: - CREATE opt_unique INDEX opt_concurrently opt_index_name ON table_name opt_index_access_method '(' index_params ')' opt_hash_sharded opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause + CREATE opt_unique INDEX opt_concurrently opt_index_name ON table_name opt_index_access_method '(' index_params ')' opt_hash_sharded opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause opt_index_hidden { table := $7.unresolvedObjectName().ToTableName() $$.val = &tree.CreateIndex{ @@ -8637,9 +8643,10 @@ create_index_stmt: Predicate: $16.expr(), Inverted: $8.bool(), Concurrently: $4.bool(), + Hidden: $17.bool(), } } -| CREATE opt_unique INDEX opt_concurrently IF NOT EXISTS index_name ON table_name opt_index_access_method '(' index_params ')' opt_hash_sharded opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause +| CREATE opt_unique INDEX opt_concurrently IF NOT EXISTS index_name ON table_name opt_index_access_method '(' index_params ')' opt_hash_sharded opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause opt_index_hidden { table := $10.unresolvedObjectName().ToTableName() $$.val = &tree.CreateIndex{ @@ -8655,9 +8662,10 @@ create_index_stmt: StorageParams: $18.storageParams(), Predicate: $19.expr(), Concurrently: $4.bool(), + Hidden: $20.bool(), } } -| CREATE opt_unique INVERTED INDEX opt_concurrently opt_index_name ON table_name '(' index_params ')' opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause +| CREATE opt_unique INVERTED INDEX opt_concurrently opt_index_name ON table_name '(' index_params ')' opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause opt_index_hidden { table := $8.unresolvedObjectName().ToTableName() $$.val = &tree.CreateIndex{ @@ -8671,9 +8679,10 @@ create_index_stmt: StorageParams: $14.storageParams(), Predicate: $15.expr(), Concurrently: $5.bool(), + Hidden: $16.bool(), } } -| CREATE opt_unique INVERTED INDEX opt_concurrently IF NOT EXISTS index_name ON table_name '(' index_params ')' opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause +| CREATE opt_unique INVERTED INDEX opt_concurrently IF NOT EXISTS index_name ON table_name '(' index_params ')' opt_storing opt_partition_by_index opt_with_storage_parameter_list opt_where_clause opt_index_hidden { table := $11.unresolvedObjectName().ToTableName() $$.val = &tree.CreateIndex{ @@ -8688,6 +8697,7 @@ create_index_stmt: StorageParams: $17.storageParams(), Predicate: $18.expr(), Concurrently: $5.bool(), + Hidden: $19.bool(), } } | CREATE opt_unique INDEX error // SHOW HELP: CREATE INDEX @@ -8807,6 +8817,20 @@ opt_asc_desc: $$.val = tree.DefaultDirection } +opt_index_hidden: + NOT VISIBLE + { + $$.val = true + } +| VISIBLE + { + $$.val = false + } +| /* EMPTY */ + { + $$.val = false + } + alter_database_to_schema_stmt: ALTER DATABASE database_name CONVERT TO SCHEMA WITH PARENT database_name { @@ -9112,6 +9136,26 @@ alter_rename_index_stmt: $$.val = &tree.RenameIndex{Index: $5.newTableIndexName(), NewName: tree.UnrestrictedName($8), IfExists: true} } +alter_index_visible_stmt: + ALTER INDEX table_index_name alter_index_visible + { + $$.val = &tree.AlterIndexVisible{Index: $3.newTableIndexName(), Hidden: $4.bool(), IfExists: false} + } +| ALTER INDEX IF EXISTS table_index_name alter_index_visible + { + $$.val = &tree.AlterIndexVisible{Index: $5.newTableIndexName(), Hidden: $6.bool(), IfExists: true} + } + +alter_index_visible: + NOT VISIBLE + { + $$.val = true + } +| VISIBLE + { + $$.val = false + } + // %Help: ALTER DEFAULT PRIVILEGES - alter default privileges on an object // %Category: DDL // %Text: diff --git a/pkg/sql/parser/testdata/alter_table b/pkg/sql/parser/testdata/alter_table index bb29bafeebf9..9a6cb106352b 100644 --- a/pkg/sql/parser/testdata/alter_table +++ b/pkg/sql/parser/testdata/alter_table @@ -1243,3 +1243,43 @@ at or near "EOF": syntax error: identity column type must be an INT DETAIL: source SQL: ALTER TABLE a ADD COLUMN b VARCHAR(12) GENERATED BY DEFAULT AS IDENTITY ^ + +################################################################################ +# The following test cases check to make sure unique constraints cannot be added +# with invisible index. +################################################################################ +error +ALTER TABLE a ADD CONSTRAINT a_idx UNIQUE (a) NOT VISIBLE +---- +at or near "visible": syntax error +DETAIL: source SQL: +ALTER TABLE a ADD CONSTRAINT a_idx UNIQUE (a) NOT VISIBLE + ^ +HINT: try \h ALTER TABLE + +error +ALTER TABLE a ADD CONSTRAINT IF NOT EXISTS a_idx UNIQUE (a) NOT VISIBLE +---- +at or near "visible": syntax error +DETAIL: source SQL: +ALTER TABLE a ADD CONSTRAINT IF NOT EXISTS a_idx UNIQUE (a) NOT VISIBLE + ^ +HINT: try \h ALTER TABLE + +error +ALTER TABLE IF EXISTS a ADD COLUMN b INT8 UNIQUE INDEX NOT VISIBLE, ADD CONSTRAINT a_no_idx UNIQUE (a) NOT VISIBLE +---- +at or near "index": syntax error +DETAIL: source SQL: +ALTER TABLE IF EXISTS a ADD COLUMN b INT8 UNIQUE INDEX NOT VISIBLE, ADD CONSTRAINT a_no_idx UNIQUE (a) NOT VISIBLE + ^ + +error +ALTER TABLE IF EXISTS a ADD COLUMN b INT8 UNIQUE WITH INVISIBLE INDEX, ADD CONSTRAINT a_no_idx UNIQUE WITH INVISIBLE INDEX (a) +---- +at or near "with": syntax error +DETAIL: source SQL: +ALTER TABLE IF EXISTS a ADD COLUMN b INT8 UNIQUE WITH INVISIBLE INDEX, ADD CONSTRAINT a_no_idx UNIQUE WITH INVISIBLE INDEX (a) + ^ + +##################################################################################### diff --git a/pkg/sql/parser/testdata/create_index b/pkg/sql/parser/testdata/create_index index 9d66f02fa74f..27e5ef6e8201 100644 --- a/pkg/sql/parser/testdata/create_index +++ b/pkg/sql/parser/testdata/create_index @@ -379,3 +379,64 @@ CREATE INVERTED INDEX ON a ((ARRAY[a, b])) CREATE INVERTED INDEX ON a (((ARRAY[(a), (b)]))) -- fully parenthesized CREATE INVERTED INDEX ON a ((ARRAY[a, b])) -- literals removed CREATE INVERTED INDEX ON _ ((ARRAY[_, _])) -- identifiers removed + +# The following test cases check for invisible index feature. +parse +CREATE INDEX a ON b (c) VISIBLE +---- +CREATE INDEX a ON b (c) -- normalized! +CREATE INDEX a ON b (c) -- fully parenthesized +CREATE INDEX a ON b (c) -- literals removed +CREATE INDEX _ ON _ (_) -- identifiers removed + +parse +CREATE INDEX a ON b.c (d) NOT VISIBLE +---- +CREATE INDEX a ON b.c (d) NOT VISIBLE +CREATE INDEX a ON b.c (d) NOT VISIBLE -- fully parenthesized +CREATE INDEX a ON b.c (d) NOT VISIBLE -- literals removed +CREATE INDEX _ ON _._ (_) NOT VISIBLE -- identifiers removed + +parse +CREATE INDEX ON a ((ARRAY[a, b])) STORING (c, d) NOT VISIBLE +---- +CREATE INDEX ON a ((ARRAY[a, b])) STORING (c, d) NOT VISIBLE +CREATE INDEX ON a (((ARRAY[(a), (b)]))) STORING (c, d) NOT VISIBLE -- fully parenthesized +CREATE INDEX ON a ((ARRAY[a, b])) STORING (c, d) NOT VISIBLE -- literals removed +CREATE INDEX ON _ ((ARRAY[_, _])) STORING (_, _) NOT VISIBLE -- identifiers removed + +parse +CREATE INDEX a ON b (c) WITH (fillfactor = 100, y_bounds = 50) NOT VISIBLE +---- +CREATE INDEX a ON b (c) WITH (fillfactor = 100, y_bounds = 50) NOT VISIBLE +CREATE INDEX a ON b (c) WITH (fillfactor = (100), y_bounds = (50)) NOT VISIBLE -- fully parenthesized +CREATE INDEX a ON b (c) WITH (fillfactor = _, y_bounds = _) NOT VISIBLE -- literals removed +CREATE INDEX _ ON _ (_) WITH (_ = 100, _ = 50) NOT VISIBLE -- identifiers removed + +error +CREATE UNIQUE INDEX idx ON a (((lower(a) || ' ') || lower(b))) NOT VISIBLE +---- + +parse +CREATE INVERTED INDEX IF NOT EXISTS a ON b (c) WHERE d > 3 VISIBLE +---- +CREATE INVERTED INDEX IF NOT EXISTS a ON b (c) WHERE d > 3 -- normalized! +CREATE INVERTED INDEX IF NOT EXISTS a ON b (c) WHERE ((d) > (3)) -- fully parenthesized +CREATE INVERTED INDEX IF NOT EXISTS a ON b (c) WHERE d > _ -- literals removed +CREATE INVERTED INDEX IF NOT EXISTS _ ON _ (_) WHERE _ > 3 -- identifiers removed + +parse +CREATE INDEX geom_idx_2 ON some_spatial_table USING GIST(geom) WITH (s2_max_cells = 20, s2_max_level = 12, s2_level_mod = 3) NOT VISIBLE +---- +CREATE INVERTED INDEX geom_idx_2 ON some_spatial_table (geom) WITH (s2_max_cells = 20, s2_max_level = 12, s2_level_mod = 3) NOT VISIBLE -- normalized! +CREATE INVERTED INDEX geom_idx_2 ON some_spatial_table (geom) WITH (s2_max_cells = (20), s2_max_level = (12), s2_level_mod = (3)) NOT VISIBLE -- fully parenthesized +CREATE INVERTED INDEX geom_idx_2 ON some_spatial_table (geom) WITH (s2_max_cells = _, s2_max_level = _, s2_level_mod = _) NOT VISIBLE -- literals removed +CREATE INVERTED INDEX _ ON _ (_) WITH (_ = 20, _ = 12, _ = 3) NOT VISIBLE -- identifiers removed + +parse +CREATE UNIQUE INDEX IF NOT EXISTS a ON b (c) WHERE d > 3 NOT VISIBLE +---- +CREATE UNIQUE INDEX IF NOT EXISTS a ON b (c) WHERE d > 3 NOT VISIBLE +CREATE UNIQUE INDEX IF NOT EXISTS a ON b (c) WHERE ((d) > (3)) NOT VISIBLE -- fully parenthesized +CREATE UNIQUE INDEX IF NOT EXISTS a ON b (c) WHERE d > _ NOT VISIBLE -- literals removed +CREATE UNIQUE INDEX IF NOT EXISTS _ ON _ (_) WHERE _ > 3 NOT VISIBLE -- identifiers removed diff --git a/pkg/sql/parser/testdata/create_table b/pkg/sql/parser/testdata/create_table index fc054a7e608b..31dd01f4251e 100644 --- a/pkg/sql/parser/testdata/create_table +++ b/pkg/sql/parser/testdata/create_table @@ -2406,3 +2406,84 @@ CREATE TABLE visible (visible INT4) CREATE TABLE visible (visible INT4) -- fully parenthesized CREATE TABLE visible (visible INT4) -- literals removed CREATE TABLE _ (_ INT4) -- identifiers removed + +# The following test cases check for invisible index feature. +parse +CREATE TABLE a (b INT8, c STRING, INDEX (b ASC, c DESC) STORING (c) NOT VISIBLE) +---- +CREATE TABLE a (b INT8, c STRING, INDEX (b ASC, c DESC) STORING (c) NOT VISIBLE) +CREATE TABLE a (b INT8, c STRING, INDEX (b ASC, c DESC) STORING (c) NOT VISIBLE) -- fully parenthesized +CREATE TABLE a (b INT8, c STRING, INDEX (b ASC, c DESC) STORING (c) NOT VISIBLE) -- literals removed +CREATE TABLE _ (_ INT8, _ STRING, INDEX (_ ASC, _ DESC) STORING (_) NOT VISIBLE) -- identifiers removed + +parse +CREATE TABLE a (b INT8, c STRING, INVERTED INDEX (b ASC, c DESC) WHERE c > 3 NOT VISIBLE) +---- +CREATE TABLE a (b INT8, c STRING, INVERTED INDEX (b ASC, c DESC) WHERE c > 3 NOT VISIBLE) +CREATE TABLE a (b INT8, c STRING, INVERTED INDEX (b ASC, c DESC) WHERE ((c) > (3)) NOT VISIBLE) -- fully parenthesized +CREATE TABLE a (b INT8, c STRING, INVERTED INDEX (b ASC, c DESC) WHERE c > _ NOT VISIBLE) -- literals removed +CREATE TABLE _ (_ INT8, _ STRING, INVERTED INDEX (_ ASC, _ DESC) WHERE _ > 3 NOT VISIBLE) -- identifiers removed + +# The following test cases make sure that a unique index or a unique constraint cannot be invisible. +# TODO(wenyihu6): check how we want to change the parser for invisible unique index semantic error. +error +CREATE TABLE a (b INT, UNIQUE INDEX foo (b) WHERE c > 3 NOT VISIBLE) +---- + +error +CREATE TABLE a (UNIQUE INDEX (b) PARTITION BY LIST (c) (PARTITION d VALUES IN (1)) NOT VISIBLE) +---- + +error +CREATE TABLE a (b INT8, c STRING, CONSTRAINT d UNIQUE WITH INVISIBLE INDEX (b, c)) +---- +at or near "with": syntax error +DETAIL: source SQL: +CREATE TABLE a (b INT8, c STRING, CONSTRAINT d UNIQUE WITH INVISIBLE INDEX (b, c)) + ^ +HINT: try \h CREATE TABLE + +error +CREATE TABLE a (b INT8, c STRING, CONSTRAINT d UNIQUE (b, c) NOT VISIBLE) +---- +at or near "visible": syntax error +DETAIL: source SQL: +CREATE TABLE a (b INT8, c STRING, CONSTRAINT d UNIQUE (b, c) NOT VISIBLE) + ^ +HINT: try \h CREATE TABLE + +error +CREATE TABLE a (b INT8, c STRING, CONSTRAINT d UNIQUE INDEX (b) NOT VISIBLE) +---- +at or near "index": syntax error +DETAIL: source SQL: +CREATE TABLE a (b INT8, c STRING, CONSTRAINT d UNIQUE INDEX (b) NOT VISIBLE) + ^ +HINT: try \h CREATE TABLE + +error +CREATE TABLE a (b INT8, c STRING, CONSTRAINT d INDEX (b) NOT VISIBLE) +---- +at or near "index": syntax error +DETAIL: source SQL: +CREATE TABLE a (b INT8, c STRING, CONSTRAINT d INDEX (b) NOT VISIBLE) + ^ +HINT: try \h CREATE TABLE + +# The following test cases make sure that a primary index cannot be invisible. +error +CREATE TABLE a (b INT8 PRIMARY KEY NOT VISIBLE) +---- + +error +CREATE TABLE a (b INT8, c STRING, PRIMARY KEY (b, c, "0") NOT VISIBLE) +---- +at or near "visible": syntax error +DETAIL: source SQL: +CREATE TABLE a (b INT8, c STRING, PRIMARY KEY (b, c, "0") NOT VISIBLE) + ^ +HINT: try \h CREATE TABLE + +# TODO (wenyihu6): change the parser later on to give more user-friendly error +# when primary key constriant is used with invisible index. +--- empty --- diff --git a/pkg/sql/pgwire/pgwire_test.go b/pkg/sql/pgwire/pgwire_test.go index b7128bd9f881..af15750ea276 100644 --- a/pkg/sql/pgwire/pgwire_test.go +++ b/pkg/sql/pgwire/pgwire_test.go @@ -560,9 +560,9 @@ func TestPGPreparedQuery(t *testing.T) { Results("system", "public", "users", username.RootUser, "UPDATE", true), }}, {"SHOW INDEXES FROM system.users", []preparedQueryTest{ - baseTest.Results("users", "primary", false, 1, "username", "ASC", false, false). - Results("users", "primary", false, 2, "hashedPassword", "N/A", true, false). - Results("users", "primary", false, 3, "isRole", "N/A", true, false), + baseTest.Results("users", "primary", false, 1, "username", "ASC", false, false, false). + Results("users", "primary", false, 2, "hashedPassword", "N/A", true, false, false). + Results("users", "primary", false, 3, "isRole", "N/A", true, false, false), }}, {"SHOW TABLES FROM system", []preparedQueryTest{ baseTest.Results("public", "comments", "table", gosql.NullString{}, 0, gosql.NullString{}).Others(37), diff --git a/pkg/sql/plan.go b/pkg/sql/plan.go index 363cab04a204..eb46ded97f53 100644 --- a/pkg/sql/plan.go +++ b/pkg/sql/plan.go @@ -147,6 +147,7 @@ type planNodeReadingOwnWrites interface { } var _ planNode = &alterIndexNode{} +var _ planNode = &alterIndexVisibleNode{} var _ planNode = &alterSchemaNode{} var _ planNode = &alterSequenceNode{} var _ planNode = &alterTableNode{} diff --git a/pkg/sql/plan_opt.go b/pkg/sql/plan_opt.go index 9cf9d7c4e202..f49f87695fd1 100644 --- a/pkg/sql/plan_opt.go +++ b/pkg/sql/plan_opt.go @@ -57,7 +57,7 @@ func (p *planner) prepareUsingOptimizer(ctx context.Context) (planFlags, error) opc.reset() switch t := stmt.AST.(type) { - case *tree.AlterIndex, *tree.AlterTable, *tree.AlterSequence, + case *tree.AlterIndex, *tree.AlterTable, *tree.AlterSequence, *tree.AlterIndexVisible, *tree.Analyze, *tree.BeginTransaction, *tree.CommentOnColumn, *tree.CommentOnConstraint, *tree.CommentOnDatabase, *tree.CommentOnIndex, *tree.CommentOnTable, *tree.CommentOnSchema, diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_add_column.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_add_column.go index 2b76cbf1bb9e..c08592e8918b 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_add_column.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_add_column.go @@ -589,6 +589,7 @@ func addSecondaryIndexTargetsForAddColumn( IsUnique: desc.Unique, IsInverted: desc.Type == descpb.IndexDescriptor_INVERTED, SourceIndexID: newPrimaryIdx.IndexID, + IsHidden: false, } tempIndexID := index.IndexID + 1 // this is enforced below index.TemporaryIndexID = tempIndexID diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/create_index.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/create_index.go index eabf1175064d..5fc0d1b1fddb 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/create_index.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/create_index.go @@ -43,6 +43,7 @@ func CreateIndex(b BuildCtx, n *tree.CreateIndex) { IsUnique: n.Unique, IsInverted: n.Inverted, IsConcurrently: n.Concurrently, + IsHidden: n.Hidden, } var relation scpb.Element var source *scpb.PrimaryIndex @@ -105,6 +106,12 @@ func CreateIndex(b BuildCtx, n *tree.CreateIndex) { panic(pgerror.Newf(pgcode.WrongObjectType, "%q is not an indexable table or a materialized view", n.Table.ObjectName)) } + + if index.IsUnique && index.IsHidden { + panic(pgerror.Newf(pgcode.FeatureNotSupported, + "invisible unique index is currently not supported.")) + } + // Resolve the index name and make sure it doesn't exist yet. { indexElements := b.ResolveIndex(index.TableID, n.Name, ResolveParams{ diff --git a/pkg/sql/schemachanger/scdecomp/decomp.go b/pkg/sql/schemachanger/scdecomp/decomp.go index 8706af026acf..94e2aef85c1a 100644 --- a/pkg/sql/schemachanger/scdecomp/decomp.go +++ b/pkg/sql/schemachanger/scdecomp/decomp.go @@ -456,6 +456,7 @@ func (w *walkCtx) walkIndex(tbl catalog.TableDescriptor, idx catalog.Index) { IsInverted: idx.GetType() == descpb.IndexDescriptor_INVERTED, IsCreatedExplicitly: idx.IsCreatedExplicitly(), ConstraintID: idx.GetConstraintID(), + IsHidden: idx.IsHidden(), } for i, c := range cpy.KeyColumnIDs { w.ev(scpb.Status_PUBLIC, &scpb.IndexColumn{ diff --git a/pkg/sql/schemachanger/scdecomp/testdata/sequence b/pkg/sql/schemachanger/scdecomp/testdata/sequence index 1345d8ed4094..0b16b2fcdc86 100644 --- a/pkg/sql/schemachanger/scdecomp/testdata/sequence +++ b/pkg/sql/schemachanger/scdecomp/testdata/sequence @@ -143,6 +143,7 @@ ElementState: indexId: 1 isConcurrently: false isCreatedExplicitly: false + isHidden: false isInverted: false isUnique: true sharding: null @@ -427,6 +428,7 @@ ElementState: indexId: 1 isConcurrently: false isCreatedExplicitly: false + isHidden: false isInverted: false isUnique: true sharding: null diff --git a/pkg/sql/schemachanger/scdecomp/testdata/table b/pkg/sql/schemachanger/scdecomp/testdata/table index e2b92805ca77..c9e1be61a0d7 100644 --- a/pkg/sql/schemachanger/scdecomp/testdata/table +++ b/pkg/sql/schemachanger/scdecomp/testdata/table @@ -64,6 +64,7 @@ ElementState: indexId: 1 isConcurrently: false isCreatedExplicitly: false + isHidden: false isInverted: false isUnique: true sharding: null @@ -275,6 +276,7 @@ ElementState: indexId: 1 isConcurrently: false isCreatedExplicitly: false + isHidden: false isInverted: false isUnique: true sharding: null @@ -288,6 +290,7 @@ ElementState: indexId: 2 isConcurrently: false isCreatedExplicitly: false + isHidden: false isInverted: false isUnique: false sharding: null @@ -651,6 +654,7 @@ ElementState: indexId: 1 isConcurrently: false isCreatedExplicitly: false + isHidden: false isInverted: false isUnique: true sharding: null @@ -897,6 +901,7 @@ ElementState: indexId: 1 isConcurrently: false isCreatedExplicitly: false + isHidden: false isInverted: false isUnique: true sharding: null diff --git a/pkg/sql/schemachanger/scdecomp/testdata/type b/pkg/sql/schemachanger/scdecomp/testdata/type index fabcbff7f3f2..16271645ec08 100644 --- a/pkg/sql/schemachanger/scdecomp/testdata/type +++ b/pkg/sql/schemachanger/scdecomp/testdata/type @@ -153,6 +153,7 @@ ElementState: indexId: 1 isConcurrently: false isCreatedExplicitly: false + isHidden: false isInverted: false isUnique: true sharding: null @@ -166,6 +167,7 @@ ElementState: indexId: 2 isConcurrently: false isCreatedExplicitly: false + isHidden: false isInverted: false isUnique: false sharding: null diff --git a/pkg/sql/schemachanger/scexec/scmutationexec/index.go b/pkg/sql/schemachanger/scexec/scmutationexec/index.go index db1936fe32cf..373a5be8b716 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/index.go +++ b/pkg/sql/schemachanger/scexec/scmutationexec/index.go @@ -79,6 +79,7 @@ func addNewIndexMutation( ID: opIndex.IndexID, Name: tabledesc.IndexNamePlaceholder(opIndex.IndexID), Unique: opIndex.IsUnique, + Hidden: opIndex.IsHidden, Version: indexVersion, Type: indexType, CreatedExplicitly: true, diff --git a/pkg/sql/schemachanger/scpb/elements.proto b/pkg/sql/schemachanger/scpb/elements.proto index 12e784505130..bf9cd28f176a 100644 --- a/pkg/sql/schemachanger/scpb/elements.proto +++ b/pkg/sql/schemachanger/scpb/elements.proto @@ -210,6 +210,9 @@ message Index { bool is_concurrently = 20; uint32 source_index_id = 21 [(gogoproto.customname) = "SourceIndexID", (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sem/catid.IndexID"]; uint32 temporary_index_id = 22 [(gogoproto.customname) = "TemporaryIndexID", (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sem/catid.IndexID"]; + + // IsHidden specifies whether this index is invisible. + bool is_hidden = 23; reserved 3, 4, 5, 6, 7; } diff --git a/pkg/sql/sem/tree/alter_index.go b/pkg/sql/sem/tree/alter_index.go index e7f68df8c27c..78a42b06669c 100644 --- a/pkg/sql/sem/tree/alter_index.go +++ b/pkg/sql/sem/tree/alter_index.go @@ -64,3 +64,25 @@ type AlterIndexPartitionBy struct { func (node *AlterIndexPartitionBy) Format(ctx *FmtCtx) { ctx.FormatNode(node.PartitionByIndex) } + +// AlterIndexVisible represents a ALTER INDEX statement. +type AlterIndexVisible struct { + Index *TableIndexName + IfExists bool + Hidden bool +} + +// Format implements the NodeFormatter interface. +func (node *AlterIndexVisible) Format(ctx *FmtCtx) { + ctx.WriteString("ALTER INDEX ") + if node.IfExists { + ctx.WriteString("IF EXISTS ") + } + ctx.FormatNode(node.Index) + ctx.WriteString(" ") + if node.Hidden { + ctx.WriteString(" NOT VISIBLE") + } else { + ctx.WriteString(" VISIBLE") + } +} diff --git a/pkg/sql/sem/tree/create.go b/pkg/sql/sem/tree/create.go index 9a95962577a8..65ff142473e3 100644 --- a/pkg/sql/sem/tree/create.go +++ b/pkg/sql/sem/tree/create.go @@ -225,6 +225,7 @@ type CreateIndex struct { IfNotExists bool Columns IndexElemList Sharded *ShardedIndexDef + Hidden bool // Extra columns to be stored together with the indexed ones as an optimization // for improved reading performance. Storing NameList @@ -283,6 +284,9 @@ func (node *CreateIndex) Format(ctx *FmtCtx) { ctx.WriteString(" WHERE ") ctx.FormatNode(node.Predicate) } + if node.Hidden { + ctx.WriteString(" NOT VISIBLE") + } } // CreateTypeVariety represents a particular variety of user defined types. @@ -978,6 +982,7 @@ type IndexTableDef struct { PartitionByIndex *PartitionByIndex StorageParams StorageParams Predicate Expr + Hidden bool } // Format implements the NodeFormatter interface. @@ -1013,6 +1018,9 @@ func (node *IndexTableDef) Format(ctx *FmtCtx) { ctx.WriteString(" WHERE ") ctx.FormatNode(node.Predicate) } + if node.Hidden { + ctx.WriteString(" NOT VISIBLE") + } } // ConstraintTableDef represents a constraint definition within a CREATE TABLE diff --git a/pkg/sql/sem/tree/pretty.go b/pkg/sql/sem/tree/pretty.go index 31bfc8e9b475..beb94affe476 100644 --- a/pkg/sql/sem/tree/pretty.go +++ b/pkg/sql/sem/tree/pretty.go @@ -1603,6 +1603,7 @@ func (node *CreateIndex) doc(p *PrettyCfg) pretty.Doc { // [PARTITION BY ...] // [WITH ...] // [WHERE ...] + // [NOT VISIBLE] // title := make([]pretty.Doc, 0, 6) title = append(title, pretty.Keyword("CREATE")) @@ -1652,6 +1653,9 @@ func (node *CreateIndex) doc(p *PrettyCfg) pretty.Doc { if node.Predicate != nil { clauses = append(clauses, p.nestUnder(pretty.Keyword("WHERE"), p.Doc(node.Predicate))) } + if node.Hidden { + clauses = append(clauses, pretty.Keyword(" NOT VISIBLE")) + } return p.nestUnder( pretty.Fold(pretty.ConcatSpace, title...), pretty.Group(pretty.Stack(clauses...))) @@ -1689,6 +1693,7 @@ func (node *IndexTableDef) doc(p *PrettyCfg) pretty.Doc { // [INTERLEAVE ...] // [PARTITION BY ...] // [WHERE ...] + // [NOT VISIBLE] // title := pretty.Keyword("INDEX") if node.Name != "" { @@ -1721,6 +1726,9 @@ func (node *IndexTableDef) doc(p *PrettyCfg) pretty.Doc { if node.Predicate != nil { clauses = append(clauses, p.nestUnder(pretty.Keyword("WHERE"), p.Doc(node.Predicate))) } + if node.Hidden { + clauses = append(clauses, pretty.Keyword(" NOT VISIBLE")) + } if len(clauses) == 0 { return title @@ -1736,6 +1744,7 @@ func (node *UniqueConstraintTableDef) doc(p *PrettyCfg) pretty.Doc { // [INTERLEAVE ...] // [PARTITION BY ...] // [WHERE ...] + // [NOT VISIBLE] // // or (no constraint name): // @@ -1744,6 +1753,7 @@ func (node *UniqueConstraintTableDef) doc(p *PrettyCfg) pretty.Doc { // [INTERLEAVE ...] // [PARTITION BY ...] // [WHERE ...] + // [NOT VISIBLE] // clauses := make([]pretty.Doc, 0, 5) var title pretty.Doc @@ -1776,6 +1786,9 @@ func (node *UniqueConstraintTableDef) doc(p *PrettyCfg) pretty.Doc { if node.Predicate != nil { clauses = append(clauses, p.nestUnder(pretty.Keyword("WHERE"), p.Doc(node.Predicate))) } + if node.Hidden { + clauses = append(clauses, pretty.Keyword(" NOT VISIBLE")) + } if len(clauses) == 0 { return title diff --git a/pkg/sql/sem/tree/stmt.go b/pkg/sql/sem/tree/stmt.go index 9c703d9bd973..cc6a54569ee4 100644 --- a/pkg/sql/sem/tree/stmt.go +++ b/pkg/sql/sem/tree/stmt.go @@ -321,6 +321,17 @@ func (*AlterIndex) StatementTag() string { return "ALTER INDEX" } func (*AlterIndex) hiddenFromShowQueries() {} +// StatementReturnType implements the Statement interface. +func (*AlterIndexVisible) StatementReturnType() StatementReturnType { return DDL } + +// StatementType implements the Statement interface. +func (*AlterIndexVisible) StatementType() StatementType { return TypeDDL } + +// StatementTag returns a short string identifying the type of statement. +func (*AlterIndexVisible) StatementTag() string { return "ALTER INDEX VISIBILITY" } + +func (*AlterIndexVisible) hiddenFromShowQueries() {} + // StatementReturnType implements the Statement interface. func (*AlterTable) StatementReturnType() StatementReturnType { return DDL } @@ -1782,7 +1793,6 @@ func (*ValuesClause) StatementTag() string { return "VALUES" } func (n *AlterChangefeed) String() string { return AsString(n) } func (n *AlterChangefeedCmds) String() string { return AsString(n) } func (n *AlterBackup) String() string { return AsString(n) } -func (n *AlterIndex) String() string { return AsString(n) } func (n *AlterDatabaseOwner) String() string { return AsString(n) } func (n *AlterDatabaseAddRegion) String() string { return AsString(n) } func (n *AlterDatabaseDropRegion) String() string { return AsString(n) } @@ -1793,6 +1803,8 @@ func (n *AlterDatabaseAddSuperRegion) String() string { return AsString(n) } func (n *AlterDatabaseDropSuperRegion) String() string { return AsString(n) } func (n *AlterDatabaseAlterSuperRegion) String() string { return AsString(n) } func (n *AlterDefaultPrivileges) String() string { return AsString(n) } +func (n *AlterIndex) String() string { return AsString(n) } +func (n *AlterIndexVisible) String() string { return AsString(n) } func (n *AlterSchema) String() string { return AsString(n) } func (n *AlterTable) String() string { return AsString(n) } func (n *AlterTableCmds) String() string { return AsString(n) } diff --git a/pkg/sql/walk.go b/pkg/sql/walk.go index 5365477a3e4a..037c8ec2b98d 100644 --- a/pkg/sql/walk.go +++ b/pkg/sql/walk.go @@ -334,130 +334,130 @@ func nodeName(plan planNode) string { // strings are constant and not precomputed so that the type names can // be changed without changing the output of "EXPLAIN". var planNodeNames = map[reflect.Type]string{ - reflect.TypeOf(&alterDatabaseOwnerNode{}): "alter database owner", - reflect.TypeOf(&alterDatabaseAddRegionNode{}): "alter database add region", - reflect.TypeOf(&alterDatabasePrimaryRegionNode{}): "alter database primary region", - reflect.TypeOf(&alterDatabasePlacementNode{}): "alter database placement", - reflect.TypeOf(&alterDatabaseSurvivalGoalNode{}): "alter database survive", - reflect.TypeOf(&alterDatabaseDropRegionNode{}): "alter database drop region", - reflect.TypeOf(&alterDatabaseAddSuperRegion{}): "alter database add super region", - reflect.TypeOf(&alterDatabaseDropSuperRegion{}): "alter database alter super region", - reflect.TypeOf(&alterDatabaseAlterSuperRegion{}): "alter database drop super region", - reflect.TypeOf(&alterDefaultPrivilegesNode{}): "alter default privileges", - reflect.TypeOf(&alterIndexNode{}): "alter index", - reflect.TypeOf(&alterSequenceNode{}): "alter sequence", - reflect.TypeOf(&alterSchemaNode{}): "alter schema", - reflect.TypeOf(&alterTableNode{}): "alter table", - reflect.TypeOf(&alterTableOwnerNode{}): "alter table owner", - reflect.TypeOf(&alterTableSetLocalityNode{}): "alter table set locality", - reflect.TypeOf(&alterTableSetSchemaNode{}): "alter table set schema", - reflect.TypeOf(&alterTenantSetClusterSettingNode{}): "alter tenant set cluster setting", - reflect.TypeOf(&alterTypeNode{}): "alter type", - reflect.TypeOf(&alterRoleNode{}): "alter role", - reflect.TypeOf(&alterRoleSetNode{}): "alter role set var", - reflect.TypeOf(&applyJoinNode{}): "apply join", - reflect.TypeOf(&bufferNode{}): "buffer", - reflect.TypeOf(&cancelQueriesNode{}): "cancel queries", - reflect.TypeOf(&cancelSessionsNode{}): "cancel sessions", - reflect.TypeOf(&changeDescriptorBackedPrivilegesNode{}): "change privileges", - reflect.TypeOf(&changeNonDescriptorBackedPrivilegesNode{}): "change system privileges", - reflect.TypeOf(&commentOnColumnNode{}): "comment on column", - reflect.TypeOf(&commentOnConstraintNode{}): "comment on constraint", - reflect.TypeOf(&commentOnDatabaseNode{}): "comment on database", - reflect.TypeOf(&commentOnIndexNode{}): "comment on index", - reflect.TypeOf(&commentOnTableNode{}): "comment on table", - reflect.TypeOf(&commentOnSchemaNode{}): "comment on schema", - reflect.TypeOf(&controlJobsNode{}): "control jobs", - reflect.TypeOf(&controlSchedulesNode{}): "control schedules", - reflect.TypeOf(&createDatabaseNode{}): "create database", - reflect.TypeOf(&createExtensionNode{}): "create extension", - reflect.TypeOf(&createIndexNode{}): "create index", - reflect.TypeOf(&createSequenceNode{}): "create sequence", - reflect.TypeOf(&createSchemaNode{}): "create schema", - reflect.TypeOf(&createStatsNode{}): "create statistics", - reflect.TypeOf(&createTableNode{}): "create table", - reflect.TypeOf(&createTypeNode{}): "create type", - reflect.TypeOf(&CreateRoleNode{}): "create user/role", - reflect.TypeOf(&createViewNode{}): "create view", - reflect.TypeOf(&delayedNode{}): "virtual table", - reflect.TypeOf(&deleteNode{}): "delete", - reflect.TypeOf(&deleteRangeNode{}): "delete range", - reflect.TypeOf(&distinctNode{}): "distinct", - reflect.TypeOf(&dropDatabaseNode{}): "drop database", - reflect.TypeOf(&dropIndexNode{}): "drop index", - reflect.TypeOf(&dropSequenceNode{}): "drop sequence", - reflect.TypeOf(&dropSchemaNode{}): "drop schema", - reflect.TypeOf(&dropTableNode{}): "drop table", - reflect.TypeOf(&dropTypeNode{}): "drop type", - reflect.TypeOf(&DropRoleNode{}): "drop user/role", - reflect.TypeOf(&dropViewNode{}): "drop view", - reflect.TypeOf(&errorIfRowsNode{}): "error if rows", - reflect.TypeOf(&explainPlanNode{}): "explain plan", - reflect.TypeOf(&explainVecNode{}): "explain vectorized", - reflect.TypeOf(&explainDDLNode{}): "explain ddl", - reflect.TypeOf(&exportNode{}): "export", - reflect.TypeOf(&fetchNode{}): "fetch", - reflect.TypeOf(&filterNode{}): "filter", - reflect.TypeOf(&GrantRoleNode{}): "grant role", - reflect.TypeOf(&groupNode{}): "group", - reflect.TypeOf(&hookFnNode{}): "plugin", - reflect.TypeOf(&indexJoinNode{}): "index join", - reflect.TypeOf(&insertNode{}): "insert", - reflect.TypeOf(&insertFastPathNode{}): "insert fast path", - reflect.TypeOf(&invertedFilterNode{}): "inverted filter", - reflect.TypeOf(&invertedJoinNode{}): "inverted join", - reflect.TypeOf(&joinNode{}): "join", - reflect.TypeOf(&limitNode{}): "limit", - reflect.TypeOf(&lookupJoinNode{}): "lookup join", - reflect.TypeOf(&max1RowNode{}): "max1row", - reflect.TypeOf(&ordinalityNode{}): "ordinality", - reflect.TypeOf(&projectSetNode{}): "project set", - reflect.TypeOf(&reassignOwnedByNode{}): "reassign owned by", - reflect.TypeOf(&dropOwnedByNode{}): "drop owned by", - reflect.TypeOf(&recursiveCTENode{}): "recursive cte", - reflect.TypeOf(&refreshMaterializedViewNode{}): "refresh materialized view", - reflect.TypeOf(&relocateNode{}): "relocate", - reflect.TypeOf(&relocateRange{}): "relocate range", - reflect.TypeOf(&renameColumnNode{}): "rename column", - reflect.TypeOf(&renameDatabaseNode{}): "rename database", - reflect.TypeOf(&renameIndexNode{}): "rename index", - reflect.TypeOf(&renameTableNode{}): "rename table", - reflect.TypeOf(&reparentDatabaseNode{}): "reparent database", - reflect.TypeOf(&renderNode{}): "render", - reflect.TypeOf(&resetAllNode{}): "reset all", - reflect.TypeOf(&RevokeRoleNode{}): "revoke role", - reflect.TypeOf(&rowCountNode{}): "count", - reflect.TypeOf(&rowSourceToPlanNode{}): "row source to plan node", - reflect.TypeOf(&saveTableNode{}): "save table", - reflect.TypeOf(&scanBufferNode{}): "scan buffer", - reflect.TypeOf(&scanNode{}): "scan", - reflect.TypeOf(&scatterNode{}): "scatter", - reflect.TypeOf(&scrubNode{}): "scrub", - reflect.TypeOf(&sequenceSelectNode{}): "sequence select", - reflect.TypeOf(&serializeNode{}): "run", - reflect.TypeOf(&setClusterSettingNode{}): "set cluster setting", - reflect.TypeOf(&setVarNode{}): "set", - reflect.TypeOf(&setZoneConfigNode{}): "configure zone", - reflect.TypeOf(&showFingerprintsNode{}): "show fingerprints", - reflect.TypeOf(&showTraceNode{}): "show trace for", - reflect.TypeOf(&showTraceReplicaNode{}): "replica trace", - reflect.TypeOf(&showVarNode{}): "show", - reflect.TypeOf(&sortNode{}): "sort", - reflect.TypeOf(&splitNode{}): "split", - reflect.TypeOf(&topKNode{}): "top-k", - reflect.TypeOf(&unsplitNode{}): "unsplit", - reflect.TypeOf(&unsplitAllNode{}): "unsplit all", - reflect.TypeOf(&spoolNode{}): "spool", - reflect.TypeOf(&truncateNode{}): "truncate", - reflect.TypeOf(&unaryNode{}): "emptyrow", - reflect.TypeOf(&unionNode{}): "union", - reflect.TypeOf(&updateNode{}): "update", - reflect.TypeOf(&upsertNode{}): "upsert", - reflect.TypeOf(&valuesNode{}): "values", - reflect.TypeOf(&virtualTableNode{}): "virtual table values", - reflect.TypeOf(&vTableLookupJoinNode{}): "virtual table lookup join", - reflect.TypeOf(&windowNode{}): "window", - reflect.TypeOf(&zeroNode{}): "norows", - reflect.TypeOf(&zigzagJoinNode{}): "zigzag join", - reflect.TypeOf(&schemaChangePlanNode{}): "schema change", + reflect.TypeOf(&alterDatabaseOwnerNode{}): "alter database owner", + reflect.TypeOf(&alterDatabaseAddRegionNode{}): "alter database add region", + reflect.TypeOf(&alterDatabasePrimaryRegionNode{}): "alter database primary region", + reflect.TypeOf(&alterDatabasePlacementNode{}): "alter database placement", + reflect.TypeOf(&alterDatabaseSurvivalGoalNode{}): "alter database survive", + reflect.TypeOf(&alterDatabaseDropRegionNode{}): "alter database drop region", + reflect.TypeOf(&alterDatabaseAddSuperRegion{}): "alter database add super region", + reflect.TypeOf(&alterDatabaseDropSuperRegion{}): "alter database alter super region", + reflect.TypeOf(&alterDatabaseAlterSuperRegion{}): "alter database drop super region", + reflect.TypeOf(&alterDefaultPrivilegesNode{}): "alter default privileges", + reflect.TypeOf(&alterIndexNode{}): "alter index", + reflect.TypeOf(&alterIndexVisibleNode{}): "alter index visibility", + reflect.TypeOf(&alterSequenceNode{}): "alter sequence", + reflect.TypeOf(&alterSchemaNode{}): "alter schema", + reflect.TypeOf(&alterTableNode{}): "alter table", + reflect.TypeOf(&alterTableOwnerNode{}): "alter table owner", + reflect.TypeOf(&alterTableSetLocalityNode{}): "alter table set locality", + reflect.TypeOf(&alterTableSetSchemaNode{}): "alter table set schema", + reflect.TypeOf(&alterTenantSetClusterSettingNode{}): "alter tenant set cluster setting", + reflect.TypeOf(&alterTypeNode{}): "alter type", + reflect.TypeOf(&alterRoleNode{}): "alter role", + reflect.TypeOf(&alterRoleSetNode{}): "alter role set var", + reflect.TypeOf(&applyJoinNode{}): "apply join", + reflect.TypeOf(&bufferNode{}): "buffer", + reflect.TypeOf(&cancelQueriesNode{}): "cancel queries", + reflect.TypeOf(&cancelSessionsNode{}): "cancel sessions", + reflect.TypeOf(&changePrivilegesNode{}): "change privileges", + reflect.TypeOf(&commentOnColumnNode{}): "comment on column", + reflect.TypeOf(&commentOnConstraintNode{}): "comment on constraint", + reflect.TypeOf(&commentOnDatabaseNode{}): "comment on database", + reflect.TypeOf(&commentOnIndexNode{}): "comment on index", + reflect.TypeOf(&commentOnTableNode{}): "comment on table", + reflect.TypeOf(&commentOnSchemaNode{}): "comment on schema", + reflect.TypeOf(&controlJobsNode{}): "control jobs", + reflect.TypeOf(&controlSchedulesNode{}): "control schedules", + reflect.TypeOf(&createDatabaseNode{}): "create database", + reflect.TypeOf(&createExtensionNode{}): "create extension", + reflect.TypeOf(&createIndexNode{}): "create index", + reflect.TypeOf(&createSequenceNode{}): "create sequence", + reflect.TypeOf(&createSchemaNode{}): "create schema", + reflect.TypeOf(&createStatsNode{}): "create statistics", + reflect.TypeOf(&createTableNode{}): "create table", + reflect.TypeOf(&createTypeNode{}): "create type", + reflect.TypeOf(&CreateRoleNode{}): "create user/role", + reflect.TypeOf(&createViewNode{}): "create view", + reflect.TypeOf(&delayedNode{}): "virtual table", + reflect.TypeOf(&deleteNode{}): "delete", + reflect.TypeOf(&deleteRangeNode{}): "delete range", + reflect.TypeOf(&distinctNode{}): "distinct", + reflect.TypeOf(&dropDatabaseNode{}): "drop database", + reflect.TypeOf(&dropIndexNode{}): "drop index", + reflect.TypeOf(&dropSequenceNode{}): "drop sequence", + reflect.TypeOf(&dropSchemaNode{}): "drop schema", + reflect.TypeOf(&dropTableNode{}): "drop table", + reflect.TypeOf(&dropTypeNode{}): "drop type", + reflect.TypeOf(&DropRoleNode{}): "drop user/role", + reflect.TypeOf(&dropViewNode{}): "drop view", + reflect.TypeOf(&errorIfRowsNode{}): "error if rows", + reflect.TypeOf(&explainPlanNode{}): "explain plan", + reflect.TypeOf(&explainVecNode{}): "explain vectorized", + reflect.TypeOf(&explainDDLNode{}): "explain ddl", + reflect.TypeOf(&exportNode{}): "export", + reflect.TypeOf(&fetchNode{}): "fetch", + reflect.TypeOf(&filterNode{}): "filter", + reflect.TypeOf(&GrantRoleNode{}): "grant role", + reflect.TypeOf(&groupNode{}): "group", + reflect.TypeOf(&hookFnNode{}): "plugin", + reflect.TypeOf(&indexJoinNode{}): "index join", + reflect.TypeOf(&insertNode{}): "insert", + reflect.TypeOf(&insertFastPathNode{}): "insert fast path", + reflect.TypeOf(&invertedFilterNode{}): "inverted filter", + reflect.TypeOf(&invertedJoinNode{}): "inverted join", + reflect.TypeOf(&joinNode{}): "join", + reflect.TypeOf(&limitNode{}): "limit", + reflect.TypeOf(&lookupJoinNode{}): "lookup join", + reflect.TypeOf(&max1RowNode{}): "max1row", + reflect.TypeOf(&ordinalityNode{}): "ordinality", + reflect.TypeOf(&projectSetNode{}): "project set", + reflect.TypeOf(&reassignOwnedByNode{}): "reassign owned by", + reflect.TypeOf(&dropOwnedByNode{}): "drop owned by", + reflect.TypeOf(&recursiveCTENode{}): "recursive cte", + reflect.TypeOf(&refreshMaterializedViewNode{}): "refresh materialized view", + reflect.TypeOf(&relocateNode{}): "relocate", + reflect.TypeOf(&relocateRange{}): "relocate range", + reflect.TypeOf(&renameColumnNode{}): "rename column", + reflect.TypeOf(&renameDatabaseNode{}): "rename database", + reflect.TypeOf(&renameIndexNode{}): "rename index", + reflect.TypeOf(&renameTableNode{}): "rename table", + reflect.TypeOf(&reparentDatabaseNode{}): "reparent database", + reflect.TypeOf(&renderNode{}): "render", + reflect.TypeOf(&resetAllNode{}): "reset all", + reflect.TypeOf(&RevokeRoleNode{}): "revoke role", + reflect.TypeOf(&rowCountNode{}): "count", + reflect.TypeOf(&rowSourceToPlanNode{}): "row source to plan node", + reflect.TypeOf(&saveTableNode{}): "save table", + reflect.TypeOf(&scanBufferNode{}): "scan buffer", + reflect.TypeOf(&scanNode{}): "scan", + reflect.TypeOf(&scatterNode{}): "scatter", + reflect.TypeOf(&scrubNode{}): "scrub", + reflect.TypeOf(&sequenceSelectNode{}): "sequence select", + reflect.TypeOf(&serializeNode{}): "run", + reflect.TypeOf(&setClusterSettingNode{}): "set cluster setting", + reflect.TypeOf(&setVarNode{}): "set", + reflect.TypeOf(&setZoneConfigNode{}): "configure zone", + reflect.TypeOf(&showFingerprintsNode{}): "show fingerprints", + reflect.TypeOf(&showTraceNode{}): "show trace for", + reflect.TypeOf(&showTraceReplicaNode{}): "replica trace", + reflect.TypeOf(&showVarNode{}): "show", + reflect.TypeOf(&sortNode{}): "sort", + reflect.TypeOf(&splitNode{}): "split", + reflect.TypeOf(&topKNode{}): "top-k", + reflect.TypeOf(&unsplitNode{}): "unsplit", + reflect.TypeOf(&unsplitAllNode{}): "unsplit all", + reflect.TypeOf(&spoolNode{}): "spool", + reflect.TypeOf(&truncateNode{}): "truncate", + reflect.TypeOf(&unaryNode{}): "emptyrow", + reflect.TypeOf(&unionNode{}): "union", + reflect.TypeOf(&updateNode{}): "update", + reflect.TypeOf(&upsertNode{}): "upsert", + reflect.TypeOf(&valuesNode{}): "values", + reflect.TypeOf(&virtualTableNode{}): "virtual table values", + reflect.TypeOf(&vTableLookupJoinNode{}): "virtual table lookup join", + reflect.TypeOf(&windowNode{}): "window", + reflect.TypeOf(&zeroNode{}): "norows", + reflect.TypeOf(&zigzagJoinNode{}): "zigzag join", + reflect.TypeOf(&schemaChangePlanNode{}): "schema change", }