sql/catalog: cache negative name lookups within a transaction#171979
Open
virajchogle wants to merge 1 commit into
Open
sql/catalog: cache negative name lookups within a transaction#171979virajchogle wants to merge 1 commit into
virajchogle wants to merge 1 commit into
Conversation
By-name resolution of an absent object (e.g. 'east'::region when region is not on the search path) re-read system.namespace on every occurrence. Names have no leasable carrier for the negative case, and the cached reader's miss bit was never exposed to the resolver. Add CatalogReader.IsNameKnownToNotExist and consult it in lookupStoreCacheID so subsequent references to an absent name halt before the leased lookup. The check is per-txn; in-txn creates run through the uncommitted layer first, so they are never blocked. Fixes cockroachdb#171543 Epic: none Release note: none
|
Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
By-name resolution of an unqualified object (notably a UDT cast like
'east'::region) probes each schema on thesearch_pathin order. The not-found result was not cached: descriptor leases carry their own embedded name, so positive lookups are transitively cached via the leased descriptor, but a negative lookup has no leasable carrier. The miss bit lives incachedCatalogReader.byNameStatebut was never exposed to the layer that decides whether to call into the lease subsystem.Reproducer (from #171543):
system.namespacereads scale linearly in rows × non-matching schemas.Fix
Add
CatalogReader.IsNameKnownToNotExist, consulted in thelookupStoreCacheIDlayer ofCollection.getNonVirtualDescriptorID. Subsequent references to the same absent name within a txn halt beforelookupLeasedID, which would otherwise callresolveNameand re-readsystem.namespace.Per-txn only: the cached reader is reset at txn boundaries, and in-txn creates go through
lookupUncommittedID(which runs first), so a name created mid-txn is never blocked. Cross-txn negative caching is left as a follow-up.Tests
Extends
TestDataDriveninpkg/sql/catalog/internal/catkvwith anis_name_known_to_not_existdirective covering post-miss / unrelated absent / positive entry / post-reset cases, mirrored across both tenant testdata files.Fixes #171543
Epic: none
Release note: none