Real-time Query Analytics
1. Overview
ivy_mooncake is the IvorySQL distribution of pg_mooncake. The PostgreSQL extension creates Apache Iceberg columnstore mirrors of transactional tables for low-latency analytical (OLAP) queries with sub-second freshness as a design goal.
-
Real-time ingestion.
ivy_moonlinkreplicates committedINSERT,UPDATE, andDELETEoperations from the source table, including streaming and batch writes. -
DuckDB acceleration. The Oracle-mode examples below show how to check query plans and compare measured execution times.
-
PostgreSQL-native access. Query a columnstore mirror as you would an ordinary PostgreSQL table.
-
Iceberg-native storage. Compatible query engines can access published Iceberg data with the appropriate catalog and storage configuration.
3. Installation
3.1. Run the Preview Image with Docker
ivy_mooncake:0.3 is based on IvorySQL 6.0 (PostgreSQL 19.0) and includes pg_duckdb and pg_mooncake. Enter a test password at the prompt and start the container.
read -rsp 'IvorySQL test password: ' IVORYSQL_PASSWORD
printf '\n'
export IVORYSQL_PASSWORD
docker run -d --name ivy_mooncake_10 \
-e IVORYSQL_PASSWORD \
registry.highgo.com/mooncake/ivy_mooncake:0.3
unset IVORYSQL_PASSWORD
docker exec -it ivy_mooncake_10 bash
If the container is already running, run docker exec -it ivy_mooncake_10 bash directly. Run the remaining psql commands inside the container.
For standalone installation and configuration, see the ivy_duckdb guide and the ivy_mooncake guide.
4. Quick Start
These examples use one test container to check mirror replication in PG and Oracle modes and compare the Oracle-mode query plans with DuckDB forced execution on and off. Each example uses its own table names. Those tables should be absent the first time you run it.
4.1. Verify Mirror Replication in PG Mode
Connect to port 5432 inside the container.
psql -X -p 5432 -U ivorysql -d postgres -v ON_ERROR_STOP=1
SELECT version();
SHOW ivorysql.compatible_mode;
CREATE EXTENSION IF NOT EXISTS pg_mooncake CASCADE;
SELECT extname, extversion
FROM pg_extension
WHERE extname IN ('pg_duckdb', 'pg_mooncake')
ORDER BY extname;
CREATE TABLE htap_test_source (id integer PRIMARY KEY, amount integer);
INSERT INTO htap_test_source VALUES (1, 10), (2, 20);
CALL mooncake.create_table('htap_test_mirror', 'htap_test_source');
SELECT COUNT(*) AS rows, SUM(amount) AS total FROM htap_test_mirror;
UPDATE htap_test_source SET amount = 25 WHERE id = 2;
SELECT COUNT(*) AS rows, SUM(amount) AS total FROM htap_test_mirror;
ivorysql.compatible_mode should return pg. The tested versions were pg_duckdb 1.2.2 and pg_mooncake 0.3.0. Both mirror queries report rows = 2, and the total changes from 30 to 35. If the mirror has yet to apply the update, wait for replication and query it again.
4.2. Verify the Mirror and DuckDB Plans in Oracle Mode
Enter \q in psql to return to the container shell, then connect to port 1521.
psql -X -p 1521 -U ivorysql -d postgres -v ON_ERROR_STOP=1
SHOW ivorysql.compatible_mode;
SELECT CAST(42 AS NUMBER(10,0)) FROM dual;
CREATE EXTENSION IF NOT EXISTS pg_mooncake CASCADE;
CREATE TABLE htap_ora_source (
id NUMBER(10,0) PRIMARY KEY,
amount NUMBER(10,2),
channel VARCHAR2(12)
);
INSERT INTO htap_ora_source VALUES (1, 10.50, 'online');
INSERT INTO htap_ora_source VALUES (2, 20.00, 'store');
SET duckdb.force_execution = off;
EXPLAIN (COSTS OFF)
SELECT channel, SUM(amount) FROM htap_ora_source GROUP BY channel;
SET duckdb.force_execution = on;
EXPLAIN (COSTS OFF)
SELECT channel, SUM(amount) FROM htap_ora_source GROUP BY channel;
SELECT channel, SUM(amount)
FROM htap_ora_source
GROUP BY channel
ORDER BY channel;
RESET duckdb.force_execution;
CALL mooncake.create_table('htap_ora_mirror', 'htap_ora_source');
SELECT COUNT(*) AS rows, SUM(amount) AS total FROM htap_ora_mirror;
UPDATE htap_ora_source SET amount = 25.00 WHERE id = 2;
SELECT COUNT(*) AS rows, SUM(amount) AS total FROM htap_ora_mirror;
ivorysql.compatible_mode should return oracle. With forced execution off, this query uses HashAggregate and Seq Scan. With it on, the plan shows Custom Scan (DuckDBScan). Both mirror queries report rows = 2, and the total changes from 30.50 to 35.50.
duckdb.force_execution controls whether eligible queries in the current session are forced to run in DuckDB. With it off, ordinary table queries follow the default planning path. The DuckDB scan extension reads Mooncake mirrors.
4.3. Compare Query Times on Two Million Rows
Stay in Oracle mode. Count distinct customers by region on the same source table.
CREATE EXTENSION IF NOT EXISTS pg_mooncake CASCADE;
CREATE TABLE htap_bench_orders (
region_id INT,
customer_id INT,
amount NUMBER(10,2)
);
INSERT INTO htap_bench_orders
SELECT MOD(n, 32), MOD(n, 180013), MOD(n, 10000) / 100.0
FROM pg_catalog.generate_series(1, 2000000) AS g(n);
ANALYZE htap_bench_orders;
In psql, enable \timing and record the Time after each SELECT. Alternate between the two settings for several runs and take the median for each setting.
\timing on
SET duckdb.force_execution = off;
SELECT region_id, COUNT(DISTINCT customer_id) AS unique_customers
FROM htap_bench_orders
GROUP BY region_id
ORDER BY region_id;
SET duckdb.force_execution = on;
SELECT region_id, COUNT(DISTINCT customer_id) AS unique_customers
FROM htap_bench_orders
GROUP BY region_id
ORDER BY region_id;
EXPLAIN (COSTS OFF)
SELECT region_id, COUNT(DISTINCT customer_id) AS unique_customers
FROM htap_bench_orders
GROUP BY region_id
ORDER BY region_id;
RESET duckdb.force_execution;
\timing off
Each setting was tested three times in the same local linux/amd64 container. Both returned the same results for all 32 regions.
duckdb.force_execution |
Three query times | Median |
|---|---|---|
|
2.23 s, 1.83 s, 1.71 s |
1.83 s |
|
0.52 s, 0.30 s, 0.45 s |
0.45 s |
This query ran about 4.1 times as fast with DuckDB forced execution on. Use Custom Scan (DuckDBScan) in EXPLAIN to check the execution path and the measured SELECT times to compare performance.