Skip to content

Conversation

@DrewKimball
Copy link
Collaborator

@DrewKimball DrewKimball commented Jan 30, 2026

sql/opt: add execbuilder test for query caching behavior

We didn't catch #162055 in our opt tests because they go through the
test catalog, while #162055 requires a real catalog to reproduce. This
commit adds an execbuilder test to show the query plan caching behavior
for different types of prepared statements, including some that contain
a reference to a routine.

Informs #162055

Release note: None

sql/opt: allow plans with routines to be cached

This commit slightly modifies the metadata staleness check so that:

  • The version is not checked when resolving a routine by name. This is
    necessary because overloads looked up by name are not fully hydrated
    and do not have the version set.
  • All routines are checked against the overload resolved by OID regardless
    of whether the reference in the query was by name. This lets us do the
    version check with the correct version.

As a result of these changes, the staleness check now correctly identifies
when a routine descriptor has not changed since a query plan was cached.

Fixes #162055

Release note (performance improvement): Fixed a performance bug that
prevented query plans containing user-defined functions from being
cached. Repeated executions of prepared statements containing UDFs
will now have less planning overhead.

We didn't catch cockroachdb#162055 in our opt tests because they go through the
test catalog, while cockroachdb#162055 requires a real catalog to reproduce. This
commit adds an execbuilder test to show the query plan caching behavior
for different types of prepared statements, including some that contain
a reference to a routine.

Informs cockroachdb#162055

Release note: None
@DrewKimball DrewKimball requested a review from a team January 30, 2026 00:00
@DrewKimball DrewKimball requested a review from a team as a code owner January 30, 2026 00:00
@DrewKimball DrewKimball requested review from michae2 and removed request for a team January 30, 2026 00:00
@blathers-crl
Copy link

blathers-crl bot commented Jan 30, 2026

Your pull request contains more than 1000 changes. It is strongly encouraged to split big PRs into smaller chunks.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@DrewKimball DrewKimball changed the title sql/opt: add execbuilder test for query caching behavior sql/opt: allow plans with routines to be cached Jan 30, 2026
@DrewKimball DrewKimball requested a review from a team January 30, 2026 00:38
@DrewKimball
Copy link
Collaborator Author

This was originally just going to add tests, but the fix ended up being pretty simple, so included that too.

This commit slightly modifies the metadata staleness check so that:
* The version is not checked when resolving a routine by name. This is
  necessary because overloads looked up by name are not fully hydrated
  and do not have the version set.
* All routines are checked against the overload resolved by OID regardless
  of whether the reference in the query was by name. This lets us do the
  version check with the correct version.

As a result of these changes, the staleness check now correctly identifies
when a routine descriptor has not changed since a query plan was cached.

Fixes cockroachdb#162055

Release note (performance improvement): Fixed a performance bug that
prevented query plans containing user-defined functions from being
cached. Repeated executions of prepared statements containing UDFs
will now have less planning overhead.
Copy link
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: Nice fix!

Is it intentional that we're adding all these logictest configs to the exec logictest?

@michae2 reviewed 24 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball).

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.

opt: cached plans with routines are never reused

3 participants