Skip to content

sql: add cache invalidation builtin functions#127414

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
DrewKimball:cache-builtin
Jul 24, 2024
Merged

sql: add cache invalidation builtin functions#127414
craig[bot] merged 1 commit intocockroachdb:masterfrom
DrewKimball:cache-builtin

Conversation

@DrewKimball
Copy link
Copy Markdown
Collaborator

This commit adds builtin functions that can be used to invalidate the query plan cache and table statistics cache. This is useful for preventing test flakes due to asynchronous cache updates, as well as for tests that involve the caches in general.

Fixes #122543

Release note: None

@DrewKimball DrewKimball requested a review from a team July 18, 2024 05:23
@DrewKimball DrewKimball requested review from a team as code owners July 18, 2024 05:23
@DrewKimball DrewKimball requested review from mgartner and removed request for a team July 18, 2024 05:23
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Collaborator

@michae2 michae2 left a comment

Choose a reason for hiding this comment

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

:lgtm: Awesome!

Reviewed 7 of 7 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball and @mgartner)


pkg/sql/sem/builtins/builtins.go line 8807 at r1 (raw file):

				return tree.DVoidDatum, nil
			},
			Info:       `This function is used to clear the query plan cache`,

Might be worth saying that this only affects the local / gateway node.


pkg/sql/sem/builtins/builtins.go line 8820 at r1 (raw file):

			ReturnType: tree.FixedReturnType(types.Void),
			Fn: func(ctx context.Context, evalCtx *eval.Context, args tree.Datums) (tree.Datum, error) {
				evalCtx.Planner.ClearTableStatsCache()

random idea: It might also be worth creating an overload that takes an int and calls InvalidateTableStats to flush just a single table's stats.


pkg/sql/sem/builtins/builtins.go line 8823 at r1 (raw file):

				return tree.DVoidDatum, nil
			},
			Info:       `This function is used to clear the table statistics cache`,

(Same comment here about local / gateway node.)

Copy link
Copy Markdown
Contributor

@mgartner mgartner left a comment

Choose a reason for hiding this comment

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

cc @Uzair5162 to update the changes in #127395 (before or after it merges) to use this new built-in and remove the retries.

:lgtm:

Reviewed 7 of 7 files at r1, all commit messages.
Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @DrewKimball and @michae2)


pkg/sql/sem/builtins/builtins.go line 8820 at r1 (raw file):

Previously, michae2 (Michael Erickson) wrote…

random idea: It might also be worth creating an overload that takes an int and calls InvalidateTableStats to flush just a single table's stats.

Good idea, but I'd prefer to only add it if we have a specific need for it.


pkg/ccl/logictestccl/testdata/logic_test/builtins line 91 at r1 (raw file):


statement ok
SELECT crdb_internal.clear_query_plan_cache();

It would be cool to have a builtin like this defined as a stored procedure, rather than a function, because it never needs to be invoked in arbitrary scalar expressions, like a function can. I don't know if Postgres has precedence for built-in stored procedures, though.

This commit adds builtin functions that can be used to invalidate the
query plan cache and table statistics cache. This is useful for preventing
test flakes due to asynchronous cache updates, as well as for tests that
involve the caches in general.

Fixes cockroachdb#122543

Release note: None
Copy link
Copy Markdown
Collaborator Author

@DrewKimball DrewKimball left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @mgartner and @michae2)


pkg/sql/sem/builtins/builtins.go line 8807 at r1 (raw file):

Previously, michae2 (Michael Erickson) wrote…

Might be worth saying that this only affects the local / gateway node.

Done.


pkg/sql/sem/builtins/builtins.go line 8823 at r1 (raw file):

Previously, michae2 (Michael Erickson) wrote…

(Same comment here about local / gateway node.)

Done.


pkg/ccl/logictestccl/testdata/logic_test/builtins line 91 at r1 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

It would be cool to have a builtin like this defined as a stored procedure, rather than a function, because it never needs to be invoked in arbitrary scalar expressions, like a function can. I don't know if Postgres has precedence for built-in stored procedures, though.

That's an interesting idea. I think a bunch of our builtins might be nicer as procedures.

@DrewKimball
Copy link
Copy Markdown
Collaborator Author

TFTRs!

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jul 24, 2024

@craig craig bot merged commit 1fa0970 into cockroachdb:master Jul 24, 2024
@DrewKimball DrewKimball deleted the cache-builtin branch July 24, 2024 06:54
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.

sql: add builtin function to clear the query cache

4 participants