Skip to content
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

release-22.1: opt: check UDTs by name when checking metadata dependencies #100358

Merged

Conversation

DrewKimball
Copy link
Collaborator

Backport 2/4 commits from #96045.

/cc @cockroachdb/release


opt: refactor metadata dependency tracking

This commit performs some refactoring for the way data source objects
are tracked in opt.Metadata in order to make future changes to UDT
and UDF dependency tracking easier. More particularly, UDTs and UDFs
will be able to re-resolve any references by name. This is necessary
in order to handle cases where changes to the search-path cause names
in the query to resolve to different objects.

opt: track UDT references by name in the Metadata

Previously, it was possible for invalid queries to be kept in the cache
after a schema change, since user-defined types were tracked only by OID.
This missed cases where the search path changed which object a name in
the query resolved to (or whether it resolved at all).

This patch fixes this behavior by tracking UDT references by name, similar
to what was already done for data sources. This ensures that the query
staleness check doesn't miss changes to the search path.

Fixes #96674

Release note (bug fix): Fixed a bug that could prevent a cached query from being invalidated when a UDT referenced by that query was altered or dropped, or when the schema or database of a UDT was altered or dropped.

Release Justification: low-risk bug fix for rare incorrect results for UDTs

This commit performs some refactoring for the way data source objects
are tracked in `opt.Metadata` in order to make future changes to UDT
and UDF dependency tracking easier. More particularly, UDTs and UDFs
will be able to re-resolve any references by name. This is necessary
in order to handle cases where changes to the search-path cause names
in the query to resolve to different objects.

Release note: None
Previously, it was possible for invalid queries to be kept in the cache
after a schema change, since user-defined types were tracked only by OID.
This missed cases where the search path changed which object a name in
the query resolved to (or whether it resolved at all).

This patch fixes this behavior by tracking UDT references by name, similar
to what was already done for data sources. This ensures that the query
staleness check doesn't miss changes to the search path.

Fixes cockroachdb#96674

Release note (bug fix): Fixed a bug that could prevent a cached query with
a user-defined type reference from being invalidated even after a schema
change that should prevent the type from being resolved.
@DrewKimball DrewKimball requested review from mgartner and a team March 31, 2023 22:26
@DrewKimball DrewKimball requested a review from a team as a code owner March 31, 2023 22:26
@blathers-crl
Copy link

blathers-crl bot commented Mar 31, 2023

Thanks for opening a backport.

Please check the backport criteria before merging:

  • Patches should only be created for serious issues or test-only changes.
  • Patches should not break backwards-compatibility.
  • Patches should change as little code as possible.
  • Patches should not change on-disk formats or node communication protocols.
  • Patches should not add new functionality.
  • Patches must not add, edit, or otherwise modify cluster versions; or add version gates.
If some of the basic criteria cannot be satisfied, ensure that the exceptional criteria are satisfied within.
  • There is a high priority need for the functionality that cannot wait until the next release and is difficult to address in another way.
  • The new functionality is additive-only and only runs for clusters which have specifically “opted in” to it (e.g. by a cluster setting).
  • New code is protected by a conditional check that is trivial to verify and ensures that it only runs for opt-in clusters.
  • The PM and TL on the team that owns the changed code have signed off that the change obeys the above rules.

Add a brief release justification to the body of your PR to justify this backport.

Some other things to consider:

  • What did we do to ensure that a user that doesn’t know & care about this backport, has no idea that it happened?
  • Will this work in a cluster of mixed patch versions? Did we test that?
  • If a user upgrades a patch version, uses this feature, and then downgrades, what happens?

@DrewKimball DrewKimball removed the request for review from a team March 31, 2023 22:26
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@DrewKimball DrewKimball changed the title release-22.1: opt: check UDFs and UDTs by name when checking metadata dependencies release-22.1: opt: check UDTs by name when checking metadata dependencies Mar 31, 2023
Copy link
Collaborator

@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.

LGTM

@DrewKimball
Copy link
Collaborator Author

TFYR!

@DrewKimball DrewKimball merged commit a8f387e into cockroachdb:release-22.1 Apr 3, 2023
@DrewKimball DrewKimball deleted the backport22.1-96045 branch April 3, 2023 23:56
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.

3 participants