sql_saga_native
sql_saga · Rust/pgrx companion library that accelerates sql_saga temporal_merge planning and executor introspection.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100938 | sql_saga_native | sql_saga | 0.1.0 | TIME | MIT | Rust |
PostgreSQL · 18
| Relationships | |
|---|---|
| Requires | sql_saga |
Usage
Sources:
- Official native component control file
- Official native SQL bindings
- Official architecture decision
- Official Rust implementation
sql_saga_native is the Rust/pgrx companion library for sql_saga’s performance-critical temporal_merge planner and executor-introspection cache. It is a headless component with no independently created extension object. The main sql_saga extension registers SQL functions backed by the matching $libdir/sql_saga_native library.
Core Workflow
Install a package that provides both matching sql_saga and sql_saga_native artifacts. After the main extension is installed, inspect the current connection’s native cache through its registered functions:
Normal applications call sql_saga.temporal_merge(...); they do not call the native planner directly. The main procedure uses the native sweep-line planner by default. For diagnosis, a session can select the PL/pgSQL planner instead:
Native Interfaces
temporal_merge_plan_native(...): internal planner that fillspg_temp.temporal_merge_planand returns its row count.temporal_merge_executor_introspect(...): internal per-connection cache of target/source metadata and generated DML fragments.temporal_merge_native_cache_stats(): reports planner/executor cache entries, prepared read statements, hits, and misses for the current connection.temporal_merge_native_cache_reset(): clears current-connection native caches, prepared statements, and counters.
The planner reads source and target rows in bulk, performs temporal segmentation/coalescing in Rust with a sweep-line algorithm, and emits the same plan shape consumed by the PL/pgSQL executor. Cache state is thread-local, which maps to one PostgreSQL backend connection.
Caveats
There is no independent DDL lifecycle for sql_saga_native; version and ABI must match the sql_saga SQL bindings that name its C symbols. Do not create a separate extension or expose the internal planner as an application API. Upgrade the main extension and companion library atomically, then exercise temporal merges and cache reset/stats on the target PostgreSQL 18 build.
Caches are per connection, not shared across sessions. Source column names and types participate in cache validation, but operational DDL and role changes should still be tested with fresh sessions. The upstream performance ratios are measurements from its own benchmark, not guarantees for other schemas or workloads.