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

Faster Prepared Statement Execution by Using Raw SQL for Caching #17777

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

harshit-gangal
Copy link
Member

@harshit-gangal harshit-gangal commented Feb 13, 2025

Description

This PR changes the way Vitess handles prepared statements by modifying the plan cache lookup mechanism. Instead of normalizing and parsing the SQL string before looking up a cached execution plan, we now use the raw SQL string as provided in the PREPARE statement. This eliminates unnecessary parsing, improves lookup efficiency, and reduces overhead in query execution.

Problem Statement

Currently, when a client issues a PREPARE statement, vtgate:

  1. Parses the SQL query.
  2. Normalizes it to a canonical form.
  3. Uses the normalized query string to check for an existing cached execution plan.

What to do About it

Instead of parsing and normalizing the query before checking the plan cache, we will:
• Directly store the original SQL string from the PREPARE statement in the cache.
• Use this unmodified SQL string for cache lookups.
• Only parse the query when the plan is not found in the cache.

Related Issue(s)

Checklist

  • 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 Feb 13, 2025

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, 2025
@harshit-gangal harshit-gangal added the Skip CI Skip CI actions from running label Feb 13, 2025
@github-actions github-actions bot added this to the v22.0.0 milestone Feb 13, 2025
@harshit-gangal harshit-gangal added Component: Query Serving Type: Performance and removed Skip CI Skip CI actions from running NeedsWebsiteDocsUpdate What it says NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Feb 14, 2025
Copy link

codecov bot commented Feb 14, 2025

Codecov Report

Attention: Patch coverage is 84.30913% with 67 lines in your changes missing coverage. Please review.

Project coverage is 67.44%. Comparing base (67d081a) to head (62636f9).
Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/vtgate/executor.go 92.59% 8 Missing ⚠️
go/vt/vtgate/planbuilder/plan_test_vindex.go 0.00% 8 Missing ⚠️
go/mysql/conn.go 57.14% 6 Missing ⚠️
go/vt/vtgate/fakerpcvtgateconn/conn.go 0.00% 6 Missing ⚠️
go/vt/sqlparser/analyzer.go 37.50% 5 Missing ⚠️
go/cmd/vtgateclienttest/services/errors.go 0.00% 4 Missing ⚠️
go/vt/vtgate/executorcontext/vcursor_impl.go 83.33% 4 Missing ⚠️
go/vt/vtgate/plugin_mysql_server.go 0.00% 4 Missing ⚠️
go/cmd/vtgateclienttest/services/echo.go 0.00% 3 Missing ⚠️
go/cmd/vtgateclienttest/services/fallback.go 0.00% 2 Missing ⚠️
... and 10 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17777      +/-   ##
==========================================
+ Coverage   67.41%   67.44%   +0.02%     
==========================================
  Files        1592     1592              
  Lines      258024   258148     +124     
==========================================
+ Hits       173948   174102     +154     
+ Misses      84076    84046      -30     

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

@harshit-gangal harshit-gangal force-pushed the prepare-fastpath branch 2 times, most recently from ffdc432 to aa4830b Compare February 17, 2025 07:15
systay and others added 8 commits February 17, 2025 20:55
Signed-off-by: Andres Taylor <andres@planetscale.com>
…d in normalizer

Signed-off-by: Harshit Gangal <harshit@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: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
@systay systay changed the title [WIP] Prepare Execute fastpath Faster Prepared Statement Execution by Using Raw SQL for Caching Feb 17, 2025
@systay systay removed the NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work label Feb 17, 2025
@systay systay removed the NeedsIssue A linked issue is missing for this Pull Request label Feb 17, 2025
harshit-gangal and others added 2 commits February 18, 2025 09:45
…sion

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
systay and others added 9 commits February 18, 2025 11:17
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: Harshit Gangal <harshit@planetscale.com>
…ding the plan

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
@harshit-gangal harshit-gangal added the Benchmark me Add label to PR to run benchmarks label Feb 21, 2025
Copy link
Contributor

vitess-bot bot commented Feb 21, 2025

Hello! 👋

This Pull Request is now handled by arewefastyet. The current HEAD and future commits will be benchmarked.

You can find the performance comparison on the arewefastyet website.

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.

Prepare statement execution optimization
2 participants