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

opt: improve re-typing to equivalent but non-identical types #51023

Merged
merged 1 commit into from
Jul 10, 2020
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
14 changes: 9 additions & 5 deletions pkg/sql/logictest/testdata/logic_test/vectorize_local
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,15 @@ EXPLAIN (VEC) SELECT _int2 * _int2 FROM ints WHERE _int4 + _int4 = _int8 + 2
----
└ Node 1
└ *colexec.projMultInt16Int16Op
└ *colexec.selEQInt64Int64Op
└ *colexec.projPlusInt64Int64ConstOp
└ *colexec.projPlusInt32Int32Op
└ *colfetcher.colBatchScan
└ *colexec.projMultInt64Int64Op
└ *colexec.castOp
└ *colexec.castOp
└ *colexec.selEQInt64Int64Op
└ *colexec.projPlusInt64Int64ConstOp
└ *colexec.projPlusInt64Int64Op
└ *colexec.castOp
└ *colexec.castOp
└ *colfetcher.colBatchScan

query I
SELECT _int2 * _int2 FROM ints WHERE _int4 + _int4 = _int8 + 2
Expand Down
56 changes: 34 additions & 22 deletions pkg/sql/logictest/testdata/logic_test/vectorize_overloads
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,28 @@ EXPLAIN (VEC) SELECT _inet - _int2 FROM many_types
----
└ Node 1
└ *colexec.projMinusDatumInt16Op
└ *colfetcher.colBatchScan
└ *colexec.projMinusDatumInt64Op
└ *colexec.castOp
└ *colfetcher.colBatchScan

query T
EXPLAIN (VEC) SELECT _int2^_int4 FROM many_types
----
└ Node 1
└ *colexec.projPowInt16Int32Op
└ *colfetcher.colBatchScan
└ *colexec.projPowInt64Int64Op
└ *colexec.castOp
└ *colexec.castOp
└ *colfetcher.colBatchScan

query T
EXPLAIN (VEC) SELECT _int2^_int FROM many_types
----
└ Node 1
└ *colexec.projPowInt16Int64Op
└ *colfetcher.colBatchScan
└ *colexec.projPowInt64Int64Op
└ *colexec.castOp
└ *colfetcher.colBatchScan

query T
EXPLAIN (VEC) SELECT _float^_float FROM many_types
Expand All @@ -138,8 +142,9 @@ EXPLAIN (VEC) SELECT _decimal^_int4 FROM many_types
----
└ Node 1
└ *colexec.projPowDecimalInt32Op
└ *colfetcher.colBatchScan
└ *colexec.projPowDecimalInt64Op
└ *colexec.castOp
└ *colfetcher.colBatchScan

query R rowsort
SELECT _float^_float FROM many_types
Expand Down Expand Up @@ -182,8 +187,9 @@ EXPLAIN (VEC) SELECT _int4 + _inet FROM many_types
----
└ Node 1
└ *colexec.projPlusInt32DatumOp
└ *colfetcher.colBatchScan
└ *colexec.projPlusDatumInt64Op
└ *colexec.castOp
└ *colfetcher.colBatchScan

query T rowsort
SELECT _int4 + _inet FROM many_types
Expand Down Expand Up @@ -377,16 +383,18 @@ EXPLAIN (VEC) SELECT _varbit << _int2 FROM many_types
----
└ Node 1
└ *colexec.projLShiftDatumInt16Op
└ *colfetcher.colBatchScan
└ *colexec.projLShiftDatumInt64Op
└ *colexec.castOp
└ *colfetcher.colBatchScan

query T
EXPLAIN (VEC) SELECT _varbit << _int4 FROM many_types
----
└ Node 1
└ *colexec.projLShiftDatumInt32Op
└ *colfetcher.colBatchScan
└ *colexec.projLShiftDatumInt64Op
└ *colexec.castOp
└ *colfetcher.colBatchScan

query T
EXPLAIN (VEC) SELECT _varbit << _int FROM many_types
Expand All @@ -410,16 +418,18 @@ EXPLAIN (VEC) SELECT _varbit >> _int2 FROM many_types
----
└ Node 1
└ *colexec.projRShiftDatumInt16Op
└ *colfetcher.colBatchScan
└ *colexec.projRShiftDatumInt64Op
└ *colexec.castOp
└ *colfetcher.colBatchScan

query T
EXPLAIN (VEC) SELECT _varbit >> _int4 FROM many_types
----
└ Node 1
└ *colexec.projRShiftDatumInt32Op
└ *colfetcher.colBatchScan
└ *colexec.projRShiftDatumInt64Op
└ *colexec.castOp
└ *colfetcher.colBatchScan

query T
EXPLAIN (VEC) SELECT _varbit >> _int FROM many_types
Expand Down Expand Up @@ -458,8 +468,9 @@ EXPLAIN (VEC) SELECT _json -> _int2 FROM many_types
----
└ Node 1
└ *colexec.projJSONFetchValDatumInt16Op
└ *colfetcher.colBatchScan
└ *colexec.projJSONFetchValDatumInt64Op
└ *colexec.castOp
└ *colfetcher.colBatchScan

query I rowsort
SELECT _int2^_int FROM many_types WHERE _int2 < 10 AND _int < 10
Expand Down Expand Up @@ -492,8 +503,9 @@ EXPLAIN (VEC) SELECT _json -> _int4 FROM many_types
----
└ Node 1
└ *colexec.projJSONFetchValDatumInt32Op
└ *colfetcher.colBatchScan
└ *colexec.projJSONFetchValDatumInt64Op
└ *colexec.castOp
└ *colfetcher.colBatchScan

query T
SELECT _json -> _int4 FROM many_types
Expand Down
46 changes: 23 additions & 23 deletions pkg/sql/opt/exec/execbuilder/testdata/insert
Original file line number Diff line number Diff line change
Expand Up @@ -424,29 +424,29 @@ query TTTTT
EXPLAIN (VERBOSE)
INSERT INTO insert_t (SELECT length(k), 2 FROM kv ORDER BY k || v LIMIT 10) RETURNING x+v
----
· distribution local · ·
· vectorized false · ·
render · · ("?column?") ·
│ render 0 x + v · ·
└── run · · (x, v, rowid[hidden]) ·
└── insert · · (x, v, rowid[hidden]) ·
│ into insert_t(x, v, rowid) · ·
│ strategy inserter · ·
└── render · · (length, "?column?", column9) ·
│ render 0 length · ·
│ render 1 "?column?" · ·
│ render 2 unique_rowid() · ·
└── limit · · (length, "?column?", column8) +column8
│ count 10 · ·
└── sort · · (length, "?column?", column8) +column8
│ order +column8 · ·
└── render · · (length, "?column?", column8) ·
│ render 0 length(k) · ·
│ render 1 2 · ·
│ render 2 k || v · ·
└── scan · · (k, v) ·
· table kv@primary · ·
· spans FULL SCAN · ·
· distribution local · ·
· vectorized false · ·
render · · ("?column?") ·
│ render 0 x + v · ·
└── run · · (x, v, rowid[hidden]) ·
└── insert · · (x, v, rowid[hidden]) ·
│ into insert_t(x, v, rowid) · ·
│ strategy inserter · ·
└── render · · (length, "?column?", column9) ·
│ render 0 length · ·
│ render 1 "?column?" · ·
│ render 2 unique_rowid() · ·
└── limit · · (length, "?column?", column8) +column8
│ count 10 · ·
└── sort · · (length, "?column?", column8) +column8
│ order +column8 · ·
└── render · · (length, "?column?", column8) ·
│ render 0 length(k) · ·
│ render 1 2 · ·
│ render 2 k::STRING || v::STRING · ·
└── scan · · (k, v) ·
· table kv@primary · ·
· spans FULL SCAN · ·

# ------------------------------------------------------------------------------
# Insert rows into table during schema changes.
Expand Down
5 changes: 3 additions & 2 deletions pkg/sql/opt/optbuilder/testdata/scalar
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,9 @@ concat [type=int[]]
├── array: [type=int[]]
│ ├── const: 1 [type=int]
│ └── const: 2 [type=int]
└── cast: INT2 [type=int2]
└── null [type=unknown]
└── cast: INT8 [type=int]
└── cast: INT2 [type=int2]
└── null [type=unknown]

build-scalar
NULL::oid || ARRAY[1, 2]
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/opt/optbuilder/testdata/select
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ project
├── scan kv
│ └── columns: k:1!null v:2
└── projections
└── v:2 || 'foo' [as=r:3]
└── v:2::STRING || 'foo' [as=r:3]

build
SELECT lower(v) FROM kv
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/opt/optbuilder/testdata/update
Original file line number Diff line number Diff line change
Expand Up @@ -1646,15 +1646,15 @@ update decimals
│ │ │ │ │ ├── columns: decimals.a:5!null decimals.b:6 c:7 decimals.d:8
│ │ │ │ │ └── computed column expressions
│ │ │ │ │ └── decimals.d:8
│ │ │ │ │ └── decimals.a:5 + c:7
│ │ │ │ │ └── decimals.a:5::DECIMAL + c:7::DECIMAL
│ │ │ │ └── projections
│ │ │ │ ├── 1.1 [as=a_new:9]
│ │ │ │ └── ARRAY[0.95,NULL,15] [as=b_new:10]
│ │ │ └── projections
│ │ │ ├── crdb_internal.round_decimal_values(a_new:9, 0) [as=a:11]
│ │ │ └── crdb_internal.round_decimal_values(b_new:10, 1) [as=b:12]
│ │ └── projections
│ │ └── a:11 + c:7 [as=column13:13]
│ │ └── a:11 + c:7::DECIMAL [as=column13:13]
│ └── projections
│ └── crdb_internal.round_decimal_values(column13:13, 1) [as=d:14]
└── projections
Expand Down
12 changes: 6 additions & 6 deletions pkg/sql/opt/optbuilder/testdata/upsert
Original file line number Diff line number Diff line change
Expand Up @@ -1689,13 +1689,13 @@ upsert decimals
│ │ │ │ │ │ ├── columns: decimals.a:13!null decimals.b:14 decimals.c:15 decimals.d:16
│ │ │ │ │ │ └── computed column expressions
│ │ │ │ │ │ └── decimals.d:16
│ │ │ │ │ │ └── decimals.a:13 + decimals.c:15
│ │ │ │ │ │ └── decimals.a:13::DECIMAL + decimals.c:15::DECIMAL
│ │ │ │ │ └── filters
│ │ │ │ │ └── a:8 = decimals.a:13
│ │ │ │ └── projections
│ │ │ │ └── crdb_internal.round_decimal_values(b:9, 1) [as=b:17]
│ │ │ └── projections
│ │ │ └── decimals.a:13 + decimals.c:15 [as=column18:18]
│ │ │ └── decimals.a:13::DECIMAL + decimals.c:15::DECIMAL [as=column18:18]
│ │ └── projections
│ │ └── crdb_internal.round_decimal_values(column18:18, 1) [as=d:19]
│ └── projections
Expand Down Expand Up @@ -1768,11 +1768,11 @@ upsert decimals
│ │ │ │ │ ├── columns: decimals.a:13!null decimals.b:14 decimals.c:15 decimals.d:16
│ │ │ │ │ └── computed column expressions
│ │ │ │ │ └── decimals.d:16
│ │ │ │ │ └── decimals.a:13 + decimals.c:15
│ │ │ │ │ └── decimals.a:13::DECIMAL + decimals.c:15::DECIMAL
│ │ │ │ └── filters
│ │ │ │ └── a:8 = decimals.a:13
│ │ │ └── projections
│ │ │ └── decimals.a:13 + decimals.c:15 [as=column17:17]
│ │ │ └── decimals.a:13::DECIMAL + decimals.c:15::DECIMAL [as=column17:17]
│ │ └── projections
│ │ └── crdb_internal.round_decimal_values(column17:17, 1) [as=d:18]
│ └── projections
Expand Down Expand Up @@ -1852,15 +1852,15 @@ upsert decimals
│ │ │ │ │ │ │ ├── columns: decimals.a:13!null decimals.b:14 decimals.c:15 decimals.d:16
│ │ │ │ │ │ │ └── computed column expressions
│ │ │ │ │ │ │ └── decimals.d:16
│ │ │ │ │ │ │ └── decimals.a:13 + decimals.c:15
│ │ │ │ │ │ │ └── decimals.a:13::DECIMAL + decimals.c:15::DECIMAL
│ │ │ │ │ │ └── filters
│ │ │ │ │ │ └── a:8 = decimals.a:13
│ │ │ │ │ └── projections
│ │ │ │ │ └── ARRAY[0.99] [as=b_new:17]
│ │ │ │ └── projections
│ │ │ │ └── crdb_internal.round_decimal_values(b_new:17, 1) [as=b:18]
│ │ │ └── projections
│ │ │ └── decimals.a:13 + decimals.c:15 [as=column19:19]
│ │ │ └── decimals.a:13::DECIMAL + decimals.c:15::DECIMAL [as=column19:19]
│ │ └── projections
│ │ └── crdb_internal.round_decimal_values(column19:19, 1) [as=d:20]
│ └── projections
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/opt/xform/testdata/external/hibernate
Original file line number Diff line number Diff line change
Expand Up @@ -2020,7 +2020,7 @@ project
│ │ │ │ └── filters
│ │ │ │ └── li.productid:10 = p.productid:12 [outer=(10,12), constraints=(/10: (/NULL - ]; /12: (/NULL - ]), fd=(10)==(12), (12)==(10)]
│ │ │ └── projections
│ │ │ └── li.quantity:11 * cost:14 [as=column16:16, outer=(11,14), immutable]
│ │ │ └── li.quantity:11::INT8 * cost:14::DECIMAL [as=column16:16, outer=(11,14), immutable]
│ │ ├── left-join (merge)
│ │ │ ├── columns: order0_.customerid:1!null order0_.ordernumber:2!null orderdate:3!null lineitems1_.customerid:4 lineitems1_.ordernumber:5 lineitems1_.productid:6 lineitems1_.quantity:7
│ │ │ ├── left ordering: +1,+2
Expand Down Expand Up @@ -2198,7 +2198,7 @@ project
│ │ │ │ │ │ └── filters
│ │ │ │ │ │ └── li.productid:17 = p.productid:19 [outer=(17,19), constraints=(/17: (/NULL - ]; /19: (/NULL - ]), fd=(17)==(19), (19)==(17)]
│ │ │ │ │ └── projections
│ │ │ │ │ └── li.quantity:18 * p.cost:21 [as=column23:23, outer=(18,21), immutable]
│ │ │ │ │ └── li.quantity:18::INT8 * p.cost:21::DECIMAL [as=column23:23, outer=(18,21), immutable]
│ │ │ │ └── filters
│ │ │ │ ├── li.customerid:15 = orders1_.customerid:4 [outer=(4,15), constraints=(/4: (/NULL - ]; /15: (/NULL - ]), fd=(4)==(15), (15)==(4)]
│ │ │ │ └── li.ordernumber:16 = orders1_.ordernumber:5 [outer=(5,16), constraints=(/5: (/NULL - ]; /16: (/NULL - ]), fd=(5)==(16), (16)==(5)]
Expand Down Expand Up @@ -2316,7 +2316,7 @@ project
│ │ │ │ └── filters
│ │ │ │ └── li.productid:10 = p.productid:12 [outer=(10,12), constraints=(/10: (/NULL - ]; /12: (/NULL - ]), fd=(10)==(12), (12)==(10)]
│ │ │ └── projections
│ │ │ └── li.quantity:11 * cost:14 [as=column16:16, outer=(11,14), immutable]
│ │ │ └── li.quantity:11::INT8 * cost:14::DECIMAL [as=column16:16, outer=(11,14), immutable]
│ │ ├── left-join (merge)
│ │ │ ├── columns: order0_.customerid:1!null order0_.ordernumber:2!null orderdate:3!null lineitems1_.customerid:4 lineitems1_.ordernumber:5 lineitems1_.productid:6 lineitems1_.quantity:7
│ │ │ ├── left ordering: +1,+2
Expand Down Expand Up @@ -2414,7 +2414,7 @@ project
│ │ │ │ └── filters
│ │ │ │ └── li.productid:6 = p.productid:8 [outer=(6,8), constraints=(/6: (/NULL - ]; /8: (/NULL - ]), fd=(6)==(8), (8)==(6)]
│ │ │ └── projections
│ │ │ └── quantity:7 * cost:10 [as=column12:12, outer=(7,10), immutable]
│ │ │ └── quantity:7::INT8 * cost:10::DECIMAL [as=column12:12, outer=(7,10), immutable]
│ │ └── filters
│ │ ├── li.customerid:4 = order0_.customerid:1 [outer=(1,4), constraints=(/1: (/NULL - ]; /4: (/NULL - ]), fd=(1)==(4), (4)==(1)]
│ │ └── li.ordernumber:5 = order0_.ordernumber:2 [outer=(2,5), constraints=(/2: (/NULL - ]; /5: (/NULL - ]), fd=(2)==(5), (5)==(2)]
Expand Down
Loading