Skip to content

Commit

Permalink
sql: update crdb_internal.interleaved to be more usable
Browse files Browse the repository at this point in the history
Previous, when we added the crdb_internal.interleaved table that
showed all interleaved indexes, however it was impossible tell
which table the primary key of the parent table was interleaved.
This was inadequate because users could not tell what the parent
table was. To address this, this patch modifies
crdb_internal.interleaved to add a parent_table_name column
replacing the parent_index one, since that column could only be
the primary key.

Release note (sql change): Updated crdb_internal.interleaved to
add the parent_table_name column replacing the parent_index_name
column.
  • Loading branch information
fqazi committed Mar 18, 2021
1 parent 98ae002 commit 011bbfb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 27 deletions.
21 changes: 11 additions & 10 deletions pkg/sql/crdb_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4144,7 +4144,11 @@ CREATE TABLE crdb_internal.interleaved (
STRING NOT NULL,
index_name
STRING NOT NULL,
parent_index
parent_database_name
STRING NOT NULL,
parent_schema_name
STRING NOT NULL,
parent_table_name
STRING NOT NULL
);`,
populate: func(ctx context.Context, p *planner, dbContext *dbdesc.Immutable, addRow func(...tree.Datum) error) error {
Expand All @@ -4158,30 +4162,27 @@ CREATE TABLE crdb_internal.interleaved (
if index.NumInterleaveAncestors() == 0 {
continue
}

ancestor := index.GetInterleaveAncestor(index.NumInterleaveAncestors() - 1)
parentTable, err := lookupFn.getTableByID(ancestor.TableID)
if err != nil {
return err
}
parentIndex, err := parentTable.FindIndexWithID(ancestor.IndexID)
if err != nil {
return err
}
parentSchemaName, err := lookupFn.getSchemaNameByID(parentTable.GetParentSchemaID())
if err != nil {
return err
}
database, err := lookupFn.getDatabaseByID(parentTable.GetParentID())
parentDatabase, err := lookupFn.getDatabaseByID(parentTable.GetParentID())
if err != nil {
return err
}

if err := addRow(tree.NewDString(database.GetName()),
tree.NewDString(parentSchemaName),
if err := addRow(tree.NewDString(db.GetName()),
tree.NewDString(schemaName),
tree.NewDString(table.GetName()),
tree.NewDString(index.GetName()),
tree.NewDString(parentIndex.GetName())); err != nil {
tree.NewDString(parentDatabase.GetName()),
tree.NewDString(parentSchemaName),
tree.NewDString(parentTable.GetName())); err != nil {
return err
}
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/create_statements
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,17 @@ CREATE TABLE crdb_internal.interleaved (
schema_name STRING NOT NULL,
table_name STRING NOT NULL,
index_name STRING NOT NULL,
parent_index STRING NOT NULL
parent_database_name STRING NOT NULL,
parent_schema_name STRING NOT NULL,
parent_table_name STRING NOT NULL
) CREATE TABLE crdb_internal.interleaved (
database_name STRING NOT NULL,
schema_name STRING NOT NULL,
table_name STRING NOT NULL,
index_name STRING NOT NULL,
parent_index STRING NOT NULL
parent_database_name STRING NOT NULL,
parent_schema_name STRING NOT NULL,
parent_table_name STRING NOT NULL
) {} {}
CREATE TABLE crdb_internal.invalid_objects (
id INT8 NULL,
Expand Down
42 changes: 27 additions & 15 deletions pkg/sql/logictest/testdata/logic_test/interleaved
Original file line number Diff line number Diff line change
Expand Up @@ -497,22 +497,34 @@ CREATE INDEX NIINDX3 ON CHILD(z);
statement ok
CREATE INDEX IINDX ON CHILD(rowid,x,y,z) INTERLEAVE IN PARENT PARENT(rowid);

# Child in different schema then parent
statement ok
CREATE TABLE parentDS (k STRING PRIMARY KEY);

statement ok
CREATE SCHEMA child_schema;

statement ok
CREATE TABLE child_schema.child (ck INT8 PRIMARY KEY, k STRING NOT NULL UNIQUE);

statement ok
CREATE INDEX interl ON child_schema.child (k) INTERLEAVE IN PARENT parentDS (k);

query TTTTT
query TTTTTTT
select * from "".crdb_internal.interleaved;
----
test public p1_1 p1_id primary
test public all_interleaves primary primary
test public all_interleaves all_interleaves_c_d_idx primary
test public all_interleaves all_interleaves_d_c_key primary
test public orders primary primary
other public interdb primary primary
test public c20067 primary primary
test public documents primary primary
test public big_interleave_parent primary primary
test public big_interleave_child primary primary
test public interleave_create_notice primary primary
test public interleave_create_notice interleave_index primary
test public interleave_pk_notice primary primary
test public child iindx primary
test public p1_1 p1_id test public p1_1
test public all_interleaves primary test public p1_1
test public all_interleaves all_interleaves_c_d_idx test public p1_1
test public all_interleaves all_interleaves_d_c_key test public p1_1
test public orders primary test public customers
test public interdb primary other public foo
test public c20067 primary test public p20067
test public documents primary test public users
test public big_interleave_parent primary test public big_interleave_grandparent
test public big_interleave_child primary test public big_interleave_parent
test public interleave_create_notice primary test public interleave_parent
test public interleave_create_notice interleave_index test public interleave_parent
test public interleave_pk_notice primary test public interleave_parent
test public child iindx test public parent
test child_schema child interl test public parentds

0 comments on commit 011bbfb

Please sign in to comment.