Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: add proper support for hidden columns #26644

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/generated/sql/bnf/alter_column.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ alter_onetable_stmt ::=
| 'ALTER' 'TABLE' table_name 'ALTER' 'COLUMN' column_name 'DROP' 'DEFAULT'
| 'ALTER' 'TABLE' table_name 'ALTER' column_name 'SET' 'DEFAULT' a_expr
| 'ALTER' 'TABLE' table_name 'ALTER' column_name 'DROP' 'DEFAULT'
| 'ALTER' 'TABLE' table_name 'ALTER' 'COLUMN' column_name 'SET' 'NOT' 'VISIBLE'
| 'ALTER' 'TABLE' table_name 'ALTER' column_name 'SET' 'NOT' 'VISIBLE'
| 'ALTER' 'TABLE' table_name 'ALTER' 'COLUMN' column_name 'SET' 'VISIBLE'
| 'ALTER' 'TABLE' table_name 'ALTER' column_name 'SET' 'VISIBLE'
| 'ALTER' 'TABLE' table_name 'ALTER' 'COLUMN' column_name 'DROP' 'NOT' 'NULL'
| 'ALTER' 'TABLE' table_name 'ALTER' column_name 'DROP' 'NOT' 'NULL'
| 'ALTER' 'TABLE' table_name 'ALTER' 'COLUMN' column_name 'DROP' 'STORED'
Expand All @@ -27,6 +31,10 @@ alter_onetable_stmt ::=
| 'ALTER' 'TABLE' 'IF' 'EXISTS' table_name 'ALTER' 'COLUMN' column_name 'DROP' 'DEFAULT'
| 'ALTER' 'TABLE' 'IF' 'EXISTS' table_name 'ALTER' column_name 'SET' 'DEFAULT' a_expr
| 'ALTER' 'TABLE' 'IF' 'EXISTS' table_name 'ALTER' column_name 'DROP' 'DEFAULT'
| 'ALTER' 'TABLE' 'IF' 'EXISTS' table_name 'ALTER' 'COLUMN' column_name 'SET' 'NOT' 'VISIBLE'
| 'ALTER' 'TABLE' 'IF' 'EXISTS' table_name 'ALTER' column_name 'SET' 'NOT' 'VISIBLE'
| 'ALTER' 'TABLE' 'IF' 'EXISTS' table_name 'ALTER' 'COLUMN' column_name 'SET' 'VISIBLE'
| 'ALTER' 'TABLE' 'IF' 'EXISTS' table_name 'ALTER' column_name 'SET' 'VISIBLE'
| 'ALTER' 'TABLE' 'IF' 'EXISTS' table_name 'ALTER' 'COLUMN' column_name 'DROP' 'NOT' 'NULL'
| 'ALTER' 'TABLE' 'IF' 'EXISTS' table_name 'ALTER' column_name 'DROP' 'NOT' 'NULL'
| 'ALTER' 'TABLE' 'IF' 'EXISTS' table_name 'ALTER' 'COLUMN' column_name 'DROP' 'STORED'
Expand Down
4 changes: 2 additions & 2 deletions docs/generated/sql/bnf/alter_table.bnf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
alter_onetable_stmt ::=
'ALTER' 'TABLE' table_name ( ( ( 'ADD' ( column_name typename col_qual_list ) | 'ADD' 'IF' 'NOT' 'EXISTS' ( column_name typename col_qual_list ) | 'ADD' 'COLUMN' ( column_name typename col_qual_list ) | 'ADD' 'COLUMN' 'IF' 'NOT' 'EXISTS' ( column_name typename col_qual_list ) | 'ALTER' ( 'COLUMN' | ) column_name ( 'SET' 'DEFAULT' a_expr | 'DROP' 'DEFAULT' ) | 'ALTER' ( 'COLUMN' | ) column_name 'DROP' 'NOT' 'NULL' | 'ALTER' ( 'COLUMN' | ) column_name 'DROP' 'STORED' | 'DROP' ( 'COLUMN' | ) 'IF' 'EXISTS' column_name ( 'CASCADE' | 'RESTRICT' | ) | 'DROP' ( 'COLUMN' | ) column_name ( 'CASCADE' | 'RESTRICT' | ) | 'ALTER' ( 'COLUMN' | ) column_name ( 'SET' 'DATA' | ) 'TYPE' typename ( 'COLLATE' collation_name | ) ( 'USING' a_expr | ) | 'ADD' ( 'CONSTRAINT' constraint_name constraint_elem | constraint_elem ) | 'VALIDATE' 'CONSTRAINT' constraint_name | 'DROP' 'CONSTRAINT' 'IF' 'EXISTS' constraint_name ( 'CASCADE' | 'RESTRICT' | ) | 'DROP' 'CONSTRAINT' constraint_name ( 'CASCADE' | 'RESTRICT' | ) | 'EXPERIMENTAL_AUDIT' 'SET' audit_mode | partition_by | 'INJECT' 'STATISTICS' a_expr ) ) ( ( ',' ( 'ADD' ( column_name typename col_qual_list ) | 'ADD' 'IF' 'NOT' 'EXISTS' ( column_name typename col_qual_list ) | 'ADD' 'COLUMN' ( column_name typename col_qual_list ) | 'ADD' 'COLUMN' 'IF' 'NOT' 'EXISTS' ( column_name typename col_qual_list ) | 'ALTER' ( 'COLUMN' | ) column_name ( 'SET' 'DEFAULT' a_expr | 'DROP' 'DEFAULT' ) | 'ALTER' ( 'COLUMN' | ) column_name 'DROP' 'NOT' 'NULL' | 'ALTER' ( 'COLUMN' | ) column_name 'DROP' 'STORED' | 'DROP' ( 'COLUMN' | ) 'IF' 'EXISTS' column_name ( 'CASCADE' | 'RESTRICT' | ) | 'DROP' ( 'COLUMN' | ) column_name ( 'CASCADE' | 'RESTRICT' | ) | 'ALTER' ( 'COLUMN' | ) column_name ( 'SET' 'DATA' | ) 'TYPE' typename ( 'COLLATE' collation_name | ) ( 'USING' a_expr | ) | 'ADD' ( 'CONSTRAINT' constraint_name constraint_elem | constraint_elem ) | 'VALIDATE' 'CONSTRAINT' constraint_name | 'DROP' 'CONSTRAINT' 'IF' 'EXISTS' constraint_name ( 'CASCADE' | 'RESTRICT' | ) | 'DROP' 'CONSTRAINT' constraint_name ( 'CASCADE' | 'RESTRICT' | ) | 'EXPERIMENTAL_AUDIT' 'SET' audit_mode | partition_by | 'INJECT' 'STATISTICS' a_expr ) ) )* )
| 'ALTER' 'TABLE' 'IF' 'EXISTS' table_name ( ( ( 'ADD' ( column_name typename col_qual_list ) | 'ADD' 'IF' 'NOT' 'EXISTS' ( column_name typename col_qual_list ) | 'ADD' 'COLUMN' ( column_name typename col_qual_list ) | 'ADD' 'COLUMN' 'IF' 'NOT' 'EXISTS' ( column_name typename col_qual_list ) | 'ALTER' ( 'COLUMN' | ) column_name ( 'SET' 'DEFAULT' a_expr | 'DROP' 'DEFAULT' ) | 'ALTER' ( 'COLUMN' | ) column_name 'DROP' 'NOT' 'NULL' | 'ALTER' ( 'COLUMN' | ) column_name 'DROP' 'STORED' | 'DROP' ( 'COLUMN' | ) 'IF' 'EXISTS' column_name ( 'CASCADE' | 'RESTRICT' | ) | 'DROP' ( 'COLUMN' | ) column_name ( 'CASCADE' | 'RESTRICT' | ) | 'ALTER' ( 'COLUMN' | ) column_name ( 'SET' 'DATA' | ) 'TYPE' typename ( 'COLLATE' collation_name | ) ( 'USING' a_expr | ) | 'ADD' ( 'CONSTRAINT' constraint_name constraint_elem | constraint_elem ) | 'VALIDATE' 'CONSTRAINT' constraint_name | 'DROP' 'CONSTRAINT' 'IF' 'EXISTS' constraint_name ( 'CASCADE' | 'RESTRICT' | ) | 'DROP' 'CONSTRAINT' constraint_name ( 'CASCADE' | 'RESTRICT' | ) | 'EXPERIMENTAL_AUDIT' 'SET' audit_mode | partition_by | 'INJECT' 'STATISTICS' a_expr ) ) ( ( ',' ( 'ADD' ( column_name typename col_qual_list ) | 'ADD' 'IF' 'NOT' 'EXISTS' ( column_name typename col_qual_list ) | 'ADD' 'COLUMN' ( column_name typename col_qual_list ) | 'ADD' 'COLUMN' 'IF' 'NOT' 'EXISTS' ( column_name typename col_qual_list ) | 'ALTER' ( 'COLUMN' | ) column_name ( 'SET' 'DEFAULT' a_expr | 'DROP' 'DEFAULT' ) | 'ALTER' ( 'COLUMN' | ) column_name 'DROP' 'NOT' 'NULL' | 'ALTER' ( 'COLUMN' | ) column_name 'DROP' 'STORED' | 'DROP' ( 'COLUMN' | ) 'IF' 'EXISTS' column_name ( 'CASCADE' | 'RESTRICT' | ) | 'DROP' ( 'COLUMN' | ) column_name ( 'CASCADE' | 'RESTRICT' | ) | 'ALTER' ( 'COLUMN' | ) column_name ( 'SET' 'DATA' | ) 'TYPE' typename ( 'COLLATE' collation_name | ) ( 'USING' a_expr | ) | 'ADD' ( 'CONSTRAINT' constraint_name constraint_elem | constraint_elem ) | 'VALIDATE' 'CONSTRAINT' constraint_name | 'DROP' 'CONSTRAINT' 'IF' 'EXISTS' constraint_name ( 'CASCADE' | 'RESTRICT' | ) | 'DROP' 'CONSTRAINT' constraint_name ( 'CASCADE' | 'RESTRICT' | ) | 'EXPERIMENTAL_AUDIT' 'SET' audit_mode | partition_by | 'INJECT' 'STATISTICS' a_expr ) ) )* )
'ALTER' 'TABLE' table_name ( ( ( 'ADD' ( column_name typename col_qual_list ) | 'ADD' 'IF' 'NOT' 'EXISTS' ( column_name typename col_qual_list ) | 'ADD' 'COLUMN' ( column_name typename col_qual_list ) | 'ADD' 'COLUMN' 'IF' 'NOT' 'EXISTS' ( column_name typename col_qual_list ) | 'ALTER' ( 'COLUMN' | ) column_name ( 'SET' 'DEFAULT' a_expr | 'DROP' 'DEFAULT' ) | 'ALTER' ( 'COLUMN' | ) column_name 'SET' 'NOT' 'VISIBLE' | 'ALTER' ( 'COLUMN' | ) column_name 'SET' 'VISIBLE' | 'ALTER' ( 'COLUMN' | ) column_name 'DROP' 'NOT' 'NULL' | 'ALTER' ( 'COLUMN' | ) column_name 'DROP' 'STORED' | 'DROP' ( 'COLUMN' | ) 'IF' 'EXISTS' column_name ( 'CASCADE' | 'RESTRICT' | ) | 'DROP' ( 'COLUMN' | ) column_name ( 'CASCADE' | 'RESTRICT' | ) | 'ALTER' ( 'COLUMN' | ) column_name ( 'SET' 'DATA' | ) 'TYPE' typename ( 'COLLATE' collation_name | ) ( 'USING' a_expr | ) | 'ADD' ( 'CONSTRAINT' constraint_name constraint_elem | constraint_elem ) | 'VALIDATE' 'CONSTRAINT' constraint_name | 'DROP' 'CONSTRAINT' 'IF' 'EXISTS' constraint_name ( 'CASCADE' | 'RESTRICT' | ) | 'DROP' 'CONSTRAINT' constraint_name ( 'CASCADE' | 'RESTRICT' | ) | 'EXPERIMENTAL_AUDIT' 'SET' audit_mode | partition_by | 'INJECT' 'STATISTICS' a_expr ) ) ( ( ',' ( 'ADD' ( column_name typename col_qual_list ) | 'ADD' 'IF' 'NOT' 'EXISTS' ( column_name typename col_qual_list ) | 'ADD' 'COLUMN' ( column_name typename col_qual_list ) | 'ADD' 'COLUMN' 'IF' 'NOT' 'EXISTS' ( column_name typename col_qual_list ) | 'ALTER' ( 'COLUMN' | ) column_name ( 'SET' 'DEFAULT' a_expr | 'DROP' 'DEFAULT' ) | 'ALTER' ( 'COLUMN' | ) column_name 'SET' 'NOT' 'VISIBLE' | 'ALTER' ( 'COLUMN' | ) column_name 'SET' 'VISIBLE' | 'ALTER' ( 'COLUMN' | ) column_name 'DROP' 'NOT' 'NULL' | 'ALTER' ( 'COLUMN' | ) column_name 'DROP' 'STORED' | 'DROP' ( 'COLUMN' | ) 'IF' 'EXISTS' column_name ( 'CASCADE' | 'RESTRICT' | ) | 'DROP' ( 'COLUMN' | ) column_name ( 'CASCADE' | 'RESTRICT' | ) | 'ALTER' ( 'COLUMN' | ) column_name ( 'SET' 'DATA' | ) 'TYPE' typename ( 'COLLATE' collation_name | ) ( 'USING' a_expr | ) | 'ADD' ( 'CONSTRAINT' constraint_name constraint_elem | constraint_elem ) | 'VALIDATE' 'CONSTRAINT' constraint_name | 'DROP' 'CONSTRAINT' 'IF' 'EXISTS' constraint_name ( 'CASCADE' | 'RESTRICT' | ) | 'DROP' 'CONSTRAINT' constraint_name ( 'CASCADE' | 'RESTRICT' | ) | 'EXPERIMENTAL_AUDIT' 'SET' audit_mode | partition_by | 'INJECT' 'STATISTICS' a_expr ) ) )* )
| 'ALTER' 'TABLE' 'IF' 'EXISTS' table_name ( ( ( 'ADD' ( column_name typename col_qual_list ) | 'ADD' 'IF' 'NOT' 'EXISTS' ( column_name typename col_qual_list ) | 'ADD' 'COLUMN' ( column_name typename col_qual_list ) | 'ADD' 'COLUMN' 'IF' 'NOT' 'EXISTS' ( column_name typename col_qual_list ) | 'ALTER' ( 'COLUMN' | ) column_name ( 'SET' 'DEFAULT' a_expr | 'DROP' 'DEFAULT' ) | 'ALTER' ( 'COLUMN' | ) column_name 'SET' 'NOT' 'VISIBLE' | 'ALTER' ( 'COLUMN' | ) column_name 'SET' 'VISIBLE' | 'ALTER' ( 'COLUMN' | ) column_name 'DROP' 'NOT' 'NULL' | 'ALTER' ( 'COLUMN' | ) column_name 'DROP' 'STORED' | 'DROP' ( 'COLUMN' | ) 'IF' 'EXISTS' column_name ( 'CASCADE' | 'RESTRICT' | ) | 'DROP' ( 'COLUMN' | ) column_name ( 'CASCADE' | 'RESTRICT' | ) | 'ALTER' ( 'COLUMN' | ) column_name ( 'SET' 'DATA' | ) 'TYPE' typename ( 'COLLATE' collation_name | ) ( 'USING' a_expr | ) | 'ADD' ( 'CONSTRAINT' constraint_name constraint_elem | constraint_elem ) | 'VALIDATE' 'CONSTRAINT' constraint_name | 'DROP' 'CONSTRAINT' 'IF' 'EXISTS' constraint_name ( 'CASCADE' | 'RESTRICT' | ) | 'DROP' 'CONSTRAINT' constraint_name ( 'CASCADE' | 'RESTRICT' | ) | 'EXPERIMENTAL_AUDIT' 'SET' audit_mode | partition_by | 'INJECT' 'STATISTICS' a_expr ) ) ( ( ',' ( 'ADD' ( column_name typename col_qual_list ) | 'ADD' 'IF' 'NOT' 'EXISTS' ( column_name typename col_qual_list ) | 'ADD' 'COLUMN' ( column_name typename col_qual_list ) | 'ADD' 'COLUMN' 'IF' 'NOT' 'EXISTS' ( column_name typename col_qual_list ) | 'ALTER' ( 'COLUMN' | ) column_name ( 'SET' 'DEFAULT' a_expr | 'DROP' 'DEFAULT' ) | 'ALTER' ( 'COLUMN' | ) column_name 'SET' 'NOT' 'VISIBLE' | 'ALTER' ( 'COLUMN' | ) column_name 'SET' 'VISIBLE' | 'ALTER' ( 'COLUMN' | ) column_name 'DROP' 'NOT' 'NULL' | 'ALTER' ( 'COLUMN' | ) column_name 'DROP' 'STORED' | 'DROP' ( 'COLUMN' | ) 'IF' 'EXISTS' column_name ( 'CASCADE' | 'RESTRICT' | ) | 'DROP' ( 'COLUMN' | ) column_name ( 'CASCADE' | 'RESTRICT' | ) | 'ALTER' ( 'COLUMN' | ) column_name ( 'SET' 'DATA' | ) 'TYPE' typename ( 'COLLATE' collation_name | ) ( 'USING' a_expr | ) | 'ADD' ( 'CONSTRAINT' constraint_name constraint_elem | constraint_elem ) | 'VALIDATE' 'CONSTRAINT' constraint_name | 'DROP' 'CONSTRAINT' 'IF' 'EXISTS' constraint_name ( 'CASCADE' | 'RESTRICT' | ) | 'DROP' 'CONSTRAINT' constraint_name ( 'CASCADE' | 'RESTRICT' | ) | 'EXPERIMENTAL_AUDIT' 'SET' audit_mode | partition_by | 'INJECT' 'STATISTICS' a_expr ) ) )* )
2 changes: 2 additions & 0 deletions docs/generated/sql/bnf/col_qualification.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ col_qualification ::=
| 'CONSTRAINT' constraint_name 'DEFAULT' b_expr
| 'CONSTRAINT' constraint_name 'REFERENCES' table_name opt_name_parens reference_actions
| 'CONSTRAINT' constraint_name 'AS' '(' a_expr ')' 'STORED'
| 'CONSTRAINT' constraint_name 'NOT' 'VISIBLE'
| 'NOT' 'NULL'
| 'NULL'
| 'UNIQUE'
Expand All @@ -15,6 +16,7 @@ col_qualification ::=
| 'DEFAULT' b_expr
| 'REFERENCES' table_name opt_name_parens reference_actions
| 'AS' '(' a_expr ')' 'STORED'
| 'NOT' 'VISIBLE'
| 'COLLATE' collation_name
| 'FAMILY' family_name
| 'CREATE' 'FAMILY' family_name
Expand Down
4 changes: 4 additions & 0 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ unreserved_keyword ::=
| 'VALIDATE'
| 'VALUE'
| 'VARYING'
| 'VISIBLE'
| 'WITHIN'
| 'WITHOUT'
| 'WRITE'
Expand Down Expand Up @@ -1769,6 +1770,8 @@ alter_table_cmd ::=
| 'ADD' 'COLUMN' column_def
| 'ADD' 'COLUMN' 'IF' 'NOT' 'EXISTS' column_def
| 'ALTER' opt_column column_name alter_column_default
| 'ALTER' opt_column column_name 'SET' 'NOT' 'VISIBLE'
| 'ALTER' opt_column column_name 'SET' 'VISIBLE'
| 'ALTER' opt_column column_name 'DROP' 'NOT' 'NULL'
| 'ALTER' opt_column column_name 'DROP' 'STORED'
| 'DROP' opt_column 'IF' 'EXISTS' column_name opt_drop_behavior
Expand Down Expand Up @@ -1991,6 +1994,7 @@ col_qualification_elem ::=
| 'DEFAULT' b_expr
| 'REFERENCES' table_name opt_name_parens reference_actions
| 'AS' '(' a_expr ')' 'STORED'
| 'NOT' 'VISIBLE'

family_name ::=
name
Expand Down
4 changes: 4 additions & 0 deletions pkg/cli/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ func TestDumpAsOf(t *testing.T) {
const want1 = `dump d t
CREATE TABLE t (
i INT NULL,
rowid INT NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT "primary" PRIMARY KEY (rowid ASC),
FAMILY "primary" (i, rowid)
);

Expand All @@ -412,7 +414,9 @@ INSERT INTO t (i) VALUES
const want2 = `dump d t
CREATE TABLE t (
i INT NULL,
rowid INT NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
j INT NULL DEFAULT 2:::INT,
CONSTRAINT "primary" PRIMARY KEY (rowid ASC),
FAMILY "primary" (i, rowid, j)
);

Expand Down
4 changes: 4 additions & 0 deletions pkg/cli/testdata/dump/flags
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ dump t f --dump-mode=both
CREATE TABLE f (
x INT NULL,
y INT NULL,
rowid INT NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT "primary" PRIMARY KEY (rowid ASC),
FAMILY "primary" (x, y, rowid)
);

Expand All @@ -24,6 +26,8 @@ dump t f --dump-mode=schema
CREATE TABLE f (
x INT NULL,
y INT NULL,
rowid INT NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT "primary" PRIMARY KEY (rowid ASC),
FAMILY "primary" (x, y, rowid)
);

Expand Down
2 changes: 2 additions & 0 deletions pkg/cli/testdata/dump/identifiers
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ dump d
----
CREATE TABLE ";" (
";" INT NULL,
rowid INT NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT "primary" PRIMARY KEY (rowid ASC),
INDEX ";_;_idx" (";" ASC),
FAMILY "primary" (";", rowid)
);
Expand Down
2 changes: 2 additions & 0 deletions pkg/cli/testdata/dump/inverted_index
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ dump d t
CREATE TABLE t (
a JSON NULL,
b JSON NULL,
rowid INT NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT "primary" PRIMARY KEY (rowid ASC),
INVERTED INDEX idx (a),
INVERTED INDEX idx2 (b),
FAMILY "primary" (a, b, rowid)
Expand Down
8 changes: 8 additions & 0 deletions pkg/cli/testdata/dump/multiple
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ dump t f g
CREATE TABLE f (
x INT NULL,
y INT NULL,
rowid INT NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT "primary" PRIMARY KEY (rowid ASC),
FAMILY "primary" (x, y, rowid)
);

CREATE TABLE g (
x INT NULL,
y INT NULL,
rowid INT NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT "primary" PRIMARY KEY (rowid ASC),
FAMILY "primary" (x, y, rowid)
);

Expand All @@ -36,12 +40,16 @@ dump t
CREATE TABLE f (
x INT NULL,
y INT NULL,
rowid INT NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT "primary" PRIMARY KEY (rowid ASC),
FAMILY "primary" (x, y, rowid)
);

CREATE TABLE g (
x INT NULL,
y INT NULL,
rowid INT NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT "primary" PRIMARY KEY (rowid ASC),
FAMILY "primary" (x, y, rowid)
);

Expand Down
4 changes: 4 additions & 0 deletions pkg/cli/testdata/dump/reference_order
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ CREATE TABLE b (

CREATE TABLE a (
i INT NULL,
rowid INT NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT "primary" PRIMARY KEY (rowid ASC),
INDEX a_auto_index_fk_i_ref_b (i ASC),
FAMILY "primary" (i, rowid)
);
Expand Down Expand Up @@ -79,6 +81,8 @@ CREATE TABLE d (

CREATE TABLE c (
i INT NULL,
rowid INT NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT "primary" PRIMARY KEY (rowid ASC),
INDEX c_auto_index_fk_i_ref_d (i ASC),
FAMILY "primary" (i, rowid)
);
Expand Down
3 changes: 2 additions & 1 deletion pkg/cli/testdata/dump/row
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ CREATE TABLE t (
e1 DECIMAL(2) NULL,
e2 DECIMAL(2,1) NULL,
s1 STRING(1) NULL,
rowid INT NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT "primary" PRIMARY KEY (rowid ASC),
FAMILY "primary" (i, f, d, t, ts, n, o, u, ip, j, ary, tz, e1, e2, s1, rowid),
FAMILY fam_1_s (s),
FAMILY fam_2_b (b),
Expand All @@ -91,4 +93,3 @@ INSERT INTO t (i, f, s, b, d, t, ts, n, o, e, u, ip, j, ary, tz, e1, e2, s1) VAL
(NULL, 'NaN', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'NaN', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
----
----

17 changes: 17 additions & 0 deletions pkg/sql/alter_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,20 @@ func (n *alterTableNode) startExec(params runParams) error {
return err
}

case *tree.AlterTableSetHidden:
col, dropped, err := n.tableDesc.FindColumnByName(t.GetColumn())
if err != nil {
return err
}
if dropped {
return fmt.Errorf("column %q in the middle of being dropped", t.GetColumn())
}
if err := applyColumnMutation(n.tableDesc, &col, t, params); err != nil {
return err
}
n.tableDesc.UpdateColumnDescriptor(col)
descriptorChanged = true

case *tree.AlterTableInjectStats:
sd, ok := n.statsData[i]
if !ok {
Expand Down Expand Up @@ -757,6 +771,9 @@ func applyColumnMutation(

case *tree.AlterTableDropStored:
col.ComputeExpr = nil

case *tree.AlterTableSetHidden:
col.Hidden = t.Hidden
}
return nil
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/sql/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,11 @@ func makeTableDescIfAs(
if err != nil {
return desc, err
}
columnTableDef := tree.ColumnTableDef{Name: tree.Name(colRes.Name), Type: colType}
columnTableDef := tree.ColumnTableDef{
Name: tree.Name(colRes.Name),
Hidden: colRes.Hidden,
Type: colType,
}
columnTableDef.Nullable.Nullability = tree.SilentNull
if len(p.AsColumnNames) > i {
columnTableDef.Name = p.AsColumnNames[i]
Expand Down
6 changes: 5 additions & 1 deletion pkg/sql/create_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ func (n *createViewNode) makeViewTableDesc(
if err != nil {
return desc, err
}
columnTableDef := tree.ColumnTableDef{Name: tree.Name(colRes.Name), Type: colType}
columnTableDef := tree.ColumnTableDef{
Name: tree.Name(colRes.Name),
Hidden: colRes.Hidden,
Type: colType,
}
if len(columnNames) > i {
columnTableDef.Name = columnNames[i]
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/sql/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,7 @@ func (p *planner) processColumns(
if ensureColumns {
// VisibleColumns is used here to prevent INSERT INTO <table> VALUES (...)
// (as opposed to INSERT INTO <table> (...) VALUES (...)) from writing
// hidden columns. At present, the only hidden column is the implicit rowid
// primary key column.
// hidden columns.
return tableDesc.VisibleColumns(), nil
}
return nil, nil
Expand Down
12 changes: 7 additions & 5 deletions pkg/sql/logictest/testdata/logic_test/alias_types
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ SHOW CREATE TABLE aliases
----
Table CreateTable
aliases CREATE TABLE aliases (
a OID NULL,
b NAME NULL,
FAMILY "primary" (a, rowid),
FAMILY fam_1_b (b)
)
a OID NULL,
b NAME NULL,
rowid INT NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT "primary" PRIMARY KEY (rowid ASC),
FAMILY "primary" (a, rowid),
FAMILY fam_1_b (b)
)

statement ok
INSERT INTO aliases VALUES (100, 'abc')
Expand Down
24 changes: 15 additions & 9 deletions pkg/sql/logictest/testdata/logic_test/array
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,11 @@ query TT
SHOW CREATE TABLE a
----
a CREATE TABLE a (
b INT[] NULL,
FAMILY "primary" (b, rowid)
)
b INT[] NULL,
rowid INT NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT "primary" PRIMARY KEY (rowid ASC),
FAMILY "primary" (b, rowid)
)

statement ok
DROP TABLE a
Expand Down Expand Up @@ -452,9 +454,11 @@ query TT
SHOW CREATE TABLE a
----
a CREATE TABLE a (
b INT[] NULL,
FAMILY "primary" (b, rowid)
)
b INT[] NULL,
rowid INT NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT "primary" PRIMARY KEY (rowid ASC),
FAMILY "primary" (b, rowid)
)

statement error could not parse "foo" as type int
INSERT INTO a VALUES (ARRAY['foo'])
Expand Down Expand Up @@ -523,9 +527,11 @@ query TT
SHOW CREATE TABLE a
----
a CREATE TABLE a (
b SMALLINT[] NULL,
FAMILY "primary" (b, rowid)
)
b SMALLINT[] NULL,
rowid INT NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT "primary" PRIMARY KEY (rowid ASC),
FAMILY "primary" (b, rowid)
)

statement error integer out of range for type SMALLINT \(column "b"\)
INSERT INTO a VALUES (ARRAY[100000])
Expand Down
Loading