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

backport-2.1: sql: fix pg_catalog.pg_attribute #34734

Merged
merged 1 commit into from
Feb 11, 2019
Merged
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
10 changes: 5 additions & 5 deletions pkg/sql/logictest/testdata/logic_test/pg_catalog
Original file line number Diff line number Diff line change
Expand Up @@ -355,18 +355,18 @@ attrelid relname attname atttypid attstattarget attlen attnum attn
4183203597 t1 b 20 0 8 3 0 -1
4183203597 t1 c 20 0 8 4 0 -1
586319997 primary p 701 0 8 1 0 -1
586319998 t1_a_key a 20 0 8 1 0 -1
586319999 index_key b 20 0 8 1 0 -1
586319999 index_key c 20 0 8 2 0 -1
586319998 t1_a_key a 20 0 8 2 0 -1
586319999 index_key b 20 0 8 3 0 -1
586319999 index_key c 20 0 8 4 0 -1
192646233 t2 t1_id 20 0 8 1 0 -1
192646233 t2 rowid 20 0 8 2 0 -1
2761941313 primary rowid 20 0 8 1 0 -1
2761941313 primary rowid 20 0 8 2 0 -1
2761941314 t2_t1_id_idx t1_id 20 0 8 1 0 -1
226054345 t3 a 20 0 8 1 0 -1
226054345 t3 b 20 0 8 2 0 -1
226054345 t3 c 25 0 -1 3 0 -1
226054345 t3 rowid 20 0 8 4 0 -1
4084598993 primary rowid 20 0 8 1 0 -1
4084598993 primary rowid 20 0 8 4 0 -1
4084598994 t3_a_b_idx a 20 0 8 1 0 -1
4084598994 t3_a_b_idx b 20 0 8 2 0 -1
4252432642 v1 p 701 0 8 1 0 -1
Expand Down
26 changes: 10 additions & 16 deletions pkg/sql/pg_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,7 @@ CREATE TABLE pg_catalog.pg_attrdef (
h := makeOidHasher()
return forEachTableDesc(ctx, p, dbContext, virtualMany,
func(db *sqlbase.DatabaseDescriptor, scName string, table *sqlbase.TableDescriptor) error {
colNum := 0
return forEachColumnInTable(table, func(column *sqlbase.ColumnDescriptor) error {
colNum++
if column.DefaultExpr == nil {
// pg_attrdef only expects rows for columns with default values.
return nil
Expand All @@ -338,7 +336,7 @@ CREATE TABLE pg_catalog.pg_attrdef (
return addRow(
h.ColumnOid(db, scName, table, column), // oid
h.TableOid(db, scName, table), // adrelid
tree.NewDInt(tree.DInt(colNum)), // adnum
tree.NewDInt(tree.DInt(column.ID)), // adnum
defSrc, // adbin
defSrc, // adsrc
)
Expand Down Expand Up @@ -378,15 +376,15 @@ CREATE TABLE pg_catalog.pg_attribute (
h := makeOidHasher()
return forEachTableDesc(ctx, p, dbContext, virtualMany, func(db *sqlbase.DatabaseDescriptor, scName string, table *sqlbase.TableDescriptor) error {
// addColumn adds adds either a table or a index column to the pg_attribute table.
addColumn := func(column *sqlbase.ColumnDescriptor, attRelID tree.Datum, colNum int) error {
addColumn := func(column *sqlbase.ColumnDescriptor, attRelID tree.Datum) error {
colTyp := column.Type.ToDatumType()
return addRow(
attRelID, // attrelid
tree.NewDName(column.Name), // attname
typOid(colTyp), // atttypid
zeroVal, // attstattarget
typLen(colTyp), // attlen
tree.NewDInt(tree.DInt(colNum)), // attnum
attRelID, // attrelid
tree.NewDName(column.Name), // attname
typOid(colTyp), // atttypid
zeroVal, // attstattarget
typLen(colTyp), // attlen
tree.NewDInt(tree.DInt(column.ID)), // attnum
zeroVal, // attndims
negOneVal, // attcacheoff
negOneVal, // atttypmod
Expand All @@ -406,23 +404,19 @@ CREATE TABLE pg_catalog.pg_attribute (
}

// Columns for table.
colNum := 0
if err := forEachColumnInTable(table, func(column *sqlbase.ColumnDescriptor) error {
colNum++
tableID := h.TableOid(db, scName, table)
return addColumn(column, tableID, colNum)
return addColumn(column, tableID)
}); err != nil {
return err
}

// Columns for each index.
return forEachIndexInTable(table, func(index *sqlbase.IndexDescriptor) error {
colNum := 0
return forEachColumnInIndex(table, index,
func(column *sqlbase.ColumnDescriptor) error {
colNum++
idxID := h.IndexOid(db, scName, table, index)
return addColumn(column, idxID, colNum)
return addColumn(column, idxID)
},
)
})
Expand Down