postgres/: pgrx-based PostgreSQL extension (pg_fusion), planner/worker hooks and embedding. Binary:src/bin/pgrx_embed.rs.executor/: DataFusion-powered execution runtime (buffers, layout, server, SQL helpers).protocol/: IPC/message definitions shared between extension and runtime (bind/parse/columns/etc.).common/: Shared types and errors (e.g.,FusionError).storage/: Low-level Postgres storage helpers (heap pages, tuple iteration/decoding).storage/src/heap.rs: Heap page reader with tuple iterators and zero-allocation tuple decoder to Arrow/DataFusionScalarValue. Supports fixed-width, date/time/timestamp/interval, inline varlena text. Projected compressed/external varlena returns an error; non-projected is skipped safely.
storage/pg_test/: pgrx-based test crate for storage (integration tests against a live Postgres). Depends onstorageand exercises heap iteration/decoding.- Workspace is managed by the root
Cargo.toml.
- Build (all crates):
cargo build --workspace(use--releasefor optimized artifacts). - Check types fast:
cargo check --workspace. - Unit/integration tests:
cargo test --workspace. - pgrx toolchain:
- Install:
cargo install cargo-pgrxthencargo pgrx init --pg17 $(which pg_config). - Run extension in a dev cluster:
cargo pgrx run. - pgrx tests (PG 17):
cargo pgrx test pg17.
- Install:
- Build only the extension crate:
cargo build -p pg_fusion.
Storage-specific:
- Build storage lib:
cargo build -p storage. - Run storage’s pgx tests:
cargo pgrx test pg17 -p pg_test.
- Rust 2021 edition. Prefer idiomatic Rust: small modules, explicit
use, and clear error paths. - Formatting: run
cargo fmtbefore pushing. - Linting: run
cargo clippy -D warningsand address issues. - Naming: modules
snake_case, typesCamelCase, constantsSCREAMING_SNAKE_CASE.
- Place Rust tests in
tests/ormod tests { ... }within modules. - For extension-level behavior, add pgrx tests and run with
cargo pgrx test pg17. - Storage-heavy behavior (heap/tuple decoding) is tested via the
storage/pg_testcrate usingcargo pgrx test pg17 -p pg_test. - Keep tests deterministic; prefer table-driven cases and cover error paths.
- Commits: imperative mood, concise scope first line (e.g.,
executor: fix buffer rollback), followed by context where helpful. - PRs: include motivation, summary of changes, testing notes (commands used), and any config/doc updates.
- Ensure
cargo fmt,cargo clippy -D warnings, andcargo test --workspacepass locally before requesting review.
- PostgreSQL: add
shared_preload_libraries = 'pg_fusion'in the target cluster. - GUC: toggle runtime via
pg_fusion.enable. - Avoid panics in extension code paths; return structured errors (
common::FusionError).
- The extension hooks Postgres planner/worker, communicates with the runtime via the
protocolcrate, and executes queries through theexecutorbacked by Apache DataFusion.