From d9c7f5f6f4973fe9dd9bcf00050f06ac8aad7552 Mon Sep 17 00:00:00 2001 From: Arthur Schreiber Date: Tue, 13 Jan 2026 14:39:03 +0000 Subject: [PATCH 1/7] Remove conversion of predicate into Filter. Signed-off-by: Arthur Schreiber --- go/vt/vtgate/planbuilder/operators/union.go | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/go/vt/vtgate/planbuilder/operators/union.go b/go/vt/vtgate/planbuilder/operators/union.go index ebdc80d6179..c7463e59494 100644 --- a/go/vt/vtgate/planbuilder/operators/union.go +++ b/go/vt/vtgate/planbuilder/operators/union.go @@ -109,11 +109,7 @@ func (u *Union) AddPredicate(ctx *plancontext.PlanningContext, expr sqlparser.Ex ctx.PredTracker.Skip(jp.ID) } - needsFilter, exprPerSource := u.predicatePerSource(expr, offsets) - if needsFilter { - return newFilter(u, expr) - } - + exprPerSource := u.predicatePerSource(expr, offsets) for i, src := range u.Sources { u.Sources[i] = src.AddPredicate(ctx, exprPerSource[i]) } @@ -121,8 +117,7 @@ func (u *Union) AddPredicate(ctx *plancontext.PlanningContext, expr sqlparser.Ex return u } -func (u *Union) predicatePerSource(expr sqlparser.Expr, offsets map[string]int) (bool, []sqlparser.Expr) { - needsFilter := false +func (u *Union) predicatePerSource(expr sqlparser.Expr, offsets map[string]int) []sqlparser.Expr { exprPerSource := make([]sqlparser.Expr, len(u.Sources)) for i := range u.Sources { @@ -134,9 +129,7 @@ func (u *Union) predicatePerSource(expr sqlparser.Expr, offsets map[string]int) idx, ok := offsets[col.Name.Lowered()] if !ok { - needsFilter = true - cursor.StopTreeWalk() - return + panic(vterrors.VT13001(fmt.Sprintf("column '%s' not found in UNION output columns", col.Name.String()))) } sel := u.GetSelectFor(i) @@ -151,7 +144,7 @@ func (u *Union) predicatePerSource(expr sqlparser.Expr, offsets map[string]int) exprPerSource[i] = predicate } - return needsFilter, exprPerSource + return exprPerSource } func (u *Union) GetSelectFor(source int) *sqlparser.Select { From 0e2dae184b0056645e25ba4b76a56de902f6c91b Mon Sep 17 00:00:00 2001 From: Arthur Schreiber Date: Tue, 13 Jan 2026 17:06:47 +0000 Subject: [PATCH 2/7] Fix column names not being treated as case-insensitive. Signed-off-by: Arthur Schreiber --- go/vt/vtgate/planbuilder/operators/union.go | 3 +- .../planbuilder/testdata/union_cases.json | 143 ++++++++---------- 2 files changed, 67 insertions(+), 79 deletions(-) diff --git a/go/vt/vtgate/planbuilder/operators/union.go b/go/vt/vtgate/planbuilder/operators/union.go index c7463e59494..24ab0911d5c 100644 --- a/go/vt/vtgate/planbuilder/operators/union.go +++ b/go/vt/vtgate/planbuilder/operators/union.go @@ -19,6 +19,7 @@ package operators import ( "fmt" "slices" + "strings" "vitess.io/vitess/go/slice" "vitess.io/vitess/go/vt/sqlparser" @@ -101,7 +102,7 @@ func (u *Union) AddPredicate(ctx *plancontext.PlanningContext, expr sqlparser.Ex if !ok { panic(vterrors.VT12001("pushing predicates on UNION where the first SELECT contains * or NEXT")) } - offsets[ae.ColumnName()] = i + offsets[strings.ToLower(ae.ColumnName())] = i } if jp, ok := expr.(*predicates.JoinPredicate); ok { diff --git a/go/vt/vtgate/planbuilder/testdata/union_cases.json b/go/vt/vtgate/planbuilder/testdata/union_cases.json index 756bfa7fb98..0c953187990 100644 --- a/go/vt/vtgate/planbuilder/testdata/union_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/union_cases.json @@ -1306,43 +1306,37 @@ "QueryType": "SELECT", "Original": "select * from (select kcu.`COLUMN_NAME` from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'user_extra' union select kcu.`COLUMN_NAME` from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'music') `kcu` where `COLUMN_NAME` = 'primary'", "Instructions": { - "OperatorType": "Filter", - "Predicate": "`COLUMN_NAME` = 'primary'", + "OperatorType": "Distinct", + "Collations": [ + "0: utf8mb3_general_ci" + ], "Inputs": [ { - "OperatorType": "Distinct", - "Collations": [ - "0: utf8mb3_general_ci" - ], + "OperatorType": "Concatenate", "Inputs": [ { - "OperatorType": "Concatenate", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select kcu.`COLUMN_NAME` from information_schema.key_column_usage as kcu where 1 != 1", - "Query": "select distinct kcu.`COLUMN_NAME` from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname /* VARCHAR */ and kcu.`table_name` = :kcu_table_name /* VARCHAR */", - "SysTableTableName": "[kcu_table_name:'user_extra']", - "SysTableTableSchema": "['user']" - }, - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select kcu.`COLUMN_NAME` from information_schema.key_column_usage as kcu where 1 != 1", - "Query": "select distinct kcu.`COLUMN_NAME` from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname /* VARCHAR */ and kcu.`table_name` = :kcu_table_name1 /* VARCHAR */", - "SysTableTableName": "[kcu_table_name1:'music']", - "SysTableTableSchema": "['user']" - } - ] + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select kcu.`COLUMN_NAME` from information_schema.key_column_usage as kcu where 1 != 1", + "Query": "select distinct kcu.`COLUMN_NAME` from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname /* VARCHAR */ and kcu.`table_name` = :kcu_table_name /* VARCHAR */ and `COLUMN_NAME` = 'primary'", + "SysTableTableName": "[kcu_table_name:'user_extra']", + "SysTableTableSchema": "['user']" + }, + { + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select kcu.`COLUMN_NAME` from information_schema.key_column_usage as kcu where 1 != 1", + "Query": "select distinct kcu.`COLUMN_NAME` from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname /* VARCHAR */ and kcu.`table_name` = :kcu_table_name1 /* VARCHAR */ and `COLUMN_NAME` = 'primary'", + "SysTableTableName": "[kcu_table_name1:'music']", + "SysTableTableSchema": "['user']" } ] } @@ -1385,54 +1379,48 @@ "QueryType": "SELECT", "Original": "select * from (select * from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'user_extra' union select * from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'music') `kcu` where `constraint_name` = 'primary'", "Instructions": { - "OperatorType": "Filter", - "Predicate": "`constraint_name` = 'primary'", + "OperatorType": "Distinct", + "Collations": [ + "0: utf8mb3_general_ci", + "1: utf8mb3_general_ci", + "2: utf8mb3_general_ci", + "3: utf8mb3_general_ci", + "4: utf8mb3_general_ci", + "5: utf8mb3_general_ci", + "6: utf8mb3_general_ci", + "7", + "8", + "9: utf8mb3_general_ci", + "10: utf8mb3_general_ci", + "11: utf8mb3_general_ci" + ], "Inputs": [ { - "OperatorType": "Distinct", - "Collations": [ - "0: utf8mb3_general_ci", - "1: utf8mb3_general_ci", - "2: utf8mb3_general_ci", - "3: utf8mb3_general_ci", - "4: utf8mb3_general_ci", - "5: utf8mb3_general_ci", - "6: utf8mb3_general_ci", - "7", - "8", - "9: utf8mb3_general_ci", - "10: utf8mb3_general_ci", - "11: utf8mb3_general_ci" - ], + "OperatorType": "Concatenate", "Inputs": [ { - "OperatorType": "Concatenate", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select `CONSTRAINT_CATALOG`, `CONSTRAINT_SCHEMA`, `CONSTRAINT_NAME`, TABLE_CATALOG, TABLE_SCHEMA, `TABLE_NAME`, `COLUMN_NAME`, ORDINAL_POSITION, POSITION_IN_UNIQUE_CONSTRAINT, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from information_schema.key_column_usage as kcu where 1 != 1", - "Query": "select distinct `CONSTRAINT_CATALOG`, `CONSTRAINT_SCHEMA`, `CONSTRAINT_NAME`, TABLE_CATALOG, TABLE_SCHEMA, `TABLE_NAME`, `COLUMN_NAME`, ORDINAL_POSITION, POSITION_IN_UNIQUE_CONSTRAINT, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname /* VARCHAR */ and kcu.`table_name` = :kcu_table_name /* VARCHAR */", - "SysTableTableName": "[kcu_table_name:'user_extra']", - "SysTableTableSchema": "['user']" - }, - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select `CONSTRAINT_CATALOG`, `CONSTRAINT_SCHEMA`, `CONSTRAINT_NAME`, TABLE_CATALOG, TABLE_SCHEMA, `TABLE_NAME`, `COLUMN_NAME`, ORDINAL_POSITION, POSITION_IN_UNIQUE_CONSTRAINT, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from information_schema.key_column_usage as kcu where 1 != 1", - "Query": "select distinct `CONSTRAINT_CATALOG`, `CONSTRAINT_SCHEMA`, `CONSTRAINT_NAME`, TABLE_CATALOG, TABLE_SCHEMA, `TABLE_NAME`, `COLUMN_NAME`, ORDINAL_POSITION, POSITION_IN_UNIQUE_CONSTRAINT, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname /* VARCHAR */ and kcu.`table_name` = :kcu_table_name1 /* VARCHAR */", - "SysTableTableName": "[kcu_table_name1:'music']", - "SysTableTableSchema": "['user']" - } - ] + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select `CONSTRAINT_CATALOG`, `CONSTRAINT_SCHEMA`, `CONSTRAINT_NAME`, TABLE_CATALOG, TABLE_SCHEMA, `TABLE_NAME`, `COLUMN_NAME`, ORDINAL_POSITION, POSITION_IN_UNIQUE_CONSTRAINT, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from information_schema.key_column_usage as kcu where 1 != 1", + "Query": "select distinct `CONSTRAINT_CATALOG`, `CONSTRAINT_SCHEMA`, `CONSTRAINT_NAME`, TABLE_CATALOG, TABLE_SCHEMA, `TABLE_NAME`, `COLUMN_NAME`, ORDINAL_POSITION, POSITION_IN_UNIQUE_CONSTRAINT, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname /* VARCHAR */ and kcu.`table_name` = :kcu_table_name /* VARCHAR */ and `CONSTRAINT_NAME` = 'primary'", + "SysTableTableName": "[kcu_table_name:'user_extra']", + "SysTableTableSchema": "['user']" + }, + { + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select `CONSTRAINT_CATALOG`, `CONSTRAINT_SCHEMA`, `CONSTRAINT_NAME`, TABLE_CATALOG, TABLE_SCHEMA, `TABLE_NAME`, `COLUMN_NAME`, ORDINAL_POSITION, POSITION_IN_UNIQUE_CONSTRAINT, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from information_schema.key_column_usage as kcu where 1 != 1", + "Query": "select distinct `CONSTRAINT_CATALOG`, `CONSTRAINT_SCHEMA`, `CONSTRAINT_NAME`, TABLE_CATALOG, TABLE_SCHEMA, `TABLE_NAME`, `COLUMN_NAME`, ORDINAL_POSITION, POSITION_IN_UNIQUE_CONSTRAINT, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname /* VARCHAR */ and kcu.`table_name` = :kcu_table_name1 /* VARCHAR */ and `CONSTRAINT_NAME` = 'primary'", + "SysTableTableName": "[kcu_table_name1:'music']", + "SysTableTableSchema": "['user']" } ] } @@ -2138,5 +2126,4 @@ ] } } - ] From fc8b5fd62f8188c8a51d5c3242e267cb02489185 Mon Sep 17 00:00:00 2001 From: Arthur Schreiber Date: Tue, 13 Jan 2026 17:09:36 +0000 Subject: [PATCH 3/7] Align error message. Signed-off-by: Arthur Schreiber --- go/vt/vtgate/planbuilder/operators/union.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/vt/vtgate/planbuilder/operators/union.go b/go/vt/vtgate/planbuilder/operators/union.go index 24ab0911d5c..cf0a837ec4f 100644 --- a/go/vt/vtgate/planbuilder/operators/union.go +++ b/go/vt/vtgate/planbuilder/operators/union.go @@ -130,7 +130,7 @@ func (u *Union) predicatePerSource(expr sqlparser.Expr, offsets map[string]int) idx, ok := offsets[col.Name.Lowered()] if !ok { - panic(vterrors.VT13001(fmt.Sprintf("column '%s' not found in UNION output columns", col.Name.String()))) + panic(vterrors.VT13001(fmt.Sprintf("could not find the column '%s' on the UNION", sqlparser.String(col)))) } sel := u.GetSelectFor(i) From b9bafeab4aff41448747ed03c574397ec420b424 Mon Sep 17 00:00:00 2001 From: Arthur Schreiber Date: Tue, 13 Jan 2026 10:29:58 +0000 Subject: [PATCH 4/7] Add `infoSchema` route type merging support to union queries Signed-off-by: Arthur Schreiber --- .../planbuilder/operators/union_merging.go | 44 +++ .../testdata/info_schema57_cases.json | 292 ++++-------------- .../testdata/info_schema80_cases.json | 292 ++++-------------- .../planbuilder/testdata/union_cases.json | 146 ++------- 4 files changed, 193 insertions(+), 581 deletions(-) diff --git a/go/vt/vtgate/planbuilder/operators/union_merging.go b/go/vt/vtgate/planbuilder/operators/union_merging.go index cd8acdab9d3..4562a25943d 100644 --- a/go/vt/vtgate/planbuilder/operators/union_merging.go +++ b/go/vt/vtgate/planbuilder/operators/union_merging.go @@ -131,6 +131,9 @@ func mergeUnionInputs( if res != nil { return res, exprs } + + case a == infoSchema && b == infoSchema: + return tryMergeUnionInfoSchemaRouting(ctx, lhsRoute, rhsRoute, lhsExprs, rhsExprs, distinct) } return nil, nil } @@ -176,6 +179,47 @@ func tryMergeUnionShardedRouting( return nil, nil } +func tryMergeUnionInfoSchemaRouting( + ctx *plancontext.PlanningContext, + routeA, routeB *Route, + exprsA, exprsB []sqlparser.SelectExpr, + distinct bool, +) (Operator, []sqlparser.SelectExpr) { + isrA := routeA.Routing.(*InfoSchemaRouting) + isrB := routeB.Routing.(*InfoSchemaRouting) + emptyA := len(isrA.SysTableTableName) == 0 && len(isrA.SysTableTableSchema) == 0 + emptyB := len(isrB.SysTableTableName) == 0 && len(isrB.SysTableTableSchema) == 0 + + switch { + // if either side has no predicates to help us route, we can merge them + case emptyA: + return createMergedUnion(ctx, routeA, routeB, exprsA, exprsB, distinct, isrB, nil) + case emptyB: + return createMergedUnion(ctx, routeA, routeB, exprsA, exprsB, distinct, isrA, nil) + + // if we have no schema predicates on either side, we can merge if the table info is compatible + case len(isrA.SysTableTableSchema) == 0 && len(isrB.SysTableTableSchema) == 0: + for k, expr := range isrB.SysTableTableName { + if e, found := isrA.SysTableTableName[k]; found && !sqlparser.Equals.Expr(expr, e) { + // contradicting table names, give up + return nil, nil + } + isrA.SysTableTableName[k] = expr + } + return createMergedUnion(ctx, routeA, routeB, exprsA, exprsB, distinct, isrA, nil) + + // if both sides have the same schema predicate, we can safely merge them + case equalExprs(isrA.SysTableTableSchema, isrB.SysTableTableSchema): + for k, expr := range isrB.SysTableTableName { + isrA.SysTableTableName[k] = expr + } + return createMergedUnion(ctx, routeA, routeB, exprsA, exprsB, distinct, isrA, nil) + + default: + return nil, nil + } +} + func createMergedUnion( ctx *plancontext.PlanningContext, lhsRoute, rhsRoute *Route, diff --git a/go/vt/vtgate/planbuilder/testdata/info_schema57_cases.json b/go/vt/vtgate/planbuilder/testdata/info_schema57_cases.json index efed1db91a7..ee279c2f6c8 100644 --- a/go/vt/vtgate/planbuilder/testdata/info_schema57_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/info_schema57_cases.json @@ -98,41 +98,18 @@ "comment": "union of information_schema", "query": "select TABLE_NAME from information_schema.columns union select table_schema from information_schema.tables", "plan": { - "Type": "Complex", + "Type": "Passthrough", "QueryType": "SELECT", "Original": "select TABLE_NAME from information_schema.columns union select table_schema from information_schema.tables", "Instructions": { - "OperatorType": "Distinct", - "Collations": [ - "0: utf8mb3_general_ci" - ], - "Inputs": [ - { - "OperatorType": "Concatenate", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select `TABLE_NAME` from information_schema.`columns` where 1 != 1", - "Query": "select distinct `TABLE_NAME` from information_schema.`columns`" - }, - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select table_schema from information_schema.`tables` where 1 != 1", - "Query": "select distinct table_schema from information_schema.`tables`" - } - ] - } - ] + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select `TABLE_NAME` from information_schema.`columns` where 1 != 1 union select table_schema from information_schema.`tables` where 1 != 1", + "Query": "select `TABLE_NAME` from information_schema.`columns` union select table_schema from information_schema.`tables`" } } }, @@ -774,42 +751,19 @@ "comment": "select sum(found) from (select 1 as found from information_schema.`tables` where table_schema = 'music' union all (select 1 as found from information_schema.views where table_schema = 'music' limit 1)) as t", "query": "select sum(found) from (select 1 as found from information_schema.`tables` where table_schema = 'music' union all (select 1 as found from information_schema.views where table_schema = 'music' limit 1)) as t", "plan": { - "Type": "Complex", + "Type": "Passthrough", "QueryType": "SELECT", "Original": "select sum(found) from (select 1 as found from information_schema.`tables` where table_schema = 'music' union all (select 1 as found from information_schema.views where table_schema = 'music' limit 1)) as t", "Instructions": { - "OperatorType": "Aggregate", - "Variant": "Scalar", - "Aggregates": "sum(0) AS sum(`found`)", - "Inputs": [ - { - "OperatorType": "Concatenate", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.`tables` where 1 != 1", - "Query": "select 1 as `found` from information_schema.`tables` where table_schema = :__vtschemaname /* VARCHAR */", - "SysTableTableSchema": "['music']" - }, - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.views where 1 != 1", - "Query": "select 1 as `found` from information_schema.views where table_schema = :__vtschemaname /* VARCHAR */ limit 1", - "SysTableTableSchema": "['music']" - } - ] - } - ] + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select sum(`found`) from (select 1 as `found` from information_schema.`tables` where 1 != 1 union all (select 1 as `found` from information_schema.views where 1 != 1)) as t where 1 != 1", + "Query": "select sum(`found`) from (select 1 as `found` from information_schema.`tables` where table_schema = :__vtschemaname /* VARCHAR */ union all (select 1 as `found` from information_schema.views where table_schema = :__vtschemaname /* VARCHAR */ limit 1)) as t", + "SysTableTableSchema": "['music']" } } }, @@ -817,35 +771,19 @@ "comment": "union as a derived table", "query": "select found from (select 1 as found from information_schema.`tables` where table_schema = 'music' union all (select 1 as found from information_schema.views where table_schema = 'music' limit 1)) as t", "plan": { - "Type": "Complex", + "Type": "Passthrough", "QueryType": "SELECT", "Original": "select found from (select 1 as found from information_schema.`tables` where table_schema = 'music' union all (select 1 as found from information_schema.views where table_schema = 'music' limit 1)) as t", "Instructions": { - "OperatorType": "Concatenate", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.`tables` where 1 != 1", - "Query": "select 1 as `found` from information_schema.`tables` where table_schema = :__vtschemaname /* VARCHAR */", - "SysTableTableSchema": "['music']" - }, - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.views where 1 != 1", - "Query": "select 1 as `found` from information_schema.views where table_schema = :__vtschemaname /* VARCHAR */ limit 1", - "SysTableTableSchema": "['music']" - } - ] + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select `found` from (select 1 as `found` from information_schema.`tables` where 1 != 1 union all (select 1 as `found` from information_schema.views where 1 != 1)) as t where 1 != 1", + "Query": "select `found` from (select 1 as `found` from information_schema.`tables` where table_schema = :__vtschemaname /* VARCHAR */ union all (select 1 as `found` from information_schema.views where table_schema = :__vtschemaname /* VARCHAR */ limit 1)) as t", + "SysTableTableSchema": "['music']" } } }, @@ -925,63 +863,19 @@ "comment": "merge union subquery with outer query referencing the same system schemas", "query": "select 1 as found from information_schema.`tables` where table_name = 'music' and table_name = 'Music' and exists (select 1 as found from information_schema.`tables` where table_name = 'music' and table_name = 'Music' union all (select 1 as found from information_schema.views where table_name = 'music' and table_name = 'user' limit 1))", "plan": { - "Type": "Complex", + "Type": "Passthrough", "QueryType": "SELECT", "Original": "select 1 as found from information_schema.`tables` where table_name = 'music' and table_name = 'Music' and exists (select 1 as found from information_schema.`tables` where table_name = 'music' and table_name = 'Music' union all (select 1 as found from information_schema.views where table_name = 'music' and table_name = 'user' limit 1))", "Instructions": { - "OperatorType": "UncorrelatedSubquery", - "Variant": "PulloutExists", - "PulloutVars": [ - "__sq_has_values" - ], - "Inputs": [ - { - "InputName": "SubQuery", - "OperatorType": "Limit", - "Count": "1", - "Inputs": [ - { - "OperatorType": "Concatenate", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.`tables` where 1 != 1", - "Query": "select 1 as `found` from information_schema.`tables` where `table_name` = :table_name1 /* VARCHAR */ and `table_name` = :table_name1 /* VARCHAR */ limit :__upper_limit", - "SysTableTableName": "[table_name1:'Music']" - }, - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.views where 1 != 1", - "Query": "select 1 as `found` from information_schema.views where `table_name` = :table_name2 /* VARCHAR */ and `table_name` = :table_name2 /* VARCHAR */ limit :__upper_limit", - "SysTableTableName": "[table_name2:'user']" - } - ] - } - ] - }, - { - "InputName": "Outer", - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.`tables` where 1 != 1", - "Query": "select 1 as `found` from information_schema.`tables` where `table_name` = :table_name /* VARCHAR */ and `table_name` = :table_name /* VARCHAR */ and :__sq_has_values", - "SysTableTableName": "[table_name:'Music']" - } - ] + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select 1 as `found` from information_schema.`tables` where 1 != 1", + "Query": "select 1 as `found` from information_schema.`tables` where `table_name` = :table_name /* VARCHAR */ and `table_name` = :table_name /* VARCHAR */ and exists (select 1 as `found` from information_schema.`tables` where `table_name` = :table_name1 /* VARCHAR */ and `table_name` = :table_name1 /* VARCHAR */ union all (select 1 as `found` from information_schema.views where `table_name` = :table_name2 /* VARCHAR */ and `table_name` = :table_name2 /* VARCHAR */ limit 1))", + "SysTableTableName": "[table_name1:'Music', table_name2:'user', table_name:'Music']" } } }, @@ -989,42 +883,19 @@ "comment": "merge even one side have schema name in derived table", "query": "select * from (select TABLE_NAME from information_schema.tables t where t.TABLE_SCHEMA = 'a' union select TABLE_NAME from information_schema.columns) dt", "plan": { - "Type": "Complex", + "Type": "Passthrough", "QueryType": "SELECT", "Original": "select * from (select TABLE_NAME from information_schema.tables t where t.TABLE_SCHEMA = 'a' union select TABLE_NAME from information_schema.columns) dt", "Instructions": { - "OperatorType": "Distinct", - "Collations": [ - "0: utf8mb3_general_ci" - ], - "Inputs": [ - { - "OperatorType": "Concatenate", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select `TABLE_NAME` from information_schema.`tables` as t where 1 != 1", - "Query": "select distinct `TABLE_NAME` from information_schema.`tables` as t where t.TABLE_SCHEMA = :__vtschemaname /* VARCHAR */", - "SysTableTableSchema": "['a']" - }, - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select `TABLE_NAME` from information_schema.`columns` where 1 != 1", - "Query": "select distinct `TABLE_NAME` from information_schema.`columns`" - } - ] - } - ] + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select `TABLE_NAME` from (select `TABLE_NAME` from information_schema.`tables` as t where 1 != 1 union select `TABLE_NAME` from information_schema.`columns` where 1 != 1) as dt where 1 != 1", + "Query": "select `TABLE_NAME` from (select `TABLE_NAME` from information_schema.`tables` as t where t.TABLE_SCHEMA = :__vtschemaname /* VARCHAR */ union select `TABLE_NAME` from information_schema.`columns`) as dt", + "SysTableTableSchema": "['a']" } } }, @@ -1032,64 +903,19 @@ "comment": "merge even one side have schema name in subquery", "query": "select `COLLATION_NAME` from information_schema.`COLUMNS` t where `COLUMN_NAME` in (select `TABLE_NAME` from information_schema.tables t where t.TABLE_SCHEMA = 'a' union select `COLUMN_NAME` from information_schema.columns)", "plan": { - "Type": "Complex", + "Type": "Passthrough", "QueryType": "SELECT", "Original": "select `COLLATION_NAME` from information_schema.`COLUMNS` t where `COLUMN_NAME` in (select `TABLE_NAME` from information_schema.tables t where t.TABLE_SCHEMA = 'a' union select `COLUMN_NAME` from information_schema.columns)", "Instructions": { - "OperatorType": "UncorrelatedSubquery", - "Variant": "PulloutIn", - "PulloutVars": [ - "__sq_has_values", - "__sq1" - ], - "Inputs": [ - { - "InputName": "SubQuery", - "OperatorType": "Distinct", - "Collations": [ - "0: utf8mb3_general_ci" - ], - "Inputs": [ - { - "OperatorType": "Concatenate", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select `TABLE_NAME` from information_schema.`tables` as t where 1 != 1", - "Query": "select distinct `TABLE_NAME` from information_schema.`tables` as t where t.TABLE_SCHEMA = :__vtschemaname /* VARCHAR */", - "SysTableTableSchema": "['a']" - }, - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select `COLUMN_NAME` from information_schema.`columns` where 1 != 1", - "Query": "select distinct `COLUMN_NAME` from information_schema.`columns`" - } - ] - } - ] - }, - { - "InputName": "Outer", - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select COLLATION_NAME from information_schema.`COLUMNS` as t where 1 != 1", - "Query": "select COLLATION_NAME from information_schema.`COLUMNS` as t where :__sq_has_values and `COLUMN_NAME` in ::__sq1" - } - ] + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select COLLATION_NAME from information_schema.`COLUMNS` as t where 1 != 1", + "Query": "select COLLATION_NAME from information_schema.`COLUMNS` as t where `COLUMN_NAME` in (select `TABLE_NAME` from information_schema.`tables` as t where t.TABLE_SCHEMA = :__vtschemaname /* VARCHAR */ union select `COLUMN_NAME` from information_schema.`columns`)", + "SysTableTableSchema": "['a']" } } }, diff --git a/go/vt/vtgate/planbuilder/testdata/info_schema80_cases.json b/go/vt/vtgate/planbuilder/testdata/info_schema80_cases.json index fcf78c4159f..9b1ed9bc2c6 100644 --- a/go/vt/vtgate/planbuilder/testdata/info_schema80_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/info_schema80_cases.json @@ -98,41 +98,18 @@ "comment": "union of information_schema", "query": "select TABLE_NAME from information_schema.columns union select table_schema from information_schema.tables", "plan": { - "Type": "Complex", + "Type": "Passthrough", "QueryType": "SELECT", "Original": "select TABLE_NAME from information_schema.columns union select table_schema from information_schema.tables", "Instructions": { - "OperatorType": "Distinct", - "Collations": [ - "0: utf8mb3_general_ci" - ], - "Inputs": [ - { - "OperatorType": "Concatenate", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select `TABLE_NAME` from information_schema.`columns` where 1 != 1", - "Query": "select distinct `TABLE_NAME` from information_schema.`columns`" - }, - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select table_schema from information_schema.`tables` where 1 != 1", - "Query": "select distinct table_schema from information_schema.`tables`" - } - ] - } - ] + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select `TABLE_NAME` from information_schema.`columns` where 1 != 1 union select table_schema from information_schema.`tables` where 1 != 1", + "Query": "select `TABLE_NAME` from information_schema.`columns` union select table_schema from information_schema.`tables`" } } }, @@ -837,42 +814,19 @@ "comment": "select sum(found) from (select 1 as found from information_schema.`tables` where table_schema = 'music' union all (select 1 as found from information_schema.views where table_schema = 'music' limit 1)) as t", "query": "select sum(found) from (select 1 as found from information_schema.`tables` where table_schema = 'music' union all (select 1 as found from information_schema.views where table_schema = 'music' limit 1)) as t", "plan": { - "Type": "Complex", + "Type": "Passthrough", "QueryType": "SELECT", "Original": "select sum(found) from (select 1 as found from information_schema.`tables` where table_schema = 'music' union all (select 1 as found from information_schema.views where table_schema = 'music' limit 1)) as t", "Instructions": { - "OperatorType": "Aggregate", - "Variant": "Scalar", - "Aggregates": "sum(0) AS sum(`found`)", - "Inputs": [ - { - "OperatorType": "Concatenate", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.`tables` where 1 != 1", - "Query": "select 1 as `found` from information_schema.`tables` where table_schema = :__vtschemaname /* VARCHAR */", - "SysTableTableSchema": "['music']" - }, - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.views where 1 != 1", - "Query": "select 1 as `found` from information_schema.views where table_schema = :__vtschemaname /* VARCHAR */ limit 1", - "SysTableTableSchema": "['music']" - } - ] - } - ] + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select sum(`found`) from (select 1 as `found` from information_schema.`tables` where 1 != 1 union all (select 1 as `found` from information_schema.views where 1 != 1)) as t where 1 != 1", + "Query": "select sum(`found`) from (select 1 as `found` from information_schema.`tables` where table_schema = :__vtschemaname /* VARCHAR */ union all (select 1 as `found` from information_schema.views where table_schema = :__vtschemaname /* VARCHAR */ limit 1)) as t", + "SysTableTableSchema": "['music']" } } }, @@ -880,35 +834,19 @@ "comment": "union as a derived table", "query": "select found from (select 1 as found from information_schema.`tables` where table_schema = 'music' union all (select 1 as found from information_schema.views where table_schema = 'music' limit 1)) as t", "plan": { - "Type": "Complex", + "Type": "Passthrough", "QueryType": "SELECT", "Original": "select found from (select 1 as found from information_schema.`tables` where table_schema = 'music' union all (select 1 as found from information_schema.views where table_schema = 'music' limit 1)) as t", "Instructions": { - "OperatorType": "Concatenate", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.`tables` where 1 != 1", - "Query": "select 1 as `found` from information_schema.`tables` where table_schema = :__vtschemaname /* VARCHAR */", - "SysTableTableSchema": "['music']" - }, - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.views where 1 != 1", - "Query": "select 1 as `found` from information_schema.views where table_schema = :__vtschemaname /* VARCHAR */ limit 1", - "SysTableTableSchema": "['music']" - } - ] + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select `found` from (select 1 as `found` from information_schema.`tables` where 1 != 1 union all (select 1 as `found` from information_schema.views where 1 != 1)) as t where 1 != 1", + "Query": "select `found` from (select 1 as `found` from information_schema.`tables` where table_schema = :__vtschemaname /* VARCHAR */ union all (select 1 as `found` from information_schema.views where table_schema = :__vtschemaname /* VARCHAR */ limit 1)) as t", + "SysTableTableSchema": "['music']" } } }, @@ -988,63 +926,19 @@ "comment": "merge union subquery with outer query referencing the same system schemas", "query": "select 1 as found from information_schema.`tables` where table_name = 'music' and table_name = 'Music' and exists (select 1 as found from information_schema.`tables` where table_name = 'music' and table_name = 'Music' union all (select 1 as found from information_schema.views where table_name = 'music' and table_name = 'user' limit 1))", "plan": { - "Type": "Complex", + "Type": "Passthrough", "QueryType": "SELECT", "Original": "select 1 as found from information_schema.`tables` where table_name = 'music' and table_name = 'Music' and exists (select 1 as found from information_schema.`tables` where table_name = 'music' and table_name = 'Music' union all (select 1 as found from information_schema.views where table_name = 'music' and table_name = 'user' limit 1))", "Instructions": { - "OperatorType": "UncorrelatedSubquery", - "Variant": "PulloutExists", - "PulloutVars": [ - "__sq_has_values" - ], - "Inputs": [ - { - "InputName": "SubQuery", - "OperatorType": "Limit", - "Count": "1", - "Inputs": [ - { - "OperatorType": "Concatenate", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.`tables` where 1 != 1", - "Query": "select 1 as `found` from information_schema.`tables` where `table_name` = :table_name1 /* VARCHAR */ and `table_name` = :table_name1 /* VARCHAR */ limit :__upper_limit", - "SysTableTableName": "[table_name1:'Music']" - }, - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.views where 1 != 1", - "Query": "select 1 as `found` from information_schema.views where `table_name` = :table_name2 /* VARCHAR */ and `table_name` = :table_name2 /* VARCHAR */ limit :__upper_limit", - "SysTableTableName": "[table_name2:'user']" - } - ] - } - ] - }, - { - "InputName": "Outer", - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.`tables` where 1 != 1", - "Query": "select 1 as `found` from information_schema.`tables` where `table_name` = :table_name /* VARCHAR */ and `table_name` = :table_name /* VARCHAR */ and :__sq_has_values", - "SysTableTableName": "[table_name:'Music']" - } - ] + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select 1 as `found` from information_schema.`tables` where 1 != 1", + "Query": "select 1 as `found` from information_schema.`tables` where `table_name` = :table_name /* VARCHAR */ and `table_name` = :table_name /* VARCHAR */ and exists (select 1 as `found` from information_schema.`tables` where `table_name` = :table_name1 /* VARCHAR */ and `table_name` = :table_name1 /* VARCHAR */ union all (select 1 as `found` from information_schema.views where `table_name` = :table_name2 /* VARCHAR */ and `table_name` = :table_name2 /* VARCHAR */ limit 1))", + "SysTableTableName": "[table_name1:'Music', table_name2:'user', table_name:'Music']" } } }, @@ -1052,42 +946,19 @@ "comment": "merge even one side have schema name in derived table", "query": "select * from (select TABLE_NAME from information_schema.tables t where t.TABLE_SCHEMA = 'a' union select TABLE_NAME from information_schema.columns) dt", "plan": { - "Type": "Complex", + "Type": "Passthrough", "QueryType": "SELECT", "Original": "select * from (select TABLE_NAME from information_schema.tables t where t.TABLE_SCHEMA = 'a' union select TABLE_NAME from information_schema.columns) dt", "Instructions": { - "OperatorType": "Distinct", - "Collations": [ - "0: utf8mb3_general_ci" - ], - "Inputs": [ - { - "OperatorType": "Concatenate", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select `TABLE_NAME` from information_schema.`tables` as t where 1 != 1", - "Query": "select distinct `TABLE_NAME` from information_schema.`tables` as t where t.TABLE_SCHEMA = :__vtschemaname /* VARCHAR */", - "SysTableTableSchema": "['a']" - }, - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select `TABLE_NAME` from information_schema.`columns` where 1 != 1", - "Query": "select distinct `TABLE_NAME` from information_schema.`columns`" - } - ] - } - ] + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select `TABLE_NAME` from (select `TABLE_NAME` from information_schema.`tables` as t where 1 != 1 union select `TABLE_NAME` from information_schema.`columns` where 1 != 1) as dt where 1 != 1", + "Query": "select `TABLE_NAME` from (select `TABLE_NAME` from information_schema.`tables` as t where t.TABLE_SCHEMA = :__vtschemaname /* VARCHAR */ union select `TABLE_NAME` from information_schema.`columns`) as dt", + "SysTableTableSchema": "['a']" } } }, @@ -1095,64 +966,19 @@ "comment": "merge even one side have schema name in subquery", "query": "select `COLLATION_NAME` from information_schema.`COLUMNS` t where `COLUMN_NAME` in (select `TABLE_NAME` from information_schema.tables t where t.TABLE_SCHEMA = 'a' union select `COLUMN_NAME` from information_schema.columns)", "plan": { - "Type": "Complex", + "Type": "Passthrough", "QueryType": "SELECT", "Original": "select `COLLATION_NAME` from information_schema.`COLUMNS` t where `COLUMN_NAME` in (select `TABLE_NAME` from information_schema.tables t where t.TABLE_SCHEMA = 'a' union select `COLUMN_NAME` from information_schema.columns)", "Instructions": { - "OperatorType": "UncorrelatedSubquery", - "Variant": "PulloutIn", - "PulloutVars": [ - "__sq_has_values", - "__sq1" - ], - "Inputs": [ - { - "InputName": "SubQuery", - "OperatorType": "Distinct", - "Collations": [ - "0: utf8mb3_general_ci" - ], - "Inputs": [ - { - "OperatorType": "Concatenate", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select `TABLE_NAME` from information_schema.`tables` as t where 1 != 1", - "Query": "select distinct `TABLE_NAME` from information_schema.`tables` as t where t.TABLE_SCHEMA = :__vtschemaname /* VARCHAR */", - "SysTableTableSchema": "['a']" - }, - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select `COLUMN_NAME` from information_schema.`columns` where 1 != 1", - "Query": "select distinct `COLUMN_NAME` from information_schema.`columns`" - } - ] - } - ] - }, - { - "InputName": "Outer", - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select COLLATION_NAME from information_schema.`COLUMNS` as t where 1 != 1", - "Query": "select COLLATION_NAME from information_schema.`COLUMNS` as t where :__sq_has_values and `COLUMN_NAME` in ::__sq1" - } - ] + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select COLLATION_NAME from information_schema.`COLUMNS` as t where 1 != 1", + "Query": "select COLLATION_NAME from information_schema.`COLUMNS` as t where `COLUMN_NAME` in (select `TABLE_NAME` from information_schema.`tables` as t where t.TABLE_SCHEMA = :__vtschemaname /* VARCHAR */ union select `COLUMN_NAME` from information_schema.`columns`)", + "SysTableTableSchema": "['a']" } } }, diff --git a/go/vt/vtgate/planbuilder/testdata/union_cases.json b/go/vt/vtgate/planbuilder/testdata/union_cases.json index 0c953187990..4b18b236181 100644 --- a/go/vt/vtgate/planbuilder/testdata/union_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/union_cases.json @@ -982,41 +982,18 @@ "comment": "test handling of TEXT column type handling", "query": "select table_comment from information_schema.tables union select table_comment from information_schema.tables", "plan": { - "Type": "Complex", + "Type": "Passthrough", "QueryType": "SELECT", "Original": "select table_comment from information_schema.tables union select table_comment from information_schema.tables", "Instructions": { - "OperatorType": "Distinct", - "Collations": [ - "0" - ], - "Inputs": [ - { - "OperatorType": "Concatenate", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select table_comment from information_schema.`tables` where 1 != 1", - "Query": "select distinct table_comment from information_schema.`tables`" - }, - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select table_comment from information_schema.`tables` where 1 != 1", - "Query": "select distinct table_comment from information_schema.`tables`" - } - ] - } - ] + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select table_comment from information_schema.`tables` where 1 != 1 union select table_comment from information_schema.`tables` where 1 != 1", + "Query": "select table_comment from information_schema.`tables` union select table_comment from information_schema.`tables`" } } }, @@ -1302,45 +1279,20 @@ "comment": "systable union query in derived table with constraint on outside (without star projection)", "query": "select * from (select kcu.`COLUMN_NAME` from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'user_extra' union select kcu.`COLUMN_NAME` from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'music') `kcu` where `COLUMN_NAME` = 'primary'", "plan": { - "Type": "Complex", + "Type": "Passthrough", "QueryType": "SELECT", "Original": "select * from (select kcu.`COLUMN_NAME` from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'user_extra' union select kcu.`COLUMN_NAME` from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'music') `kcu` where `COLUMN_NAME` = 'primary'", "Instructions": { - "OperatorType": "Distinct", - "Collations": [ - "0: utf8mb3_general_ci" - ], - "Inputs": [ - { - "OperatorType": "Concatenate", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select kcu.`COLUMN_NAME` from information_schema.key_column_usage as kcu where 1 != 1", - "Query": "select distinct kcu.`COLUMN_NAME` from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname /* VARCHAR */ and kcu.`table_name` = :kcu_table_name /* VARCHAR */ and `COLUMN_NAME` = 'primary'", - "SysTableTableName": "[kcu_table_name:'user_extra']", - "SysTableTableSchema": "['user']" - }, - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select kcu.`COLUMN_NAME` from information_schema.key_column_usage as kcu where 1 != 1", - "Query": "select distinct kcu.`COLUMN_NAME` from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname /* VARCHAR */ and kcu.`table_name` = :kcu_table_name1 /* VARCHAR */ and `COLUMN_NAME` = 'primary'", - "SysTableTableName": "[kcu_table_name1:'music']", - "SysTableTableSchema": "['user']" - } - ] - } - ] + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select `COLUMN_NAME` from (select kcu.`COLUMN_NAME` from information_schema.key_column_usage as kcu where 1 != 1 union select kcu.`COLUMN_NAME` from information_schema.key_column_usage as kcu where 1 != 1) as kcu where 1 != 1", + "Query": "select `COLUMN_NAME` from (select kcu.`COLUMN_NAME` from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname /* VARCHAR */ and kcu.`table_name` = :kcu_table_name /* VARCHAR */ and `COLUMN_NAME` = 'primary' union select kcu.`COLUMN_NAME` from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname /* VARCHAR */ and kcu.`table_name` = :kcu_table_name1 /* VARCHAR */ and `COLUMN_NAME` = 'primary') as kcu", + "SysTableTableName": "[kcu_table_name1:'music', kcu_table_name:'user_extra']", + "SysTableTableSchema": "['user']" } } }, @@ -1375,56 +1327,20 @@ "comment": "systable union query in derived table with constraint on outside (star projection)", "query": "select * from (select * from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'user_extra' union select * from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'music') `kcu` where `constraint_name` = 'primary'", "plan": { - "Type": "Complex", + "Type": "Passthrough", "QueryType": "SELECT", "Original": "select * from (select * from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'user_extra' union select * from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'music') `kcu` where `constraint_name` = 'primary'", "Instructions": { - "OperatorType": "Distinct", - "Collations": [ - "0: utf8mb3_general_ci", - "1: utf8mb3_general_ci", - "2: utf8mb3_general_ci", - "3: utf8mb3_general_ci", - "4: utf8mb3_general_ci", - "5: utf8mb3_general_ci", - "6: utf8mb3_general_ci", - "7", - "8", - "9: utf8mb3_general_ci", - "10: utf8mb3_general_ci", - "11: utf8mb3_general_ci" - ], - "Inputs": [ - { - "OperatorType": "Concatenate", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select `CONSTRAINT_CATALOG`, `CONSTRAINT_SCHEMA`, `CONSTRAINT_NAME`, TABLE_CATALOG, TABLE_SCHEMA, `TABLE_NAME`, `COLUMN_NAME`, ORDINAL_POSITION, POSITION_IN_UNIQUE_CONSTRAINT, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from information_schema.key_column_usage as kcu where 1 != 1", - "Query": "select distinct `CONSTRAINT_CATALOG`, `CONSTRAINT_SCHEMA`, `CONSTRAINT_NAME`, TABLE_CATALOG, TABLE_SCHEMA, `TABLE_NAME`, `COLUMN_NAME`, ORDINAL_POSITION, POSITION_IN_UNIQUE_CONSTRAINT, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname /* VARCHAR */ and kcu.`table_name` = :kcu_table_name /* VARCHAR */ and `CONSTRAINT_NAME` = 'primary'", - "SysTableTableName": "[kcu_table_name:'user_extra']", - "SysTableTableSchema": "['user']" - }, - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select `CONSTRAINT_CATALOG`, `CONSTRAINT_SCHEMA`, `CONSTRAINT_NAME`, TABLE_CATALOG, TABLE_SCHEMA, `TABLE_NAME`, `COLUMN_NAME`, ORDINAL_POSITION, POSITION_IN_UNIQUE_CONSTRAINT, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from information_schema.key_column_usage as kcu where 1 != 1", - "Query": "select distinct `CONSTRAINT_CATALOG`, `CONSTRAINT_SCHEMA`, `CONSTRAINT_NAME`, TABLE_CATALOG, TABLE_SCHEMA, `TABLE_NAME`, `COLUMN_NAME`, ORDINAL_POSITION, POSITION_IN_UNIQUE_CONSTRAINT, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname /* VARCHAR */ and kcu.`table_name` = :kcu_table_name1 /* VARCHAR */ and `CONSTRAINT_NAME` = 'primary'", - "SysTableTableName": "[kcu_table_name1:'music']", - "SysTableTableSchema": "['user']" - } - ] - } - ] + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select `CONSTRAINT_CATALOG`, `CONSTRAINT_SCHEMA`, `CONSTRAINT_NAME`, TABLE_CATALOG, TABLE_SCHEMA, `TABLE_NAME`, `COLUMN_NAME`, ORDINAL_POSITION, POSITION_IN_UNIQUE_CONSTRAINT, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from (select `CONSTRAINT_CATALOG`, `CONSTRAINT_SCHEMA`, `CONSTRAINT_NAME`, TABLE_CATALOG, TABLE_SCHEMA, `TABLE_NAME`, `COLUMN_NAME`, ORDINAL_POSITION, POSITION_IN_UNIQUE_CONSTRAINT, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from information_schema.key_column_usage as kcu where 1 != 1 union select `CONSTRAINT_CATALOG`, `CONSTRAINT_SCHEMA`, `CONSTRAINT_NAME`, TABLE_CATALOG, TABLE_SCHEMA, `TABLE_NAME`, `COLUMN_NAME`, ORDINAL_POSITION, POSITION_IN_UNIQUE_CONSTRAINT, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from information_schema.key_column_usage as kcu where 1 != 1) as kcu where 1 != 1", + "Query": "select `CONSTRAINT_CATALOG`, `CONSTRAINT_SCHEMA`, `CONSTRAINT_NAME`, TABLE_CATALOG, TABLE_SCHEMA, `TABLE_NAME`, `COLUMN_NAME`, ORDINAL_POSITION, POSITION_IN_UNIQUE_CONSTRAINT, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from (select `CONSTRAINT_CATALOG`, `CONSTRAINT_SCHEMA`, `CONSTRAINT_NAME`, TABLE_CATALOG, TABLE_SCHEMA, `TABLE_NAME`, `COLUMN_NAME`, ORDINAL_POSITION, POSITION_IN_UNIQUE_CONSTRAINT, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname /* VARCHAR */ and kcu.`table_name` = :kcu_table_name /* VARCHAR */ and `CONSTRAINT_NAME` = 'primary' union select `CONSTRAINT_CATALOG`, `CONSTRAINT_SCHEMA`, `CONSTRAINT_NAME`, TABLE_CATALOG, TABLE_SCHEMA, `TABLE_NAME`, `COLUMN_NAME`, ORDINAL_POSITION, POSITION_IN_UNIQUE_CONSTRAINT, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname /* VARCHAR */ and kcu.`table_name` = :kcu_table_name1 /* VARCHAR */ and `CONSTRAINT_NAME` = 'primary') as kcu", + "SysTableTableName": "[kcu_table_name1:'music', kcu_table_name:'user_extra']", + "SysTableTableSchema": "['user']" } } }, From 4e08f1f7d1b72f0380c86b8c6b0ca97a5446042e Mon Sep 17 00:00:00 2001 From: Arthur Schreiber Date: Tue, 13 Jan 2026 14:40:03 +0000 Subject: [PATCH 5/7] Add more detailed debug output. Signed-off-by: Arthur Schreiber --- .../operators/info_schema_planning.go | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/go/vt/vtgate/planbuilder/operators/info_schema_planning.go b/go/vt/vtgate/planbuilder/operators/info_schema_planning.go index e1d66e98d39..ba1eb71deca 100644 --- a/go/vt/vtgate/planbuilder/operators/info_schema_planning.go +++ b/go/vt/vtgate/planbuilder/operators/info_schema_planning.go @@ -42,6 +42,25 @@ type InfoSchemaRouting struct { seenPredicates []sqlparser.Expr } +func (isr *InfoSchemaRouting) extraInfo() string { + var parts []string + if len(isr.SysTableTableSchema) > 0 { + var exprs []string + for _, expr := range isr.SysTableTableSchema { + exprs = append(exprs, sqlparser.String(expr)) + } + parts = append(parts, "SysTableTableSchema:["+strings.Join(exprs, ", ")+"]") + } + if len(isr.SysTableTableName) > 0 { + var exprs []string + for k, expr := range isr.SysTableTableName { + exprs = append(exprs, k+"="+sqlparser.String(expr)) + } + parts = append(parts, "SysTableTableName:["+strings.Join(exprs, ", ")+"]") + } + return strings.Join(parts, " ") +} + func (isr *InfoSchemaRouting) UpdateRoutingParams(ctx *plancontext.PlanningContext, rp *engine.RoutingParameters) { rp.SysTableTableSchema = nil for _, expr := range isr.SysTableTableSchema { @@ -224,15 +243,12 @@ func tryMergeInfoSchemaRoutings(ctx *plancontext.PlanningContext, routingA, rout } func equalExprs(a, b []sqlparser.Expr) bool { - if len(a) != len(b) { - return false - } for i := range a { - if !sqlparser.Equals.Expr(a[i], b[i]) { - return false + if sqlparser.Equals.Expr(a[i], b[i]) { + return true } } - return true + return false } var ( From 991dea504e6feee95ad8e01e9dee072358327a1c Mon Sep 17 00:00:00 2001 From: Arthur Schreiber Date: Tue, 13 Jan 2026 14:41:06 +0000 Subject: [PATCH 6/7] Update test cases. Signed-off-by: Arthur Schreiber --- .../testdata/info_schema57_cases.json | 72 ++++++------------- .../testdata/info_schema80_cases.json | 72 ++++++------------- 2 files changed, 40 insertions(+), 104 deletions(-) diff --git a/go/vt/vtgate/planbuilder/testdata/info_schema57_cases.json b/go/vt/vtgate/planbuilder/testdata/info_schema57_cases.json index ee279c2f6c8..663df75c2d4 100644 --- a/go/vt/vtgate/planbuilder/testdata/info_schema57_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/info_schema57_cases.json @@ -791,35 +791,19 @@ "comment": "merge system schema queries as long as they have any same table_schema", "query": "select 1 as found from information_schema.`tables` where table_schema = 'music' and table_schema = 'Music' union all (select 1 as found from information_schema.views where table_schema = 'music' and table_schema = 'user' limit 1)", "plan": { - "Type": "Complex", + "Type": "Passthrough", "QueryType": "SELECT", "Original": "select 1 as found from information_schema.`tables` where table_schema = 'music' and table_schema = 'Music' union all (select 1 as found from information_schema.views where table_schema = 'music' and table_schema = 'user' limit 1)", "Instructions": { - "OperatorType": "Concatenate", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.`tables` where 1 != 1", - "Query": "select 1 as `found` from information_schema.`tables` where table_schema = :__vtschemaname /* VARCHAR */ and table_schema = :__vtschemaname /* VARCHAR */", - "SysTableTableSchema": "['music', 'Music']" - }, - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.views where 1 != 1", - "Query": "select 1 as `found` from information_schema.views where table_schema = :__vtschemaname /* VARCHAR */ and table_schema = :__vtschemaname /* VARCHAR */ limit 1", - "SysTableTableSchema": "['music', 'user']" - } - ] + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select 1 as `found` from information_schema.`tables` where 1 != 1 union all (select 1 as `found` from information_schema.views where 1 != 1)", + "Query": "select 1 as `found` from information_schema.`tables` where table_schema = :__vtschemaname /* VARCHAR */ and table_schema = :__vtschemaname /* VARCHAR */ union all (select 1 as `found` from information_schema.views where table_schema = :__vtschemaname /* VARCHAR */ and table_schema = :__vtschemaname /* VARCHAR */ limit 1)", + "SysTableTableSchema": "['music', 'Music']" } } }, @@ -827,35 +811,19 @@ "comment": "merge system schema queries as long as they have any same table_name", "query": "select 1 as found from information_schema.`tables` where table_schema = 'music' and table_schema = 'Music' union all (select 1 as found from information_schema.views where table_schema = 'music' and table_schema = 'user' limit 1)", "plan": { - "Type": "Complex", + "Type": "Passthrough", "QueryType": "SELECT", "Original": "select 1 as found from information_schema.`tables` where table_schema = 'music' and table_schema = 'Music' union all (select 1 as found from information_schema.views where table_schema = 'music' and table_schema = 'user' limit 1)", "Instructions": { - "OperatorType": "Concatenate", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.`tables` where 1 != 1", - "Query": "select 1 as `found` from information_schema.`tables` where table_schema = :__vtschemaname /* VARCHAR */ and table_schema = :__vtschemaname /* VARCHAR */", - "SysTableTableSchema": "['music', 'Music']" - }, - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.views where 1 != 1", - "Query": "select 1 as `found` from information_schema.views where table_schema = :__vtschemaname /* VARCHAR */ and table_schema = :__vtschemaname /* VARCHAR */ limit 1", - "SysTableTableSchema": "['music', 'user']" - } - ] + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select 1 as `found` from information_schema.`tables` where 1 != 1 union all (select 1 as `found` from information_schema.views where 1 != 1)", + "Query": "select 1 as `found` from information_schema.`tables` where table_schema = :__vtschemaname /* VARCHAR */ and table_schema = :__vtschemaname /* VARCHAR */ union all (select 1 as `found` from information_schema.views where table_schema = :__vtschemaname /* VARCHAR */ and table_schema = :__vtschemaname /* VARCHAR */ limit 1)", + "SysTableTableSchema": "['music', 'Music']" } } }, diff --git a/go/vt/vtgate/planbuilder/testdata/info_schema80_cases.json b/go/vt/vtgate/planbuilder/testdata/info_schema80_cases.json index 9b1ed9bc2c6..0fbca119dae 100644 --- a/go/vt/vtgate/planbuilder/testdata/info_schema80_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/info_schema80_cases.json @@ -854,35 +854,19 @@ "comment": "merge system schema queries as long as they have any same table_schema", "query": "select 1 as found from information_schema.`tables` where table_schema = 'music' and table_schema = 'Music' union all (select 1 as found from information_schema.views where table_schema = 'music' and table_schema = 'user' limit 1)", "plan": { - "Type": "Complex", + "Type": "Passthrough", "QueryType": "SELECT", "Original": "select 1 as found from information_schema.`tables` where table_schema = 'music' and table_schema = 'Music' union all (select 1 as found from information_schema.views where table_schema = 'music' and table_schema = 'user' limit 1)", "Instructions": { - "OperatorType": "Concatenate", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.`tables` where 1 != 1", - "Query": "select 1 as `found` from information_schema.`tables` where table_schema = :__vtschemaname /* VARCHAR */ and table_schema = :__vtschemaname /* VARCHAR */", - "SysTableTableSchema": "['music', 'Music']" - }, - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.views where 1 != 1", - "Query": "select 1 as `found` from information_schema.views where table_schema = :__vtschemaname /* VARCHAR */ and table_schema = :__vtschemaname /* VARCHAR */ limit 1", - "SysTableTableSchema": "['music', 'user']" - } - ] + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select 1 as `found` from information_schema.`tables` where 1 != 1 union all (select 1 as `found` from information_schema.views where 1 != 1)", + "Query": "select 1 as `found` from information_schema.`tables` where table_schema = :__vtschemaname /* VARCHAR */ and table_schema = :__vtschemaname /* VARCHAR */ union all (select 1 as `found` from information_schema.views where table_schema = :__vtschemaname /* VARCHAR */ and table_schema = :__vtschemaname /* VARCHAR */ limit 1)", + "SysTableTableSchema": "['music', 'Music']" } } }, @@ -890,35 +874,19 @@ "comment": "merge system schema queries as long as they have any same table_name", "query": "select 1 as found from information_schema.`tables` where table_schema = 'music' and table_schema = 'Music' union all (select 1 as found from information_schema.views where table_schema = 'music' and table_schema = 'user' limit 1)", "plan": { - "Type": "Complex", + "Type": "Passthrough", "QueryType": "SELECT", "Original": "select 1 as found from information_schema.`tables` where table_schema = 'music' and table_schema = 'Music' union all (select 1 as found from information_schema.views where table_schema = 'music' and table_schema = 'user' limit 1)", "Instructions": { - "OperatorType": "Concatenate", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.`tables` where 1 != 1", - "Query": "select 1 as `found` from information_schema.`tables` where table_schema = :__vtschemaname /* VARCHAR */ and table_schema = :__vtschemaname /* VARCHAR */", - "SysTableTableSchema": "['music', 'Music']" - }, - { - "OperatorType": "Route", - "Variant": "DBA", - "Keyspace": { - "Name": "main", - "Sharded": false - }, - "FieldQuery": "select 1 as `found` from information_schema.views where 1 != 1", - "Query": "select 1 as `found` from information_schema.views where table_schema = :__vtschemaname /* VARCHAR */ and table_schema = :__vtschemaname /* VARCHAR */ limit 1", - "SysTableTableSchema": "['music', 'user']" - } - ] + "OperatorType": "Route", + "Variant": "DBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select 1 as `found` from information_schema.`tables` where 1 != 1 union all (select 1 as `found` from information_schema.views where 1 != 1)", + "Query": "select 1 as `found` from information_schema.`tables` where table_schema = :__vtschemaname /* VARCHAR */ and table_schema = :__vtschemaname /* VARCHAR */ union all (select 1 as `found` from information_schema.views where table_schema = :__vtschemaname /* VARCHAR */ and table_schema = :__vtschemaname /* VARCHAR */ limit 1)", + "SysTableTableSchema": "['music', 'Music']" } } }, From 53bc759bf415c3eb9608bbc7aa3b002887ff79b1 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Wed, 14 Jan 2026 12:08:12 +0100 Subject: [PATCH 7/7] wip --- go/vt/vtgate/planbuilder/operators/info_schema_planning.go | 4 +++- go/vt/vtgate/planbuilder/operators/union_merging.go | 2 ++ go/vt/vtgate/planbuilder/testdata/onecase.json | 5 +++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/go/vt/vtgate/planbuilder/operators/info_schema_planning.go b/go/vt/vtgate/planbuilder/operators/info_schema_planning.go index ba1eb71deca..73483b70b21 100644 --- a/go/vt/vtgate/planbuilder/operators/info_schema_planning.go +++ b/go/vt/vtgate/planbuilder/operators/info_schema_planning.go @@ -100,7 +100,7 @@ func (isr *InfoSchemaRouting) Clone() Routing { func (isr *InfoSchemaRouting) updateRoutingLogic(ctx *plancontext.PlanningContext, expr sqlparser.Expr) Routing { isr.seenPredicates = append(isr.seenPredicates, expr) - isTableSchema, bvName, out := extractInfoSchemaRoutingPredicate(ctx, expr) + isTableSchema, bvName, out := extractInfoSchemaRoutingPredicate(ctx, sqlparser.CloneExpr(expr)) if out == nil { return isr } @@ -220,6 +220,7 @@ func tryMergeInfoSchemaRoutings(ctx *plancontext.PlanningContext, routingA, rout // if we have no schema predicates on either side, we can merge if the table info is the same case len(isrA.SysTableTableSchema) == 0 && len(isrB.SysTableTableSchema) == 0: + isrA.seenPredicates = append(isrA.seenPredicates, isrB.seenPredicates...) for k, expr := range isrB.SysTableTableName { if e, found := isrA.SysTableTableName[k]; found && !sqlparser.Equals.Expr(expr, e) { // schema names are the same, but we have contradicting table names, so we give up @@ -231,6 +232,7 @@ func tryMergeInfoSchemaRoutings(ctx *plancontext.PlanningContext, routingA, rout // if both sides have the same schema predicate, we can safely merge them case equalExprs(isrA.SysTableTableSchema, isrB.SysTableTableSchema): + isrA.seenPredicates = append(isrA.seenPredicates, isrB.seenPredicates...) for k, expr := range isrB.SysTableTableName { isrA.SysTableTableName[k] = expr } diff --git a/go/vt/vtgate/planbuilder/operators/union_merging.go b/go/vt/vtgate/planbuilder/operators/union_merging.go index 4562a25943d..79558d67789 100644 --- a/go/vt/vtgate/planbuilder/operators/union_merging.go +++ b/go/vt/vtgate/planbuilder/operators/union_merging.go @@ -199,6 +199,7 @@ func tryMergeUnionInfoSchemaRouting( // if we have no schema predicates on either side, we can merge if the table info is compatible case len(isrA.SysTableTableSchema) == 0 && len(isrB.SysTableTableSchema) == 0: + isrA.seenPredicates = append(isrA.seenPredicates, isrB.seenPredicates...) for k, expr := range isrB.SysTableTableName { if e, found := isrA.SysTableTableName[k]; found && !sqlparser.Equals.Expr(expr, e) { // contradicting table names, give up @@ -210,6 +211,7 @@ func tryMergeUnionInfoSchemaRouting( // if both sides have the same schema predicate, we can safely merge them case equalExprs(isrA.SysTableTableSchema, isrB.SysTableTableSchema): + isrA.seenPredicates = append(isrA.seenPredicates, isrB.seenPredicates...) for k, expr := range isrB.SysTableTableName { isrA.SysTableTableName[k] = expr } diff --git a/go/vt/vtgate/planbuilder/testdata/onecase.json b/go/vt/vtgate/planbuilder/testdata/onecase.json index 9d653b2f6e9..7aea4a82d4b 100644 --- a/go/vt/vtgate/planbuilder/testdata/onecase.json +++ b/go/vt/vtgate/planbuilder/testdata/onecase.json @@ -1,8 +1,9 @@ [ { - "comment": "Add your test case here for debugging and run go test -run=One.", - "query": "", + "comment": "systable union query in derived tables with join", + "query": "SELECT 1 FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu INNER JOIN (SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS cols WHERE cols.TABLE_SCHEMA = 'ks' AND cols.TABLE_NAME = 't1' UNION SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS cols WHERE cols.TABLE_SCHEMA = 'ks' AND cols.TABLE_NAME = 't7_xxhash') cols ON kcu.TABLE_SCHEMA = cols.TABLE_SCHEMA AND kcu.TABLE_NAME = cols.TABLE_NAME AND kcu.COLUMN_NAME = cols.COLUMN_NAME WHERE kcu.TABLE_SCHEMA = 'ks' AND kcu.TABLE_NAME = 't1'", "plan": { + } } ] \ No newline at end of file