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

Avoid rewriting unsharded queries and split semantic analysis in two #15217

Merged
merged 12 commits into from
Feb 14, 2024

Conversation

frouioui
Copy link
Member

@frouioui frouioui commented Feb 13, 2024

Description

In a recent PR, we introduced a column alias expansion that has lead to a few users running into issues.
The idea with the column expansion was to make everything cleaner and simpler for the planner. In the cases where the planner was not involved (queries to a single unsharded keyspace), this however lead to problems.

With this PR, we change the semantic analysis and the early rewriter so that we do minimal work on the query when we don't need it.

In the early phase of the analyzer, we go over tables in FROM clauses, and see if any of them needs additional planning. If after this step we know that we don't need to plan the query, we are done and finish early, bypassing a lot of steps that are not necessary.

Related Issue(s)

PR that introduced the bug: #14935

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Deployment Notes

Copy link
Contributor

vitess-bot bot commented Feb 13, 2024

Review Checklist

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

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Feb 13, 2024
@github-actions github-actions bot added this to the v20.0.0 milestone Feb 13, 2024
Signed-off-by: Andres Taylor <andres@planetscale.com>
@systay systay force-pushed the split-sem-analysis branch from c7c7536 to b51d049 Compare February 14, 2024 06:32
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
@systay systay added Type: Bug Component: Query Serving and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Feb 14, 2024
@systay systay marked this pull request as ready for review February 14, 2024 11:07
@GrahamCampbell
Copy link
Contributor

Do we need to backport this to 18 and 19?

@systay systay added the Backport to: release-19.0 Needs to be back ported to release-19.0 label Feb 14, 2024
@harshit-gangal
Copy link
Member

unit test are failing

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

codecov bot commented Feb 14, 2024

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (a0ce8bc) 67.43% compared to head (f44bfce) 67.44%.
Report is 1 commits behind head on main.

Files Patch % Lines
go/vt/vtgate/semantics/analyzer.go 96.00% 3 Missing ⚠️
go/vt/vtgate/planbuilder/operators/hash_join.go 0.00% 1 Missing ⚠️
go/vt/vtgate/semantics/semantic_state.go 75.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #15217    +/-   ##
========================================
  Coverage   67.43%   67.44%            
========================================
  Files        1560     1560            
  Lines      192789   192899   +110     
========================================
+ Hits       130014   130099    +85     
- Misses      62775    62800    +25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@systay systay force-pushed the split-sem-analysis branch from 7434e1f to f44bfce Compare February 14, 2024 13:51
@frouioui frouioui merged commit c4d2a5a into vitessio:main Feb 14, 2024
201 checks passed
@frouioui frouioui deleted the split-sem-analysis branch February 14, 2024 14:45
frouioui added a commit that referenced this pull request Feb 14, 2024
…15217)

Signed-off-by: Andres Taylor <andres@planetscale.com>
Co-authored-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
@harshit-gangal
Copy link
Member

There is still an issue with the routing

{
        "from_table": "ps.route2",
        "to_tables": [
          "main.unsharded"
        ]
      },
{
          "QueryType": "SELECT",
          "Original": "select * from ps.route2 where id > 2",
          "Instructions": {
            "OperatorType": "Route",
            "Variant": "Unsharded",
            "Keyspace": {
              "Name": "ps",
              "Sharded": false
            },
            "FieldQuery": "select * from unsharded as route2 where 1 != 1",
            "Query": "select * from unsharded as route2 where id > 2",
            "Table": "unsharded"
          },
          "TablesUsed": [
            "ps.unsharded"
          ]
        }

This is being sent to the wrong keyspace

@systay
Copy link
Collaborator

systay commented Feb 14, 2024

There is still an issue with the routing
...
This is being sent to the wrong keyspace

This hasn't changed with this PR. The same thing happens on main

systay pushed a commit that referenced this pull request Feb 14, 2024
…15217)

Signed-off-by: Andres Taylor <andres@planetscale.com>
dbussink pushed a commit that referenced this pull request Feb 15, 2024
…nalysis in two (#15217) (#15230)

Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Co-authored-by: Florent Poinsard <35779988+frouioui@users.noreply.github.com>
Co-authored-by: Andres Taylor <andres@planetscale.com>
dbussink pushed a commit that referenced this pull request Feb 15, 2024
…nalysis in two (#15217) (#15229)

Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Florent Poinsard <35779988+frouioui@users.noreply.github.com>
Co-authored-by: Florent Poinsard <35779988+frouioui@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants