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

Fixing Column aliases in outer join queries #15384

Merged
merged 8 commits into from
Mar 5, 2024

Conversation

GuptaManan100
Copy link
Member

Description

This PR fixes the issue specified in #15383.

As the issue describes, the problem occurred when we had column aliasing on top of an outer join query. While investigating, it was noticed that we aren't pushing the alias down for outer join queries, and eventually were also getting rid of the Projection operator altogether, causing the aliases to be lost.

The fix in this PR entails 2 things -

  1. Projection operator shouldn't be omitted if there are column aliases present that we couldn't push down.
  2. Extend SimpleProjection to also change column names rather than just reordering and truncating output.

Related Issue(s)

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 29, 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 29, 2024
@github-actions github-actions bot added this to the v20.0.0 milestone Feb 29, 2024
@GuptaManan100 GuptaManan100 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 29, 2024
Signed-off-by: Manan Gupta <[email protected]>
Copy link
Member

@harshit-gangal harshit-gangal left a comment

Choose a reason for hiding this comment

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

We should only keep the SimpleProjection when the query has column with alias otherwise we should remove this if possible.
The new changes seem to [always/most of the time] keep it.

Copy link

codecov bot commented Feb 29, 2024

Codecov Report

Attention: Patch coverage is 89.28571% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 65.44%. Comparing base (696fe0e) to head (604503e).
Report is 70 commits behind head on main.

Files Patch % Lines
go/vt/vtgate/engine/simple_projection.go 84.61% 2 Missing ⚠️
go/vt/vtgate/planbuilder/operators/projection.go 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15384      +/-   ##
==========================================
- Coverage   67.41%   65.44%   -1.98%     
==========================================
  Files        1560     1562       +2     
  Lines      192752   193937    +1185     
==========================================
- Hits       129952   126923    -3029     
- Misses      62800    67014    +4214     

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

var colName *sqlparser.ColName
var alias sqlparser.IdentifierCI
if withQualifier {
if e.needsQualifier {
Copy link
Member

Choose a reason for hiding this comment

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

👍

@frouioui frouioui assigned frouioui and unassigned frouioui Mar 4, 2024
@GuptaManan100 GuptaManan100 merged commit 0eadbe8 into vitessio:main Mar 5, 2024
102 checks passed
@GuptaManan100 GuptaManan100 deleted the left-join-alias-fix branch March 5, 2024 04:05
GrahamCampbell pushed a commit to GrahamCampbell/vitess that referenced this pull request Mar 6, 2024
Signed-off-by: Manan Gupta <[email protected]>
Signed-off-by: Florent Poinsard <[email protected]>
Co-authored-by: Florent Poinsard <[email protected]>
@chhan-coupang
Copy link

I would like to ask if this fix can be reverse-merged into v19 version?

@GrahamCampbell
Copy link
Contributor

GrahamCampbell commented Nov 13, 2024

v19 is not affected by this issue (EDIT: for the same reason).

@chhan-coupang
Copy link

chhan-coupang commented Nov 14, 2024

@GrahamCampbell Thanks for your reply!
I encountered this problem in v19.0.6-percona80, and it was tested in v20.
v19.0.6-percona80:
image
v20.0.2-percona80:
image

CREATE TABLE `item1` (
  `i_id` int NOT NULL,
  `i_im_id` int DEFAULT NULL,
  `i_name` varchar(24) DEFAULT NULL,
  `i_price` decimal(5,2) DEFAULT NULL,
  `i_data` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`i_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

select a.i_name as name1,b.i_name as name2,b.i_id as id2, c.i_name as name3 
from item1 a inner join item2 b on a.i_id = b.i_im_id 
LEFT OUTER JOIN item3 c on a.i_id = c.i_id 
where a.i_id < 10 limit 1;

@chhan-coupang
Copy link

I would like to ask if this fix can be reverse-merged into v19 version? Please help confirm.

@nonbb
Copy link

nonbb commented Dec 19, 2024

v19 is affected by this issue, I also am encountering the same for v19.0.8-mysql80 🙇 @GrahamCampbell

harshit-gangal pushed a commit to planetscale/vitess that referenced this pull request Dec 20, 2024
Signed-off-by: Manan Gupta <[email protected]>
Signed-off-by: Florent Poinsard <[email protected]>
Co-authored-by: Florent Poinsard <[email protected]>
Signed-off-by: Harshit Gangal <[email protected]>
systay pushed a commit that referenced this pull request Dec 20, 2024
…17418)

Signed-off-by: Manan Gupta <[email protected]>
Signed-off-by: Florent Poinsard <[email protected]>
Signed-off-by: Harshit Gangal <[email protected]>
Co-authored-by: Manan Gupta <[email protected]>
Co-authored-by: Florent Poinsard <[email protected]>
@mattlord
Copy link
Contributor

@GrahamCampbell, @chhan-coupang , and @nonbb this was backported to the v19 release branch here: #17418

Thanks!

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.

Bug Report: Column Aliases are not respected in some queries that have outer join clauses
7 participants