Skip to content

Commit

Permalink
opt: give synthesized assignment cast columns descriptive names
Browse files Browse the repository at this point in the history
Columns synthesized for assignment casts now have more descriptive
metadata names in the form `<target_column_name>_cast`. This is purely
an aesthetic change and has no effect on semantics.

Release note: None
  • Loading branch information
mgartner committed Dec 30, 2021
1 parent df7a7e8 commit 4afae3c
Show file tree
Hide file tree
Showing 20 changed files with 634 additions and 634 deletions.
20 changes: 10 additions & 10 deletions pkg/sql/opt/exec/execbuilder/testdata/hash_sharded_index
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ vectorized: true
│ auto commit
└── • render
│ columns: (column7, column1, check1)
│ columns: (crdb_internal_a_shard_11_cast, column1, check1)
│ estimated row count: 2
│ render check1: column7 IN (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
│ render check1: crdb_internal_a_shard_11_cast IN (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
│ render column1: column1
│ render column7: column7
│ render crdb_internal_a_shard_11_cast: crdb_internal_a_shard_11_cast
└── • render
│ columns: (column7, column1)
│ columns: (crdb_internal_a_shard_11_cast, column1)
│ estimated row count: 2
│ render column7: crdb_internal.assignment_cast(mod(fnv32(crdb_internal.datums_to_bytes(column1)), 11), NULL::INT4)
│ render crdb_internal_a_shard_11_cast: crdb_internal.assignment_cast(mod(fnv32(crdb_internal.datums_to_bytes(column1)), 11), NULL::INT4)
│ render column1: column1
└── • values
Expand All @@ -53,17 +53,17 @@ vectorized: true
│ auto commit
└── • render
│ columns: (column1, column9, rowid_default, check1)
│ columns: (column1, crdb_internal_a_shard_12_cast, rowid_default, check1)
│ estimated row count: 2
│ render check1: column9 IN (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
│ render check1: crdb_internal_a_shard_12_cast IN (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
│ render column1: column1
│ render rowid_default: rowid_default
│ render column9: column9
│ render crdb_internal_a_shard_12_cast: crdb_internal_a_shard_12_cast
└── • render
│ columns: (column9, rowid_default, column1)
│ columns: (crdb_internal_a_shard_12_cast, rowid_default, column1)
│ estimated row count: 2
│ render column9: crdb_internal.assignment_cast(mod(fnv32(crdb_internal.datums_to_bytes(column1)), 12), NULL::INT4)
│ render crdb_internal_a_shard_12_cast: crdb_internal.assignment_cast(mod(fnv32(crdb_internal.datums_to_bytes(column1)), 12), NULL::INT4)
│ render rowid_default: unique_rowid()
│ render column1: column1
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/opt/exec/explain/testdata/gists_tpce
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ explain(shape):
│ │
│ └── • lookup join (anti)
│ │ table: status_type@status_type_pkey
│ │ equality: (column62) = (st_id)
│ │ equality: (th_st_id_cast) = (st_id)
│ │ equality cols are key
│ │
│ └── • scan buffer
Expand All @@ -361,7 +361,7 @@ explain(shape):
└── • lookup join (anti)
│ table: status_type@status_type_pkey
│ equality: (column127) = (st_id)
│ equality: (t_st_id_cast) = (st_id)
│ equality cols are key
└── • scan buffer
Expand Down
24 changes: 12 additions & 12 deletions pkg/sql/opt/norm/testdata/rules/fold_constants
Original file line number Diff line number Diff line change
Expand Up @@ -832,15 +832,15 @@ INSERT INTO assn_cast (c, qc, i, s) VALUES (' ', 'foo', '1', 2)
insert assn_cast
├── columns: <none>
├── insert-mapping:
│ ├── column12:12 => c:1
│ ├── column13:13 => qc:2
│ ├── c_cast:12 => c:1
│ ├── qc_cast:13 => qc:2
│ ├── column3:10 => i:3
│ ├── column14:14 => s:4
│ ├── s_cast:14 => s:4
│ └── rowid_default:15 => rowid:5
├── cardinality: [0 - 0]
├── volatile, mutations
└── values
├── columns: column3:10!null column12:12!null column13:13!null column14:14!null rowid_default:15
├── columns: column3:10!null c_cast:12!null qc_cast:13!null s_cast:14!null rowid_default:15
├── cardinality: [1 - 1]
├── volatile
├── key: ()
Expand All @@ -854,15 +854,15 @@ INSERT INTO assn_cast (c) VALUES ('foo')
insert assn_cast
├── columns: <none>
├── insert-mapping:
│ ├── column9:9 => c:1
│ ├── c_cast:9 => c:1
│ ├── qc_default:10 => qc:2
│ ├── i_default:11 => i:3
│ ├── s_default:12 => s:4
│ └── rowid_default:13 => rowid:5
├── cardinality: [0 - 0]
├── volatile, mutations
└── values
├── columns: column9:9 qc_default:10 i_default:11 s_default:12 rowid_default:13
├── columns: c_cast:9 qc_default:10 i_default:11 s_default:12 rowid_default:13
├── cardinality: [1 - 1]
├── volatile
├── key: ()
Expand All @@ -882,15 +882,15 @@ INSERT INTO assn_cast(c) VALUES ($1)
insert assn_cast
├── columns: <none>
├── insert-mapping:
│ ├── column9:9 => c:1
│ ├── c_cast:9 => c:1
│ ├── qc_default:10 => qc:2
│ ├── i_default:11 => i:3
│ ├── s_default:12 => s:4
│ └── rowid_default:13 => rowid:5
├── cardinality: [0 - 0]
├── volatile, mutations, has-placeholder
└── values
├── columns: column9:9 qc_default:10 i_default:11 s_default:12 rowid_default:13
├── columns: c_cast:9 qc_default:10 i_default:11 s_default:12 rowid_default:13
├── cardinality: [1 - 1]
├── volatile, has-placeholder
├── key: ()
Expand All @@ -913,12 +913,12 @@ insert assn_cast
│ ├── c_default:10 => c:1
│ ├── qc_default:11 => qc:2
│ ├── i_default:12 => i:3
│ ├── column9:9 => s:4
│ ├── s_cast:9 => s:4
│ └── rowid_default:13 => rowid:5
├── cardinality: [0 - 0]
├── volatile, mutations
└── values
├── columns: column9:9!null c_default:10 qc_default:11 i_default:12 rowid_default:13
├── columns: s_cast:9!null c_default:10 qc_default:11 i_default:12 rowid_default:13
├── cardinality: [1 - 1]
├── volatile
├── key: ()
Expand All @@ -935,12 +935,12 @@ insert assn_cast
│ ├── c_default:10 => c:1
│ ├── qc_default:11 => qc:2
│ ├── i_default:12 => i:3
│ ├── column9:9 => s:4
│ ├── s_cast:9 => s:4
│ └── rowid_default:13 => rowid:5
├── cardinality: [0 - 0]
├── stable+volatile, mutations
└── values
├── columns: column9:9 c_default:10 qc_default:11 i_default:12 rowid_default:13
├── columns: s_cast:9 c_default:10 qc_default:11 i_default:12 rowid_default:13
├── cardinality: [1 - 1]
├── stable+volatile
├── key: ()
Expand Down
32 changes: 16 additions & 16 deletions pkg/sql/opt/norm/testdata/rules/project
Original file line number Diff line number Diff line change
Expand Up @@ -1050,19 +1050,19 @@ INSERT INTO assn_cast (c, qc, i, s) VALUES (' ', 'foo', '1', 2), ('bar', 'baz',
insert assn_cast
├── columns: <none>
├── insert-mapping:
│ ├── column12:12 => c:1
│ ├── column13:13 => qc:2
│ ├── c_cast:12 => c:1
│ ├── qc_cast:13 => qc:2
│ ├── column3:10 => i:3
│ ├── column14:14 => s:4
│ ├── s_cast:14 => s:4
│ └── rowid_default:15 => rowid:5
├── cardinality: [0 - 0]
├── volatile, mutations
└── project
├── columns: rowid_default:15 column3:10!null column12:12 column13:13!null column14:14!null
├── columns: rowid_default:15 column3:10!null c_cast:12 qc_cast:13!null s_cast:14!null
├── cardinality: [2 - 2]
├── volatile
├── values
│ ├── columns: column12:12 column13:13!null column3:10!null column14:14!null
│ ├── columns: c_cast:12 qc_cast:13!null column3:10!null s_cast:14!null
│ ├── cardinality: [2 - 2]
│ ├── immutable
│ ├── ('', 'f', 1, '2')
Expand All @@ -1082,19 +1082,19 @@ INSERT INTO assn_cast (c, qc, i, s) VALUES (' ', 'foo', 1, 'bar'), ($1, $2, $3,
insert assn_cast
├── columns: <none>
├── insert-mapping:
│ ├── column12:12 => c:1
│ ├── column13:13 => qc:2
│ ├── c_cast:12 => c:1
│ ├── qc_cast:13 => qc:2
│ ├── column3:10 => i:3
│ ├── column4:11 => s:4
│ └── rowid_default:14 => rowid:5
├── cardinality: [0 - 0]
├── volatile, mutations, has-placeholder
└── project
├── columns: rowid_default:14 column3:10 column4:11 column12:12 column13:13
├── columns: rowid_default:14 column3:10 column4:11 c_cast:12 qc_cast:13
├── cardinality: [2 - 2]
├── volatile, has-placeholder
├── values
│ ├── columns: column12:12 column13:13 column3:10 column4:11
│ ├── columns: c_cast:12 qc_cast:13 column3:10 column4:11
│ ├── cardinality: [2 - 2]
│ ├── immutable, has-placeholder
│ ├── ('', 'f', 1, 'bar')
Expand All @@ -1116,28 +1116,28 @@ INSERT INTO assn_cast (c, qc, i, s) (SELECT ' ', 'foo', '1', unnest(ARRAY[1, 2,
insert assn_cast
├── columns: <none>
├── insert-mapping:
│ ├── column12:12 => c:1
│ ├── column13:13 => qc:2
│ ├── c_cast:12 => c:1
│ ├── qc_cast:13 => qc:2
│ ├── "?column?":11 => i:3
│ ├── column14:14 => s:4
│ ├── s_cast:14 => s:4
│ └── rowid_default:15 => rowid:5
├── cardinality: [0 - 0]
├── volatile, mutations
└── project
├── columns: rowid_default:15 column12:12!null column13:13!null "?column?":11!null column14:14!null
├── columns: rowid_default:15 c_cast:12!null qc_cast:13!null "?column?":11!null s_cast:14!null
├── cardinality: [3 - 3]
├── volatile
├── fd: ()-->(11-13)
├── values
│ ├── columns: column14:14!null
│ ├── columns: s_cast:14!null
│ ├── cardinality: [3 - 3]
│ ├── ('1',)
│ ├── ('2',)
│ └── ('3',)
└── projections
├── unique_rowid() [as=rowid_default:15, volatile]
├── '' [as=column12:12]
├── 'f' [as=column13:13]
├── '' [as=c_cast:12]
├── 'f' [as=qc_cast:13]
└── 1 [as="?column?":11]

# Do not push assignment casts into values when other projections reference the
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/opt/optbuilder/mutation_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,7 @@ func (mb *mutationBuilder) addAssignmentCasts(srcCols opt.OptionalColList) {
// two columns with different names but the same ID. To get the correct
// column, we perform a lookup with the ID and the name. See #61520.
scopeCol := projectionScope.getColumnWithIDAndReferenceName(colID, targetCol.ColName())
scopeCol.name = scopeCol.name.WithMetadataName("")
scopeCol.name = scopeCol.name.WithMetadataName(fmt.Sprintf("%s_cast", targetCol.ColName()))
mb.b.populateSynthesizedColumn(scopeCol, cast)

// Replace old source column with the new one.
Expand Down
24 changes: 12 additions & 12 deletions pkg/sql/opt/optbuilder/testdata/fk-on-update-cascade
Original file line number Diff line number Diff line change
Expand Up @@ -752,12 +752,12 @@ root
│ ├── columns: <none>
│ ├── fetch columns: p:4
│ ├── update-mapping:
│ │ └── column8:8 => p:1
│ │ └── p_cast:8 => p:1
│ ├── input binding: &1
│ ├── cascades
│ │ └── child_assn_cast_p_fkey
│ └── project
│ ├── columns: column8:8!null p:4!null crdb_internal_mvcc_timestamp:5 tableoid:6
│ ├── columns: p_cast:8!null p:4!null crdb_internal_mvcc_timestamp:5 tableoid:6
│ ├── project
│ │ ├── columns: p_new:7!null p:4!null crdb_internal_mvcc_timestamp:5 tableoid:6
│ │ ├── select
Expand All @@ -769,17 +769,17 @@ root
│ │ └── projections
│ │ └── 1.45 [as=p_new:7]
│ └── projections
│ └── assignment-cast: DECIMAL(10,2) [as=column8:8]
│ └── assignment-cast: DECIMAL(10,2) [as=p_cast:8]
│ └── p_new:7
└── cascade
└── update child_assn_cast
├── columns: <none>
├── fetch columns: c:13 child_assn_cast.p:14
├── update-mapping:
│ └── column19:19 => child_assn_cast.p:10
│ └── p_cast:19 => child_assn_cast.p:10
├── input binding: &2
├── project
│ ├── columns: column19:19!null c:13!null child_assn_cast.p:14!null p_old:17!null p_new:18!null
│ ├── columns: p_cast:19!null c:13!null child_assn_cast.p:14!null p_old:17!null p_new:18!null
│ ├── inner-join (hash)
│ │ ├── columns: c:13!null child_assn_cast.p:14!null p_old:17!null p_new:18!null
│ │ ├── scan child_assn_cast
Expand All @@ -790,13 +790,13 @@ root
│ │ │ │ ├── columns: p_old:17!null p_new:18!null
│ │ │ │ └── mapping:
│ │ │ │ ├── parent_assn_cast.p:4 => p_old:17
│ │ │ │ └── column8:8 => p_new:18
│ │ │ │ └── p_cast:8 => p_new:18
│ │ │ └── filters
│ │ │ └── p_old:17 IS DISTINCT FROM p_new:18
│ │ └── filters
│ │ └── child_assn_cast.p:14 = p_old:17
│ └── projections
│ └── assignment-cast: DECIMAL(10) [as=column19:19]
│ └── assignment-cast: DECIMAL(10) [as=p_cast:19]
│ └── p_new:18
└── f-k-checks
└── f-k-checks-item: child_assn_cast(p) -> parent_assn_cast(p)
Expand All @@ -805,7 +805,7 @@ root
├── with-scan &2
│ ├── columns: p:20!null
│ └── mapping:
│ └── column19:19 => p:20
│ └── p_cast:19 => p:20
├── scan parent_assn_cast
│ └── columns: parent_assn_cast.p:21!null
└── filters
Expand Down Expand Up @@ -1326,13 +1326,13 @@ root
├── columns: <none>
├── fetch columns: t.public.child_diff_type.c:12(int) t.public.child_diff_type.p:13(int2)
├── update-mapping:
│ └── column18:18 => t.public.child_diff_type.p:9
│ └── p_cast:18 => t.public.child_diff_type.p:9
├── input binding: &2
├── cardinality: [0 - 0]
├── volatile, mutations
├── stats: [rows=0]
├── project
│ ├── columns: column18:18(int2!null) t.public.child_diff_type.c:12(int!null) t.public.child_diff_type.p:13(int2!null) p_old:16(int!null) p_new:17(int!null)
│ ├── columns: p_cast:18(int2!null) t.public.child_diff_type.c:12(int!null) t.public.child_diff_type.p:13(int2!null) p_old:16(int!null) p_new:17(int!null)
│ ├── immutable
│ ├── stats: [rows=3.3, distinct(18)=0.333317413, null(18)=0]
│ ├── key: (12)
Expand Down Expand Up @@ -1376,7 +1376,7 @@ root
│ │ ├── variable: t.public.child_diff_type.p:13 [type=int2]
│ │ └── variable: p_old:16 [type=int]
│ └── projections
│ └── assignment-cast: INT2 [as=column18:18, type=int2, outer=(17), immutable]
│ └── assignment-cast: INT2 [as=p_cast:18, type=int2, outer=(17), immutable]
│ └── variable: p_new:17 [type=int]
└── f-k-checks
└── f-k-checks-item: child_diff_type(p) -> parent_diff_type(p)
Expand All @@ -1389,7 +1389,7 @@ root
├── with-scan &2
│ ├── columns: p:19(int2!null)
│ ├── mapping:
│ │ └── column18:18(int2) => p:19(int2)
│ │ └── p_cast:18(int2) => p:19(int2)
│ ├── stats: [rows=3.3, distinct(19)=0.333317413, null(19)=0]
│ ├── fd: ()-->(19)
│ └── cte-uses
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/opt/optbuilder/testdata/fk-on-update-set-default
Original file line number Diff line number Diff line change
Expand Up @@ -804,10 +804,10 @@ root
├── columns: <none>
├── fetch columns: c:12 child_assn_cast.p:13
├── update-mapping:
│ └── column19:19 => child_assn_cast.p:9
│ └── p_cast:19 => child_assn_cast.p:9
├── input binding: &2
├── project
│ ├── columns: column19:19!null c:12!null child_assn_cast.p:13!null p_old:16!null p_new:17!null
│ ├── columns: p_cast:19!null c:12!null child_assn_cast.p:13!null p_old:16!null p_new:17!null
│ ├── project
│ │ ├── columns: p_new:18!null c:12!null child_assn_cast.p:13!null p_old:16!null p_new:17!null
│ │ ├── inner-join (cross)
Expand All @@ -828,7 +828,7 @@ root
│ │ └── projections
│ │ └── 1.45::DECIMAL(10,2) [as=p_new:18]
│ └── projections
│ └── assignment-cast: DECIMAL(10) [as=column19:19]
│ └── assignment-cast: DECIMAL(10) [as=p_cast:19]
│ └── p_new:18
└── f-k-checks
└── f-k-checks-item: child_assn_cast(p) -> parent_assn_cast(p)
Expand All @@ -837,7 +837,7 @@ root
├── with-scan &2
│ ├── columns: p:20!null
│ └── mapping:
│ └── column19:19 => p:20
│ └── p_cast:19 => p:20
├── scan parent_assn_cast
│ └── columns: parent_assn_cast.p:21!null
└── filters
Expand Down
Loading

0 comments on commit 4afae3c

Please sign in to comment.