From a9bd95d830a5c652fe06150e164f59e703ecca60 Mon Sep 17 00:00:00 2001 From: Harshit Gangal Date: Thu, 18 Nov 2021 19:49:33 +0530 Subject: [PATCH 1/2] feat: support pushpredicate in concatenate operator for starExpr projection case only Signed-off-by: Harshit Gangal --- go/vt/vtgate/planbuilder/abstract/concatenate.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/go/vt/vtgate/planbuilder/abstract/concatenate.go b/go/vt/vtgate/planbuilder/abstract/concatenate.go index f522c4f4b0f..205fa575368 100644 --- a/go/vt/vtgate/planbuilder/abstract/concatenate.go +++ b/go/vt/vtgate/planbuilder/abstract/concatenate.go @@ -44,8 +44,20 @@ func (c *Concatenate) TableID() semantics.TableSet { } // PushPredicate implements the Operator interface -func (c *Concatenate) PushPredicate(sqlparser.Expr, *semantics.SemTable) error { - return vterrors.Errorf(vtrpcpb.Code_UNIMPLEMENTED, "can't push predicates on concatenate") +func (c *Concatenate) PushPredicate(expr sqlparser.Expr, semTable *semantics.SemTable) error { + for index, source := range c.Sources { + if len(c.SelectStmts[index].SelectExprs) != 1 { + return vterrors.Errorf(vtrpcpb.Code_UNIMPLEMENTED, "can't push predicates on concatenate") + } + if _, isStarExpr := c.SelectStmts[index].SelectExprs[0].(*sqlparser.StarExpr); !isStarExpr { + return vterrors.Errorf(vtrpcpb.Code_UNIMPLEMENTED, "can't push predicates on concatenate") + } + err := source.PushPredicate(expr, semTable) + if err != nil { + return err + } + } + return nil } // UnsolvedPredicates implements the Operator interface From d64f72774d3cb1d7352282eac93a8ecfc8d778fe Mon Sep 17 00:00:00 2001 From: Harshit Gangal Date: Thu, 18 Nov 2021 19:54:13 +0530 Subject: [PATCH 2/2] test: added planner test for select on derived union case on system table with filter Signed-off-by: Harshit Gangal --- .../testdata/systemtables_cases.txt | 21 +++++++++++++++++++ .../testdata/unsupported_cases.txt | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/go/vt/vtgate/planbuilder/testdata/systemtables_cases.txt b/go/vt/vtgate/planbuilder/testdata/systemtables_cases.txt index ca5fbb12c1e..7d26c02dd27 100644 --- a/go/vt/vtgate/planbuilder/testdata/systemtables_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/systemtables_cases.txt @@ -1425,3 +1425,24 @@ Gen4 plan same as above "Table": "information_schema.random" } } + +# systable union query in derived table with constraint on outside (star projection) +"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'" +"symbol constraint_name not found in table or subquery" +{ + "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": "Route", + "Variant": "SelectDBA", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "FieldQuery": "select * from (select * from information_schema.key_column_usage as kcu where 1 != 1 union select * from information_schema.key_column_usage as kcu where 1 != 1) as kcu where 1 != 1", + "Query": "select * from (select * from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname and kcu.table_name = :kcu_table_name and constraint_name = 'primary' union select * from information_schema.key_column_usage as kcu where kcu.table_schema = :__vtschemaname and kcu.table_name = :kcu_table_name1 and constraint_name = 'primary') as kcu", + "SysTableTableName": "[kcu_table_name1:VARBINARY(\"music\"), kcu_table_name:VARBINARY(\"user_extra\")]", + "SysTableTableSchema": "[VARBINARY(\"user\"), VARBINARY(\"user\")]", + "Table": "information_schema.key_column_usage" + } +} diff --git a/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt b/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt index f9755132a62..9caafc33da1 100644 --- a/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt @@ -642,3 +642,8 @@ Gen4 error: unsupported: in scatter query: complex order by expression: a + 1 "select sum(col) from (select col from user union all select col from unsharded) t" "unsupported: cross-shard query with aggregates" Gen4 error: unsupported: aggregation on unions + +# systable union query in derived table with constraint on outside (without star projection) +"select id from (select id from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'user_extra' union select id from `information_schema`.`key_column_usage` `kcu` where `kcu`.`table_schema` = 'user' and `kcu`.`table_name` = 'music') `kcu` where `id` = 'primary'" +"unsupported: filtering on results of cross-shard subquery" +Gen4 error: can't push predicates on concatenate