diff --git a/CN/modules/ROOT/nav.adoc b/CN/modules/ROOT/nav.adoc index 063bbdd3..b7f001e5 100644 --- a/CN/modules/ROOT/nav.adoc +++ b/CN/modules/ROOT/nav.adoc @@ -67,6 +67,14 @@ ** xref:v6.0/oracle_compatibility/compat_to_binary_float_function.adoc[二进制浮点转换函数] ** xref:v6.0/oracle_compatibility/compat_to_binary_double_function.adoc[双精度浮点转换函数] ** xref:v6.0/oracle_compatibility/compat_create_type_as_object.adoc[类型对象] +* 实时查询分析 +** xref:v6.0/realtime_query.adoc[快速上手] +** ivy_duckdb +*** xref:v6.0/htap/ivy_duckdb/user_guide.adoc[使用场景与指南] +*** xref:v6.0/htap/ivy_duckdb/design.adoc[技术设计] +** ivy_mooncake +*** xref:v6.0/htap/ivy_mooncake/user_guide.adoc[使用场景与指南] +*** xref:v6.0/htap/ivy_mooncake/design.adoc[技术设计] * 容器化与云服务 ** 容器化指南 *** xref:v6.0/containerization/k8s_deployment.adoc[K8S部署] diff --git a/CN/modules/ROOT/pages/v6.0/htap/ivy_duckdb/design.adoc b/CN/modules/ROOT/pages/v6.0/htap/ivy_duckdb/design.adoc new file mode 100644 index 00000000..e645be61 --- /dev/null +++ b/CN/modules/ROOT/pages/v6.0/htap/ivy_duckdb/design.adoc @@ -0,0 +1,26 @@ += ivy_duckdb 技术设计 +:sectnums: +:sectnumlevels: 5 + +`ivy_duckdb` 是 `pg_duckdb` 在 IvorySQL 上的适配。它把 DuckDB 的向量化执行引擎嵌入 IvorySQL,支持直接分析原有行存表。 + +== 查询执行路径 + +[literal] +---- +SQL 客户端 -> IvorySQL -> pg_duckdb / DuckDB -> 扫描 IvorySQL 行存表 +---- + +客户端使用原有数据库连接提交 SQL。对仅访问 IvorySQL 表的查询,`duckdb.force_execution` 控制是否尝试交给 DuckDB 执行。使用 DuckDB 专属能力的查询也可以由该扩展处理。DuckDB 执行支持的扫描、过滤和聚合,再通过 IvorySQL 连接返回结果。业务仍可使用原来的表、索引和写入接口。 + +== SQL 与类型边界 + +执行过程中,扩展需要在 IvorySQL 和 DuckDB 之间传递查询、列类型和结果。`ivy_duckdb` 包含面向 IvorySQL Oracle 兼容类型的适配。具体能否执行仍取决于 SQL 所用的操作符、函数、数据类型和安装的扩展版本。 + +验证时可以对同一条 SQL 分别记录 IvorySQL 和 DuckDB 路径的 `EXPLAIN`、结果和耗时。日期时间、数值精度和隐式转换适合纳入对照用例。 + +== 资源和数据读取 + +DuckDB 查询在实例内运行,会与事务业务共享 CPU、内存和 I/O。DuckDB 的内存与线程参数按使用 DuckDB 的连接生效,因此并发分析时需要按连接数评估资源。直接分析原表时,查询读取原表数据。需要持续维护列存副本时,见 xref:v6.0/htap/ivy_mooncake/design.adoc[ivy_mooncake 技术设计]。 + +配置项及版本说明见 https://github.com/IvorySQL/ivy_duckdb[ivy_duckdb 项目]和 https://github.com/IvorySQL/ivy_duckdb/blob/main/docs/settings.md[DuckDB 配置参考]。 diff --git a/CN/modules/ROOT/pages/v6.0/htap/ivy_duckdb/user_guide.adoc b/CN/modules/ROOT/pages/v6.0/htap/ivy_duckdb/user_guide.adoc new file mode 100644 index 00000000..184dd432 --- /dev/null +++ b/CN/modules/ROOT/pages/v6.0/htap/ivy_duckdb/user_guide.adoc @@ -0,0 +1,53 @@ += ivy_duckdb 使用场景与指南 +:sectnums: +:sectnumlevels: 5 + +`ivy_duckdb` 适合直接在 IvorySQL 行存表上运行报表、分组聚合和临时分析。业务继续向原表写入,分析会话可以把支持的查询交给 DuckDB 执行。如果需要维护一份可持续同步的 Iceberg 列存镜像,参见 xref:v6.0/htap/ivy_mooncake/user_guide.adoc[ivy_mooncake 使用指南]。 + +== 准备扩展 + +选择与当前 IvorySQL 版本匹配的 https://github.com/IvorySQL/ivy_duckdb[ivy_duckdb 构建]。安装文件后,在 `postgresql.conf` 的 `shared_preload_libraries` 中加入 `pg_duckdb`,保留已有的库,再重启实例。 + +[source,sql] +---- +CREATE EXTENSION IF NOT EXISTS pg_duckdb; +---- + +扩展在数据库级创建。请在运行报告的目标数据库中执行此命令。若分析角色需要使用 DuckDB,请按部署要求配置 https://github.com/IvorySQL/ivy_duckdb/blob/main/docs/settings.md#duckdbpostgres_role[`duckdb.postgres_role`],并授予访问相关表所需的权限。 + +== 确认原表查询使用 DuckDB + +先创建 xref:v6.0/realtime_query.adoc#trades-example[示例表及数据]。在同一个分析会话里,对只访问行存表的 SQL 分别检查启用前后的计划。 + +[source,sql] +---- +SET duckdb.force_execution = false; + +EXPLAIN (COSTS OFF) +SELECT count(*) AS trade_count, avg(price) AS average_price +FROM trades +WHERE symbol = 'AMZN'; + +SET duckdb.force_execution = true; + +EXPLAIN (COSTS OFF) +SELECT count(*) AS trade_count, avg(price) AS average_price +FROM trades +WHERE symbol = 'AMZN'; + +SELECT count(*) AS trade_count, avg(price) AS average_price +FROM trades +WHERE symbol = 'AMZN'; + +RESET duckdb.force_execution; +---- + +对比两份计划,确认启用后的计划包含 DuckDB 执行节点。示例查询应返回两笔交易,平均价格为 179。在生产中使用代表性 SQL 验证结果和性能,尤其是包含 Oracle 兼容类型、隐式转换或专用函数的查询。 + +== 管理分析会话 + +* 建议先在专用会话中启用 `duckdb.force_execution`,完成分析后还原会话设置。 +* 并发分析时,检查 https://github.com/IvorySQL/ivy_duckdb/blob/main/docs/settings.md#resource-management[每个连接的 DuckDB 内存和线程配置]。 +* 查询报错时,记录 SQL、数据类型和执行计划。对于普通行存查询,可以关闭 `duckdb.force_execution`,用 IvorySQL 执行同一条 SQL 作为对照。 + +执行链路和兼容边界参见 xref:v6.0/htap/ivy_duckdb/design.adoc[ivy_duckdb 技术设计]。 diff --git a/CN/modules/ROOT/pages/v6.0/htap/ivy_mooncake/design.adoc b/CN/modules/ROOT/pages/v6.0/htap/ivy_mooncake/design.adoc new file mode 100644 index 00000000..c7fae0b2 --- /dev/null +++ b/CN/modules/ROOT/pages/v6.0/htap/ivy_mooncake/design.adoc @@ -0,0 +1,25 @@ += ivy_mooncake 技术设计 +:sectnums: +:sectnumlevels: 5 + +`ivy_mooncake` 是 `pg_mooncake` 在 IvorySQL 上的适配。它在事务行存表之外维护 Apache Iceberg 列存镜像,分析查询通过 `ivy_duckdb` 使用 DuckDB 执行。 + +== 数据链路 + +[literal] +---- +业务写入 -> IvorySQL 行存表 -> WAL 逻辑复制 -> ivy_moonlink -> Iceberg 列存镜像 +分析查询 -> pg_mooncake / ivy_duckdb -> Iceberg 列存镜像 +---- + +用 `mooncake.create_table` 为源表创建镜像。摄取过程先复制已有数据,再通过逻辑复制处理源表提交的变更。业务应用继续向原表执行插入、更新和删除,分析 SQL 访问镜像表。DuckDB 通过 https://github.com/IvorySQL/ivy_duckdb_mooncake[ivy_duckdb_mooncake] 读取镜像数据。查询如何进入 DuckDB,见 xref:v6.0/htap/ivy_duckdb/design.adoc[ivy_duckdb 技术设计]。 + +== 数据可见性 + +源表提交、变更摄取、镜像查询可见和 Iceberg 数据持久化是不同阶段。查询某条刚提交的记录前,应考虑同步延迟。首次建立镜像时,先验证初始数据齐全,再验证后续变更。只有在相关数据已经作为 Iceberg 快照发布,且外部引擎使用兼容的目录和存储配置时,才适合通过外部引擎读取该数据。 + +== 存储与恢复 + +行存表、逻辑复制所需的 WAL 和列存镜像都占用空间。部署时应一起监控源实例的 WAL 保留量、复制槽进度及镜像存储容量。摄取中断时,先恢复 `ivy_moonlink` 和存储访问,再验证复制位置与镜像数据是否继续更新。工作进程重启后的会话重连和 Iceberg 恢复支持见 xref:v6.0/release_notes.adoc[IvorySQL 6.0 发行说明]。 + +安装前提和验证步骤见 xref:v6.0/htap/ivy_mooncake/user_guide.adoc[ivy_mooncake 使用指南]。组件实现见 https://github.com/IvorySQL/ivy_mooncake[ivy_mooncake] 和 https://github.com/IvorySQL/ivy_moonlink[ivy_moonlink] 项目。 diff --git a/CN/modules/ROOT/pages/v6.0/htap/ivy_mooncake/user_guide.adoc b/CN/modules/ROOT/pages/v6.0/htap/ivy_mooncake/user_guide.adoc new file mode 100644 index 00000000..7094972e --- /dev/null +++ b/CN/modules/ROOT/pages/v6.0/htap/ivy_mooncake/user_guide.adoc @@ -0,0 +1,54 @@ += ivy_mooncake 使用场景与指南 +:sectnums: +:sectnumlevels: 5 + +`ivy_mooncake` 适合需要持续查询最新业务数据的场景,例如交易看板和实时运营报表。应用写入 IvorySQL 行存表,报表查询对应的 Iceberg 列存镜像。选用这条路径时,需要为镜像分配存储并监控同步进度。 + +== 准备扩展和逻辑复制 + +选择与当前 IvorySQL 版本匹配的 https://github.com/IvorySQL/ivy_mooncake[ivy_mooncake 构建],并安装它依赖的 `ivy_duckdb`。使用源码构建或部署镜像时,按同一发行版本的说明配置 `ivy_moonlink` 和镜像存储。 + +在 `postgresql.conf` 中将 `pg_duckdb` 和 `pg_mooncake` 加入 `shared_preload_libraries`,保留已有的库,并将 `wal_level` 设为 `logical`。如果所选版本按项目源码安装指南加载 DuckDB 社区版 Mooncake 扩展,还需将 `duckdb.allow_community_extensions` 设为 `true`。重启后,在目标数据库创建扩展。 + +[source,sql] +---- +CREATE EXTENSION IF NOT EXISTS pg_mooncake CASCADE; +---- + +== 创建镜像并验证增量同步 + +先在测试数据库中创建带主键的 xref:v6.0/realtime_query.adoc#trades-example[示例表]。保持 `trades` 为空,再创建 `trades_iceberg`。 + +[source,sql] +---- +CALL mooncake.create_table('trades_iceberg', 'trades'); +---- + +xref:v6.0/realtime_query.adoc#trades-data[插入示例数据]并提交后,等待镜像应用变更。以下查询应返回两笔 AMZN 交易。 + +[source,sql] +---- +SELECT count(*) AS trade_count, avg(price) AS average_price +FROM trades_iceberg +WHERE symbol = 'AMZN'; +---- + +然后在源表插入第三笔 AMZN 交易。如关闭了客户端的自动提交,请先提交事务,再重复执行上面的镜像查询。镜像应用变更后,交易数会从 2 增至 3。 + +[source,sql] +---- +INSERT INTO trades VALUES (5, 'AMZN', '2024-06-05 10:20:00', 180); +---- + +== 检查同步 + +镜像读取有时会晚于源表提交。如果结果迟迟未更新,先在源表确认该笔交易已提交,再检查 `ivy_moonlink` 工作进程、负责同步的逻辑复制槽和镜像存储。 + +[source,sql] +---- +SELECT slot_name, active, restart_lsn, confirmed_flush_lsn +FROM pg_replication_slots +WHERE slot_type = 'logical'; +---- + +从结果中找到对应的复制槽。槽是否活跃和复制位置是否前进可帮助诊断摄取状态。镜像的实际新鲜度仍应通过查询已知变更来验证。数据链路和恢复边界参见 xref:v6.0/htap/ivy_mooncake/design.adoc[ivy_mooncake 技术设计]。 diff --git a/CN/modules/ROOT/pages/v6.0/realtime_query.adoc b/CN/modules/ROOT/pages/v6.0/realtime_query.adoc new file mode 100644 index 00000000..bd61b534 --- /dev/null +++ b/CN/modules/ROOT/pages/v6.0/realtime_query.adoc @@ -0,0 +1,96 @@ += 实时查询分析快速上手 +:sectnums: +:sectnumlevels: 5 + +IvorySQL 提供两种实时分析路径。`ivy_duckdb` 使用 DuckDB 直接分析现有行存表。`ivy_mooncake` 使用 `ivy_moonlink` 将事务表同步到 Apache Iceberg 列存镜像,再用 DuckDB 执行分析查询。 + +本页用同一张 `trades` 表演示两种路径。请在测试数据库中运行示例。 + +== 准备环境 + +旧版文档提供了预装 `pg_duckdb` 和 `pg_mooncake` 的 `0.1` 预览镜像,可在本机体验这两个扩展。 + +[source,bash] +---- +docker run --name ivy_mooncake \ + -e IVORYSQL_PASSWORD=password \ + -p 127.0.0.1:5432:5432 -p 127.0.0.1:1521:1521 \ + -v ivy_mooncake_data:/var/lib/ivorysql/data \ + -v ivy_mooncake_warehouse:/tmp/moonlink_iceberg \ + registry.highgo.com/mooncake/ivy_mooncake:0.1 +---- + +在 IvorySQL 6.0 环境安装或部署扩展时,参见 xref:v6.0/htap/ivy_duckdb/user_guide.adoc[ivy_duckdb 使用指南]、xref:v6.0/htap/ivy_mooncake/user_guide.adoc[ivy_mooncake 使用指南]和 xref:v6.0/release_notes.adoc[IvorySQL 6.0 发行说明]。 + +[[trades-example]] +== 创建示例表 + +[source,sql] +---- +CREATE TABLE trades ( + id bigint PRIMARY KEY, + symbol text, + time timestamp, + price real +); +---- + +== 准备列存镜像(可选) + +体验 `ivy_mooncake` 时,请先在已配置逻辑复制的实例上创建镜像,再插入示例数据。`CASCADE` 会一并创建所需的 `pg_duckdb` 扩展。只体验 `ivy_duckdb` 时,可以直接跳到<>。 + +[source,sql] +---- +CREATE EXTENSION IF NOT EXISTS pg_mooncake CASCADE; + +CALL mooncake.create_table('trades_iceberg', 'trades'); +---- + +[[trades-data]] +== 插入示例数据 + +[source,sql] +---- +INSERT INTO trades VALUES + (1, 'AMD', '2024-06-05 10:00:00', 119), + (2, 'AMZN', '2024-06-05 10:05:00', 207), + (3, 'AAPL', '2024-06-05 10:10:00', 155), + (4, 'AMZN', '2024-06-05 10:15:00', 151); +---- + +== 用 ivy_duckdb 分析行存表 + +安装并预加载 `pg_duckdb` 后,在当前数据库创建扩展。在分析会话里启用 DuckDB 执行,直接查询 `trades`。 + +[source,sql] +---- +CREATE EXTENSION IF NOT EXISTS pg_duckdb; + +SET duckdb.force_execution = true; + +SELECT count(*) AS trade_count, avg(price) AS average_price +FROM trades +WHERE symbol = 'AMZN'; + +RESET duckdb.force_execution; +---- + +查询结果是两笔交易,平均价格为 179。执行计划的检查方式见 xref:v6.0/htap/ivy_duckdb/user_guide.adoc[ivy_duckdb 使用指南]。 + +== 用 ivy_mooncake 分析列存镜像 + +如果已创建 `trades_iceberg`,等待变更同步后,在镜像上运行同样的查询。 + +[source,sql] +---- +SELECT count(*) AS trade_count, avg(price) AS average_price +FROM trades_iceberg +WHERE symbol = 'AMZN'; +---- + +镜像应用示例变更后,也会返回两笔交易,平均价格为 179。后续交易仍写入 `trades`,提交的变更由 `ivy_moonlink` 同步。如何验证增量同步见 xref:v6.0/htap/ivy_mooncake/user_guide.adoc[ivy_mooncake 使用指南]。 + +== 旧版资料 + +* https://github.com/IvorySQL/ivorysql_docs/blob/v5.6/CN/modules/ROOT/attachments/ivy_mooncake%E6%8A%80%E6%9C%AF%E7%99%BD%E7%9A%AE%E4%B9%A6-v1.0beta1.docx[ivy_mooncake 技术白皮书(V1.0 beta1)] +* https://github.com/IvorySQL/ivorysql_docs/blob/v5.6/CN/modules/ROOT/attachments/ivy_mooncake%E7%94%A8%E6%88%B7%E4%BD%BF%E7%94%A8%E6%89%8B%E5%86%8C-v1.0beta1.docx[ivy_mooncake 用户使用手册(V1.0 beta1)] diff --git a/EN/modules/ROOT/nav.adoc b/EN/modules/ROOT/nav.adoc index 52fec218..2a7aaaec 100644 --- a/EN/modules/ROOT/nav.adoc +++ b/EN/modules/ROOT/nav.adoc @@ -66,6 +66,14 @@ ** xref:v6.0/oracle_compatibility/compat_to_binary_float_function.adoc[TO_BINARY_FLOAT Function] ** xref:v6.0/oracle_compatibility/compat_to_binary_double_function.adoc[TO_BINARY_DOUBLE Function] ** xref:v6.0/oracle_compatibility/compat_create_type_as_object_en.adoc[TYPE AS OBJECT] +* Real-time Query Analytics +** xref:v6.0/realtime_query.adoc[Quick Start] +** ivy_duckdb +*** xref:v6.0/htap/ivy_duckdb/user_guide.adoc[Use Cases and User Guide] +*** xref:v6.0/htap/ivy_duckdb/design.adoc[Technical Design] +** ivy_mooncake +*** xref:v6.0/htap/ivy_mooncake/user_guide.adoc[Use Cases and User Guide] +*** xref:v6.0/htap/ivy_mooncake/design.adoc[Technical Design] * Containerization and Cloud Service ** Containerization *** xref:v6.0/containerization/k8s_deployment.adoc[K8S deployment] diff --git a/EN/modules/ROOT/pages/v6.0/htap/ivy_duckdb/design.adoc b/EN/modules/ROOT/pages/v6.0/htap/ivy_duckdb/design.adoc new file mode 100644 index 00000000..4b4418cb --- /dev/null +++ b/EN/modules/ROOT/pages/v6.0/htap/ivy_duckdb/design.adoc @@ -0,0 +1,26 @@ += ivy_duckdb Technical Design +:sectnums: +:sectnumlevels: 5 + +`ivy_duckdb` adapts `pg_duckdb` to IvorySQL. It embeds DuckDB's vectorized execution engine in IvorySQL and can analyze existing row-store tables directly. + +== Query execution path + +[literal] +---- +SQL client -> IvorySQL -> pg_duckdb / DuckDB -> Scan IvorySQL row-store tables +---- + +The client submits SQL over its existing database connection. For a query that accesses only IvorySQL tables, `duckdb.force_execution` controls whether the extension attempts DuckDB execution. The extension can also handle queries that use DuckDB-specific features. DuckDB runs supported scans, filters, and aggregations and returns the result through the IvorySQL connection. Applications can keep using their existing tables, indexes, and write interfaces. + +== SQL and data type boundaries + +The extension passes queries, column types, and results between IvorySQL and DuckDB. `ivy_duckdb` includes adaptations for IvorySQL's Oracle-compatible types. Execution depends on the operators, functions, and data types in the query and the installed extension version. + +To validate a workload, compare `EXPLAIN`, results, and execution time for the same SQL on the IvorySQL and DuckDB paths. Include date and time types, numeric precision, and implicit conversions in the comparison. + +== Resource use and data access + +DuckDB queries run inside the instance and share CPU, memory, and I/O with transactional workloads. DuckDB memory and thread settings apply to each connection that uses the engine, so account for the number of concurrent analytics sessions. Direct analysis reads the source tables. For a continuously maintained columnstore copy, see the xref:v6.0/htap/ivy_mooncake/design.adoc[ivy_mooncake technical design]. + +See the https://github.com/IvorySQL/ivy_duckdb[ivy_duckdb project] and https://github.com/IvorySQL/ivy_duckdb/blob/main/docs/settings.md[DuckDB settings reference] for configuration and version details. diff --git a/EN/modules/ROOT/pages/v6.0/htap/ivy_duckdb/user_guide.adoc b/EN/modules/ROOT/pages/v6.0/htap/ivy_duckdb/user_guide.adoc new file mode 100644 index 00000000..20b0efe6 --- /dev/null +++ b/EN/modules/ROOT/pages/v6.0/htap/ivy_duckdb/user_guide.adoc @@ -0,0 +1,53 @@ += ivy_duckdb Use Cases and User Guide +:sectnums: +:sectnumlevels: 5 + +Use `ivy_duckdb` for reporting, aggregations, and ad hoc analysis on existing IvorySQL row-store tables. Applications continue writing to those tables while analytics sessions can send supported queries to DuckDB. If you need a continuously synchronized Iceberg columnstore mirror, see the xref:v6.0/htap/ivy_mooncake/user_guide.adoc[ivy_mooncake user guide]. + +== Set up the extension + +Choose an https://github.com/IvorySQL/ivy_duckdb[ivy_duckdb build] that matches your IvorySQL version. After installing the extension files, add `pg_duckdb` to `shared_preload_libraries` in `postgresql.conf`, keep the existing entries, and restart the instance. + +[source,sql] +---- +CREATE EXTENSION IF NOT EXISTS pg_duckdb; +---- + +Create the extension in the database where you will run reports. To authorize an analytics role to use DuckDB, configure https://github.com/IvorySQL/ivy_duckdb/blob/main/docs/settings.md#duckdbpostgres_role[`duckdb.postgres_role`] as appropriate for your deployment and grant the role access to the required tables. + +== Verify DuckDB execution on a row-store query + +Create the xref:v6.0/realtime_query.adoc#trades-example[sample table and data]. In one analytics session, compare the plans for a query that accesses only the row-store table before and after enabling DuckDB execution. + +[source,sql] +---- +SET duckdb.force_execution = false; + +EXPLAIN (COSTS OFF) +SELECT count(*) AS trade_count, avg(price) AS average_price +FROM trades +WHERE symbol = 'AMZN'; + +SET duckdb.force_execution = true; + +EXPLAIN (COSTS OFF) +SELECT count(*) AS trade_count, avg(price) AS average_price +FROM trades +WHERE symbol = 'AMZN'; + +SELECT count(*) AS trade_count, avg(price) AS average_price +FROM trades +WHERE symbol = 'AMZN'; + +RESET duckdb.force_execution; +---- + +Compare the plans and check for a DuckDB execution node in the second one. The sample query should return two trades with an average price of 179. Before using the extension in production, compare results and performance on representative queries, especially those using Oracle-compatible types, implicit conversions, or specialized functions. + +== Manage analytics sessions + +* Start by enabling `duckdb.force_execution` in a dedicated analytics session, then reset the setting when finished. +* For concurrent analytics sessions, review https://github.com/IvorySQL/ivy_duckdb/blob/main/docs/settings.md#resource-management[DuckDB memory and thread settings per connection]. +* If a query fails, record the SQL, data types, and plan. For a standard row-store query, turn off `duckdb.force_execution` and run the same SQL through IvorySQL for comparison. + +See the xref:v6.0/htap/ivy_duckdb/design.adoc[ivy_duckdb technical design] for the execution path and compatibility boundaries. diff --git a/EN/modules/ROOT/pages/v6.0/htap/ivy_mooncake/design.adoc b/EN/modules/ROOT/pages/v6.0/htap/ivy_mooncake/design.adoc new file mode 100644 index 00000000..e298dfcb --- /dev/null +++ b/EN/modules/ROOT/pages/v6.0/htap/ivy_mooncake/design.adoc @@ -0,0 +1,26 @@ += ivy_mooncake Technical Design +:sectnums: +:sectnumlevels: 5 + +`ivy_mooncake` adapts `pg_mooncake` to IvorySQL. It maintains Apache Iceberg columnstore mirrors alongside transactional row-store tables. Analytical queries use DuckDB through `ivy_duckdb`. + +== Data path + +[literal] +---- +Application writes -> IvorySQL row-store table -> logical WAL replication + -> ivy_moonlink -> Iceberg columnstore mirror +Analytics queries -> pg_mooncake / ivy_duckdb -> Iceberg columnstore mirror +---- + +Use `mooncake.create_table` to create a mirror for a source table. Ingestion copies existing data and then applies committed source changes through logical replication. Applications continue to insert, update, and delete rows in the source table while analytical SQL reads the mirror. DuckDB reads the mirror through https://github.com/IvorySQL/ivy_duckdb_mooncake[ivy_duckdb_mooncake]. See the xref:v6.0/htap/ivy_duckdb/design.adoc[ivy_duckdb technical design] for how queries reach DuckDB. + +== Data visibility + +A source commit, change ingestion, visibility to a mirror query, and persistence to Iceberg are distinct stages. Account for replication lag when querying a change that has just committed. When creating a mirror for the first time, check the initial data and then verify that later changes appear. External query engines can read data published as Iceberg snapshots when they use compatible catalog and storage settings. + +== Storage and recovery + +Row-store tables, WAL retained for logical replication, and mirrors all consume storage. Monitor source WAL retention, replication progress, and space available to the mirror. If ingestion stops, restore the `ivy_moonlink` worker and storage access, then verify that replication and mirror updates resume. See the xref:v6.0/release_notes.adoc[IvorySQL 6.0 release notes] for session reconnection after worker restarts and Iceberg-based recovery support. + +For setup and verification, see the xref:v6.0/htap/ivy_mooncake/user_guide.adoc[ivy_mooncake user guide]. Implementation details are available in the https://github.com/IvorySQL/ivy_mooncake[ivy_mooncake] and https://github.com/IvorySQL/ivy_moonlink[ivy_moonlink] repositories. diff --git a/EN/modules/ROOT/pages/v6.0/htap/ivy_mooncake/user_guide.adoc b/EN/modules/ROOT/pages/v6.0/htap/ivy_mooncake/user_guide.adoc new file mode 100644 index 00000000..caae9e5c --- /dev/null +++ b/EN/modules/ROOT/pages/v6.0/htap/ivy_mooncake/user_guide.adoc @@ -0,0 +1,54 @@ += ivy_mooncake Use Cases and User Guide +:sectnums: +:sectnumlevels: 5 + +Use `ivy_mooncake` for workloads such as trading dashboards and operational reports that continuously query recent business data. Applications write to IvorySQL row-store tables and reports query the corresponding Iceberg columnstore mirrors. Plan storage for the mirrors and monitor replication progress. + +== Set up the extensions and logical replication + +Choose an https://github.com/IvorySQL/ivy_mooncake[ivy_mooncake build] that matches your IvorySQL version and install its `ivy_duckdb` dependency. Follow the instructions for the same release to configure `ivy_moonlink` and mirror storage, whether building from source or deploying an image. + +In `postgresql.conf`, add `pg_duckdb` and `pg_mooncake` to `shared_preload_libraries`, keep the existing entries, and set `wal_level` to `logical`. If you installed from source and your release loads the DuckDB community Mooncake extension, set `duckdb.allow_community_extensions` to `true` as described in the project's installation guide. Restart the instance and create the extension in the target database. + +[source,sql] +---- +CREATE EXTENSION IF NOT EXISTS pg_mooncake CASCADE; +---- + +== Create a mirror and verify incremental replication + +In a test database, create the xref:v6.0/realtime_query.adoc#trades-example[sample table] with its primary key. Keep `trades` empty while creating `trades_iceberg`. + +[source,sql] +---- +CALL mooncake.create_table('trades_iceberg', 'trades'); +---- + +xref:v6.0/realtime_query.adoc#trades-data[Insert the sample data] and commit it, then wait for the mirror to apply the changes. This query should return two AMZN trades. + +[source,sql] +---- +SELECT count(*) AS trade_count, avg(price) AS average_price +FROM trades_iceberg +WHERE symbol = 'AMZN'; +---- + +Insert a third AMZN trade into the source. If autocommit is disabled in your client, commit the transaction before repeating the mirror query above. The count increases from 2 to 3 once the mirror applies the change. + +[source,sql] +---- +INSERT INTO trades VALUES (5, 'AMZN', '2024-06-05 10:20:00', 180); +---- + +== Check replication + +A mirror can take time to reflect a commit on the source. If the result remains stale, confirm the source commit and check the `ivy_moonlink` worker, the logical replication slot used for ingestion, and mirror storage. + +[source,sql] +---- +SELECT slot_name, active, restart_lsn, confirmed_flush_lsn +FROM pg_replication_slots +WHERE slot_type = 'logical'; +---- + +Identify the relevant slot in the result. Its activity and advancing replication positions help diagnose ingestion. Verify what users can actually see in the mirror by querying for a known change. See the xref:v6.0/htap/ivy_mooncake/design.adoc[ivy_mooncake technical design] for the data path and recovery behavior. diff --git a/EN/modules/ROOT/pages/v6.0/realtime_query.adoc b/EN/modules/ROOT/pages/v6.0/realtime_query.adoc new file mode 100644 index 00000000..95194484 --- /dev/null +++ b/EN/modules/ROOT/pages/v6.0/realtime_query.adoc @@ -0,0 +1,96 @@ += Real-time Query Analytics Quick Start +:sectnums: +:sectnumlevels: 5 + +IvorySQL offers two paths for real-time analytics. `ivy_duckdb` uses DuckDB to analyze existing IvorySQL row-store tables. `ivy_mooncake` uses `ivy_moonlink` to replicate transactional tables into Apache Iceberg columnstore mirrors, then uses DuckDB to run analytical queries. + +This guide uses the same `trades` table for both paths. Run the examples in a test database. + +== Set up a test environment + +The earlier documentation provides a `0.1` preview image with `pg_duckdb` and `pg_mooncake` already installed. You can use it to try both extensions locally. + +[source,bash] +---- +docker run --name ivy_mooncake \ + -e IVORYSQL_PASSWORD=password \ + -p 127.0.0.1:5432:5432 -p 127.0.0.1:1521:1521 \ + -v ivy_mooncake_data:/var/lib/ivorysql/data \ + -v ivy_mooncake_warehouse:/tmp/moonlink_iceberg \ + registry.highgo.com/mooncake/ivy_mooncake:0.1 +---- + +To install or deploy the extensions on IvorySQL 6.0, see the xref:v6.0/htap/ivy_duckdb/user_guide.adoc[ivy_duckdb user guide], the xref:v6.0/htap/ivy_mooncake/user_guide.adoc[ivy_mooncake user guide], and the xref:v6.0/release_notes.adoc[IvorySQL 6.0 release notes]. + +[[trades-example]] +== Create the sample table + +[source,sql] +---- +CREATE TABLE trades ( + id bigint PRIMARY KEY, + symbol text, + time timestamp, + price real +); +---- + +== Set up the columnstore mirror (optional) + +To try `ivy_mooncake`, create the mirror on an instance configured for logical replication before inserting the sample data. `CASCADE` also creates the required `pg_duckdb` extension. To try `ivy_duckdb` on its own, skip to <>. + +[source,sql] +---- +CREATE EXTENSION IF NOT EXISTS pg_mooncake CASCADE; + +CALL mooncake.create_table('trades_iceberg', 'trades'); +---- + +[[trades-data]] +== Insert the sample data + +[source,sql] +---- +INSERT INTO trades VALUES + (1, 'AMD', '2024-06-05 10:00:00', 119), + (2, 'AMZN', '2024-06-05 10:05:00', 207), + (3, 'AAPL', '2024-06-05 10:10:00', 155), + (4, 'AMZN', '2024-06-05 10:15:00', 151); +---- + +== Analyze the row-store table with ivy_duckdb + +After installing and preloading `pg_duckdb`, create the extension in the current database. Enable DuckDB execution in your analytics session and query `trades` directly. + +[source,sql] +---- +CREATE EXTENSION IF NOT EXISTS pg_duckdb; + +SET duckdb.force_execution = true; + +SELECT count(*) AS trade_count, avg(price) AS average_price +FROM trades +WHERE symbol = 'AMZN'; + +RESET duckdb.force_execution; +---- + +The query returns two trades with an average price of 179. For instructions on checking the execution plan, see the xref:v6.0/htap/ivy_duckdb/user_guide.adoc[ivy_duckdb user guide]. + +== Analyze the columnstore mirror with ivy_mooncake + +If you created `trades_iceberg`, wait for replication to apply the inserts, then run the same query against the mirror. + +[source,sql] +---- +SELECT count(*) AS trade_count, avg(price) AS average_price +FROM trades_iceberg +WHERE symbol = 'AMZN'; +---- + +After the mirror applies the sample inserts, it also returns two trades with an average price of 179. Continue writing trades to `trades`. `ivy_moonlink` replicates the committed changes. See the xref:v6.0/htap/ivy_mooncake/user_guide.adoc[ivy_mooncake user guide] to verify incremental replication. + +== Earlier documentation + +* https://github.com/IvorySQL/ivorysql_docs/blob/v5.6/EN/modules/ROOT/attachments/ivy_mooncake-technical-whitepaper-v1.0beta1.docx[ivy_mooncake Technical White Paper (V1.0 beta1)] +* https://github.com/IvorySQL/ivorysql_docs/blob/v5.6/EN/modules/ROOT/attachments/ivy_mooncake-user-manual-v1.0beta1.docx[ivy_mooncake User Manual (V1.0 beta1)]