Expand description
samkhya-postgres — PostgreSQL adapter for samkhya.
§Build modes
-
Default (no features): empty
rlib. Compiles without PostgreSQL development headers; suitable forcargo check --workspacein CI environments that do not havelibpq-dev/postgresql-server-dev-*installed. -
pg_extensionfeature plussamkhya_pgrx_enabledrustc cfg flag: pulls in pgrx and exposes the functions defined below as a loadable PostgreSQL extension targeting PostgreSQL 17 (the only major supported in v1.0). Build withcargo pgrx— see this crate’s README. The recommended invocation is:RUSTFLAGS="--cfg=samkhya_pgrx_enabled" \ cargo pgrx run pg17 --features pg_extension --package samkhya-postgres
§v1.0 double-gating + single-version pin (pg17)
pgrx 0.12.9’s pgrx-pg-sys build script panics at bindgen-time
when more than one pg$VERSION feature is simultaneously active:
Error: Multiple `pg$VERSION` features found.
`--no-default-features` may be required.
Found: pg13, pg14, pg15, pg16, pg17Cargo’s --all-features (used by cargo check --workspace --all-features and similar workspace-wide gates) activates every
feature in a crate’s [features] table simultaneously. With the
canonical pgrx feature-flag pattern (pg13..pg17 as parallel
features that each forward pgrx/pgNN), workspace gates therefore
cannot pass — pgrx-pg-sys’s build script panics before any
manifest-level compile_error! we add ever fires.
For v1.0 the design is:
- Single-version pin (pg17). The
pg_extensionCargo feature forwardspgrx/pg17. No pg13..pg16 features are declared. - Target-cfg dep isolation. The pgrx dependency lives under
[target.'cfg(samkhya_pgrx_enabled)'.dependencies]inCargo.toml. Undercargo check --workspace --all-features(wheresamkhya_pgrx_enabledis unset), pgrx is excluded from the dep graph andpg_extensionis a harmless no-op. UnderRUSTFLAGS="--cfg=samkhya_pgrx_enabled" cargo pgrx run pg17 --features pg_extension, pgrx enters the dep graph and the extension module below compiles.
v1.1 will restore pg13..pg16 when one of:
- pgrx 0.13+ removes the feature-multiplexing constraint, or
- the pgrx-using code is moved to a non-workspace sub-crate that
does not participate in
--workspace --all-featuresgates.
See feedback-pgrx-feature-isolation memory for the full
design-decision record and retire conditions.
§Provided SQL functions (when built as an extension)
samkhya_hll_count(input anyarray) -> bigint— build a samkhyaHllSketchfrom the input array and return its estimated distinct-element count. Useful as a quick sanity check that the in-engine sketch agrees with the portable sketch produced by samkhya-core.samkhya_puffin_inspect(path text) -> jsonb— open a Puffin sidecar file on the server filesystem and return per-blob metadata (kind,offset,length,fields,compression-codec).
§Scope
This is the v1.0 scaffold. A v1.1 target is the operator-side
cardinality hook (replacing get_relation_info_hook and friends)
so the planner picks up samkhya’s portable, feedback-driven,
self-correcting row estimates without per-query SQL changes. The
get_relation_info_hook integration is intentionally deferred
because it requires deeper pgrx hook plumbing than belongs in a
scaffold.
Functions§
- version
- Returns the samkhya-postgres crate version string.