diff --git a/go/vt/vtgate/planbuilder/testdata/filter_cases.txt b/go/vt/vtgate/planbuilder/testdata/filter_cases.txt index f0d8fc4182d..29e6c03d578 100644 --- a/go/vt/vtgate/planbuilder/testdata/filter_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/filter_cases.txt @@ -691,10 +691,10 @@ Gen4 plan same as above } # Multi-route unique vindex constraint -"select /*vt+ ALLOW_HASH_JOIN */ user_extra.id from user join user_extra on user.col = user_extra.col where user.id = 5" +"select user_extra.id from user join user_extra on user.col = user_extra.col where user.id = 5" { "QueryType": "SELECT", - "Original": "select /*vt+ ALLOW_HASH_JOIN */ user_extra.id from user join user_extra on user.col = user_extra.col where user.id = 5", + "Original": "select user_extra.id from user join user_extra on user.col = user_extra.col where user.id = 5", "Instructions": { "OperatorType": "Join", "Variant": "Join", @@ -712,7 +712,7 @@ Gen4 plan same as above "Sharded": true }, "FieldQuery": "select `user`.col from `user` where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ `user`.col from `user` where `user`.id = 5", + "Query": "select `user`.col from `user` where `user`.id = 5", "Table": "`user`", "Values": [ 5 @@ -727,7 +727,7 @@ Gen4 plan same as above "Sharded": true }, "FieldQuery": "select user_extra.id from user_extra where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ user_extra.id from user_extra where user_extra.col = :user_col", + "Query": "select user_extra.id from user_extra where user_extra.col = :user_col", "Table": "user_extra" } ] @@ -735,12 +735,14 @@ Gen4 plan same as above } { "QueryType": "SELECT", - "Original": "select /*vt+ ALLOW_HASH_JOIN */ user_extra.id from user join user_extra on user.col = user_extra.col where user.id = 5", + "Original": "select user_extra.id from user join user_extra on user.col = user_extra.col where user.id = 5", "Instructions": { "OperatorType": "Join", - "Variant": "HashJoin", - "ComparisonType": "INT16", - "JoinColumnIndexes": "2", + "Variant": "Join", + "JoinColumnIndexes": "1", + "JoinVars": { + "user_col": 0 + }, "Predicate": "`user`.col = user_extra.col", "TableName": "`user`_user_extra", "Inputs": [ @@ -752,7 +754,7 @@ Gen4 plan same as above "Sharded": true }, "FieldQuery": "select `user`.col from `user` where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ `user`.col from `user` where `user`.id = 5", + "Query": "select `user`.col from `user` where `user`.id = 5", "Table": "`user`", "Values": [ 5 @@ -766,8 +768,8 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select user_extra.col, user_extra.id from user_extra where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ user_extra.col, user_extra.id from user_extra", + "FieldQuery": "select user_extra.id from user_extra where 1 != 1", + "Query": "select user_extra.id from user_extra where user_extra.col = :user_col", "Table": "user_extra" } ] @@ -928,10 +930,10 @@ Gen4 plan same as above } # Multi-route with non-route constraint, should use first route. -"select /*vt+ ALLOW_HASH_JOIN */ user_extra.id from user join user_extra on user.col = user_extra.col where 1 = 1" +"select user_extra.id from user join user_extra on user.col = user_extra.col where 1 = 1" { "QueryType": "SELECT", - "Original": "select /*vt+ ALLOW_HASH_JOIN */ user_extra.id from user join user_extra on user.col = user_extra.col where 1 = 1", + "Original": "select user_extra.id from user join user_extra on user.col = user_extra.col where 1 = 1", "Instructions": { "OperatorType": "Join", "Variant": "Join", @@ -949,7 +951,7 @@ Gen4 plan same as above "Sharded": true }, "FieldQuery": "select `user`.col from `user` where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ `user`.col from `user` where 1 = 1", + "Query": "select `user`.col from `user` where 1 = 1", "Table": "`user`" }, { @@ -960,7 +962,7 @@ Gen4 plan same as above "Sharded": true }, "FieldQuery": "select user_extra.id from user_extra where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ user_extra.id from user_extra where user_extra.col = :user_col", + "Query": "select user_extra.id from user_extra where user_extra.col = :user_col", "Table": "user_extra" } ] @@ -968,12 +970,14 @@ Gen4 plan same as above } { "QueryType": "SELECT", - "Original": "select /*vt+ ALLOW_HASH_JOIN */ user_extra.id from user join user_extra on user.col = user_extra.col where 1 = 1", + "Original": "select user_extra.id from user join user_extra on user.col = user_extra.col where 1 = 1", "Instructions": { "OperatorType": "Join", - "Variant": "HashJoin", - "ComparisonType": "INT16", - "JoinColumnIndexes": "2", + "Variant": "Join", + "JoinColumnIndexes": "1", + "JoinVars": { + "user_col": 0 + }, "Predicate": "`user`.col = user_extra.col", "TableName": "`user`_user_extra", "Inputs": [ @@ -985,7 +989,7 @@ Gen4 plan same as above "Sharded": true }, "FieldQuery": "select `user`.col from `user` where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ `user`.col from `user` where 1 = 1", + "Query": "select `user`.col from `user` where 1 = 1", "Table": "`user`" }, { @@ -995,8 +999,8 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select user_extra.col, user_extra.id from user_extra where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ user_extra.col, user_extra.id from user_extra where 1 = 1", + "FieldQuery": "select user_extra.id from user_extra where 1 != 1", + "Query": "select user_extra.id from user_extra where 1 = 1 and user_extra.col = :user_col", "Table": "user_extra" } ] @@ -3497,3 +3501,163 @@ Gen4 plan same as above } } Gen4 plan same as above + +# Multi-route unique vindex constraint (with hash join) +"select /*vt+ ALLOW_HASH_JOIN */ user_extra.id from user join user_extra on user.col = user_extra.col where user.id = 5" +{ + "QueryType": "SELECT", + "Original": "select /*vt+ ALLOW_HASH_JOIN */ user_extra.id from user join user_extra on user.col = user_extra.col where user.id = 5", + "Instructions": { + "OperatorType": "Join", + "Variant": "Join", + "JoinColumnIndexes": "1", + "JoinVars": { + "user_col": 0 + }, + "TableName": "`user`_user_extra", + "Inputs": [ + { + "OperatorType": "Route", + "Variant": "SelectEqualUnique", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select `user`.col from `user` where 1 != 1", + "Query": "select /*vt+ ALLOW_HASH_JOIN */ `user`.col from `user` where `user`.id = 5", + "Table": "`user`", + "Values": [ + 5 + ], + "Vindex": "user_index" + }, + { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select user_extra.id from user_extra where 1 != 1", + "Query": "select /*vt+ ALLOW_HASH_JOIN */ user_extra.id from user_extra where user_extra.col = :user_col", + "Table": "user_extra" + } + ] + } +} +{ + "QueryType": "SELECT", + "Original": "select /*vt+ ALLOW_HASH_JOIN */ user_extra.id from user join user_extra on user.col = user_extra.col where user.id = 5", + "Instructions": { + "OperatorType": "Join", + "Variant": "HashJoin", + "ComparisonType": "INT16", + "JoinColumnIndexes": "2", + "Predicate": "`user`.col = user_extra.col", + "TableName": "`user`_user_extra", + "Inputs": [ + { + "OperatorType": "Route", + "Variant": "SelectEqualUnique", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select `user`.col from `user` where 1 != 1", + "Query": "select /*vt+ ALLOW_HASH_JOIN */ `user`.col from `user` where `user`.id = 5", + "Table": "`user`", + "Values": [ + 5 + ], + "Vindex": "user_index" + }, + { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select user_extra.col, user_extra.id from user_extra where 1 != 1", + "Query": "select /*vt+ ALLOW_HASH_JOIN */ user_extra.col, user_extra.id from user_extra", + "Table": "user_extra" + } + ] + } +} + +# Multi-route with non-route constraint, should use first route. +"select /*vt+ ALLOW_HASH_JOIN */ user_extra.id from user join user_extra on user.col = user_extra.col where 1 = 1" +{ + "QueryType": "SELECT", + "Original": "select /*vt+ ALLOW_HASH_JOIN */ user_extra.id from user join user_extra on user.col = user_extra.col where 1 = 1", + "Instructions": { + "OperatorType": "Join", + "Variant": "Join", + "JoinColumnIndexes": "1", + "JoinVars": { + "user_col": 0 + }, + "TableName": "`user`_user_extra", + "Inputs": [ + { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select `user`.col from `user` where 1 != 1", + "Query": "select /*vt+ ALLOW_HASH_JOIN */ `user`.col from `user` where 1 = 1", + "Table": "`user`" + }, + { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select user_extra.id from user_extra where 1 != 1", + "Query": "select /*vt+ ALLOW_HASH_JOIN */ user_extra.id from user_extra where user_extra.col = :user_col", + "Table": "user_extra" + } + ] + } +} +{ + "QueryType": "SELECT", + "Original": "select /*vt+ ALLOW_HASH_JOIN */ user_extra.id from user join user_extra on user.col = user_extra.col where 1 = 1", + "Instructions": { + "OperatorType": "Join", + "Variant": "HashJoin", + "ComparisonType": "INT16", + "JoinColumnIndexes": "2", + "Predicate": "`user`.col = user_extra.col", + "TableName": "`user`_user_extra", + "Inputs": [ + { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select `user`.col from `user` where 1 != 1", + "Query": "select /*vt+ ALLOW_HASH_JOIN */ `user`.col from `user` where 1 = 1", + "Table": "`user`" + }, + { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select user_extra.col, user_extra.id from user_extra where 1 != 1", + "Query": "select /*vt+ ALLOW_HASH_JOIN */ user_extra.col, user_extra.id from user_extra where 1 = 1", + "Table": "user_extra" + } + ] + } +} diff --git a/go/vt/vtgate/planbuilder/testdata/from_cases.txt b/go/vt/vtgate/planbuilder/testdata/from_cases.txt index b7d31570e04..6d979273589 100644 --- a/go/vt/vtgate/planbuilder/testdata/from_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/from_cases.txt @@ -2662,10 +2662,10 @@ Gen4 plan same as above } # wire-up on within cross-shard derived table -"select /*vt+ ALLOW_HASH_JOIN */ t.id from (select user.id, user.col1 from user join user_extra on user_extra.col = user.col) as t" +"select t.id from (select user.id, user.col1 from user join user_extra on user_extra.col = user.col) as t" { "QueryType": "SELECT", - "Original": "select /*vt+ ALLOW_HASH_JOIN */ t.id from (select user.id, user.col1 from user join user_extra on user_extra.col = user.col) as t", + "Original": "select t.id from (select user.id, user.col1 from user join user_extra on user_extra.col = user.col) as t", "Instructions": { "OperatorType": "SimpleProjection", "Columns": [ @@ -2689,7 +2689,7 @@ Gen4 plan same as above "Sharded": true }, "FieldQuery": "select `user`.id, `user`.col1, `user`.col from `user` where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ `user`.id, `user`.col1, `user`.col from `user`", + "Query": "select `user`.id, `user`.col1, `user`.col from `user`", "Table": "`user`" }, { @@ -2700,7 +2700,7 @@ Gen4 plan same as above "Sharded": true }, "FieldQuery": "select 1 from user_extra where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ 1 from user_extra where user_extra.col = :user_col", + "Query": "select 1 from user_extra where user_extra.col = :user_col", "Table": "user_extra" } ] @@ -2710,7 +2710,7 @@ Gen4 plan same as above } { "QueryType": "SELECT", - "Original": "select /*vt+ ALLOW_HASH_JOIN */ t.id from (select user.id, user.col1 from user join user_extra on user_extra.col = user.col) as t", + "Original": "select t.id from (select user.id, user.col1 from user join user_extra on user_extra.col = user.col) as t", "Instructions": { "OperatorType": "SimpleProjection", "Columns": [ @@ -2719,9 +2719,11 @@ Gen4 plan same as above "Inputs": [ { "OperatorType": "Join", - "Variant": "HashJoin", - "ComparisonType": "INT16", + "Variant": "Join", "JoinColumnIndexes": "-2,-3", + "JoinVars": { + "user_col": 0 + }, "Predicate": "user_extra.col = `user`.col", "TableName": "`user`_user_extra", "Inputs": [ @@ -2733,7 +2735,7 @@ Gen4 plan same as above "Sharded": true }, "FieldQuery": "select `user`.col, `user`.id, `user`.col1 from `user` where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ `user`.col, `user`.id, `user`.col1 from `user`", + "Query": "select `user`.col, `user`.id, `user`.col1 from `user`", "Table": "`user`" }, { @@ -2743,8 +2745,8 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select user_extra.col from user_extra where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ user_extra.col from user_extra", + "FieldQuery": "select 1 from user_extra where 1 != 1", + "Query": "select 1 from user_extra where user_extra.col = :user_col", "Table": "user_extra" } ] @@ -4540,6 +4542,176 @@ Gen4 plan same as above } } +# join on int columns +"select u.id from user as u join user as uu on u.intcol = uu.intcol" +{ + "QueryType": "SELECT", + "Original": "select u.id from user as u join user as uu on u.intcol = uu.intcol", + "Instructions": { + "OperatorType": "Join", + "Variant": "Join", + "JoinColumnIndexes": "-1", + "JoinVars": { + "u_intcol": 1 + }, + "TableName": "`user`_`user`", + "Inputs": [ + { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select u.id, u.intcol from `user` as u where 1 != 1", + "Query": "select u.id, u.intcol from `user` as u", + "Table": "`user`" + }, + { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select 1 from `user` as uu where 1 != 1", + "Query": "select 1 from `user` as uu where uu.intcol = :u_intcol", + "Table": "`user`" + } + ] + } +} +{ + "QueryType": "SELECT", + "Original": "select u.id from user as u join user as uu on u.intcol = uu.intcol", + "Instructions": { + "OperatorType": "Join", + "Variant": "Join", + "JoinColumnIndexes": "-2", + "JoinVars": { + "u_intcol": 0 + }, + "Predicate": "u.intcol = uu.intcol", + "TableName": "`user`_`user`", + "Inputs": [ + { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select u.intcol, u.id from `user` as u where 1 != 1", + "Query": "select u.intcol, u.id from `user` as u", + "Table": "`user`" + }, + { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select 1 from `user` as uu where 1 != 1", + "Query": "select 1 from `user` as uu where uu.intcol = :u_intcol", + "Table": "`user`" + } + ] + } +} + +# wire-up on within cross-shard derived table (hash-join version) +"select /*vt+ ALLOW_HASH_JOIN */ t.id from (select user.id, user.col1 from user join user_extra on user_extra.col = user.col) as t" +{ + "QueryType": "SELECT", + "Original": "select /*vt+ ALLOW_HASH_JOIN */ t.id from (select user.id, user.col1 from user join user_extra on user_extra.col = user.col) as t", + "Instructions": { + "OperatorType": "SimpleProjection", + "Columns": [ + 0 + ], + "Inputs": [ + { + "OperatorType": "Join", + "Variant": "Join", + "JoinColumnIndexes": "-1,-2", + "JoinVars": { + "user_col": 2 + }, + "TableName": "`user`_user_extra", + "Inputs": [ + { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select `user`.id, `user`.col1, `user`.col from `user` where 1 != 1", + "Query": "select /*vt+ ALLOW_HASH_JOIN */ `user`.id, `user`.col1, `user`.col from `user`", + "Table": "`user`" + }, + { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select 1 from user_extra where 1 != 1", + "Query": "select /*vt+ ALLOW_HASH_JOIN */ 1 from user_extra where user_extra.col = :user_col", + "Table": "user_extra" + } + ] + } + ] + } +} +{ + "QueryType": "SELECT", + "Original": "select /*vt+ ALLOW_HASH_JOIN */ t.id from (select user.id, user.col1 from user join user_extra on user_extra.col = user.col) as t", + "Instructions": { + "OperatorType": "SimpleProjection", + "Columns": [ + 0 + ], + "Inputs": [ + { + "OperatorType": "Join", + "Variant": "HashJoin", + "ComparisonType": "INT16", + "JoinColumnIndexes": "-2,-3", + "Predicate": "user_extra.col = `user`.col", + "TableName": "`user`_user_extra", + "Inputs": [ + { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select `user`.col, `user`.id, `user`.col1 from `user` where 1 != 1", + "Query": "select /*vt+ ALLOW_HASH_JOIN */ `user`.col, `user`.id, `user`.col1 from `user`", + "Table": "`user`" + }, + { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select user_extra.col from user_extra where 1 != 1", + "Query": "select /*vt+ ALLOW_HASH_JOIN */ user_extra.col from user_extra", + "Table": "user_extra" + } + ] + } + ] + } +} + # hash join on int columns "select /*vt+ ALLOW_HASH_JOIN */ u.id from user as u join user as uu on u.intcol = uu.intcol" { diff --git a/go/vt/vtgate/planbuilder/testdata/rails_cases.txt b/go/vt/vtgate/planbuilder/testdata/rails_cases.txt index 8b290f73a95..bfd7ca0514c 100644 --- a/go/vt/vtgate/planbuilder/testdata/rails_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/rails_cases.txt @@ -1,4 +1,212 @@ # Author5.joins(books: [{orders: :customer}, :supplier]) +"select author5s.* from author5s join book6s on book6s.author5_id = author5s.id join book6s_order2s on book6s_order2s.book6_id = book6s.id join order2s on order2s.id = book6s_order2s.order2_id join customer2s on customer2s.id = order2s.customer2_id join supplier5s on supplier5s.id = book6s.supplier5_id" +{ + "QueryType": "SELECT", + "Original": "select author5s.* from author5s join book6s on book6s.author5_id = author5s.id join book6s_order2s on book6s_order2s.book6_id = book6s.id join order2s on order2s.id = book6s_order2s.order2_id join customer2s on customer2s.id = order2s.customer2_id join supplier5s on supplier5s.id = book6s.supplier5_id", + "Instructions": { + "OperatorType": "Join", + "Variant": "Join", + "JoinColumnIndexes": "-1,-2,-3,-4", + "JoinVars": { + "book6s_supplier5_id": 4 + }, + "TableName": "author5s, book6s_book6s_order2s_order2s_customer2s_supplier5s", + "Inputs": [ + { + "OperatorType": "Join", + "Variant": "Join", + "JoinColumnIndexes": "-1,-2,-3,-4,-5", + "JoinVars": { + "order2s_customer2_id": 5 + }, + "TableName": "author5s, book6s_book6s_order2s_order2s_customer2s", + "Inputs": [ + { + "OperatorType": "Join", + "Variant": "Join", + "JoinColumnIndexes": "-1,-2,-3,-4,-5,1", + "JoinVars": { + "book6s_order2s_order2_id": 5 + }, + "TableName": "author5s, book6s_book6s_order2s_order2s", + "Inputs": [ + { + "OperatorType": "Join", + "Variant": "Join", + "JoinColumnIndexes": "-1,-2,-3,-4,-5,1", + "JoinVars": { + "book6s_id": 5 + }, + "TableName": "author5s, book6s_book6s_order2s", + "Inputs": [ + { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select author5s.id, author5s.`name`, author5s.created_at, author5s.updated_at, book6s.supplier5_id, book6s.id from author5s join book6s on book6s.author5_id = author5s.id where 1 != 1", + "Query": "select author5s.id, author5s.`name`, author5s.created_at, author5s.updated_at, book6s.supplier5_id, book6s.id from author5s join book6s on book6s.author5_id = author5s.id", + "Table": "author5s, book6s" + }, + { + "OperatorType": "Route", + "Variant": "SelectEqualUnique", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select book6s_order2s.order2_id from book6s_order2s where 1 != 1", + "Query": "select book6s_order2s.order2_id from book6s_order2s where book6s_order2s.book6_id = :book6s_id", + "Table": "book6s_order2s", + "Values": [ + ":book6s_id" + ], + "Vindex": "binary_md5" + } + ] + }, + { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select order2s.customer2_id from order2s where 1 != 1", + "Query": "select order2s.customer2_id from order2s where order2s.id = :book6s_order2s_order2_id", + "Table": "order2s" + } + ] + }, + { + "OperatorType": "Route", + "Variant": "SelectEqualUnique", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select 1 from customer2s where 1 != 1", + "Query": "select 1 from customer2s where customer2s.id = :order2s_customer2_id", + "Table": "customer2s", + "Values": [ + ":order2s_customer2_id" + ], + "Vindex": "binary_md5" + } + ] + }, + { + "OperatorType": "Route", + "Variant": "SelectEqualUnique", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select 1 from supplier5s where 1 != 1", + "Query": "select 1 from supplier5s where supplier5s.id = :book6s_supplier5_id", + "Table": "supplier5s", + "Values": [ + ":book6s_supplier5_id" + ], + "Vindex": "binary_md5" + } + ] + } +} +{ + "QueryType": "SELECT", + "Original": "select author5s.* from author5s join book6s on book6s.author5_id = author5s.id join book6s_order2s on book6s_order2s.book6_id = book6s.id join order2s on order2s.id = book6s_order2s.order2_id join customer2s on customer2s.id = order2s.customer2_id join supplier5s on supplier5s.id = book6s.supplier5_id", + "Instructions": { + "OperatorType": "Join", + "Variant": "HashJoin", + "ComparisonType": "INT64", + "JoinColumnIndexes": "2,3,4,5", + "Predicate": "order2s.id = book6s_order2s.order2_id", + "TableName": "customer2s, order2s_author5s, book6s_book6s_order2s_supplier5s", + "Inputs": [ + { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select order2s.id from order2s, customer2s where 1 != 1", + "Query": "select order2s.id from order2s, customer2s where customer2s.id = order2s.customer2_id", + "Table": "customer2s, order2s" + }, + { + "OperatorType": "Join", + "Variant": "Join", + "JoinColumnIndexes": "-1,-2,-3,-4,-5", + "JoinVars": { + "book6s_supplier5_id": 0 + }, + "Predicate": "supplier5s.id = book6s.supplier5_id", + "TableName": "author5s, book6s_book6s_order2s_supplier5s", + "Inputs": [ + { + "OperatorType": "Join", + "Variant": "Join", + "JoinColumnIndexes": "1,-3,-4,-5,-6", + "JoinVars": { + "book6s_id": 0 + }, + "Predicate": "book6s_order2s.book6_id = book6s.id", + "TableName": "author5s, book6s_book6s_order2s", + "Inputs": [ + { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select book6s.id, book6s.supplier5_id, author5s.id as id, author5s.`name` as `name`, author5s.created_at as created_at, author5s.updated_at as updated_at from author5s, book6s where 1 != 1", + "Query": "select book6s.id, book6s.supplier5_id, author5s.id as id, author5s.`name` as `name`, author5s.created_at as created_at, author5s.updated_at as updated_at from author5s, book6s where book6s.author5_id = author5s.id", + "Table": "author5s, book6s" + }, + { + "OperatorType": "Route", + "Variant": "SelectEqualUnique", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select book6s_order2s.order2_id from book6s_order2s where 1 != 1", + "Query": "select book6s_order2s.order2_id from book6s_order2s where book6s_order2s.book6_id = :book6s_id", + "Table": "book6s_order2s", + "Values": [ + ":book6s_id" + ], + "Vindex": "binary_md5" + } + ] + }, + { + "OperatorType": "Route", + "Variant": "SelectEqualUnique", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select 1 from supplier5s where 1 != 1", + "Query": "select 1 from supplier5s where supplier5s.id = :book6s_supplier5_id", + "Table": "supplier5s", + "Values": [ + ":book6s_supplier5_id" + ], + "Vindex": "binary_md5" + } + ] + } + ] + } +} + +# Author5.joins(books: [{orders: :customer}, :supplier]) (with hash join) "select /*vt+ ALLOW_HASH_JOIN */ author5s.* from author5s join book6s on book6s.author5_id = author5s.id join book6s_order2s on book6s_order2s.book6_id = book6s.id join order2s on order2s.id = book6s_order2s.order2_id join customer2s on customer2s.id = order2s.customer2_id join supplier5s on supplier5s.id = book6s.supplier5_id" { "QueryType": "SELECT", @@ -204,4 +412,4 @@ } ] } -} +} \ No newline at end of file diff --git a/go/vt/vtgate/planbuilder/testdata/wireup_cases.txt b/go/vt/vtgate/planbuilder/testdata/wireup_cases.txt index 5622c685ceb..f4a5180e3f7 100644 --- a/go/vt/vtgate/planbuilder/testdata/wireup_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/wireup_cases.txt @@ -394,10 +394,10 @@ } # wire-up join with join, reuse existing result from a lower join -"select /*vt+ ALLOW_HASH_JOIN */ u1.id from user u1 join user u2 on u2.col = u1.col join user u3 where u3.col = u1.col" +"select u1.id from user u1 join user u2 on u2.col = u1.col join user u3 where u3.col = u1.col" { "QueryType": "SELECT", - "Original": "select /*vt+ ALLOW_HASH_JOIN */ u1.id from user u1 join user u2 on u2.col = u1.col join user u3 where u3.col = u1.col", + "Original": "select u1.id from user u1 join user u2 on u2.col = u1.col join user u3 where u3.col = u1.col", "Instructions": { "OperatorType": "Join", "Variant": "Join", @@ -424,7 +424,7 @@ "Sharded": true }, "FieldQuery": "select u1.id, u1.col from `user` as u1 where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ u1.id, u1.col from `user` as u1", + "Query": "select u1.id, u1.col from `user` as u1", "Table": "`user`" }, { @@ -435,7 +435,7 @@ "Sharded": true }, "FieldQuery": "select 1 from `user` as u2 where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ 1 from `user` as u2 where u2.col = :u1_col", + "Query": "select 1 from `user` as u2 where u2.col = :u1_col", "Table": "`user`" } ] @@ -448,7 +448,7 @@ "Sharded": true }, "FieldQuery": "select 1 from `user` as u3 where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ 1 from `user` as u3 where u3.col = :u1_col", + "Query": "select 1 from `user` as u3 where u3.col = :u1_col", "Table": "`user`" } ] @@ -456,12 +456,14 @@ } { "QueryType": "SELECT", - "Original": "select /*vt+ ALLOW_HASH_JOIN */ u1.id from user u1 join user u2 on u2.col = u1.col join user u3 where u3.col = u1.col", + "Original": "select u1.id from user u1 join user u2 on u2.col = u1.col join user u3 where u3.col = u1.col", "Instructions": { "OperatorType": "Join", - "Variant": "HashJoin", - "ComparisonType": "INT16", - "JoinColumnIndexes": "2", + "Variant": "Join", + "JoinColumnIndexes": "1", + "JoinVars": { + "u3_col": 0 + }, "Predicate": "u3.col = u1.col", "TableName": "`user`_`user`_`user`", "Inputs": [ @@ -473,15 +475,17 @@ "Sharded": true }, "FieldQuery": "select u3.col from `user` as u3 where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ u3.col from `user` as u3", + "Query": "select u3.col from `user` as u3", "Table": "`user`" }, { "OperatorType": "Join", - "Variant": "HashJoin", - "ComparisonType": "INT16", - "JoinColumnIndexes": "-1,-2", - "Predicate": "u2.col = u1.col", + "Variant": "Join", + "JoinColumnIndexes": "-2", + "JoinVars": { + "u1_col": 0 + }, + "Predicate": "u2.col = u1.col and u1.col = :u3_col", "TableName": "`user`_`user`", "Inputs": [ { @@ -492,7 +496,7 @@ "Sharded": true }, "FieldQuery": "select u1.col, u1.id from `user` as u1 where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ u1.col, u1.id from `user` as u1", + "Query": "select u1.col, u1.id from `user` as u1 where u1.col = :u3_col", "Table": "`user`" }, { @@ -502,8 +506,8 @@ "Name": "user", "Sharded": true }, - "FieldQuery": "select u2.col from `user` as u2 where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ u2.col from `user` as u2", + "FieldQuery": "select 1 from `user` as u2 where 1 != 1", + "Query": "select 1 from `user` as u2 where u2.col = :u1_col", "Table": "`user`" } ] @@ -516,10 +520,10 @@ # You need two levels of join nesting to test this: when u3 requests # col from u1, the u1-u2 joins exports the column to u2-u3. When # u4 requests it, it should be reused from the u1-u2 join. -"select /*vt+ ALLOW_HASH_JOIN */ u1.id from user u1 join user u2 join user u3 on u3.id = u1.col join user u4 where u4.col = u1.col" +"select u1.id from user u1 join user u2 join user u3 on u3.id = u1.col join user u4 where u4.col = u1.col" { "QueryType": "SELECT", - "Original": "select /*vt+ ALLOW_HASH_JOIN */ u1.id from user u1 join user u2 join user u3 on u3.id = u1.col join user u4 where u4.col = u1.col", + "Original": "select u1.id from user u1 join user u2 join user u3 on u3.id = u1.col join user u4 where u4.col = u1.col", "Instructions": { "OperatorType": "Join", "Variant": "Join", @@ -552,7 +556,7 @@ "Sharded": true }, "FieldQuery": "select u1.id, u1.col from `user` as u1 where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ u1.id, u1.col from `user` as u1", + "Query": "select u1.id, u1.col from `user` as u1", "Table": "`user`" }, { @@ -563,7 +567,7 @@ "Sharded": true }, "FieldQuery": "select 1 from `user` as u2 where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ 1 from `user` as u2", + "Query": "select 1 from `user` as u2", "Table": "`user`" } ] @@ -576,7 +580,7 @@ "Sharded": true }, "FieldQuery": "select 1 from `user` as u3 where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ 1 from `user` as u3 where u3.id = :u1_col", + "Query": "select 1 from `user` as u3 where u3.id = :u1_col", "Table": "`user`", "Values": [ ":u1_col" @@ -593,7 +597,7 @@ "Sharded": true }, "FieldQuery": "select 1 from `user` as u4 where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ 1 from `user` as u4 where u4.col = :u1_col", + "Query": "select 1 from `user` as u4 where u4.col = :u1_col", "Table": "`user`" } ] @@ -601,7 +605,7 @@ } { "QueryType": "SELECT", - "Original": "select /*vt+ ALLOW_HASH_JOIN */ u1.id from user u1 join user u2 join user u3 on u3.id = u1.col join user u4 where u4.col = u1.col", + "Original": "select u1.id from user u1 join user u2 join user u3 on u3.id = u1.col join user u4 where u4.col = u1.col", "Instructions": { "OperatorType": "Join", "Variant": "Join", @@ -616,14 +620,16 @@ "Sharded": true }, "FieldQuery": "select 1 from `user` as u2 where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ 1 from `user` as u2", + "Query": "select 1 from `user` as u2", "Table": "`user`" }, { "OperatorType": "Join", - "Variant": "HashJoin", - "ComparisonType": "INT16", - "JoinColumnIndexes": "2", + "Variant": "Join", + "JoinColumnIndexes": "1", + "JoinVars": { + "u4_col": 0 + }, "Predicate": "u4.col = u1.col", "TableName": "`user`_`user`_`user`", "Inputs": [ @@ -635,17 +641,17 @@ "Sharded": true }, "FieldQuery": "select u4.col from `user` as u4 where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ u4.col from `user` as u4", + "Query": "select u4.col from `user` as u4", "Table": "`user`" }, { "OperatorType": "Join", "Variant": "Join", - "JoinColumnIndexes": "-1,-2", + "JoinColumnIndexes": "-2", "JoinVars": { "u1_col": 0 }, - "Predicate": "u3.id = u1.col", + "Predicate": "u3.id = u1.col and u1.col = :u4_col", "TableName": "`user`_`user`", "Inputs": [ { @@ -656,7 +662,7 @@ "Sharded": true }, "FieldQuery": "select u1.col, u1.id from `user` as u1 where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ u1.col, u1.id from `user` as u1", + "Query": "select u1.col, u1.id from `user` as u1 where u1.col = :u4_col", "Table": "`user`" }, { @@ -667,7 +673,7 @@ "Sharded": true }, "FieldQuery": "select 1 from `user` as u3 where 1 != 1", - "Query": "select /*vt+ ALLOW_HASH_JOIN */ 1 from `user` as u3 where u3.id = :u1_col", + "Query": "select 1 from `user` as u3 where u3.id = :u1_col", "Table": "`user`", "Values": [ ":u1_col"