Skip to content

release-26.1: sql: add lookup fallback in internalLookupCtx#165274

Merged
fqazi merged 1 commit intocockroachdb:release-26.1from
fqazi:blathers/backport-release-26.1-164942
Mar 16, 2026
Merged

release-26.1: sql: add lookup fallback in internalLookupCtx#165274
fqazi merged 1 commit intocockroachdb:release-26.1from
fqazi:blathers/backport-release-26.1-164942

Conversation

@fqazi
Copy link
Copy Markdown
Collaborator

@fqazi fqazi commented Mar 10, 2026

Backport 1/1 commits from #164942 on behalf of @fqazi.


Previously, when internalLookupCtx was used by crdb_internal or pg_catalog functions, it was assumed that reading system.namespace would cache all references in a database. While this worked when fetching descriptors from KV, this assumption can break when using leased descriptors.

This occurs because system.namespace may be newer than the leased descriptor timestamp. For example, if a table referenced by a foreign key is being dropped, the referencing table may still contain the entry. When the lookup context attempts to resolve that referenced table, the entry will be missing.

To address this, this patch allows internalLookupCtx to use a fallback, enabling it to query missing objects using the descriptor collection.

Fixes: #164430
Fixes: #164648

Release note (bug fix): Fixed a rare race condition where SHOW CREATE TABLE could fail with a "relation does not exist" error if a table referenced by a foreign key was being concurrently dropped.


Release justification: low risk change that prevents errors with leased descriptors for crdb_internal / pg_catalog and concurrent drops

@fqazi fqazi requested a review from a team as a code owner March 10, 2026 03:12
@blathers-crl blathers-crl bot added blathers-backport This is a backport that Blathers created automatically. O-robot Originated from a bot. labels Mar 10, 2026
@blathers-crl blathers-crl bot requested a review from rafiss March 10, 2026 03:12
@blathers-crl
Copy link
Copy Markdown

blathers-crl bot commented Mar 10, 2026

Thanks for opening a backport.

Before merging, please confirm that the change does not break backwards compatibility and otherwise complies with the backport policy. Include a brief release justification in the PR description explaining why the backport is appropriate. All backports must be reviewed by the TL for the owning area. While the stricter LTS policy does not yet apply, please exercise judgment and consider gating non-critical changes behind a disabled-by-default feature flag when appropriate.

@blathers-crl blathers-crl bot added backport Label PR's that are backports to older release branches T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) labels Mar 10, 2026
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

pkg/sql/database.go:115:57: not enough arguments in call to newInternalLookupCtx
	have ([]"github.com/cockroachdb/cockroach/pkg/sql/catalog".Descriptor, "github.com/cockroachdb/cockroach/pkg/sql/catalog".DatabaseDescriptor)
	want ([]"github.com/cockroachdb/cockroach/pkg/sql/catalog".Descriptor, "github.com/cockroachdb/cockroach/pkg/sql/catalog".DatabaseDescriptor, internalLookupCtxFallbackFn)

Previously, when internalLookupCtx was used by crdb_internal or
pg_catalog functions, it was assumed that reading system.namespace would
cache all references in a database. While this worked when fetching
descriptors from KV, this assumption can break when using leased
descriptors.

This occurs because system.namespace may be newer than the leased
descriptor timestamp. For example, if a table referenced by a foreign
key is being dropped, the referencing table may still contain the entry.
When the lookup context attempts to resolve that referenced table, the
entry will be missing.

To address this, this patch allows internalLookupCtx to use a fallback,
enabling it to query missing objects using the descriptor collection.

Fixes: cockroachdb#164430
Fixes: cockroachdb#164648

Release note (bug fix): Fixed a rare race condition where SHOW CREATE
TABLE could fail with a "relation does not exist" error if a table
referenced by a foreign key was being concurrently dropped.
@fqazi fqazi force-pushed the blathers/backport-release-26.1-164942 branch from 92f62e3 to 433ee1f Compare March 16, 2026 13:21
@fqazi fqazi merged commit 5d921e9 into cockroachdb:release-26.1 Mar 16, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Label PR's that are backports to older release branches blathers-backport This is a backport that Blathers created automatically. O-robot Originated from a bot. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) target-release-26.1.2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants