Query Columnstore Table & Supported Query Shapes
Columnstore mirror tables created with CALL mooncake.create_table(dst, src) are queried using standard PostgreSQL SELECT syntax. Behind the scenes, pg_mooncake and pg_duckdb 1.2.0 translate and route analytical scans to the embedded DuckDB v2.0.0 vectorized execution engine.
How Queries Work
When you query a USING mooncake table:
- LSN Synchronization:
duckdb_mooncakechecks PostgreSQL’s current WAL write LSN and waits formoonlinkto ingest all committed transactions up to that LSN. - Segment Elimination: DuckDB 2.0 inspects multi-file Parquet column min/max statistics to skip files and row groups that cannot match your
WHEREpredicates. - Zero-Copy Hybrid Scan: Flushed Parquet files, Roaring Bitmap deletion vectors, and the in-memory Apache Arrow write buffer are scanned in parallel across DuckDB worker threads (
duckdb.threads).
You can verify that DuckDB is executing your query by running EXPLAIN:
Analytical Query Shapes (Recommended)
Columnstore tables excel at analytical workloads that scan large numbers of rows across a subset of columns, often delivering 10× to 1000× speedups over heap tables.
1. Multi-Dimensional Aggregations
2. High-Selectivity Filtering & Top-N Ranking
3. Time-Series Rollups & Window Functions
4. Hybrid Joins with Regular PostgreSQL Heap Tables
You can join a USING mooncake columnstore mirror directly with regular PostgreSQL rowstore tables (such as dimension tables or lookup tables):
Operational Point Lookups (Use the Rowstore Table)
While pg_mooncake supports arbitrary SELECT queries, single-row point lookups (WHERE id = 12345) and tiny index range scans should be routed to your source rowstore table, where PostgreSQL’s B-tree indexes provide sub-millisecond lookup latency.
Query Translation & DuckDB Functions
Because queries on USING mooncake tables are executed by DuckDB (pg_duckdb), certain PostgreSQL-specific functions that lack a direct DuckDB equivalent (such as to_char(), certain regexp_* overloads, or specific jsonb_* operators) may require DuckDB-compatible expressions.
Exposing DuckDB Functions in PostgreSQL
You can expose native DuckDB analytical functions (such as time_bucket) inside PostgreSQL by defining a placeholder PL/pgSQL function with the matching signature. When a query targets a columnstore table, pg_duckdb intercepts the call and executes DuckDB’s native vectorized implementation: