-
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: SHOW QUERIES lazily interpolates placeholders #86968
Conversation
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.
nice improvements! both changes need tests
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @jordanlewis and @rafiss)
pkg/sql/conn_executor.go
line 3163 at r1 (raw file):
placeholders := make([]string, nPlaceholders) for i := range placeholders { placeholders[i] = query.placeholders.Values[i].String()
nit: maybe use tree.AsStringWithFlags(..., tree.FmtPgwireText)
here
pkg/sql/crdb_internal.go
line 1894 at r1 (raw file):
return err } arr := tree.NewDArray(types.String)
nit: name it placeholders
instead of arr
pkg/sql/crdb_internal.go
line 1897 at r1 (raw file):
arr.Array = make(tree.Datums, len(query.Placeholders)) for i, v := range query.Placeholders { arr.Array[i] = tree.NewDString(v)
does this need to use (*Darray).Append
?
af99535
to
ce18c4b
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.
the first commit needs new tests, and fixes to existing ones
Yes, sorry, it's not ready for review yet. |
ce18c4b
to
7e2a309
Compare
I reworked this to lazily interpolate the output of crdb_internal.cluster_statements etc as well as SHOW QUERIES, to avoid changing the API. If we want to change the API we can do it later. Now, we still gain the performance enhancements because we avoid having to unconditionally interpolate during the hot path - instead, we interpolate just when printing the active queries on the other end. |
7e2a309
to
477d515
Compare
477d515
to
b769e27
Compare
1bded82
to
ea5ac32
Compare
092c3af
to
87cad44
Compare
PTAL @rafiss |
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.
this lgtm! just had one optional comment about testing.
does the first commit mean that we will get comments in telemetry logging?
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @jordanlewis)
pkg/sql/show_test.go
line 735 at r11 (raw file):
}, { "SELECT /* test */ 'hi'::string",
what if there are two comments?
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 (waiting on @jordanlewis)
-- commits
line 28 at r11:
this release note is old
This commit adds a new array to the return value from the parser, which contains the comments that were in the parsed SQL statement. Release note: None
SHOW QUERIES (and crdb_internal.node_queries, cluster_queries) interpolates placeholder values into the statement so that it is possible to see the placeholder values of a prepared statement - but it used to do this unconditionally during statement execution. This is an expensive process that spends a lot of CPU for little reason, since the interpolation was happening in the hot path of every query. Now, we include the placeholder values as a separate array in the internal representation of active queries, and interpolate the values only when they're being pulled out to examine, to avoid the unconditional runtime interpolation costs. As a side effect of this change, the original comments in a query are now included in SHOW QUERIES and the two active queries tables. Release note (sql change): the query field in the crdb_internal.node_queries, crdb_internal.cluster_queries, and SHOW QUERIES commands now includes the original comments in the queries.
87cad44
to
f23aba7
Compare
Yes, I believe so. |
Previously, the parser (actually the scanner) removed comments that came at the end of a statement from the raw sql that was returned along with the parsed AST. This behavior is now removed. Release note: None
f23aba7
to
1de5495
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! 0 of 0 LGTMs obtained (waiting on @rafiss)
Previously, rafiss (Rafi Shamim) wrote…
this release note is old
Done.
pkg/sql/crdb_internal.go
line 1897 at r1 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
does this need to use
(*Darray).Append
?
Done.
pkg/sql/show_test.go
line 735 at r11 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
what if there are two comments?
Done.
@rafiss PTAL |
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.
lgtm! rebase to fix the TestComposeGSSPython failure
Reviewable status: complete! 0 of 0 LGTMs obtained
TFTR! I will just bors it I think that should get past the flake right? bors r+ |
Build failed: |
Unrelated flake bors r+ |
Build succeeded: |
In cockroachdb#86968 the scanner gained the ability to retain comments in scanned SQL strings, and this was an always-on feature. However, the comments are only used when populating the crdb_internal.cluster_queries table, see `sql.formatActiveQuery`. Now, comments are only retained when the parser is used from this function, reducing allocations for all other cases. Fixes cockroachdb#127713 Release note: None
In cockroachdb#86968 the scanner gained the ability to retain comments in scanned SQL strings, and this was an always-on feature. However, the comments are only used when populating the crdb_internal.cluster_queries table, see `sql.formatActiveQuery`. Now, comments are only retained when the parser is used from this function, reducing allocations for all other cases. Fixes cockroachdb#127713 Release note: None
128032: Reapply "bootstrap: create an explicit zoneconfig for timeseries data" r=rafiss a=rafiss This partially reverts commit f9d47ce. This time, rather than copying over the full zone config for the default range to the timeseries range, we only copy over gc.ttlseconds. This means that other attributes, most notably the replication factor, will be inherited from the default range. This will make it more clear that the timeseries zone config can be changed independently from all the other zone configs. fixes #123762 Release note (ops change): New clusters that are initialized for the first time will now have a zone config defined for the `timeseries` range. This zone config only specifies the gc.ttlseconds, so all the other attributes are inherited from the zone config of the `default` range, as they were before. Clusters that are upgraded to v24.3 from a previous version will also have this zone configuration applied to the timeseries range, as long as that range does not already have a zone config. 129053: sql/parser: only retain scanned SQL comments when necessary r=mgartner a=mgartner In #86968 the scanner gained the ability to retain comments in scanned SQL strings, and this was an always-on feature. However, the comments are only used when populating the crdb_internal.cluster_queries table, see `sql.formatActiveQuery`. Now, comments are only retained when the parser is used from this function, reducing allocations for all other cases. Fixes #127713 Release note: None Co-authored-by: Rafi Shamim <[email protected]> Co-authored-by: Marcus Gartner <[email protected]>
SHOW QUERIES (and crdb_internal.node_queries, cluster_queries)
interpolates placeholder values into the statement so that it is
possible to see the placeholder values of a prepared statement - but it
used to do this unconditionally during statement execution.
This is an expensive process that spends a lot of CPU for little reason,
since the interpolation was happening in the hot path of every query.
Now, we include the placeholder values as a separate array in the
internal representation of active queries, and interpolate the values
only when they're being pulled out to examine, to avoid the
unconditional runtime interpolation costs.
As a side effect of this change, the original comments in a query are
now included in SHOW QUERIES and the two active queries tables.
Release note (sql change): the query field in the
crdb_internal.node_queries, crdb_internal.cluster_queries, and SHOW
QUERIES commands now includes the original comments in the queries.
Informs CRDB-17299