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

Planner Bug: Joins inside derived table #14974

Merged
merged 14 commits into from
Feb 8, 2024

Conversation

systay
Copy link
Collaborator

@systay systay commented Jan 17, 2024

Description

In some situations, the vtgate planner was producing really bad plans around derived tables and columns.

In this PR I reworked a lot of the logic around derived tables and their columns.

Related Issue(s)

Fixes #14993

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

Copy link
Contributor

vitess-bot bot commented Jan 17, 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 Jan 17, 2024
@github-actions github-actions bot added this to the v19.0.0 milestone Jan 17, 2024
Copy link

codecov bot commented Jan 17, 2024

Codecov Report

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

Comparison is base (eddb39e) 47.29% compared to head (57aed9b) 70.60%.
Report is 114 commits behind head on main.

Files Patch % Lines
go/vt/mysqlctl/builtinbackupengine.go 12.90% 54 Missing ⚠️
go/vt/mysqlctl/backupengine.go 0.00% 20 Missing ⚠️
go/vt/mysqlctl/xtrabackupengine.go 0.00% 15 Missing ⚠️
go/vt/schemadiff/column.go 70.83% 7 Missing ⚠️
go/mysql/conn.go 53.84% 6 Missing ⚠️
go/vt/mysqlctl/backup.go 37.50% 5 Missing ⚠️
go/mysql/capabilities/capability.go 91.48% 4 Missing ⚠️
go/mysql/query.go 77.77% 4 Missing ⚠️
go/vt/mysqlctl/schema.go 72.72% 3 Missing ⚠️
go/vt/schemadiff/schema.go 92.10% 3 Missing ⚠️
... and 10 more
Additional details and impacted files
@@             Coverage Diff             @@
##             main   #14974       +/-   ##
===========================================
+ Coverage   47.29%   70.60%   +23.30%     
===========================================
  Files        1137     1379      +242     
  Lines      238684   183009    -55675     
===========================================
+ Hits       112895   129209    +16314     
+ Misses     117168    53800    -63368     
+ Partials     8621        0     -8621     

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

@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 Jan 18, 2024
@systay systay force-pushed the derived-column-exposing branch 3 times, most recently from 4df3f3a to 008098d Compare January 19, 2024 15:28
@systay systay marked this pull request as ready for review January 19, 2024 16:03
proj := createProjection(ctx, src, "")
proj.Columns = AliasedProjections(p.columns)
if dt != nil {
kopy := *dt
Copy link
Member

Choose a reason for hiding this comment

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

we do not have a proper clone function for DerivedTable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nope. I'll add one

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmm... I changed my mind. Don't think we need one. This is the only place we try to clone it, and it's not a pure cloning anyway

Copy link
Member

@frouioui frouioui left a comment

Choose a reason for hiding this comment

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

Besides that failing plan test and the comment I left, it looks good to me! That's a really good enhancement / bug fix, thank you 🙏🏻

Codecov is spanning a bunch of warnings in a lot of places in this PR, is this because of the cross-package coverage missing or is it due to actual missing plan tests?

systay and others added 9 commits February 6, 2024 07:36
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: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Co-authored-by: Florent Poinsard <35779988+frouioui@users.noreply.github.com>
Signed-off-by: Andrés Taylor <andres@taylor.se>
Signed-off-by: Andres Taylor <andres@planetscale.com>
@systay systay marked this pull request as draft February 6, 2024 10:09
@frouioui frouioui modified the milestones: v19.0.0, v20.0.0 Feb 6, 2024
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
@systay systay marked this pull request as ready for review February 7, 2024 10:09
@systay systay requested a review from frouioui February 7, 2024 10:09
Signed-off-by: Andres Taylor <andres@planetscale.com>
mcmp.Exec("INSERT INTO t1 (id1, id2) VALUES (1, 100), (2, 200), (3, 300), (4, 400), (5, 500);")
mcmp.Exec("INSERT INTO t2 (id3, id4) VALUES (10, 1), (20, 2), (30, 3), (40, 4), (50, 99)")
mcmp.Exec(`select t.a from (select t1.id2, t2.id3, (select id2 from t1 order by id2 limit 1) as a from t1 join t2 on t1.id1 = t2.id4) t`)
mcmp.Exec(`SELECT COUNT(*) FROM (SELECT DISTINCT t1.id1 FROM t1 JOIN t2 ON t1.id1 = t2.id4) dt`)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This last test will fail without the changes in this PR:

Error: Received unexpected error:
target: ks_union.-80.primary: vttablet: rpc error: code = NotFound desc = Unknown column 't2.id4' in 'field list' (errno 1054) (sqlstate 42S22) (CallerID: userData1): Sql: "select distinct t2.id4, 1, dt.`t2.id4` from (select t2.id4 as `t2.id4` from t2) as dt", BindVars: {}
target: ks_union.80-.primary: vttablet: rpc error: code = NotFound desc = Unknown column 't2.id4' in 'field list' (errno 1054) (sqlstate 42S22) (CallerID: userData1): Sql: "select distinct t2.id4, 1, dt.`t2.id4` from (select t2.id4 as `t2.id4` from t2) as dt", BindVars: {} (errno 1054) (sqlstate 42S22) during query: SELECT COUNT(*) FROM (SELECT DISTINCT t1.id1 FROM t1 JOIN t2 ON t1.id1 = t2.id4) dt

@systay systay added the Backport to: release-19.0 Needs to be back ported to release-19.0 label Feb 7, 2024
@harshit-gangal harshit-gangal merged commit 3a98b4c into vitessio:main Feb 8, 2024
103 checks passed
@harshit-gangal harshit-gangal deleted the derived-column-exposing branch February 8, 2024 11:10
vitess-bot pushed a commit that referenced this pull request Feb 8, 2024
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Andrés Taylor <andres@taylor.se>
Co-authored-by: Florent Poinsard <florent.poinsard@outlook.fr>
Co-authored-by: Florent Poinsard <35779988+frouioui@users.noreply.github.com>
systay added a commit that referenced this pull request Feb 26, 2024
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
Co-authored-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>
@harshit-gangal harshit-gangal restored the derived-column-exposing branch May 16, 2024 11:28
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.

Joins inside derived tables
3 participants