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

sql: turn on query cache #34454

Merged
merged 3 commits into from
Feb 5, 2019
Merged

sql: turn on query cache #34454

merged 3 commits into from
Feb 5, 2019

Conversation

RaduBerinde
Copy link
Member

Release note (performance improvement): A query plan cache saves a
portion of the planning time for frequent queries.

Some benchmarks with KV: https://docs.google.com/spreadsheets/d/1n818OsKTWsatbpXo5ddOJ53mL4hY-JhNJEuIlytilLc/edit#gid=0

While there is some improvement, the implicit prepare case is still nowhere close to prepare-once; I plan to benchmark and do more work on the prepare path. I think it's a good idea to enable the cache now though, so we get more time to weed out any problems.

@RaduBerinde RaduBerinde requested review from andy-kimball and a team January 31, 2019 18:23
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@andy-kimball andy-kimball left a comment

Choose a reason for hiding this comment

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

:lgtm: It does seem like there may be some kind of issue preventing us from getting close to prepare-once. I agree that we should enable for the alpha and then try to figure out what's going on.

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @andy-kimball, @justinj, and @rytaft)

@RaduBerinde
Copy link
Member Author

bors r+

@craig
Copy link
Contributor

craig bot commented Feb 3, 2019

Build failed

@RaduBerinde
Copy link
Member Author

bors r+

@andy-kimball
Copy link
Contributor

I fixed a race condition in the query cache code. The PreparedMetadata was being put into the cache, but then the InferredTypes field was being set after that by execPrepare.

@RaduBerinde, I put a TODO in the code for you to see if there's a better fix. For now, I made a copy of the PreparedMetadata struct so that it's not shared. Perhaps embedding PreparedMetadata in CachedData instead? Or changing around logic so that we don't need to set InferredTypes afterwards?

@andy-kimball
Copy link
Contributor

bors r-

@craig
Copy link
Contributor

craig bot commented Feb 5, 2019

Canceled

@andy-kimball
Copy link
Contributor

bors r+

@craig
Copy link
Contributor

craig bot commented Feb 5, 2019

Merge conflict (retrying...)

@craig
Copy link
Contributor

craig bot commented Feb 5, 2019

Build failed

RaduBerinde and others added 2 commits February 4, 2019 19:31
Release note (performance improvement): A query plan cache saves a
portion of the planning time for frequent queries.
The PreparedMetadata was being put into the cache, but then the
InferredTypes field was being set after that by execPrepare. The fix
is to make a copy of PreparedMetadata before entering it into the cache.

Release note: None
@andy-kimball
Copy link
Contributor

bors r+

craig bot pushed a commit that referenced this pull request Feb 5, 2019
34454: sql: turn on query cache r=andy-kimball a=RaduBerinde

Release note (performance improvement): A query plan cache saves a
portion of the planning time for frequent queries.

Some benchmarks with KV: https://docs.google.com/spreadsheets/d/1n818OsKTWsatbpXo5ddOJ53mL4hY-JhNJEuIlytilLc/edit#gid=0

While there is some improvement, the implicit prepare case is still nowhere close to prepare-once; I plan to benchmark and do more work on the prepare path. I think it's a good idea to enable the cache now though, so we get more time to weed out any problems. 

Co-authored-by: Radu Berinde <radu@cockroachlabs.com>
Co-authored-by: Andrew Kimball <andyk@cockroachlabs.com>
@craig
Copy link
Contributor

craig bot commented Feb 5, 2019

Build failed

@RaduBerinde
Copy link
Member Author

Thanks, LGTM! I will look at moving that InferredTypes code earlier, before we add to the cache (or otherwise remove it from PrepareMetadata).

@RaduBerinde
Copy link
Member Author

Last run was a flake in TestDockerCLI, trying again.

bors r+

@craig
Copy link
Contributor

craig bot commented Feb 5, 2019

Build failed

@RaduBerinde
Copy link
Member Author

Ah.. looks like we have to invalidate a cached memo if SafeUpdates changes. I guess I didn't run into that because updates were not planned with opt (I assume they are now?)

@RaduBerinde
Copy link
Member Author

RaduBerinde commented Feb 5, 2019

Alternatively we could move that check to execution - seems like that's where it belongs conceptually.
Edit: that won't work - I don't think we can tell the difference between no WHERE and WHERE false after planning.

Do not use cached memo if the SafeUpdates setting does not match.

Release note: None
@RaduBerinde RaduBerinde requested a review from a team as a code owner February 5, 2019 13:04
@andy-kimball
Copy link
Contributor

I added a check for it.

@andy-kimball
Copy link
Contributor

bors r+

craig bot pushed a commit that referenced this pull request Feb 5, 2019
34454: sql: turn on query cache r=andy-kimball a=RaduBerinde

Release note (performance improvement): A query plan cache saves a
portion of the planning time for frequent queries.

Some benchmarks with KV: https://docs.google.com/spreadsheets/d/1n818OsKTWsatbpXo5ddOJ53mL4hY-JhNJEuIlytilLc/edit#gid=0

While there is some improvement, the implicit prepare case is still nowhere close to prepare-once; I plan to benchmark and do more work on the prepare path. I think it's a good idea to enable the cache now though, so we get more time to weed out any problems. 

Co-authored-by: Radu Berinde <radu@cockroachlabs.com>
Co-authored-by: Andrew Kimball <andyk@cockroachlabs.com>
@craig
Copy link
Contributor

craig bot commented Feb 5, 2019

Build succeeded

@craig craig bot merged commit 8470045 into cockroachdb:master Feb 5, 2019
@RaduBerinde
Copy link
Member Author

Thank you, looks great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants