Skip to content

Add snapshot-aware catalog lookup SQL functions#9693

Open
zilder wants to merge 1 commit into
timescale:mainfrom
zilder:zilder/snapshot-aware-lookup-functions
Open

Add snapshot-aware catalog lookup SQL functions#9693
zilder wants to merge 1 commit into
timescale:mainfrom
zilder:zilder/snapshot-aware-lookup-functions

Conversation

@zilder
Copy link
Copy Markdown
Member

@zilder zilder commented Apr 29, 2026

Introduce four snapshot-aware _timescaledb_functions.* lookup functions that resolve TimescaleDB catalog entries against the active snapshot:

  • chunk_id_by_name(schema name, table name) -> int4
  • compressed_chunk_parent_id(int4) -> int4
  • chunk_hypertable_id(int4) -> int4
  • hypertable_relid_by_id(int4) -> regclass

Each function reads GetActiveSnapshot() and passes it explicitly into the catalog scan rather than relying on the scanner's default of SnapshotSelf. Callers that need a non-default snapshot -- e.g. a custom logical decoding plugin running against a HistoricSnapshot -- push it before invoking:

  PushActiveSnapshot(snapshot);
  /* DirectFunctionCall ... */
  PopActiveSnapshot();

From an ordinary SQL session the executor's transaction snapshot is in effect, so the functions also work for ad-hoc use. All four return NULL on miss rather than erroring, so callers can skip rows that don't (yet) resolve.

Follow-up for #9684

@zilder zilder force-pushed the zilder/snapshot-aware-lookup-functions branch 2 times, most recently from 78741ee to 9217153 Compare April 30, 2026 09:18
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

❌ Patch coverage is 93.82716% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/chunk.c 95.00% 0 Missing and 3 partials ⚠️
src/hypertable.c 90.47% 0 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@zilder zilder force-pushed the zilder/snapshot-aware-lookup-functions branch 2 times, most recently from 774f9a4 to 0eaddbd Compare May 4, 2026 20:58
Introduce four _timescaledb_functions.* lookups that resolve
TimescaleDB catalog entries against the active snapshot:

  chunk_id_by_name(schema name, table name) -> int4
  compressed_chunk_parent_id(int4)          -> int4
  chunk_hypertable_id(int4)                 -> int4
  hypertable_id_to_relid(int4)              -> regclass

Each function reads GetActiveSnapshot() and passes it explicitly into
the catalog scan rather than relying on the scanner's default of
SnapshotSelf. Callers that need a non-default snapshot -- e.g. a custom
logical decoding plugin running against a HistoricSnapshot -- push it
before invoking:

  PushActiveSnapshot(snapshot);
  /* DirectFunctionCall ... */
  PopActiveSnapshot();

From an ordinary SQL session the executor's transaction snapshot is in
effect, so the functions also work for ad-hoc use. All four return
NULL on miss rather than erroring, so callers can skip rows that don't
(yet) resolve.
@zilder zilder force-pushed the zilder/snapshot-aware-lookup-functions branch from 0eaddbd to f68d437 Compare May 5, 2026 08:38
@zilder zilder marked this pull request as ready for review May 5, 2026 14:15
@zilder zilder requested a review from a team May 5, 2026 14:15
@github-actions github-actions Bot requested review from antekresic and pnthao May 5, 2026 14:16
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

@pnthao, @antekresic: please review this pull request.

Powered by pull-review

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.

1 participant