Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gen4: filter on derived union system table with star projection #9263

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions go/vt/vtgate/planbuilder/abstract/concatenate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
harshit-gangal marked this conversation as resolved.
Show resolved Hide resolved
err := source.PushPredicate(expr, semTable)
if err != nil {
return err
}
}
return nil
}

// UnsolvedPredicates implements the Operator interface
Expand Down
21 changes: 21 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/systemtables_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
5 changes: 5 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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