sql/hints: use enabled and database columns#165457
sql/hints: use enabled and database columns#165457trunk-io[bot] merged 2 commits intocockroachdb:masterfrom
Conversation
|
😎 Merged successfully - details. |
cdd08b0 to
ac5e04f
Compare
|
Note that the second commit has a problem, which is that after calling Otherwise this should be RFAL. |
ZhouXing19
left a comment
There was a problem hiding this comment.
Nice! Only left some nit comments.
@ZhouXing19 reviewed 17 files and all commit messages, and made 5 comments.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on DrewKimball and michae2).
-- commits line 12 at r1:
This seems inaccurate -- we already introduce the 3-arg overload in ba61a64 for information_schema.crdb_rewrite_inline_hints. I think we can just reuse the commit message as the release note.
-- commits line 22 at r2:
hmm, should we also have it take an optional database argument, i.e. (enabled: bool, statement_fingerprint: string, database: string), matching rewriteInlineHintsWithDatabaseOverload?
pkg/sql/hints/hint_cache.go line 545 at r1 (raw file):
continue } if entry.hints[i].Database != "" && entry.hints[i].Database != currentDB {
nit: should we also include currentDB != nil? As in, only filter by db if currentDB is set?
pkg/sql/opt/exec/execbuilder/testdata/statement_hint_builtins line 1702 at r2 (raw file):
statement ok SELECT crdb_internal.await_statement_hints_cache()
nit: is this await is a no-op here (since no rangefeed event fires for enabled-only updates)? Might just remove it? Same for the awaits following the clear_statement_hints_cache() below.
|
TFTR! I'm going to try Drew's idea to force hint cache invalidation. Hold off on any more reviews for a sec... |
ac5e04f to
5e5e0fe
Compare
michae2
left a comment
There was a problem hiding this comment.
Tried Drew's idea to use a DELETE and an INSERT to force hint cache invalidation. Seems to be working!
This should be RFAL.
@michae2 made 5 comments and resolved 1 discussion.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on DrewKimball and ZhouXing19).
Previously, ZhouXing19 (Jane Xing) wrote…
This seems inaccurate -- we already introduce the 3-arg overload in ba61a64 for
information_schema.crdb_rewrite_inline_hints. I think we can just reuse the commit message as the release note.
It's true, I'm cheating a bit by using the release note that I should have used in #164562... I think it's more clear for users to explain things in terms of the builtins but this is confusing. I'll try to reword it.
Previously, ZhouXing19 (Jane Xing) wrote…
hmm, should we also have it take an optional database argument, i.e.
(enabled: bool, statement_fingerprint: string, database: string), matchingrewriteInlineHintsWithDatabaseOverload?
Good point! We might want to do this for delete_statement_hints, too?
If it's ok with you I'll open an issue and do this in another PR.
pkg/sql/hints/hint_cache.go line 545 at r1 (raw file):
Previously, ZhouXing19 (Jane Xing) wrote…
nit: should we also include
currentDB != nil? As in, only filter by db ifcurrentDBis set?
Good catch! Done.
pkg/sql/opt/exec/execbuilder/testdata/statement_hint_builtins line 1702 at r2 (raw file):
Previously, ZhouXing19 (Jane Xing) wrote…
nit: is this await is a no-op here (since no rangefeed event fires for enabled-only updates)? Might just remove it? Same for the awaits following the
clear_statement_hints_cache()below.
Good point. I've now removed the clear_statement_hints_cache since the fix seems to be working!
Read the `enabled` and `database` columns from system.statement_hints when loading hints from the database into the hint cache. Also match on current database when looking up hints with MaybeGetStatementHints. Informs: cockroachdb#163522 Release note (sql change): Rewrite-inline-hints rules can now be scoped to a specific database, and will only apply to matching statements when the current database also matches. This database can be specified with an optional third argument to `information_schema.crdb_rewrite_inline_hints`. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
Add `information_schema.crdb_enable_statement_hints` builtin with two overloads: `(enabled: bool, rowid: int)` and `(enabled: bool, statement_fingerprint: string)`. Both require REPAIRCLUSTER privilege. The implementation uses a new `SetHintEnabledInDB` function that issues a DELETE and an INSERT against `system.statement_hints` to set the `enabled` column. The Planner interface gains a `SetStatementHintEnabled` method to expose this to builtins. The DELETE and INSERT are needed to invalidate the hint cache entry on every node via the rangefeed on the secondary index of `system.statement_hints`. Fixes: cockroachdb#163522 Release note (sql change): This change introduces a new builtin `information_schema.crdb_enable_statement_hints` which can be used to enable or disable statement hints by hint ID or by statement fingerprint. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
5e5e0fe to
0ae06cd
Compare
michae2
left a comment
There was a problem hiding this comment.
@michae2 made 1 comment.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on DrewKimball and ZhouXing19).
Previously, michae2 (Michael Erickson) wrote…
It's true, I'm cheating a bit by using the release note that I should have used in #164562... I think it's more clear for users to explain things in terms of the builtins but this is confusing. I'll try to reword it.
Updated the release note.
|
/trunk merge |
DrewKimball
left a comment
There was a problem hiding this comment.
Nice work! Belated LGTM
sql/hints: read enabled and database columns during hint matching
Read the
enabledanddatabasecolumns from system.statement_hintswhen loading hints from the database into the hint cache. Also match on
current database when looking up hints with MaybeGetStatementHints.
Informs: #163522
Release note (sql change): Rewrite-inline-hints rules can now be scoped
to a specific database, and will only apply to matching statements when
the current database also matches. This database can be specified with
an optional third argument to
information_schema.crdb_rewrite_inline_hints.Co-Authored-By: roachdev-claude roachdev-claude-bot@cockroachlabs.com
sql/hints: add enable/disable statement hint builtin
Add
information_schema.crdb_enable_statement_hintsbuiltin with twooverloads:
(enabled: bool, rowid: int)and(enabled: bool, statement_fingerprint: string). Both require REPAIRCLUSTER privilege.The implementation uses a new
SetHintEnabledInDBfunction that issuesa DELETE and an INSERT against
system.statement_hintsto set theenabledcolumn. The Planner interface gains aSetStatementHintEnabledmethod to expose this to builtins.The DELETE and INSERT are needed to invalidate the hint cache entry on
every node via the rangefeed on the secondary index of
system.statement_hints.Fixes: #163522
Release note (sql change): This change introduces a new builtin
information_schema.crdb_enable_statement_hintswhich can be used toenable or disable statement hints by hint ID or by statement
fingerprint.
Co-Authored-By: roachdev-claude roachdev-claude-bot@cockroachlabs.com