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

Add a special plan type for impossible queries #4510

Merged
merged 1 commit into from
Jan 26, 2019

Conversation

eeSeeGee
Copy link
Contributor

@eeSeeGee eeSeeGee commented Jan 9, 2019

This fixes an annoying case where a missed lookup will spam a single shard with the same impossible query over and over, because the gate doesn't cache columns.

Signed-off-by: Aaron Young young@squareup.com

@eeSeeGee eeSeeGee requested a review from sougou as a code owner January 9, 2019 17:18
@@ -106,6 +106,17 @@ func (qre *QueryExecutor) Execute() (reply *sqltypes.Result, err error) {
return qre.execDDL()
case planbuilder.PlanNextval:
return qre.execNextval()
case planbuilder.PlanSelectImpossible:
if qre.plan.Fields != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible for Fields to be nil for cases where there are bind vars in the select expressions. Code path is here: https://github.com/vitessio/vitess/blob/master/go/vt/vttablet/tabletserver/planbuilder/query_gen.go#L36. In that case we should still send the impossible query to mysql and return those results.

Strangely, I only see an endtoend test for this here: https://github.com/vitessio/vitess/blob/master/go/vt/vttablet/endtoend/queries_test.go#L454. There should ideally be a unit test for this in query_executor_test.go.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I thought I handled that by treating PlanSelectImpossible as a normal select downstream, but will look into this.

// IsImpossible returns true if the comparison in the expression can never evaluate to true.
// Note that this is not currently exhaustive to ALL impossible comparisons.
func (node *ComparisonExpr) IsImpossible() bool {
return node.Operator == NotEqualStr && reflect.DeepEqual(node.Left, node.Right)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've had a policy that DeepEqual shouldn't be used in the query serving path. This is because its cost is unpredictable. However, I'll be open to arguments about why it makes sense in this particular case. Let me know what you think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just trying to be a good oss citizen by adding support for any impossible query users might throw out, in this case I can just unroll the check to something more robust.

@@ -1242,6 +1242,31 @@ func TestQueryExecutorPlanPassSelect(t *testing.T) {
}
}

func TestQueryExecutorPlanSelectImpossible(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, we'll need a test for the select :bv from t where 1 != 1 case.

@eeSeeGee eeSeeGee force-pushed the young.20190209.impossible_plan branch 2 times, most recently from af27948 to 9c8a4b7 Compare January 24, 2019 20:59
Name: "all columns",
Query: "select * from vitess_a where 1 != 1",
Rewritten: []string{
"select * from vitess_a where 1 != 1",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backing out the fix in this PR makes another query show up here, which is nice to see.

@sougou
Copy link
Contributor

sougou commented Jan 25, 2019

The tests don't look happy.

@eeSeeGee
Copy link
Contributor Author

The tests don't look happy.

Hm, not sure what's going on there.

Signed-off-by: Aaron Young <young@squareup.com>
@eeSeeGee eeSeeGee force-pushed the young.20190209.impossible_plan branch from 9c8a4b7 to 023f62e Compare January 25, 2019 04:50
@sougou sougou merged commit 869543a into vitessio:master Jan 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants