From 93873b6cbb6649c76632e627ef79ce43fb7bc8d2 Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Mon, 12 Jul 2021 08:04:07 +0200 Subject: [PATCH 1/6] Addition of aliased table expr hint to route plan Signed-off-by: Florent Poinsard --- go/vt/vtgate/planbuilder/jointree_transformers.go | 2 +- go/vt/vtgate/planbuilder/testdata/from_cases.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/go/vt/vtgate/planbuilder/jointree_transformers.go b/go/vt/vtgate/planbuilder/jointree_transformers.go index d828cc0971c..e1e06d3f23a 100644 --- a/go/vt/vtgate/planbuilder/jointree_transformers.go +++ b/go/vt/vtgate/planbuilder/jointree_transformers.go @@ -167,7 +167,7 @@ func relToTableExpr(t relation) (sqlparser.TableExpr, error) { }, Partitions: nil, As: t.qtable.Alias.As, - Hints: nil, + Hints: t.qtable.Alias.Hints, }, nil case parenTables: tables := sqlparser.TableExprs{} diff --git a/go/vt/vtgate/planbuilder/testdata/from_cases.txt b/go/vt/vtgate/planbuilder/testdata/from_cases.txt index 3a0e1b308de..ad388d800e7 100644 --- a/go/vt/vtgate/planbuilder/testdata/from_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/from_cases.txt @@ -1018,6 +1018,7 @@ Gen4 plan same as above "Table": "`user`" } } +Gen4 plan same as above # mergeable sharded join on unique vindex "select user.col from user join user_extra on user.id = user_extra.user_id" From 0e25156a68536ada326f12b3c2994d3778eead37 Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Mon, 12 Jul 2021 09:57:59 +0200 Subject: [PATCH 2/6] SelectScatter query with reference table Signed-off-by: Florent Poinsard --- go/vt/vtgate/planbuilder/route_planning.go | 7 +++++ .../planbuilder/testdata/from_cases.txt | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/go/vt/vtgate/planbuilder/route_planning.go b/go/vt/vtgate/planbuilder/route_planning.go index dc687c1b828..6a08398ef41 100644 --- a/go/vt/vtgate/planbuilder/route_planning.go +++ b/go/vt/vtgate/planbuilder/route_planning.go @@ -708,6 +708,9 @@ func tryMerge(a, b joinTree, joinPredicates []sqlparser.Expr, semTable *semantic return nil } case engine.SelectScatter, engine.SelectEqualUnique: + if bRoute.routeOpCode == engine.SelectReference { + return r + } if len(joinPredicates) == 0 { // If we are doing two Scatters, we have to make sure that the // joins are on the correct vindex to allow them to be merged @@ -720,6 +723,10 @@ func tryMerge(a, b joinTree, joinPredicates []sqlparser.Expr, semTable *semantic return nil } r.pickBestAvailableVindex() + case engine.SelectReference: + if bRoute.routeOpCode != engine.SelectReference { + return nil + } } return r } diff --git a/go/vt/vtgate/planbuilder/testdata/from_cases.txt b/go/vt/vtgate/planbuilder/testdata/from_cases.txt index ad388d800e7..b69f469a662 100644 --- a/go/vt/vtgate/planbuilder/testdata/from_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/from_cases.txt @@ -1485,6 +1485,21 @@ Gen4 plan same as above "Table": "`user`" } } +{ + "QueryType": "SELECT", + "Original": "select user.col from user join ref", + "Instructions": { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select `user`.col from `user`, ref where 1 != 1", + "Query": "select `user`.col from `user`, ref", + "Table": "`user`, ref" + } +} # reference table self-join "select r1.col from ref r1 join ref" @@ -1503,6 +1518,21 @@ Gen4 plan same as above "Table": "ref" } } +{ + "QueryType": "SELECT", + "Original": "select r1.col from ref r1 join ref", + "Instructions": { + "OperatorType": "Route", + "Variant": "SelectReference", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select r1.col from ref as r1, ref where 1 != 1", + "Query": "select r1.col from ref as r1, ref", + "Table": "ref" + } +} # reference table can merge with other opcodes left to right. "select ref.col from ref join user" From 32f28c3aab80808b6e42abf0631f8b1b44534218 Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Mon, 12 Jul 2021 11:51:47 +0200 Subject: [PATCH 3/6] Addition of expected output for select cases with gen4 Signed-off-by: Florent Poinsard --- .../planbuilder/testdata/select_cases.txt | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/go/vt/vtgate/planbuilder/testdata/select_cases.txt b/go/vt/vtgate/planbuilder/testdata/select_cases.txt index 46650433aeb..21cc3656d99 100644 --- a/go/vt/vtgate/planbuilder/testdata/select_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/select_cases.txt @@ -269,6 +269,21 @@ Gen4 plan same as above "Table": "authoritative" } } +{ + "QueryType": "SELECT", + "Original": "select * from authoritative", + "Instructions": { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select authoritative.user_id as user_id, authoritative.col1 as col1, authoritative.col2 as col2 from authoritative where 1 != 1", + "Query": "select authoritative.user_id as user_id, authoritative.col1 as col1, authoritative.col2 as col2 from authoritative", + "Table": "authoritative" + } +} # select * from join of authoritative tables "select * from authoritative a join authoritative b on a.user_id=b.user_id" @@ -287,10 +302,26 @@ Gen4 plan same as above "Table": "authoritative" } } +{ + "QueryType": "SELECT", + "Original": "select * from authoritative a join authoritative b on a.user_id=b.user_id", + "Instructions": { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select a.user_id as user_id, a.col1 as col1, a.col2 as col2, b.user_id as user_id, b.col1 as col1, b.col2 as col2 from authoritative as a, authoritative as b where 1 != 1", + "Query": "select a.user_id as user_id, a.col1 as col1, a.col2 as col2, b.user_id as user_id, b.col1 as col1, b.col2 as col2 from authoritative as a, authoritative as b where a.user_id = b.user_id", + "Table": "authoritative" + } +} # test table lookup failure for authoritative code path "select a.* from authoritative" "table a not found" +Gen4 error: Unknown table 'a' # select * from qualified authoritative table "select a.* from authoritative a" @@ -309,6 +340,21 @@ Gen4 plan same as above "Table": "authoritative" } } +{ + "QueryType": "SELECT", + "Original": "select a.* from authoritative a", + "Instructions": { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select a.user_id as user_id, a.col1 as col1, a.col2 as col2 from authoritative as a where 1 != 1", + "Query": "select a.user_id as user_id, a.col1 as col1, a.col2 as col2 from authoritative as a", + "Table": "authoritative" + } +} # select * from intermixing of authoritative table with non-authoritative results in no expansion "select * from authoritative join user on authoritative.user_id=user.id" @@ -345,6 +391,21 @@ Gen4 plan same as above "Table": "authoritative" } } +{ + "QueryType": "SELECT", + "Original": "select user.id, a.*, user.col1 from authoritative a join user on a.user_id=user.id", + "Instructions": { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select `user`.id, a.user_id as user_id, a.col1 as col1, a.col2 as col2, `user`.col1 from authoritative as a, `user` where 1 != 1", + "Query": "select `user`.id, a.user_id as user_id, a.col1 as col1, a.col2 as col2, `user`.col1 from authoritative as a, `user` where a.user_id = `user`.id", + "Table": "`user`, authoritative" + } +} # auto-resolve anonymous columns for simple route "select col from user join user_extra on user.id = user_extra.user_id" @@ -363,10 +424,26 @@ Gen4 plan same as above "Table": "`user`" } } +{ + "QueryType": "SELECT", + "Original": "select col from user join user_extra on user.id = user_extra.user_id", + "Instructions": { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select col from `user`, user_extra where 1 != 1", + "Query": "select col from `user`, user_extra where `user`.id = user_extra.user_id", + "Table": "`user`, user_extra" + } +} # Cannot auto-resolve for cross-shard joins "select col from user join user_extra" "symbol col not found" +Gen4 error: Column 'col' in field list is ambiguous # Auto-resolve should work if unique vindex columns are referenced "select id, user_id from user join user_extra" From 1111b7e595ac8647fcbf266f75d6c2fc7c4db626 Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Mon, 12 Jul 2021 21:58:45 +0200 Subject: [PATCH 4/6] Updated select cases with new supported test case Signed-off-by: Florent Poinsard --- .../planbuilder/testdata/select_cases.txt | 65 ++++++++++--------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/go/vt/vtgate/planbuilder/testdata/select_cases.txt b/go/vt/vtgate/planbuilder/testdata/select_cases.txt index 21cc3656d99..b3424d316a5 100644 --- a/go/vt/vtgate/planbuilder/testdata/select_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/select_cases.txt @@ -302,21 +302,6 @@ Gen4 plan same as above "Table": "authoritative" } } -{ - "QueryType": "SELECT", - "Original": "select * from authoritative a join authoritative b on a.user_id=b.user_id", - "Instructions": { - "OperatorType": "Route", - "Variant": "SelectScatter", - "Keyspace": { - "Name": "user", - "Sharded": true - }, - "FieldQuery": "select a.user_id as user_id, a.col1 as col1, a.col2 as col2, b.user_id as user_id, b.col1 as col1, b.col2 as col2 from authoritative as a, authoritative as b where 1 != 1", - "Query": "select a.user_id as user_id, a.col1 as col1, a.col2 as col2, b.user_id as user_id, b.col1 as col1, b.col2 as col2 from authoritative as a, authoritative as b where a.user_id = b.user_id", - "Table": "authoritative" - } -} # test table lookup failure for authoritative code path "select a.* from authoritative" @@ -391,21 +376,6 @@ Gen4 error: Unknown table 'a' "Table": "authoritative" } } -{ - "QueryType": "SELECT", - "Original": "select user.id, a.*, user.col1 from authoritative a join user on a.user_id=user.id", - "Instructions": { - "OperatorType": "Route", - "Variant": "SelectScatter", - "Keyspace": { - "Name": "user", - "Sharded": true - }, - "FieldQuery": "select `user`.id, a.user_id as user_id, a.col1 as col1, a.col2 as col2, `user`.col1 from authoritative as a, `user` where 1 != 1", - "Query": "select `user`.id, a.user_id as user_id, a.col1 as col1, a.col2 as col2, `user`.col1 from authoritative as a, `user` where a.user_id = `user`.id", - "Table": "`user`, authoritative" - } -} # auto-resolve anonymous columns for simple route "select col from user join user_extra on user.id = user_extra.user_id" @@ -443,7 +413,40 @@ Gen4 error: Unknown table 'a' # Cannot auto-resolve for cross-shard joins "select col from user join user_extra" "symbol col not found" -Gen4 error: Column 'col' in field list is ambiguous +{ + "QueryType": "SELECT", + "Original": "select col from user join user_extra", + "Instructions": { + "OperatorType": "Join", + "Variant": "Join", + "JoinColumnIndexes": "-1", + "TableName": "`user`_user_extra", + "Inputs": [ + { + "OperatorType": "Route", + "Variant": "SelectScatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select col from `user` where 1 != 1", + "Query": "select 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 1 from user_extra", + "Table": "user_extra" + } + ] + } +} # Auto-resolve should work if unique vindex columns are referenced "select id, user_id from user join user_extra" From cad6fba9e72766f4b58d9ff7c104b6d3c2e72d6d Mon Sep 17 00:00:00 2001 From: GuptaManan100 Date: Tue, 13 Jul 2021 14:33:03 +0530 Subject: [PATCH 5/6] initial support for information_schema Signed-off-by: GuptaManan100 --- go/vt/vtgate/planbuilder/abstract/operator.go | 8 +- .../vtgate/planbuilder/abstract/querygraph.go | 49 +----- go/vt/vtgate/planbuilder/jointree.go | 8 +- .../planbuilder/jointree_transformers.go | 12 +- go/vt/vtgate/planbuilder/route_planning.go | 20 +++ .../planbuilder/testdata/filter_cases.txt | 18 +-- .../planbuilder/testdata/from_cases.txt | 143 ++++++++++++++++++ .../testdata/unsupported_cases.txt | 33 ++++ go/vt/vtgate/semantics/analyzer.go | 40 ++--- go/vt/vtgate/semantics/semantic_state.go | 30 +++- 10 files changed, 282 insertions(+), 79 deletions(-) diff --git a/go/vt/vtgate/planbuilder/abstract/operator.go b/go/vt/vtgate/planbuilder/abstract/operator.go index 137a19394df..c1e9395db46 100644 --- a/go/vt/vtgate/planbuilder/abstract/operator.go +++ b/go/vt/vtgate/planbuilder/abstract/operator.go @@ -42,7 +42,13 @@ func getOperatorFromTableExpr(tableExpr sqlparser.TableExpr, semTable *semantics case *sqlparser.AliasedTableExpr: qg := newQueryGraph() tableName := tableExpr.Expr.(sqlparser.TableName) - qt := &QueryTable{Alias: tableExpr, Table: tableName, TableID: semTable.TableSetFor(tableExpr)} + tableID := semTable.TableSetFor(tableExpr) + tableInfo, err := semTable.TableInfoFor(tableID) + if err != nil { + return nil, err + } + isInfSchema := tableInfo.IsInfSchema() + qt := &QueryTable{Alias: tableExpr, Table: tableName, TableID: tableID, IsInfSchema: isInfSchema} qg.Tables = append(qg.Tables, qt) return qg, nil case *sqlparser.JoinTableExpr: diff --git a/go/vt/vtgate/planbuilder/abstract/querygraph.go b/go/vt/vtgate/planbuilder/abstract/querygraph.go index 5d75d1f4723..98129eb6084 100644 --- a/go/vt/vtgate/planbuilder/abstract/querygraph.go +++ b/go/vt/vtgate/planbuilder/abstract/querygraph.go @@ -44,10 +44,11 @@ type ( // QueryTable is a single FROM table, including all predicates particular to this table QueryTable struct { - TableID semantics.TableSet - Alias *sqlparser.AliasedTableExpr - Table sqlparser.TableName - Predicates []sqlparser.Expr + TableID semantics.TableSet + Alias *sqlparser.AliasedTableExpr + Table sqlparser.TableName + Predicates []sqlparser.Expr + IsInfSchema bool } ) @@ -90,46 +91,6 @@ func newQueryGraph() *QueryGraph { } } -func (qg *QueryGraph) collectTable(t sqlparser.TableExpr, semTable *semantics.SemTable) error { - switch table := t.(type) { - case *sqlparser.AliasedTableExpr: - tableName := table.Expr.(sqlparser.TableName) - qt := &QueryTable{Alias: table, Table: tableName, TableID: semTable.TableSetFor(table)} - qg.Tables = append(qg.Tables, qt) - case *sqlparser.JoinTableExpr: - if err := qg.collectTable(table.LeftExpr, semTable); err != nil { - return err - } - if err := qg.collectTable(table.RightExpr, semTable); err != nil { - return err - } - if table.Condition.On != nil { - for _, predicate := range sqlparser.SplitAndExpression(nil, table.Condition.On) { - err := qg.collectPredicateTable(t, predicate, semTable) - if err != nil { - return err - } - } - } - case *sqlparser.ParenTableExpr: - for _, expr := range table.Exprs { - if err := qg.collectTable(expr, semTable); err != nil { - return err - } - } - } - return nil -} - -func (qg *QueryGraph) collectTables(t sqlparser.TableExprs, semTable *semantics.SemTable) error { - for _, expr := range t { - if err := qg.collectTable(expr, semTable); err != nil { - return err - } - } - return nil -} - func (qg *QueryGraph) collectPredicates(sel *sqlparser.Select, semTable *semantics.SemTable) error { predicates := sqlparser.SplitAndExpression(nil, sel.Where.Expr) diff --git a/go/vt/vtgate/planbuilder/jointree.go b/go/vt/vtgate/planbuilder/jointree.go index dee3a07b6d6..91ff3c66751 100644 --- a/go/vt/vtgate/planbuilder/jointree.go +++ b/go/vt/vtgate/planbuilder/jointree.go @@ -140,7 +140,13 @@ func (rp *leJoin) tableNames() []string { } func (rp *routeTable) tableNames() []string { - return []string{sqlparser.String(rp.qtable.Table.Name)} + var name string + if rp.qtable.IsInfSchema { + name = sqlparser.String(rp.qtable.Table) + } else { + name = sqlparser.String(rp.qtable.Table.Name) + } + return []string{name} } func (p parenTables) tableNames() []string { diff --git a/go/vt/vtgate/planbuilder/jointree_transformers.go b/go/vt/vtgate/planbuilder/jointree_transformers.go index e1e06d3f23a..84ed72f6cf8 100644 --- a/go/vt/vtgate/planbuilder/jointree_transformers.go +++ b/go/vt/vtgate/planbuilder/jointree_transformers.go @@ -161,10 +161,16 @@ func transformRoutePlan(n *routePlan) (*route, error) { func relToTableExpr(t relation) (sqlparser.TableExpr, error) { switch t := t.(type) { case *routeTable: - return &sqlparser.AliasedTableExpr{ - Expr: sqlparser.TableName{ + var expr sqlparser.SimpleTableExpr + if t.qtable.IsInfSchema { + expr = t.qtable.Table + } else { + expr = sqlparser.TableName{ Name: t.vtable.Name, - }, + } + } + return &sqlparser.AliasedTableExpr{ + Expr: expr, Partitions: nil, As: t.qtable.Alias.As, Hints: t.qtable.Alias.Hints, diff --git a/go/vt/vtgate/planbuilder/route_planning.go b/go/vt/vtgate/planbuilder/route_planning.go index 116c2dd794c..84fdec1574f 100644 --- a/go/vt/vtgate/planbuilder/route_planning.go +++ b/go/vt/vtgate/planbuilder/route_planning.go @@ -464,6 +464,26 @@ func removeAt(plans []joinTree, idx int) []joinTree { } func createRoutePlan(table *abstract.QueryTable, solves semantics.TableSet, vschema ContextVSchema) (*routePlan, error) { + if table.IsInfSchema { + defaultKeyspace, err := vschema.DefaultKeyspace() + if err != nil { + return nil, err + } + return &routePlan{ + routeOpCode: engine.SelectDBA, + solved: solves, + // TODO: find keyspace to route using the predicates as in v3 + keyspace: defaultKeyspace, + tables: []relation{&routeTable{ + qtable: table, + vtable: &vindexes.Table{ + Name: table.Table.Name, + Keyspace: defaultKeyspace, + }, + }}, + predicates: table.Predicates, + }, nil + } vschemaTable, _, _, _, _, err := vschema.FindTableOrVindex(table.Table) if err != nil { return nil, err diff --git a/go/vt/vtgate/planbuilder/testdata/filter_cases.txt b/go/vt/vtgate/planbuilder/testdata/filter_cases.txt index 4ae8b355b64..ec1be4d0439 100644 --- a/go/vt/vtgate/planbuilder/testdata/filter_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/filter_cases.txt @@ -1947,12 +1947,9 @@ Gen4 plan same as above "Query": "select * from INFORMATION_SCHEMA.`TABLES` where TABLE_SCHEMA = database()" } } - -# table_schema predicate the wrong way around -"SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE 'ks' = TABLE_SCHEMA" { "QueryType": "SELECT", - "Original": "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE 'ks' = TABLE_SCHEMA", + "Original": "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = database()", "Instructions": { "OperatorType": "Route", "Variant": "SelectDBA", @@ -1961,16 +1958,16 @@ Gen4 plan same as above "Sharded": false }, "FieldQuery": "select * from INFORMATION_SCHEMA.`TABLES` where 1 != 1", - "Query": "select * from INFORMATION_SCHEMA.`TABLES` where TABLE_SCHEMA = :__vtschemaname", - "SysTableTableSchema": "[VARBINARY(\"ks\")]" + "Query": "select * from INFORMATION_SCHEMA.`TABLES` where TABLE_SCHEMA = database()", + "Table": "INFORMATION_SCHEMA.`TABLES`" } } -# table_schema OR predicate -"SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'ks' OR TABLE_SCHEMA = 'main'" +# table_schema predicate the wrong way around +"SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE 'ks' = TABLE_SCHEMA" { "QueryType": "SELECT", - "Original": "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'ks' OR TABLE_SCHEMA = 'main'", + "Original": "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE 'ks' = TABLE_SCHEMA", "Instructions": { "OperatorType": "Route", "Variant": "SelectDBA", @@ -1979,7 +1976,8 @@ Gen4 plan same as above "Sharded": false }, "FieldQuery": "select * from INFORMATION_SCHEMA.`TABLES` where 1 != 1", - "Query": "select * from INFORMATION_SCHEMA.`TABLES` where TABLE_SCHEMA = 'ks' or TABLE_SCHEMA = 'main'" + "Query": "select * from INFORMATION_SCHEMA.`TABLES` where TABLE_SCHEMA = :__vtschemaname", + "SysTableTableSchema": "[VARBINARY(\"ks\")]" } } diff --git a/go/vt/vtgate/planbuilder/testdata/from_cases.txt b/go/vt/vtgate/planbuilder/testdata/from_cases.txt index c1f90ccf86d..703718f97fd 100644 --- a/go/vt/vtgate/planbuilder/testdata/from_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/from_cases.txt @@ -90,6 +90,21 @@ Gen4 plan same as above "Query": "select col from information_schema.foo" } } +{ + "QueryType": "SELECT", + "Original": "select col from information_schema.foo", + "Instructions": { + "OperatorType": "Route", + "Variant": "SelectDBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select col from information_schema.foo where 1 != 1", + "Query": "select col from information_schema.foo", + "Table": "information_schema.foo" + } +} # Multi-table unsharded "select m1.col from unsharded as m1 join unsharded as m2" @@ -335,6 +350,21 @@ Gen4 plan same as above "Query": "select a.id, b.id from information_schema.a as a, information_schema.b as b" } } +{ + "QueryType": "SELECT", + "Original": "select a.id,b.id from information_schema.a as a, information_schema.b as b", + "Instructions": { + "OperatorType": "Route", + "Variant": "SelectDBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select a.id, b.id from information_schema.a as a, information_schema.b as b where 1 != 1", + "Query": "select a.id, b.id from information_schema.a as a, information_schema.b as b", + "Table": "information_schema.a, information_schema.b" + } +} # ',' 3-way join unsharded "select u1.a, u2.a from unsharded u1, unsharded u2, unsharded u3" @@ -1900,6 +1930,40 @@ Gen4 plan same as above ] } } +{ + "QueryType": "SELECT", + "Original": "select unsharded.foo from information_schema.a join unsharded", + "Instructions": { + "OperatorType": "Join", + "Variant": "Join", + "JoinColumnIndexes": "1", + "TableName": "information_schema.a_unsharded", + "Inputs": [ + { + "OperatorType": "Route", + "Variant": "SelectDBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select 1 from information_schema.a where 1 != 1", + "Query": "select 1 from information_schema.a", + "Table": "information_schema.a" + }, + { + "OperatorType": "Route", + "Variant": "SelectUnsharded", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select unsharded.foo from unsharded where 1 != 1", + "Query": "select unsharded.foo from unsharded", + "Table": "unsharded" + } + ] + } +} # join of normal table with information_schema "select unsharded.foo from unsharded join information_schema.a" @@ -1936,6 +2000,40 @@ Gen4 plan same as above ] } } +{ + "QueryType": "SELECT", + "Original": "select unsharded.foo from unsharded join information_schema.a", + "Instructions": { + "OperatorType": "Join", + "Variant": "Join", + "JoinColumnIndexes": "-1", + "TableName": "unsharded_information_schema.a", + "Inputs": [ + { + "OperatorType": "Route", + "Variant": "SelectUnsharded", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select unsharded.foo from unsharded where 1 != 1", + "Query": "select unsharded.foo from unsharded", + "Table": "unsharded" + }, + { + "OperatorType": "Route", + "Variant": "SelectDBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select 1 from information_schema.a where 1 != 1", + "Query": "select 1 from information_schema.a", + "Table": "information_schema.a" + } + ] + } +} # wire-up on join with cross-shard subquery "select t.col1 from (select user.id, user.col1 from user join user_extra) as t join unsharded on unsharded.col1 = t.col1 and unsharded.id = t.id" @@ -2797,6 +2895,21 @@ Gen4 plan same as above "Query": "select column_name from information_schema.`columns` where table_schema = schema()" } } +{ + "QueryType": "SELECT", + "Original": "select column_name from information_schema.columns where table_schema = (select schema())", + "Instructions": { + "OperatorType": "Route", + "Variant": "SelectDBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select column_name from information_schema.`columns` where 1 != 1", + "Query": "select column_name from information_schema.`columns` where table_schema = schema()", + "Table": "information_schema.`columns`" + } +} # information schema join "select * from information_schema.a join information_schema.b" @@ -2814,6 +2927,21 @@ Gen4 plan same as above "Query": "select * from information_schema.a join information_schema.b" } } +{ + "QueryType": "SELECT", + "Original": "select * from information_schema.a join information_schema.b", + "Instructions": { + "OperatorType": "Route", + "Variant": "SelectDBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select * from information_schema.a, information_schema.b where 1 != 1", + "Query": "select * from information_schema.a, information_schema.b", + "Table": "information_schema.a, information_schema.b" + } +} # rails query "select fk.referenced_table_name as to_table, fk.referenced_column_name as primary_key, fk.column_name as `column`, fk.constraint_name as name, rc.update_rule as on_update, rc.delete_rule as on_delete from information_schema.referential_constraints as rc join information_schema.key_column_usage as fk using (constraint_schema, constraint_name) where fk.referenced_column_name is not null and fk.table_schema = database() and fk.table_name = ':vtg1' and rc.constraint_schema = database() and rc.table_name = ':vtg1'" @@ -2962,6 +3090,21 @@ Gen4 plan same as above "Query": "select id from information_schema.`processlist` where info like '% FOR UPDATE'" } } +{ + "QueryType": "SELECT", + "Original": "SELECT id FROM information_schema.processlist WHERE info LIKE '% FOR UPDATE'", + "Instructions": { + "OperatorType": "Route", + "Variant": "SelectDBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select id from information_schema.`processlist` where 1 != 1", + "Query": "select id from information_schema.`processlist` where info like '% FOR UPDATE'", + "Table": "information_schema.`processlist`" + } +} #rails_query 9 "SELECT table_name FROM (SELECT * FROM information_schema.tables WHERE table_schema = 'table_schema') _subquery" diff --git a/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt b/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt index 26349d4c255..b1e99a3c15b 100644 --- a/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt @@ -491,3 +491,36 @@ Gen4 plan same as above # create view with incompatible keyspaces "create view main.view_a as select * from user.user_extra" "Select query does not belong to the same keyspace as the view statement" + +# table_schema OR predicate +# It is unsupported because we do not route queries to multiple keyspaces right now +"SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'ks' OR TABLE_SCHEMA = 'main'" +{ + "QueryType": "SELECT", + "Original": "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'ks' OR TABLE_SCHEMA = 'main'", + "Instructions": { + "OperatorType": "Route", + "Variant": "SelectDBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select * from INFORMATION_SCHEMA.`TABLES` where 1 != 1", + "Query": "select * from INFORMATION_SCHEMA.`TABLES` where TABLE_SCHEMA = 'ks' or TABLE_SCHEMA = 'main'" + } +} +{ + "QueryType": "SELECT", + "Original": "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'ks' OR TABLE_SCHEMA = 'main'", + "Instructions": { + "OperatorType": "Route", + "Variant": "SelectDBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select * from INFORMATION_SCHEMA.`TABLES` where 1 != 1", + "Query": "select * from INFORMATION_SCHEMA.`TABLES` where TABLE_SCHEMA = 'ks' or TABLE_SCHEMA = 'main'", + "Table": "INFORMATION_SCHEMA.`TABLES`" + } +} diff --git a/go/vt/vtgate/semantics/analyzer.go b/go/vt/vtgate/semantics/analyzer.go index 7eb9e4321fb..1ee90fd7d08 100644 --- a/go/vt/vtgate/semantics/analyzer.go +++ b/go/vt/vtgate/semantics/analyzer.go @@ -300,23 +300,25 @@ func (a *analyzer) tableSetFor(t *sqlparser.AliasedTableExpr) TableSet { panic("unknown table") } -func (a *analyzer) createTable(t sqlparser.TableName, alias *sqlparser.AliasedTableExpr, tbl *vindexes.Table) TableInfo { +func (a *analyzer) createTable(t sqlparser.TableName, alias *sqlparser.AliasedTableExpr, tbl *vindexes.Table, isInfSchema bool) TableInfo { dbName := t.Qualifier.String() if dbName == "" { dbName = a.currentDb } if alias.As.IsEmpty() { return &RealTable{ - dbName: dbName, - tableName: t.Name.String(), - ASTNode: alias, - Table: tbl, + dbName: dbName, + tableName: t.Name.String(), + ASTNode: alias, + Table: tbl, + isInfSchema: isInfSchema, } } return &AliasedTable{ - tableName: alias.As.String(), - ASTNode: alias, - Table: tbl, + tableName: alias.As.String(), + ASTNode: alias, + Table: tbl, + isInfSchema: isInfSchema, } } @@ -325,18 +327,22 @@ func (a *analyzer) bindTable(alias *sqlparser.AliasedTableExpr, expr sqlparser.S case *sqlparser.DerivedTable: return Gen4NotSupportedF("derived table") case sqlparser.TableName: + var tbl *vindexes.Table + var isInfSchema bool if sqlparser.SystemSchema(t.Qualifier.String()) { - return Gen4NotSupportedF("system tables") - } - tbl, vdx, _, _, _, err := a.si.FindTableOrVindex(t) - if err != nil { - return err - } - if tbl == nil && vdx != nil { - return Gen4NotSupportedF("vindex in FROM") + isInfSchema = true + } else { + table, vdx, _, _, _, err := a.si.FindTableOrVindex(t) + if err != nil { + return err + } + tbl = table + if tbl == nil && vdx != nil { + return Gen4NotSupportedF("vindex in FROM") + } } scope := a.currentScope() - tableInfo := a.createTable(t, alias, tbl) + tableInfo := a.createTable(t, alias, tbl, isInfSchema) a.Tables = append(a.Tables, tableInfo) return scope.addTable(tableInfo) diff --git a/go/vt/vtgate/semantics/semantic_state.go b/go/vt/vtgate/semantics/semantic_state.go index c2287c77846..1db90280295 100644 --- a/go/vt/vtgate/semantics/semantic_state.go +++ b/go/vt/vtgate/semantics/semantic_state.go @@ -37,6 +37,7 @@ type ( GetColumns() []ColumnInfo IsVirtual() bool DepsFor(col *sqlparser.ColName, org originable, single bool) *TableSet + IsInfSchema() bool } // ColumnInfo contains information about columns @@ -50,13 +51,15 @@ type ( dbName, tableName string ASTNode *sqlparser.AliasedTableExpr Table *vindexes.Table + isInfSchema bool } // AliasedTable contains the alias table expr and vindex table AliasedTable struct { - tableName string - ASTNode *sqlparser.AliasedTableExpr - Table *vindexes.Table + tableName string + ASTNode *sqlparser.AliasedTableExpr + Table *vindexes.Table + isInfSchema bool } vTableInfo struct { @@ -93,6 +96,7 @@ type ( } ) +// DepsFor implements the TableInfo interface func (v *vTableInfo) DepsFor(col *sqlparser.ColName, org originable, single bool) *TableSet { if !col.Qualifier.IsEmpty() { return nil @@ -106,6 +110,7 @@ func (v *vTableInfo) DepsFor(col *sqlparser.ColName, org originable, single bool return nil } +// DepsFor implements the TableInfo interface func (a *AliasedTable) DepsFor(col *sqlparser.ColName, org originable, single bool) *TableSet { if single { ts := org.tableSetFor(a.ASTNode) @@ -120,6 +125,7 @@ func (a *AliasedTable) DepsFor(col *sqlparser.ColName, org originable, single bo return nil } +// DepsFor implements the TableInfo interface func (r *RealTable) DepsFor(col *sqlparser.ColName, org originable, single bool) *TableSet { if single { ts := org.tableSetFor(r.ASTNode) @@ -134,14 +140,32 @@ func (r *RealTable) DepsFor(col *sqlparser.ColName, org originable, single bool) return nil } +// IsInfSchema implements the TableInfo interface +func (v *vTableInfo) IsInfSchema() bool { + return false +} + +// IsInfSchema implements the TableInfo interface +func (a *AliasedTable) IsInfSchema() bool { + return a.isInfSchema +} + +// IsInfSchema implements the TableInfo interface +func (r *RealTable) IsInfSchema() bool { + return r.isInfSchema +} + +// IsVirtual implements the TableInfo interface func (v *vTableInfo) IsVirtual() bool { return true } +// IsVirtual implements the TableInfo interface func (a *AliasedTable) IsVirtual() bool { return false } +// IsVirtual implements the TableInfo interface func (r *RealTable) IsVirtual() bool { return false } From 0889592b49e97761cc5b394c12badf1610e7f0e6 Mon Sep 17 00:00:00 2001 From: Harshit Gangal Date: Wed, 14 Jul 2021 23:14:35 +0530 Subject: [PATCH 6/6] fix the table names in plan description and updated the plan output Signed-off-by: Harshit Gangal --- go/vt/vtgate/planbuilder/from.go | 6 + .../planbuilder/jointree_transformers.go | 5 +- .../planbuilder/testdata/filter_cases.txt | 45 ++-- .../planbuilder/testdata/from_cases.txt | 206 +++++------------- .../testdata/postprocess_cases.txt | 7 +- .../planbuilder/testdata/select_cases.txt | 31 ++- .../planbuilder/testdata/union_cases.txt | 6 +- .../testdata/unsupported_cases.txt | 22 +- 8 files changed, 108 insertions(+), 220 deletions(-) diff --git a/go/vt/vtgate/planbuilder/from.go b/go/vt/vtgate/planbuilder/from.go index 026010585a2..f783419158a 100644 --- a/go/vt/vtgate/planbuilder/from.go +++ b/go/vt/vtgate/planbuilder/from.go @@ -19,6 +19,7 @@ package planbuilder import ( "errors" "fmt" + "strings" vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" "vitess.io/vitess/go/vt/vterrors" @@ -186,6 +187,7 @@ func (pb *primitiveBuilder) buildTablePrimitive(tableExpr *sqlparser.AliasedTabl } rb, st := newRoute(sel) rb.eroute = engine.NewSimpleRoute(engine.SelectDBA, ks) + rb.eroute.TableName = sqlparser.String(tableName) pb.plan, pb.st = rb, st // Add the table to symtab return st.AddTable(&table{ @@ -343,6 +345,10 @@ func (pb *primitiveBuilder) join(rpb *primitiveBuilder, ajoin *sqlparser.JoinTab } else { sel.From = sqlparser.TableExprs{ajoin} } + // join table name + if lRoute.eroute.TableName != rRoute.eroute.TableName { + lRoute.eroute.TableName = strings.Join([]string{lRoute.eroute.TableName, rRoute.eroute.TableName}, ", ") + } // Since the routes have merged, set st.singleRoute to point at // the merged route. diff --git a/go/vt/vtgate/planbuilder/jointree_transformers.go b/go/vt/vtgate/planbuilder/jointree_transformers.go index 84ed72f6cf8..a99c0fb16be 100644 --- a/go/vt/vtgate/planbuilder/jointree_transformers.go +++ b/go/vt/vtgate/planbuilder/jointree_transformers.go @@ -112,8 +112,9 @@ func transformRoutePlan(n *routePlan) (*route, error) { LeftExpr: lft, } tablesForSelect = sqlparser.TableExprs{joinExpr} - // todo: add table - // tableNameMap[sqlparser.String()] = nil + for _, tblNames := range leftJoin.right.tableNames() { + tableNameMap[tblNames] = nil + } } predicates := n.Predicates() diff --git a/go/vt/vtgate/planbuilder/testdata/filter_cases.txt b/go/vt/vtgate/planbuilder/testdata/filter_cases.txt index ec1be4d0439..08422d1fc76 100644 --- a/go/vt/vtgate/planbuilder/testdata/filter_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/filter_cases.txt @@ -557,7 +557,7 @@ Gen4 plan same as above }, "FieldQuery": "select user_extra.id from `user` join user_extra on `user`.id = user_extra.user_id where 1 != 1", "Query": "select user_extra.id from `user` join user_extra on `user`.id = user_extra.user_id where `user`.id = 5", - "Table": "`user`", + "Table": "`user`, user_extra", "Values": [ 5 ], @@ -598,7 +598,7 @@ Gen4 plan same as above }, "FieldQuery": "select user_extra.id from `user` join user_extra on `user`.id = user_extra.user_id where 1 != 1", "Query": "select user_extra.id from `user` join user_extra on `user`.id = user_extra.user_id where user_extra.user_id = 5", - "Table": "`user`", + "Table": "`user`, user_extra", "Values": [ 5 ], @@ -639,7 +639,7 @@ Gen4 plan same as above }, "FieldQuery": "select user_extra.id from `user` left join user_extra on `user`.id = user_extra.user_id where 1 != 1", "Query": "select user_extra.id from `user` left join user_extra on `user`.id = user_extra.user_id where `user`.id = 5", - "Table": "`user`", + "Table": "`user`, user_extra", "Values": [ 5 ], @@ -662,7 +662,7 @@ Gen4 plan same as above }, "FieldQuery": "select user_extra.id from `user` left join user_extra on `user`.id = user_extra.user_id where 1 != 1", "Query": "select user_extra.id from `user` left join user_extra on `user`.id = user_extra.user_id where user_extra.user_id = 5", - "Table": "`user`", + "Table": "`user`, user_extra", "Values": [ 5 ], @@ -1185,7 +1185,8 @@ Gen4 plan same as above "Sharded": false }, "FieldQuery": "select * from information_schema.a where 1 != 1", - "Query": "select * from information_schema.a where id in (select * from information_schema.b)" + "Query": "select * from information_schema.a where id in (select * from information_schema.b)", + "Table": "information_schema.a" } } @@ -1700,7 +1701,7 @@ Gen4 plan same as above }, "FieldQuery": "select user_extra.Id from `user` join user_extra on `user`.iD = user_extra.User_Id where 1 != 1", "Query": "select user_extra.Id from `user` join user_extra on `user`.iD = user_extra.User_Id where `user`.Id = 5", - "Table": "`user`", + "Table": "`user`, user_extra", "Values": [ 5 ], @@ -1912,7 +1913,6 @@ Gen4 plan same as above } Gen4 plan same as above - # query trying to query two different keyspaces at the same time "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'user' AND TABLE_SCHEMA = 'main'" { @@ -1927,26 +1927,13 @@ Gen4 plan same as above }, "FieldQuery": "select * from INFORMATION_SCHEMA.`TABLES` where 1 != 1", "Query": "select * from INFORMATION_SCHEMA.`TABLES` where TABLE_SCHEMA = :__vtschemaname and TABLE_SCHEMA = :__vtschemaname", - "SysTableTableSchema": "[VARBINARY(\"user\"), VARBINARY(\"main\")]" + "SysTableTableSchema": "[VARBINARY(\"user\"), VARBINARY(\"main\")]", + "Table": "INFORMATION_SCHEMA.`TABLES`" } } # information_schema query using database() func "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = database()" -{ - "QueryType": "SELECT", - "Original": "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = database()", - "Instructions": { - "OperatorType": "Route", - "Variant": "SelectDBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select * from INFORMATION_SCHEMA.`TABLES` where 1 != 1", - "Query": "select * from INFORMATION_SCHEMA.`TABLES` where TABLE_SCHEMA = database()" - } -} { "QueryType": "SELECT", "Original": "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = database()", @@ -1962,6 +1949,7 @@ Gen4 plan same as above "Table": "INFORMATION_SCHEMA.`TABLES`" } } +Gen4 plan same as above # table_schema predicate the wrong way around "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE 'ks' = TABLE_SCHEMA" @@ -1977,7 +1965,8 @@ Gen4 plan same as above }, "FieldQuery": "select * from INFORMATION_SCHEMA.`TABLES` where 1 != 1", "Query": "select * from INFORMATION_SCHEMA.`TABLES` where TABLE_SCHEMA = :__vtschemaname", - "SysTableTableSchema": "[VARBINARY(\"ks\")]" + "SysTableTableSchema": "[VARBINARY(\"ks\")]", + "Table": "INFORMATION_SCHEMA.`TABLES`" } } @@ -1996,7 +1985,8 @@ Gen4 plan same as above "FieldQuery": "select * from INFORMATION_SCHEMA.`TABLES` where 1 != 1", "Query": "select * from INFORMATION_SCHEMA.`TABLES` where TABLE_SCHEMA = :__vtschemaname and TABLE_NAME = :__vttablename", "SysTableTableName": "[VARBINARY(\"route1\")]", - "SysTableTableSchema": "[VARBINARY(\"ks\")]" + "SysTableTableSchema": "[VARBINARY(\"ks\")]", + "Table": "INFORMATION_SCHEMA.`TABLES`" } } @@ -2014,7 +2004,8 @@ Gen4 plan same as above }, "FieldQuery": "select * from INFORMATION_SCHEMA.`TABLES` where 1 != 1", "Query": "select * from INFORMATION_SCHEMA.`TABLES` where TABLE_SCHEMA = :__vtschemaname and other_column = 42", - "SysTableTableSchema": "[VARBINARY(\"ks\")]" + "SysTableTableSchema": "[VARBINARY(\"ks\")]", + "Table": "INFORMATION_SCHEMA.`TABLES`" } } @@ -2096,7 +2087,8 @@ Gen4 plan same as above }, "FieldQuery": "select * from INFORMATION_SCHEMA.`TABLES` where 1 != 1", "Query": "select * from INFORMATION_SCHEMA.`TABLES` where TABLE_SCHEMA = :__vtschemaname and (other_column = 42 or TABLE_SCHEMA = 'ks') and (other_column = 42 or foobar = 'value')", - "SysTableTableSchema": "[VARBINARY(\"ks\")]" + "SysTableTableSchema": "[VARBINARY(\"ks\")]", + "Table": "INFORMATION_SCHEMA.`TABLES`" } } @@ -2123,7 +2115,6 @@ Gen4 plan same as above } Gen4 plan same as above - "select * from samecolvin where col = :col" { "QueryType": "SELECT", diff --git a/go/vt/vtgate/planbuilder/testdata/from_cases.txt b/go/vt/vtgate/planbuilder/testdata/from_cases.txt index 703718f97fd..83539e37047 100644 --- a/go/vt/vtgate/planbuilder/testdata/from_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/from_cases.txt @@ -76,20 +76,6 @@ Gen4 plan same as above # Single information_schema query "select col from information_schema.foo" -{ - "QueryType": "SELECT", - "Original": "select col from information_schema.foo", - "Instructions": { - "OperatorType": "Route", - "Variant": "SelectDBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select col from information_schema.foo where 1 != 1", - "Query": "select col from information_schema.foo" - } -} { "QueryType": "SELECT", "Original": "select col from information_schema.foo", @@ -105,6 +91,7 @@ Gen4 plan same as above "Table": "information_schema.foo" } } +Gen4 plan same as above # Multi-table unsharded "select m1.col from unsharded as m1 join unsharded as m2" @@ -336,20 +323,6 @@ Gen4 plan same as above # ',' join information_schema "select a.id,b.id from information_schema.a as a, information_schema.b as b" -{ - "QueryType": "SELECT", - "Original": "select a.id,b.id from information_schema.a as a, information_schema.b as b", - "Instructions": { - "OperatorType": "Route", - "Variant": "SelectDBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select a.id, b.id from information_schema.a as a, information_schema.b as b where 1 != 1", - "Query": "select a.id, b.id from information_schema.a as a, information_schema.b as b" - } -} { "QueryType": "SELECT", "Original": "select a.id,b.id from information_schema.a as a, information_schema.b as b", @@ -365,6 +338,7 @@ Gen4 plan same as above "Table": "information_schema.a, information_schema.b" } } +Gen4 plan same as above # ',' 3-way join unsharded "select u1.a, u2.a from unsharded u1, unsharded u2, unsharded u3" @@ -851,7 +825,6 @@ Gen4 plan same as above } } - # Parenthesized, single chunk "select user.col from user join (unsharded as m1 join unsharded as m2)" { @@ -1064,7 +1037,7 @@ Gen4 plan same as above }, "FieldQuery": "select `user`.col from `user` join user_extra on `user`.id = user_extra.user_id where 1 != 1", "Query": "select `user`.col from `user` join user_extra on `user`.id = user_extra.user_id", - "Table": "`user`" + "Table": "`user`, user_extra" } } { @@ -1097,7 +1070,7 @@ Gen4 plan same as above }, "FieldQuery": "select `user`.col from `user` join user_extra on `user`.id = user_extra.user_id where 1 != 1", "Query": "select `user`.col from `user` join user_extra on `user`.id = user_extra.user_id", - "Table": "`user`" + "Table": "`user`, user_extra" } } { @@ -1130,7 +1103,7 @@ Gen4 plan same as above }, "FieldQuery": "select `user`.col from `user` join user_extra on `user`.col between 1 and 2 and `user`.id = user_extra.user_id where 1 != 1", "Query": "select `user`.col from `user` join user_extra on `user`.col between 1 and 2 and `user`.id = user_extra.user_id", - "Table": "`user`" + "Table": "`user`, user_extra" } } { @@ -1163,7 +1136,7 @@ Gen4 plan same as above }, "FieldQuery": "select `user`.col from `user` join user_extra on user_extra.user_id = `user`.id where 1 != 1", "Query": "select `user`.col from `user` join user_extra on user_extra.user_id = `user`.id", - "Table": "`user`" + "Table": "`user`, user_extra" } } { @@ -1196,7 +1169,7 @@ Gen4 plan same as above }, "FieldQuery": "select `user`.col from `user` join user_extra on `user`.id = 5 and `user`.id = user_extra.user_id where 1 != 1", "Query": "select `user`.col from `user` join user_extra on `user`.id = 5 and `user`.id = user_extra.user_id", - "Table": "`user`", + "Table": "`user`, user_extra", "Values": [ 5 ], @@ -1512,7 +1485,7 @@ Gen4 plan same as above }, "FieldQuery": "select `user`.col from `user` join ref where 1 != 1", "Query": "select `user`.col from `user` join ref", - "Table": "`user`" + "Table": "`user`, ref" } } { @@ -1578,7 +1551,7 @@ Gen4 plan same as above }, "FieldQuery": "select ref.col from ref join `user` where 1 != 1", "Query": "select ref.col from ref join `user`", - "Table": "`user`" + "Table": "`user`, ref" } } @@ -1597,7 +1570,7 @@ Gen4 plan same as above }, "FieldQuery": "select ref.col from ref join (select aa from `user` where 1 != 1) as `user` where 1 != 1", "Query": "select ref.col from ref join (select aa from `user` where `user`.id = 1) as `user`", - "Table": "`user`", + "Table": "`user`, ref", "Values": [ 1 ], @@ -1679,7 +1652,7 @@ Gen4 plan same as above }, "FieldQuery": "select t.id from (select id from `user` where 1 != 1) as t join user_extra on t.id = user_extra.user_id where 1 != 1", "Query": "select t.id from (select id from `user` where id = 5) as t join user_extra on t.id = user_extra.user_id", - "Table": "`user`", + "Table": "`user`, user_extra", "Values": [ 5 ], @@ -1701,7 +1674,7 @@ Gen4 plan same as above }, "FieldQuery": "select t.id from (select `user`.id from `user` where 1 != 1) as t join user_extra on t.id = user_extra.user_id where 1 != 1", "Query": "select t.id from (select `user`.id from `user` where `user`.id = 5) as t join user_extra on t.id = user_extra.user_id", - "Table": "`user`", + "Table": "`user`, user_extra", "Values": [ 5 ], @@ -1727,7 +1700,7 @@ Gen4 plan same as above }, "FieldQuery": "select t.id from user_extra join (select id from `user` where 1 != 1) as t on t.id = user_extra.user_id where 1 != 1", "Query": "select t.id from user_extra join (select id from `user` where id = 5) as t on t.id = user_extra.user_id", - "Table": "user_extra" + "Table": "user_extra, `user`" } } @@ -1838,7 +1811,6 @@ Gen4 plan same as above } } - # merge subqueries with single-shard routes "select u.col, e.col from (select col from user where id = 5) as u join (select col from user_extra where user_id = 5) as e" { @@ -1853,7 +1825,7 @@ Gen4 plan same as above }, "FieldQuery": "select u.col, e.col from (select col from `user` where 1 != 1) as u join (select col from user_extra where 1 != 1) as e where 1 != 1", "Query": "select u.col, e.col from (select col from `user` where id = 5) as u join (select col from user_extra where user_id = 5) as e", - "Table": "`user`", + "Table": "`user`, user_extra", "Values": [ 5 ], @@ -1874,9 +1846,11 @@ Gen4 plan same as above "Sharded": false }, "FieldQuery": "select * from information_schema.a where 1 != 1", - "Query": "select * from information_schema.a where b = 10" + "Query": "select * from information_schema.a where b = 10", + "Table": "information_schema.a" } } +Gen4 plan same as above # access to qualified column names in information_schema "select * from information_schema.a where information_schema.a.b=10" @@ -1891,45 +1865,14 @@ Gen4 plan same as above "Sharded": false }, "FieldQuery": "select * from information_schema.a where 1 != 1", - "Query": "select * from information_schema.a where information_schema.a.b = 10" + "Query": "select * from information_schema.a where information_schema.a.b = 10", + "Table": "information_schema.a" } } +Gen4 plan same as above # join of information_schema with normal table "select unsharded.foo from information_schema.a join unsharded" -{ - "QueryType": "SELECT", - "Original": "select unsharded.foo from information_schema.a join unsharded", - "Instructions": { - "OperatorType": "Join", - "Variant": "Join", - "JoinColumnIndexes": "1", - "TableName": "_unsharded", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "SelectDBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 from information_schema.a where 1 != 1", - "Query": "select 1 from information_schema.a" - }, - { - "OperatorType": "Route", - "Variant": "SelectUnsharded", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select unsharded.foo from unsharded where 1 != 1", - "Query": "select unsharded.foo from unsharded", - "Table": "unsharded" - } - ] - } -} { "QueryType": "SELECT", "Original": "select unsharded.foo from information_schema.a join unsharded", @@ -1964,42 +1907,10 @@ Gen4 plan same as above ] } } +Gen4 plan same as above # join of normal table with information_schema "select unsharded.foo from unsharded join information_schema.a" -{ - "QueryType": "SELECT", - "Original": "select unsharded.foo from unsharded join information_schema.a", - "Instructions": { - "OperatorType": "Join", - "Variant": "Join", - "JoinColumnIndexes": "-1", - "TableName": "unsharded_", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "SelectUnsharded", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select unsharded.foo from unsharded where 1 != 1", - "Query": "select unsharded.foo from unsharded", - "Table": "unsharded" - }, - { - "OperatorType": "Route", - "Variant": "SelectDBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 from information_schema.a where 1 != 1", - "Query": "select 1 from information_schema.a" - } - ] - } -} { "QueryType": "SELECT", "Original": "select unsharded.foo from unsharded join information_schema.a", @@ -2034,6 +1945,7 @@ Gen4 plan same as above ] } } +Gen4 plan same as above # wire-up on join with cross-shard subquery "select t.col1 from (select user.id, user.col1 from user join user_extra) as t join unsharded on unsharded.col1 = t.col1 and unsharded.id = t.id" @@ -2238,7 +2150,7 @@ Gen4 plan same as above }, "FieldQuery": "select unsharded_a.col from unsharded_a join unsharded_b on :__sq1 where 1 != 1", "Query": "select unsharded_a.col from unsharded_a join unsharded_b on :__sq1", - "Table": "unsharded_a" + "Table": "unsharded_a, unsharded_b" } ] } @@ -2273,7 +2185,7 @@ Gen4 plan same as above }, "FieldQuery": "select unsharded_a.col from unsharded_a join unsharded_b on unsharded_a.col + :__sq1 where 1 != 1", "Query": "select unsharded_a.col from unsharded_a join unsharded_b on unsharded_a.col + :__sq1", - "Table": "unsharded_a" + "Table": "unsharded_a, unsharded_b" } ] } @@ -2308,7 +2220,7 @@ Gen4 plan same as above }, "FieldQuery": "select unsharded_a.col from unsharded_a join unsharded_b on :__sq_has_values1 = 1 and unsharded_a.col in ::__sq1 where 1 != 1", "Query": "select unsharded_a.col from unsharded_a join unsharded_b on :__sq_has_values1 = 1 and unsharded_a.col in ::__sq1", - "Table": "unsharded_a" + "Table": "unsharded_a, unsharded_b" } ] } @@ -2601,7 +2513,7 @@ Gen4 plan same as above }, "FieldQuery": "select `user`.col from `user` join user_extra on `user`.ID = user_extra.User_Id where 1 != 1", "Query": "select `user`.col from `user` join user_extra on `user`.ID = user_extra.User_Id", - "Table": "`user`" + "Table": "`user`, user_extra" } } { @@ -2881,20 +2793,6 @@ Gen4 plan same as above # information schema query that uses table_schema "select column_name from information_schema.columns where table_schema = (select schema())" -{ - "QueryType": "SELECT", - "Original": "select column_name from information_schema.columns where table_schema = (select schema())", - "Instructions": { - "OperatorType": "Route", - "Variant": "SelectDBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select column_name from information_schema.`columns` where 1 != 1", - "Query": "select column_name from information_schema.`columns` where table_schema = schema()" - } -} { "QueryType": "SELECT", "Original": "select column_name from information_schema.columns where table_schema = (select schema())", @@ -2910,6 +2808,7 @@ Gen4 plan same as above "Table": "information_schema.`columns`" } } +Gen4 plan same as above # information schema join "select * from information_schema.a join information_schema.b" @@ -2924,7 +2823,8 @@ Gen4 plan same as above "Sharded": false }, "FieldQuery": "select * from information_schema.a join information_schema.b where 1 != 1", - "Query": "select * from information_schema.a join information_schema.b" + "Query": "select * from information_schema.a join information_schema.b", + "Table": "information_schema.a, information_schema.b" } } { @@ -2957,7 +2857,8 @@ Gen4 plan same as above }, "FieldQuery": "select fk.referenced_table_name as to_table, fk.referenced_column_name as primary_key, fk.column_name as `column`, fk.constraint_name as `name`, rc.update_rule as on_update, rc.delete_rule as on_delete from information_schema.referential_constraints as rc join information_schema.key_column_usage as fk on rc.constraint_schema = fk.constraint_schema and rc.constraint_name = fk.constraint_name where 1 != 1", "Query": "select fk.referenced_table_name as to_table, fk.referenced_column_name as primary_key, fk.column_name as `column`, fk.constraint_name as `name`, rc.update_rule as on_update, rc.delete_rule as on_delete from information_schema.referential_constraints as rc join information_schema.key_column_usage as fk on rc.constraint_schema = fk.constraint_schema and rc.constraint_name = fk.constraint_name where fk.referenced_column_name is not null and fk.table_schema = database() and fk.table_name = :__vttablename and rc.constraint_schema = database() and rc.table_name = :__vttablename", - "SysTableTableName": "[VARBINARY(\":vtg1\"), VARBINARY(\":vtg1\")]" + "SysTableTableName": "[VARBINARY(\":vtg1\"), VARBINARY(\":vtg1\")]", + "Table": "information_schema.referential_constraints, information_schema.key_column_usage" } } @@ -2975,7 +2876,8 @@ Gen4 plan same as above }, "FieldQuery": "select * from information_schema.schemata where 1 != 1", "Query": "select * from information_schema.schemata where schema_name = :__vtschemaname", - "SysTableTableSchema": "[VARBINARY(\"user\")]" + "SysTableTableSchema": "[VARBINARY(\"user\")]", + "Table": "information_schema.schemata" } } @@ -2994,7 +2896,8 @@ Gen4 plan same as above "FieldQuery": "select table_comment from information_schema.`tables` where 1 != 1", "Query": "select table_comment from information_schema.`tables` where table_schema = :__vtschemaname and table_name = :__vttablename", "SysTableTableName": "[VARBINARY(\"table_name\")]", - "SysTableTableSchema": "[VARBINARY(\"schema_name\")]" + "SysTableTableSchema": "[VARBINARY(\"schema_name\")]", + "Table": "information_schema.`tables`" } } @@ -3013,7 +2916,8 @@ Gen4 plan same as above "FieldQuery": "select fk.referenced_table_name as to_table, fk.referenced_column_name as primary_key, fk.column_name as `column`, fk.constraint_name as `name`, rc.update_rule as on_update, rc.delete_rule as on_delete from information_schema.referential_constraints as rc join information_schema.key_column_usage as fk on rc.constraint_schema = fk.constraint_schema and rc.constraint_name = fk.constraint_name where 1 != 1", "Query": "select fk.referenced_table_name as to_table, fk.referenced_column_name as primary_key, fk.column_name as `column`, fk.constraint_name as `name`, rc.update_rule as on_update, rc.delete_rule as on_delete from information_schema.referential_constraints as rc join information_schema.key_column_usage as fk on rc.constraint_schema = fk.constraint_schema and rc.constraint_name = fk.constraint_name where fk.referenced_column_name is not null and fk.table_schema = :__vtschemaname and fk.table_name = :__vttablename and rc.constraint_schema = :__vtschemaname and rc.table_name = :__vttablename", "SysTableTableName": "[VARBINARY(\"table_name\"), VARBINARY(\"table_name\")]", - "SysTableTableSchema": "[VARBINARY(\"table_schema\"), VARBINARY(\"table_schema\")]" + "SysTableTableSchema": "[VARBINARY(\"table_schema\"), VARBINARY(\"table_schema\")]", + "Table": "information_schema.referential_constraints, information_schema.key_column_usage" } } @@ -3032,7 +2936,8 @@ Gen4 plan same as above "FieldQuery": "select cc.constraint_name as `name`, cc.check_clause as expression from information_schema.check_constraints as cc join information_schema.table_constraints as tc on cc.constraint_schema = tc.constraint_schema and cc.constraint_name = tc.constraint_name where 1 != 1", "Query": "select cc.constraint_name as `name`, cc.check_clause as expression from information_schema.check_constraints as cc join information_schema.table_constraints as tc on cc.constraint_schema = tc.constraint_schema and cc.constraint_name = tc.constraint_name where tc.table_schema = :__vtschemaname and tc.table_name = :__vttablename and cc.constraint_schema = :__vtschemaname", "SysTableTableName": "[VARBINARY(\"table_name\")]", - "SysTableTableSchema": "[VARBINARY(\"table_schema\"), VARBINARY(\"constraint_schema\")]" + "SysTableTableSchema": "[VARBINARY(\"table_schema\"), VARBINARY(\"constraint_schema\")]", + "Table": "information_schema.check_constraints, information_schema.table_constraints" } } @@ -3051,7 +2956,8 @@ Gen4 plan same as above "FieldQuery": "select column_name from information_schema.statistics where 1 != 1", "Query": "select column_name from information_schema.statistics where index_name = 'PRIMARY' and table_schema = :__vtschemaname and table_name = :__vttablename order by seq_in_index asc", "SysTableTableName": "[VARBINARY(\"table_name\")]", - "SysTableTableSchema": "[VARBINARY(\"table_schema\")]" + "SysTableTableSchema": "[VARBINARY(\"table_schema\")]", + "Table": "information_schema.statistics" } } @@ -3070,26 +2976,13 @@ Gen4 plan same as above "FieldQuery": "select generation_expression from information_schema.`columns` where 1 != 1", "Query": "select generation_expression from information_schema.`columns` where table_schema = :__vtschemaname and table_name = :__vttablename and column_name = 'column_name'", "SysTableTableName": "[VARBINARY(\"table_name\")]", - "SysTableTableSchema": "[VARBINARY(\"table_schema\")]" + "SysTableTableSchema": "[VARBINARY(\"table_schema\")]", + "Table": "information_schema.`columns`" } } #rails_query 8 "SELECT id FROM information_schema.processlist WHERE info LIKE '% FOR UPDATE'" -{ - "QueryType": "SELECT", - "Original": "SELECT id FROM information_schema.processlist WHERE info LIKE '% FOR UPDATE'", - "Instructions": { - "OperatorType": "Route", - "Variant": "SelectDBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select id from information_schema.`processlist` where 1 != 1", - "Query": "select id from information_schema.`processlist` where info like '% FOR UPDATE'" - } -} { "QueryType": "SELECT", "Original": "SELECT id FROM information_schema.processlist WHERE info LIKE '% FOR UPDATE'", @@ -3105,6 +2998,7 @@ Gen4 plan same as above "Table": "information_schema.`processlist`" } } +Gen4 plan same as above #rails_query 9 "SELECT table_name FROM (SELECT * FROM information_schema.tables WHERE table_schema = 'table_schema') _subquery" @@ -3120,7 +3014,8 @@ Gen4 plan same as above }, "FieldQuery": "select table_name from (select * from information_schema.`tables` where 1 != 1) as _subquery where 1 != 1", "Query": "select table_name from (select * from information_schema.`tables` where table_schema = :__vtschemaname) as _subquery", - "SysTableTableSchema": "[VARBINARY(\"table_schema\")]" + "SysTableTableSchema": "[VARBINARY(\"table_schema\")]", + "Table": "information_schema.`tables`" } } @@ -3139,7 +3034,8 @@ Gen4 plan same as above "FieldQuery": "select table_name from (select * from information_schema.`tables` where 1 != 1) as _subquery where 1 != 1", "Query": "select table_name from (select * from information_schema.`tables` where table_schema = :__vtschemaname) as _subquery where _subquery.table_type = 'table_type' and _subquery.table_name = :__vttablename", "SysTableTableName": "[VARBINARY(\"table_name\")]", - "SysTableTableSchema": "[VARBINARY(\"table_schema\")]" + "SysTableTableSchema": "[VARBINARY(\"table_schema\")]", + "Table": "information_schema.`tables`" } } @@ -3157,7 +3053,8 @@ Gen4 plan same as above }, "FieldQuery": "select cc.constraint_name as `name` from information_schema.check_constraints as cc where 1 != 1", "Query": "select cc.constraint_name as `name` from information_schema.check_constraints as cc where cc.constraint_schema = :__vtschemaname and cc.table_schema = :__vtschemaname", - "SysTableTableSchema": "[VARBINARY(\"a\"), VARBINARY(\"a\")]" + "SysTableTableSchema": "[VARBINARY(\"a\"), VARBINARY(\"a\")]", + "Table": "information_schema.check_constraints" } } @@ -3176,7 +3073,8 @@ Gen4 plan same as above "FieldQuery": "select COUNT(*) from INFORMATION_SCHEMA.`TABLES` where 1 != 1", "Query": "select COUNT(*) from INFORMATION_SCHEMA.`TABLES` where table_schema = :__vtschemaname and table_name = :__vttablename", "SysTableTableName": "[VARBINARY(\"foo\")]", - "SysTableTableSchema": "[VARBINARY(\"performance_schema\")]" + "SysTableTableSchema": "[VARBINARY(\"performance_schema\")]", + "Table": "INFORMATION_SCHEMA.`TABLES`" } } diff --git a/go/vt/vtgate/planbuilder/testdata/postprocess_cases.txt b/go/vt/vtgate/planbuilder/testdata/postprocess_cases.txt index 90720212366..5e6418c4f0f 100644 --- a/go/vt/vtgate/planbuilder/testdata/postprocess_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/postprocess_cases.txt @@ -1072,7 +1072,7 @@ Gen4 plan same as above }, "FieldQuery": "select * from `user` as u join (select user_id from user_extra where 1 != 1) as eu on u.id = eu.user_id where 1 != 1", "Query": "select * from `user` as u join (select user_id from user_extra where user_id = 5) as eu on u.id = eu.user_id where u.id = 5 order by eu.user_id asc", - "Table": "`user`", + "Table": "`user`, user_extra", "Values": [ 5 ], @@ -1416,7 +1416,6 @@ Gen4 plan same as above ] } } -"gen4 does not yet support: aggregation and non-aggregation expressions, together are not supported in cross-shard query" # aggregation and non-aggregations column with order by "select count(id), num from user order by 2" @@ -1449,7 +1448,6 @@ Gen4 plan same as above ] } } -"gen4 does not yet support: aggregation and non-aggregation expressions, together are not supported in cross-shard query" # aggregation and non-aggregations column with group by "select count(id), num from user group by 2" @@ -1478,7 +1476,6 @@ Gen4 plan same as above ] } } -"gen4 does not yet support: aggregation and non-aggregation expressions, together are not supported in cross-shard query" # aggregation and non-aggregations column with group by and order by "select count(id), num from user group by 2 order by 1" @@ -1514,5 +1511,3 @@ Gen4 plan same as above ] } } -"gen4 does not yet support: aggregation and non-aggregation expressions, together are not supported in cross-shard query" - diff --git a/go/vt/vtgate/planbuilder/testdata/select_cases.txt b/go/vt/vtgate/planbuilder/testdata/select_cases.txt index b3424d316a5..68e697dbc23 100644 --- a/go/vt/vtgate/planbuilder/testdata/select_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/select_cases.txt @@ -306,7 +306,7 @@ Gen4 plan same as above # test table lookup failure for authoritative code path "select a.* from authoritative" "table a not found" -Gen4 error: Unknown table 'a' +"Unknown table 'a'" # select * from qualified authoritative table "select a.* from authoritative a" @@ -355,7 +355,7 @@ Gen4 error: Unknown table 'a' }, "FieldQuery": "select * from authoritative join `user` on authoritative.user_id = `user`.id where 1 != 1", "Query": "select * from authoritative join `user` on authoritative.user_id = `user`.id", - "Table": "authoritative" + "Table": "authoritative, `user`" } } @@ -373,7 +373,7 @@ Gen4 error: Unknown table 'a' }, "FieldQuery": "select `user`.id, a.user_id, a.col1, a.col2, `user`.col1 from authoritative as a join `user` on a.user_id = `user`.id where 1 != 1", "Query": "select `user`.id, a.user_id, a.col1, a.col2, `user`.col1 from authoritative as a join `user` on a.user_id = `user`.id", - "Table": "authoritative" + "Table": "authoritative, `user`" } } @@ -391,7 +391,7 @@ Gen4 error: Unknown table 'a' }, "FieldQuery": "select col from `user` join user_extra on `user`.id = user_extra.user_id where 1 != 1", "Query": "select col from `user` join user_extra on `user`.id = user_extra.user_id", - "Table": "`user`" + "Table": "`user`, user_extra" } } { @@ -1262,7 +1262,8 @@ Gen4 plan same as above "Sharded": false }, "FieldQuery": "select * from information_schema.a where 1 != 1 union select * from information_schema.b where 1 != 1", - "Query": "select * from information_schema.a union select * from information_schema.b" + "Query": "select * from information_schema.a union select * from information_schema.b", + "Table": "information_schema.a" } } Gen4 plan same as above @@ -1787,7 +1788,8 @@ Gen4 plan same as above "FieldQuery": "select DELETE_RULE, UPDATE_RULE from INFORMATION_SCHEMA.KEY_COLUMN_USAGE as KCU join INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS as RC on KCU.CONSTRAINT_NAME = RC.CONSTRAINT_NAME where 1 != 1", "Query": "select DELETE_RULE, UPDATE_RULE from INFORMATION_SCHEMA.KEY_COLUMN_USAGE as KCU join INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS as RC on KCU.CONSTRAINT_NAME = RC.CONSTRAINT_NAME where KCU.TABLE_SCHEMA = :__vtschemaname and KCU.TABLE_NAME = :__vttablename and KCU.COLUMN_NAME = 'id' and KCU.REFERENCED_TABLE_SCHEMA = 'test' and KCU.CONSTRAINT_NAME = 'data_type_table_id_fkey' order by KCU.CONSTRAINT_NAME asc, KCU.COLUMN_NAME asc", "SysTableTableName": "[VARBINARY(\"data_type_table\")]", - "SysTableTableSchema": "[VARBINARY(\"test\")]" + "SysTableTableSchema": "[VARBINARY(\"test\")]", + "Table": "INFORMATION_SCHEMA.KEY_COLUMN_USAGE, INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS" } } @@ -1800,7 +1802,7 @@ Gen4 plan same as above "OperatorType": "Join", "Variant": "Join", "JoinColumnIndexes": "-1,1", - "TableName": "_", + "TableName": "INFORMATION_SCHEMA.KEY_COLUMN_USAGE, INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS_INFORMATION_SCHEMA.K", "Inputs": [ { "OperatorType": "Route", @@ -1812,7 +1814,8 @@ Gen4 plan same as above "FieldQuery": "select KCU.DELETE_RULE from INFORMATION_SCHEMA.KEY_COLUMN_USAGE as KCU join INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS as RC on KCU.CONSTRAINT_NAME = RC.CONSTRAINT_NAME where 1 != 1", "Query": "select KCU.DELETE_RULE from INFORMATION_SCHEMA.KEY_COLUMN_USAGE as KCU join INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS as RC on KCU.CONSTRAINT_NAME = RC.CONSTRAINT_NAME where KCU.TABLE_SCHEMA = :__vtschemaname and KCU.TABLE_NAME = :__vttablename and KCU.TABLE_NAME = :__vttablename order by KCU.CONSTRAINT_NAME asc, KCU.COLUMN_NAME asc", "SysTableTableName": "[VARBINARY(\"data_type_table\"), VARBINARY(\"data_type_table\")]", - "SysTableTableSchema": "[VARBINARY(\"test\")]" + "SysTableTableSchema": "[VARBINARY(\"test\")]", + "Table": "INFORMATION_SCHEMA.KEY_COLUMN_USAGE, INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS" }, { "OperatorType": "Route", @@ -1824,7 +1827,8 @@ Gen4 plan same as above "FieldQuery": "select S.UPDATE_RULE from INFORMATION_SCHEMA.K as S where 1 != 1", "Query": "select S.UPDATE_RULE from INFORMATION_SCHEMA.K as S where S.TABLE_SCHEMA = :__vtschemaname and S.TABLE_NAME = :__vttablename", "SysTableTableName": "[VARBINARY(\"sc\")]", - "SysTableTableSchema": "[VARBINARY(\"test\")]" + "SysTableTableSchema": "[VARBINARY(\"test\")]", + "Table": "INFORMATION_SCHEMA.K" } ] } @@ -1844,7 +1848,8 @@ Gen4 plan same as above }, "FieldQuery": "select routine_name as `name`, routine_definition as definition from information_schema.routines where 1 != 1", "Query": "select routine_name as `name`, routine_definition as definition from information_schema.routines where ROUTINE_SCHEMA = :__vtschemaname and ROUTINE_TYPE = 'PROCEDURE'", - "SysTableTableSchema": "[:v1]" + "SysTableTableSchema": "[:v1]", + "Table": "information_schema.routines" } } @@ -1862,7 +1867,8 @@ Gen4 plan same as above }, "FieldQuery": "select SUM(data_length + index_length) as size from information_schema.`TABLES` where 1 != 1", "Query": "select SUM(data_length + index_length) as size from information_schema.`TABLES` where table_schema = :__vtschemaname", - "SysTableTableSchema": "[:v1]" + "SysTableTableSchema": "[:v1]", + "Table": "information_schema.`TABLES`" } } @@ -1880,6 +1886,7 @@ Gen4 plan same as above }, "FieldQuery": "select kcu.constraint_name as constraint_name, kcu.column_name as column_name, kcu.referenced_table_name as referenced_table_name, kcu.referenced_column_name as referenced_column_name, kcu.ordinal_position as ordinal_position, kcu.table_name as table_name, rc.delete_rule as delete_rule, rc.update_rule as update_rule from information_schema.key_column_usage as kcu join information_schema.referential_constraints as rc on kcu.constraint_name = rc.constraint_name where 1 != 1", "Query": "select kcu.constraint_name as constraint_name, kcu.column_name as column_name, kcu.referenced_table_name as referenced_table_name, kcu.referenced_column_name as referenced_column_name, kcu.ordinal_position as ordinal_position, kcu.table_name as table_name, rc.delete_rule as delete_rule, rc.update_rule as update_rule from information_schema.key_column_usage as kcu join information_schema.referential_constraints as rc on kcu.constraint_name = rc.constraint_name where kcu.table_schema = :__vtschemaname and rc.constraint_schema = :__vtschemaname and kcu.referenced_column_name is not null order by ordinal_position asc", - "SysTableTableSchema": "[:v1, :v2]" + "SysTableTableSchema": "[:v1, :v2]", + "Table": "information_schema.key_column_usage, information_schema.referential_constraints" } } diff --git a/go/vt/vtgate/planbuilder/testdata/union_cases.txt b/go/vt/vtgate/planbuilder/testdata/union_cases.txt index 18c159fd044..82e018ceeb2 100644 --- a/go/vt/vtgate/planbuilder/testdata/union_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/union_cases.txt @@ -297,7 +297,8 @@ Gen4 plan same as above "Sharded": false }, "FieldQuery": "select * from information_schema.a where 1 != 1", - "Query": "select * from information_schema.a" + "Query": "select * from information_schema.a", + "Table": "information_schema.a" }, { "OperatorType": "Route", @@ -347,7 +348,8 @@ Gen4 plan same as above "Sharded": false }, "FieldQuery": "select * from information_schema.a where 1 != 1", - "Query": "select * from information_schema.a" + "Query": "select * from information_schema.a", + "Table": "information_schema.a" } ] } diff --git a/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt b/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt index b1e99a3c15b..c2355ad7ead 100644 --- a/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt @@ -104,7 +104,7 @@ Gen4 plan same as above # Multi-value aggregates not supported "select count(a,b) from user" "unsupported: only one expression allowed inside aggregates: count(a, b)" -"aggregate functions take a single argument 'count(a, b)'" +Gen4 error: aggregate functions take a single argument 'count(a, b)' # Cannot have more than one aggr(distinct... "select count(distinct a), count(distinct b) from user" @@ -457,14 +457,15 @@ Gen4 plan same as above }, "FieldQuery": "select cc.constraint_name as `name` from information_schema.check_constraints as cc where 1 != 1", "Query": "select cc.constraint_name as `name` from information_schema.check_constraints as cc where cc.constraint_schema = :__vtschemaname and cc.table_schema = :__vtschemaname", - "SysTableTableSchema": "[VARBINARY(\"constraint_schema\"), VARBINARY(\"a\")]" + "SysTableTableSchema": "[VARBINARY(\"constraint_schema\"), VARBINARY(\"a\")]", + "Table": "information_schema.check_constraints" } } # create view with Cannot auto-resolve for cross-shard joins "create view user.view_a as select col from user join user_extra" "symbol col not found" -"Complex select queries are not supported in create or alter view statements" +Gen4 error: Complex select queries are not supported in create or alter view statements # create view with join that cannot be served in each shard separately "create view user.view_a as select user_extra.id from user join user_extra" @@ -495,20 +496,6 @@ Gen4 plan same as above # table_schema OR predicate # It is unsupported because we do not route queries to multiple keyspaces right now "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'ks' OR TABLE_SCHEMA = 'main'" -{ - "QueryType": "SELECT", - "Original": "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'ks' OR TABLE_SCHEMA = 'main'", - "Instructions": { - "OperatorType": "Route", - "Variant": "SelectDBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select * from INFORMATION_SCHEMA.`TABLES` where 1 != 1", - "Query": "select * from INFORMATION_SCHEMA.`TABLES` where TABLE_SCHEMA = 'ks' or TABLE_SCHEMA = 'main'" - } -} { "QueryType": "SELECT", "Original": "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'ks' OR TABLE_SCHEMA = 'main'", @@ -524,3 +511,4 @@ Gen4 plan same as above "Table": "INFORMATION_SCHEMA.`TABLES`" } } +Gen4 plan same as above