Skip to content

Commit

Permalink
Merge pull request #7409 from planetscale/gen4-fail
Browse files Browse the repository at this point in the history
gen4: fail unsupported queries
  • Loading branch information
harshit-gangal committed Mar 2, 2021
2 parents d2f939e + e4af5e5 commit d35cfc8
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 486 deletions.
5 changes: 3 additions & 2 deletions go/vt/vtgate/planbuilder/plan_test.go
Expand Up @@ -433,8 +433,9 @@ func testFile(t *testing.T, filename, tempDir string, vschema *vschemaWrapper, c
// this is shown by not having any info at all after the result for the V3 planner
// with this last expectation, it is an error if the V4 planner
// produces the same plan as the V3 planner does
testName := fmt.Sprintf("%d V4: %s", tcase.lineno, tcase.comments)
if !empty || checkAllTests {
t.Run(fmt.Sprintf("%d V4: %s", tcase.lineno, tcase.comments), func(t *testing.T) {
t.Run(testName, func(t *testing.T) {
if out != tcase.output2ndPlanner {
fail = true
t.Errorf("V4 - %s:%d\nDiff:\n%s\n[%s] \n[%s]", filename, tcase.lineno, cmp.Diff(tcase.output2ndPlanner, out), tcase.output, out)
Expand All @@ -452,7 +453,7 @@ func testFile(t *testing.T, filename, tempDir string, vschema *vschemaWrapper, c
})
} else {
if out == tcase.output && checkV4equalPlan {
t.Run("V4: "+tcase.comments, func(t *testing.T) {
t.Run(testName, func(t *testing.T) {
t.Errorf("V4 - %s:%d\nplanner produces same output as V3", filename, tcase.lineno)
})
}
Expand Down
19 changes: 16 additions & 3 deletions go/vt/vtgate/planbuilder/route_planning.go
Expand Up @@ -114,24 +114,32 @@ func planLimit(limit *sqlparser.Limit, plan logicalPlan) (logicalPlan, error) {

func planProjections(sel *sqlparser.Select, plan logicalPlan, semTable *semantics.SemTable) error {
rb, ok := plan.(*route)
if ok {
if ok && rb.isSingleShard() {
ast := rb.Select.(*sqlparser.Select)
ast.Distinct = sel.Distinct
ast.GroupBy = sel.GroupBy
ast.OrderBy = sel.OrderBy
ast.SelectExprs = sel.SelectExprs
ast.Comments = sel.Comments
} else {

// TODO real horizon planning to be done
if sel.Distinct {
return semantics.Gen4NotSupportedF("DISTINCT")
}
if sel.GroupBy != nil {
return semantics.Gen4NotSupportedF("GROUP BY")
}
for _, expr := range sel.SelectExprs {
switch e := expr.(type) {
case *sqlparser.AliasedExpr:
if nodeHasAggregates(e.Expr) {
return semantics.Gen4NotSupportedF("aggregation [%s]", sqlparser.String(e))
}
if _, err := pushProjection(e, plan, semTable); err != nil {
return err
}
default:
return vterrors.Errorf(vtrpcpb.Code_UNIMPLEMENTED, "not yet supported %T", e)
return semantics.Gen4NotSupportedF("%T", e)
}
}

Expand Down Expand Up @@ -312,6 +320,8 @@ func (rp *routePlan) searchForNewVindexes(predicates []sqlparser.Expr) (bool, er
}
}
}
default:
return false, semantics.Gen4NotSupportedF("%s", sqlparser.String(filter))
}
}
}
Expand Down Expand Up @@ -623,6 +633,9 @@ func createRoutePlan(table *queryTable, solves semantics.TableSet, vschema Conte
if err != nil {
return nil, err
}
if vschemaTable.Name.String() != table.table.Name.String() {
return nil, semantics.Gen4NotSupportedF("routed tables")
}
plan := &routePlan{
solved: solves,
_tables: []*routeTable{{
Expand Down
9 changes: 0 additions & 9 deletions go/vt/vtgate/planbuilder/testdata/aggr_cases.txt
Expand Up @@ -78,7 +78,6 @@ Gen4 plan same as above
"Table": "`user`"
}
}
Gen4 plan same as above

# distinct and group by together for single route.
"select distinct col1, id from user group by col1"
Expand All @@ -97,7 +96,6 @@ Gen4 plan same as above
"Table": "`user`"
}
}
Gen4 plan same as above

# scatter group by a text column
"select count(*), a, textcol1, b from user group by a, textcol1, b"
Expand Down Expand Up @@ -347,7 +345,6 @@ Gen4 plan same as above
"Table": "`user`"
}
}
Gen4 plan same as above

# group by a unique vindex and other column should use a simple route
"select id, col, count(*) from user group by id, col"
Expand All @@ -366,7 +363,6 @@ Gen4 plan same as above
"Table": "`user`"
}
}
Gen4 plan same as above

# group by a non-vindex column should use an OrderdAggregate primitive
"select col, count(*) from user group by col"
Expand Down Expand Up @@ -445,7 +441,6 @@ Gen4 plan same as above
"Table": "`user`"
}
}
Gen4 plan same as above

# group by a unique vindex where alias from select list is used
"select id as val, 1+count(*) from user group by val"
Expand All @@ -464,7 +459,6 @@ Gen4 plan same as above
"Table": "`user`"
}
}
Gen4 plan same as above

# group by a unique vindex where expression is qualified (alias should be ignored)
"select val as id, 1+count(*) from user group by user.id"
Expand All @@ -483,7 +477,6 @@ Gen4 plan same as above
"Table": "`user`"
}
}
Gen4 plan same as above

# group by a unique vindex where it should skip non-aliased expressions.
"select *, id, 1+count(*) from user group by id"
Expand All @@ -502,7 +495,6 @@ Gen4 plan same as above
"Table": "`user`"
}
}
Gen4 plan same as above

# group by a unique vindex should revert to simple route, and having clause should find the correct symbols.
"select id, count(*) c from user group by id having id=1 and c=10"
Expand Down Expand Up @@ -657,7 +649,6 @@ Gen4 plan same as above
"Table": "`user`"
}
}
Gen4 plan same as above

# count with distinct unique vindex
"select col, count(distinct id) from user group by col"
Expand Down

0 comments on commit d35cfc8

Please sign in to comment.