-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: use query cache for prepare #33575
Conversation
efed39a
to
fd834a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 9 of 9 files at r1, 3 of 3 files at r2, 8 of 8 files at r3.
Reviewable status: complete! 1 of 0 LGTMs obtained
pkg/sql/plan_opt_test.go, line 146 at r3 (raw file):
r.CheckQueryResults( t, fmt.Sprintf("EXECUTE a%d (10, 100)", i),
Should this still work with other params? If so, maybe add a couple of different params...
pkg/sql/sqlbase/prepared_statement.go, line 1 at r2 (raw file):
// Copyright 2016 The Cockroach Authors.
2016 -> 2019!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 1 of 0 LGTMs obtained
pkg/sql/plan_opt_test.go, line 146 at r3 (raw file):
Previously, rytaft wrote…
Should this still work with other params? If so, maybe add a couple of different params...
You mean with other values for the arguments (the 10, 100)?
pkg/sql/plan_opt_test.go, line 146 at r3 (raw file): Previously, RaduBerinde wrote…
Yea -- sorry, that wasn't clear |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 2 of 0 LGTMs obtained
pkg/sql/conn_executor_prepare.go, line 225 at r3 (raw file):
} // PREPARE has a limited subset of statements it can be run with. Postgres
I know this is not related to this PR, but we now support CREATE TABLE. How will a DDL statement like that interact with the PREPARE logic?
pkg/sql/plan_opt.go, line 43 at r3 (raw file):
func (p *planner) prepareUsingOptimizer( ctx context.Context, stmt Statement, ) (_ planFlags, isCorrelated bool, _ error) {
Should isCorrelated
be part of the plan flags?
pkg/sql/plan_opt.go, line 54 at r3 (raw file):
cachedData, ok := p.execCfg.QueryCache.Find(stmt.SQL) if ok && cachedData.PrepareMetadata != nil { pm := cachedData.PrepareMetadata
Should be &cachedData.PrepareMetadata
, because it's a huge struct.
pkg/sql/prepared_stmt.go, line 37 at r3 (raw file):
// information. Str string // AnonymizedStr is the anonymized statement string suitable for recording
Nice to see this particular mess cleaned up.
pkg/sql/sqlbase/prepared_statement.go, line 35 at r3 (raw file):
Statement tree.Statement tree.PlaceholderTypesInfo
NIT: Would be nice to have comments on these other fields.
fd834a3
to
7b0bb39
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 2 of 0 LGTMs obtained
pkg/sql/conn_executor_prepare.go, line 225 at r3 (raw file):
Previously, andy-kimball (Andy Kimball) wrote…
I know this is not related to this PR, but we now support CREATE TABLE. How will a DDL statement like that interact with the PREPARE logic?
Good question. I can't think of a problem OTOH, but regardless I think we should limit the preparable statements to what postgres supports. I'll follow up on this.
pkg/sql/plan_opt.go, line 43 at r3 (raw file):
Previously, andy-kimball (Andy Kimball) wrote…
Should
isCorrelated
be part of the plan flags?
It's a little different in that it's set in an error path (in fact it only matters when there's an error). I don't like it either, I wish there was a way to associate this info with the error.
pkg/sql/plan_opt.go, line 54 at r3 (raw file):
Previously, andy-kimball (Andy Kimball) wrote…
Should be
&cachedData.PrepareMetadata
, because it's a huge struct.
It's already a pointer.
pkg/sql/plan_opt_test.go, line 146 at r3 (raw file):
Previously, rytaft wrote…
Yea -- sorry, that wasn't clear
Added.
pkg/sql/sqlbase/prepared_statement.go, line 1 at r2 (raw file):
Previously, rytaft wrote…
2016 -> 2019!
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 8 of 8 files at r5.
Reviewable status: complete! 0 of 0 LGTMs obtained (and 2 stale)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (and 2 stale)
pkg/sql/plan_opt.go, line 54 at r3 (raw file):
Previously, RaduBerinde wrote…
It's already a pointer.
Ah, I was thinking this was from the PreparedStatement
.
Separating the metadata for prepared statements in a sqlbase struct, which will also be used by the plan cache. Release note: None
This change enables the use of the query cache for Prepare. The cache optionally stores a `*PrepareMetadata` for each query which can later be reused. Release note: None
7b0bb39
to
e007bc6
Compare
bors r+ |
33575: sql: use query cache for prepare r=RaduBerinde a=RaduBerinde Note: the "refactor usage of placeholder TypeHints" commit is from a separate PR, ignore that one. #### sql: separate prepared statement metadata Separating the metadata for prepared statements in a sqlbase struct, which will also be used by the plan cache. Release note: None #### sql: use query cache for prepare This change enables the use of the query cache for Prepare. The cache optionally stores a `*PrepareMetadata` for each query which can later be reused. Release note: None Co-authored-by: Radu Berinde <radu@cockroachlabs.com>
Build succeeded |
Fixes #4334. Summary of changes: - Update 'Query plan cache' section of the CBO page as follows: - Query cache is now enabled by default - BUGFIX: Updated example to use `SET CLUSTER SETTING`, was using `SET` - Removed the following limitations since (if I'm reading PRs correctly) they no longer exist: - Invalidate cached plans when stats change (cockroachdb/cockroach#34057) - Query cache works for prepared stmts (cockroachdb/cockroach#33575)
Fixes #4334. Summary of changes: - Update 'Query plan cache' section of the CBO page as follows: - Query cache is now enabled by default - BUGFIX: Updated example to use `SET CLUSTER SETTING`, was using `SET` - Removed the following limitations since (if I'm reading PRs correctly) they no longer exist: - Invalidate cached plans when stats change (cockroachdb/cockroach#34057) - Query cache works for prepared stmts (cockroachdb/cockroach#33575)
Note: the "refactor usage of placeholder TypeHints" commit is from a separate PR, ignore that one.
sql: separate prepared statement metadata
Separating the metadata for prepared statements in a sqlbase struct,
which will also be used by the plan cache.
Release note: None
sql: use query cache for prepare
This change enables the use of the query cache for Prepare. The cache
optionally stores a
*PrepareMetadata
for each query which can laterbe reused.
Release note: None