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

Fix failure when Unowned lookup IS NULL #10346

Merged
merged 2 commits into from
May 25, 2022

Conversation

systay
Copy link
Collaborator

@systay systay commented May 20, 2022

Description

We should not use the NoRoutesSpecialHandling mode for vindex lookup queries.
This PR changes when we apply this special handling mode. Before, we did it for all plans that were single routes, with this change we are more conservative and only use it in one of two situations:

  1. All select expressions are aggregations, and we have no grouping defined. These queries should not return empty result when nothing matches the WHERE clause, instead they need to return special empty values. Think select count(*) from tbl.
  2. When the query is a dual query. If we have been able to merge a dual query with a subquery, we need to run the query and return something, even if no routes can be found to match the subquery predicates. This is because the dual table always returns a single row. Example of this would be select exists(select 1 from tbl where foo = 43)

Related Issue(s)

Checklist

  • "Backport me!" label has been added if this change should be backported
  • Tests were added or are not required
  • Documentation was added or is not required

Deployment Notes

arthurschreiber and others added 2 commits May 13, 2022 14:24
This test case shows a regression in the query planner for queries that use `IS NULL` condition on an unowned lookup vindex column.

Signed-off-by: Arthur Schreiber <arthurschreiber@github.com>
Co-authored-by: Elisa Vaccaro <30807261+evaccaro@users.noreply.github.com>
Co-authored-by: Jakob Class <mikrobi@github.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
@github-actions
Copy link
Contributor

github-actions bot commented May 20, 2022

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has the correct release notes label. release notes none should only be used for PRs that are so trivial that they need not be included.
  • If a new flag is being introduced, review whether it is really needed. The flag names should be clear and intuitive (as far as possible), and the flag's help should be descriptive.

Bug fixes

  • There should be at least one unit or end-to-end test.
  • The Pull Request description should either include a link to an issue that describes the bug OR an actual description of the bug and how to reproduce, along with a description of the fix.

Non-trivial changes

  • There should be some code comments as to why things are implemented the way they are.

New/Existing features

  • Should be documented, either by modifying the existing documentation or creating new documentation.
  • New features should have a link to a feature request issue or an RFC that documents the use cases, corner cases and test cases.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • vtctl command output order should be stable and awk-able.

@frouioui frouioui changed the title Unowned lookup IS NULL fails Fix failure when Unowned lookup IS NULL May 24, 2022
@frouioui
Copy link
Member

Updating the title of this PR to facilitate the release notes generation.

utils.Exec(t, conn, "select * from t8 WHERE t9_id IS NULL")

// Cleanup
utils.Exec(t, conn, "delete from t9 WHERE parent_id = 1")
Copy link
Member

Choose a reason for hiding this comment

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

nit: we could put this in a defer in case line 88 fails. (I don't remember if utils.Exec terminate the test early if there is a failure, if not, then there is no need for a defer)

Comment on lines +1832 to +1834
if !ContainsAggregation(k) {
return false
}
Copy link
Member

Choose a reason for hiding this comment

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

this wouldn't support select exprs like count(a.id)+count(b.id) since ContainsAggregation checks for FuncExpr, is that a problem?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you're thinking of IsAggregation. ContainsAggregation checks in the whole expression tree for aggregation

@systay systay merged commit c4535fc into vitessio:main May 25, 2022
@systay systay deleted the unowned-lookup-is-null-failure branch May 25, 2022 11:47
harshit-gangal pushed a commit to planetscale/vitess that referenced this pull request Aug 16, 2022
* Add a failing test case showing Gen4 planner failure.

This test case shows a regression in the query planner for queries that use `IS NULL` condition on an unowned lookup vindex column.

Signed-off-by: Arthur Schreiber <arthurschreiber@github.com>
Co-authored-by: Elisa Vaccaro <30807261+evaccaro@users.noreply.github.com>
Co-authored-by: Jakob Class <mikrobi@github.com>

* bugfix: Limit the use of NoRoutesSpecialHandling to when it's needed

Signed-off-by: Andres Taylor <andres@planetscale.com>

Co-authored-by: Arthur Schreiber <arthurschreiber@github.com>
Co-authored-by: Elisa Vaccaro <30807261+evaccaro@users.noreply.github.com>
Co-authored-by: Jakob Class <mikrobi@github.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
deepthi added a commit that referenced this pull request Aug 16, 2022
…eeded (#11020)

* fix V3: only use the special NoRoute handling mode when needed (#10422)

Signed-off-by: Andres Taylor <andres@planetscale.com>

* fix: build

Signed-off-by: Harshit Gangal <harshit@planetscale.com>

* Fix failure when Unowned lookup IS NULL (#10346)

* Add a failing test case showing Gen4 planner failure.

This test case shows a regression in the query planner for queries that use `IS NULL` condition on an unowned lookup vindex column.

Signed-off-by: Arthur Schreiber <arthurschreiber@github.com>
Co-authored-by: Elisa Vaccaro <30807261+evaccaro@users.noreply.github.com>
Co-authored-by: Jakob Class <mikrobi@github.com>

* bugfix: Limit the use of NoRoutesSpecialHandling to when it's needed

Signed-off-by: Andres Taylor <andres@planetscale.com>

Co-authored-by: Arthur Schreiber <arthurschreiber@github.com>
Co-authored-by: Elisa Vaccaro <30807261+evaccaro@users.noreply.github.com>
Co-authored-by: Jakob Class <mikrobi@github.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>

Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: deepthi <deepthi@planetscale.com>
Co-authored-by: Andres Taylor <andres@planetscale.com>
Co-authored-by: Arthur Schreiber <arthurschreiber@github.com>
Co-authored-by: Elisa Vaccaro <30807261+evaccaro@users.noreply.github.com>
Co-authored-by: Jakob Class <mikrobi@github.com>
Co-authored-by: deepthi <deepthi@planetscale.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants