Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mgartner committed Feb 9, 2022
1 parent f1fcb83 commit 10c6604
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 38 deletions.
28 changes: 0 additions & 28 deletions pkg/sql/opt/xform/join_order_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1328,24 +1328,6 @@ func commute(op opt.Operator) bool {
// ON x = a
//
func assoc(edgeA, edgeB *edge) bool {
if edgeB.ses.intersects(edgeA.op.leftVertexes) || edgeA.ses.intersects(edgeB.op.rightVertexes) {
// Ensure that application of the associative property would not lead to
// 'orphaned' predicates, where one or more referenced relations are not in
// the resulting join's inputs. Take as an example this reordering that
// results from applying the associative property:
//
// SELECT * FROM (SELECT * FROM xy INNER JOIN ab ON y = a)
// INNER JOIN uv
// ON x = u
// =>
// SELECT * FROM xy
// INNER JOIN (SELECT * FROM ab INNER JOIN uv ON x = u)
// ON y = a
//
// Note that the x = u predicate references the xy relation, which is not
// in that join's inputs. Therefore, this transformation is invalid.
return false
}
return checkProperty(assocTable, edgeA, edgeB)
}

Expand All @@ -1368,11 +1350,6 @@ func assoc(edgeA, edgeB *edge) bool {
// INNER JOIN ab ON x = a
//
func leftAsscom(edgeA, edgeB *edge) bool {
if edgeB.ses.intersects(edgeA.op.rightVertexes) || edgeA.ses.intersects(edgeB.op.rightVertexes) {
// Ensure that application of the left-asscom property would not lead to
// 'orphaned' predicates. See the assoc() comment for why this is necessary.
return false
}
return checkProperty(leftAsscomTable, edgeA, edgeB)
}

Expand All @@ -1397,11 +1374,6 @@ func leftAsscom(edgeA, edgeB *edge) bool {
// ON x = a
//
func rightAsscom(edgeA, edgeB *edge) bool {
if edgeB.ses.intersects(edgeA.op.leftVertexes) || edgeA.ses.intersects(edgeB.op.leftVertexes) {
// Ensure that application of the right-asscom property would not lead to
// 'orphaned' predicates. See the assoc() comment for why this is necessary.
return false
}
return checkProperty(rightAsscomTable, edgeA, edgeB)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/opt/xform/testdata/external/tpce
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ project
│ │ │ ├── fd: ()-->(10), (11)-->(12), (18)-->(20), (25)-->(31), (18)==(9,11,25), (25)==(9,11,18), (11)==(9,18,25), (9)==(11,18,25)
│ │ │ ├── inner-join (lookup security)
│ │ │ │ ├── columns: symb:9!null dm_date:10!null dm_s_symb:11!null dm_close:12!null s_symb:25!null s_num_out:31!null
│ │ │ │ ├── key columns: [11] = [25]
│ │ │ │ ├── key columns: [9] = [25]
│ │ │ │ ├── lookup columns are key
│ │ │ │ ├── fd: ()-->(10), (11)-->(12), (25)-->(31), (11)==(9,25), (25)==(9,11), (9)==(11,25)
│ │ │ │ ├── inner-join (lookup daily_market)
Expand Down Expand Up @@ -1004,7 +1004,7 @@ project
│ │ │ ├── fd: ()-->(36), (37)-->(38), (44)-->(46), (51)-->(57), (44)==(35,37,51), (51)==(35,37,44), (37)==(35,44,51), (35)==(37,44,51)
│ │ │ ├── inner-join (lookup security)
│ │ │ │ ├── columns: symb:35!null dm_date:36!null dm_s_symb:37!null dm_close:38!null s_symb:51!null s_num_out:57!null
│ │ │ │ ├── key columns: [37] = [51]
│ │ │ │ ├── key columns: [35] = [51]
│ │ │ │ ├── lookup columns are key
│ │ │ │ ├── key: (51)
│ │ │ │ ├── fd: ()-->(36), (37)-->(38), (51)-->(57), (37)==(35,51), (51)==(35,37), (35)==(37,51)
Expand Down Expand Up @@ -1198,7 +1198,7 @@ project
│ │ │ ├── fd: ()-->(7), (8)-->(9), (15)-->(17), (22)-->(28), (15)==(6,8,22), (22)==(6,8,15), (8)==(6,15,22), (6)==(8,15,22)
│ │ │ ├── inner-join (lookup security)
│ │ │ │ ├── columns: symb:6!null dm_date:7!null dm_s_symb:8!null dm_close:9!null s_symb:22!null s_num_out:28!null
│ │ │ │ ├── key columns: [8] = [22]
│ │ │ │ ├── key columns: [6] = [22]
│ │ │ │ ├── lookup columns are key
│ │ │ │ ├── key: (22)
│ │ │ │ ├── fd: ()-->(7), (8)-->(9), (22)-->(28), (8)==(6,22), (22)==(6,8), (6)==(8,22)
Expand Down
14 changes: 7 additions & 7 deletions pkg/sql/opt/xform/testdata/rules/join_order
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ memo (optimized, ~62KB, required=[presentation: b:1,x:2,c:5,y:6,d:9,z:10,a:13,b:
│ └── []
│ ├── best: (scan dz,cols=(9,10))
│ └── cost: 1064.42
├── G11: (inner-join G2 G14 G4) (inner-join G14 G2 G4) (inner-join G5 G16 G4) (inner-join G16 G5 G4) (inner-join G8 G18 G23) (inner-join G18 G8 G23) (merge-join G14 G2 G19 inner-join,+6,+2) (merge-join G16 G5 G19 inner-join,+2,+6) (lookup-join G8 G19 abc,keyCols=[6],outCols=(1,2,5,6,13-16)) (merge-join G18 G8 G19 inner-join,+13,+6)
├── G11: (inner-join G2 G14 G4) (inner-join G14 G2 G4) (inner-join G5 G16 G4) (inner-join G16 G5 G4) (inner-join G8 G18 G23) (inner-join G18 G8 G23) (merge-join G14 G2 G19 inner-join,+6,+2) (merge-join G16 G5 G19 inner-join,+2,+6) (lookup-join G8 G19 abc,keyCols=[2],outCols=(1,2,5,6,13-16)) (merge-join G18 G8 G19 inner-join,+13,+2)
│ ├── [ordering: +(2|6|13)]
│ │ ├── best: (merge-join G14="[ordering: +(6|13)]" G2="[ordering: +2]" G19 inner-join,+6,+2)
│ │ └── cost: 3860.48
Expand All @@ -672,12 +672,12 @@ memo (optimized, ~62KB, required=[presentation: b:1,x:2,c:5,y:6,d:9,z:10,a:13,b:
│ └── []
│ ├── best: (inner-join G2 G10 G21)
│ └── cost: 2257.02
├── G14: (inner-join G5 G18 G23) (inner-join G18 G5 G23) (lookup-join G5 G19 abc,keyCols=[6],outCols=(5,6,13-16)) (merge-join G18 G5 G19 inner-join,+13,+6)
├── G14: (inner-join G5 G18 G25) (inner-join G18 G5 G25) (lookup-join G5 G19 abc,keyCols=[6],outCols=(5,6,13-16)) (merge-join G18 G5 G19 inner-join,+13,+6)
│ ├── [ordering: +(6|13)]
│ │ ├── best: (merge-join G18="[ordering: +13]" G5="[ordering: +6]" G19 inner-join,+13,+6)
│ │ └── cost: 2438.64
│ └── []
│ ├── best: (inner-join G5 G18 G23)
│ ├── best: (inner-join G5 G18 G25)
│ └── cost: 2209.31
├── G15: (inner-join G5 G10 G7) (inner-join G10 G5 G7)
│ ├── [ordering: +(6|10)]
Expand All @@ -686,12 +686,12 @@ memo (optimized, ~62KB, required=[presentation: b:1,x:2,c:5,y:6,d:9,z:10,a:13,b:
│ └── []
│ ├── best: (inner-join G5 G10 G7)
│ └── cost: 2257.02
├── G16: (inner-join G2 G18 G25) (inner-join G18 G2 G25) (lookup-join G2 G19 abc,keyCols=[2],outCols=(1,2,13-16)) (merge-join G18 G2 G19 inner-join,+13,+2)
├── G16: (inner-join G2 G18 G23) (inner-join G18 G2 G23) (lookup-join G2 G19 abc,keyCols=[2],outCols=(1,2,13-16)) (merge-join G18 G2 G19 inner-join,+13,+2)
│ ├── [ordering: +(2|13)]
│ │ ├── best: (merge-join G18="[ordering: +13]" G2="[ordering: +2]" G19 inner-join,+13,+2)
│ │ └── cost: 2438.64
│ └── []
│ ├── best: (inner-join G2 G18 G25)
│ ├── best: (inner-join G2 G18 G23)
│ └── cost: 2209.31
├── G17: (inner-join G2 G15 G4) (inner-join G15 G2 G4) (inner-join G5 G13 G7) (inner-join G13 G5 G7) (inner-join G8 G10 G7) (inner-join G10 G8 G7)
│ ├── [ordering: +(2|6|10)]
Expand All @@ -718,9 +718,9 @@ memo (optimized, ~62KB, required=[presentation: b:1,x:2,c:5,y:6,d:9,z:10,a:13,b:
├── G27: (variable y)
├── G28: (eq G26 G29)
├── G29: (variable z)
├── G30: (eq G27 G31)
├── G30: (eq G26 G31)
├── G31: (variable a)
└── G32: (eq G26 G31)
└── G32: (eq G27 G31)

opt
SELECT * FROM bx, cy, dz, abc WHERE x = y AND y = z AND z = a
Expand Down

0 comments on commit 10c6604

Please sign in to comment.