--- warning: DO NOT CHANGE THIS MANUALLY, THIS IS GENERATED BY https://github.com/duckdb/community-extensions repository, check README there title: openivm excerpt: | DuckDB Community Extensions Incremental materialized views for DuckDB and DuckLake extension: name: openivm description: Incremental materialized views for DuckDB and DuckLake version: 0.1.0 language: C++ build: cmake use_merged_vcpkg_manifest: true license: MIT maintainers: - ila repo: github: openivm/openivm ref: 42f8eb08a1aa49b431af3055ab96e5418a153d97 docs: hello_world: | CREATE TABLE parcels (hub VARCHAR, weight_kg INTEGER); INSERT INTO parcels VALUES ('North', 4), ('North', 6), ('South', 3); CREATE MATERIALIZED VIEW hub_totals AS SELECT hub, count(*) AS parcels, sum(weight_kg) AS total_kg FROM parcels GROUP BY hub; SELECT * FROM hub_totals ORDER BY hub; -- ┌───────┬─────────┬──────────┐ -- │ hub │ parcels │ total_kg │ -- ├───────┼─────────┼──────────┤ -- │ North │ 2 │ 10 │ -- │ South │ 1 │ 3 │ -- └───────┴─────────┴──────────┘ INSERT INTO parcels VALUES ('North', 2), ('West', 5); PRAGMA refresh('hub_totals'); SELECT * FROM hub_totals ORDER BY hub; -- ┌───────┬─────────┬──────────┐ -- │ hub │ parcels │ total_kg │ -- ├───────┼─────────┼──────────┤ -- │ North │ 3 │ 12 │ -- │ South │ 1 │ 3 │ -- │ West │ 1 │ 5 │ -- └───────┴─────────┴──────────┘ extended_description: | Define materialized views in SQL, including joins, grouped aggregates, `DISTINCT`, and `UNION ALL`. OpenIVM also supports many CTEs and window queries. It applies source changes *incrementally* where it can and recomputes the view in full when the query requires it. [Supported operators](https://github.com/openivm/openivm#supported-operators) · [Refresh strategies](https://github.com/openivm/openivm/blob/main/docs/refresh/refresh-strategies.md) Use `PRAGMA refresh_pipeline` to refresh a set of views in dependency order, with shared dependencies processed once. Set `openivm_cascade_refresh` to include **upstream** views that feed your targets, **downstream** views that depend on them, or **both**. OpenIVM uses DuckLake snapshots to track *source changes*. [Pipeline refreshes](https://github.com/openivm/openivm/blob/main/docs/refresh/pipelines.md) · [DuckLake guide](https://github.com/openivm/openivm/blob/main/docs/ducklake.md) OpenIVM's **background refresh daemon** (experimental feature) runs scheduled refreshes while the database is open. Set a schedule with `REFRESH EVERY '5 minutes'` in the view definition. [Automatic refresh](https://github.com/openivm/openivm/blob/main/docs/refresh/automatic-refresh.md) ### DuckLake Example Store visits and their running totals in a local DuckLake. A late-arriving row changes the running total for later dates in the same room. ```sql INSTALL ducklake; LOAD ducklake; ATTACH 'ducklake:openivm_demo.ducklake' AS lake (DATA_PATH 'openivm_demo_data'); CREATE TABLE lake.main.visits (room VARCHAR, visit_date DATE, visitors INTEGER); INSERT INTO lake.main.visits VALUES ('East', DATE '2026-01-01', 12), ('East', DATE '2026-01-03', 5), ('West', DATE '2026-01-01', 8); CREATE MATERIALIZED VIEW lake.main.room_running_totals AS SELECT room, visit_date, visitors, sum(visitors) OVER ( PARTITION BY room ORDER BY visit_date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) AS running_total FROM lake.main.visits; SELECT * FROM lake.main.room_running_totals ORDER BY room, visit_date; -- ┌──────┬────────────┬──────────┬───────────────┐ -- │ room │ visit_date │ visitors │ running_total │ -- ├──────┼────────────┼──────────┼───────────────┤ -- │ East │ 2026-01-01 │ 12 │ 12 │ -- │ East │ 2026-01-03 │ 5 │ 17 │ -- │ West │ 2026-01-01 │ 8 │ 8 │ -- └──────┴────────────┴──────────┴───────────────┘ INSERT INTO lake.main.visits VALUES ('East', DATE '2026-01-02', 4); PRAGMA refresh('lake.main.room_running_totals'); SELECT * FROM lake.main.room_running_totals ORDER BY room, visit_date; -- ┌──────┬────────────┬──────────┬───────────────┐ -- │ room │ visit_date │ visitors │ running_total │ -- ├──────┼────────────┼──────────┼───────────────┤ -- │ East │ 2026-01-01 │ 12 │ 12 │ -- │ East │ 2026-01-02 │ 4 │ 16 │ -- │ East │ 2026-01-03 │ 5 │ 21 │ -- │ West │ 2026-01-01 │ 8 │ 8 │ -- └──────┴────────────┴──────────┴───────────────┘ ``` ### Inspect the generated SQL OpenIVM generates SQL so you can inspect the refresh logic, run it from a client or on a server, and adapt it to other SQL dialects. SQL file export is off by default. Run this in the same session as the first example to save the refresh SQL in the current working directory. ```sql SET openivm_files_path = '.'; -- Add a change for the refresh to apply. INSERT INTO parcels VALUES ('South', 4); PRAGMA refresh('hub_totals'); -- Show the exact paths and which files exist. PRAGMA openivm_files('hub_totals'); ``` Look for the refresh file `openivm_upsert_queries_{view_key}.sql` in the output. See the [OpenIVM documentation](https://openivm.org/) for more examples and [performance optimizations](https://github.com/openivm/openivm/tree/main/docs/optimizations). Questions and feature requests are welcome in the [OpenIVM issue tracker](https://github.com/openivm/openivm/issues). extension_star_count: 119 extension_star_count_pretty: 119 extension_download_count: 43 extension_download_count_pretty: 43 image: '/images/community_extensions/social_preview/preview_community_extension_openivm.png' layout: community_extension_doc --- ### Compatibility Matrix This table covers all DuckDB releases that have not reached [end-of-life](https://duckdb.org/release_calendar), including LTS releases, and shows the 2 most recent patch releases of each. Older patch releases are not listed, but the extension may be available for them as well.
| Platform | 1.5.5 | 1.5.6 | 2.0.0 | 2.0.1 | | :--- | :---: | :---: | :---: | :---: | | Linux AMD64 | ❌ | ❌ | ❌ | ✅ | | Linux ARM64 | ❌ | ❌ | ❌ | ✅ | | macOS AMD64 | ❌ | ❌ | ❌ | ❌ | | macOS ARM64 | ❌ | ❌ | ❌ | ✅ | | Windows AMD64 | ❌ | ❌ | ❌ | ✅ | | Windows ARM64 | ❌ | ❌ | ❌ | ❌ | | WebAssembly | ❌ | ❌ | ❌ | ✅ | ### Installing and Loading ```sql INSTALL {{ page.extension.name }} FROM community; LOAD {{ page.extension.name }}; ``` {% if page.docs.hello_world %} ### Example ```sql {{ page.docs.hello_world }}``` {% endif %} {% if page.docs.extended_description %} ### About {{ page.extension.name }} {{ page.docs.extended_description }} {% endif %} ### Added Functions | function_name | function_type | description | comment | examples | |---------------------------------|---------------|-------------|---------|----------| | ComputeDelta | table | NULL | NULL | | | __openivm_spark_expression | scalar | NULL | NULL | | | add_months | scalar | NULL | NULL | | | openivm_compile_with_facts | table | NULL | NULL | | | openivm_create_delta_from_data | table | NULL | NULL | | | openivm_execute_drop_schema | table | NULL | NULL | | | openivm_execute_drop_table | table | NULL | NULL | | | openivm_execute_drop_view | table | NULL | NULL | | | openivm_files | pragma | NULL | NULL | | | openivm_internal_value_key | scalar | NULL | NULL | | | openivm_record_source_watermark | scalar | NULL | NULL | | | openivm_source_columns | table | NULL | NULL | | | refresh | pragma | NULL | NULL | | | refresh_cost | pragma | NULL | NULL | | | refresh_cross_system | pragma | NULL | NULL | | | refresh_history | pragma | NULL | NULL | | | refresh_options | pragma | NULL | NULL | | | refresh_pipeline | pragma | NULL | NULL | | | refresh_start_daemon | pragma | NULL | NULL | | | refresh_status | pragma | NULL | NULL | | ### Overloaded Functions This extension does not add any function overloads. ### Added Types This extension does not add any types. ### Added Settings | name | description | input_type | scope | aliases | typed_value | |------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------|--------|---------|-------------| | allow_parser_override_extension | Allow extensions to override the current parser. | VARCHAR | GLOBAL | [] | fallback | | openivm_adaptive_backoff | auto-increase refresh interval when refresh takes longer than the interval | BOOLEAN | GLOBAL | [] | true | | openivm_adaptive_refresh | experimental: enable adaptive cost model (when off, always use IVM) | BOOLEAN | GLOBAL | [] | false | | openivm_archive_compiled_sql | archive executed CREATE and refresh SQL in metadata tables | BOOLEAN | GLOBAL | [] | false | | openivm_cascade_refresh | cascade mode: off, upstream, downstream, or both | VARCHAR | GLOBAL | [] | downstream | | openivm_compact_deltas | compact raw delta rows into net logical Z-set deltas before refresh | BOOLEAN | GLOBAL | [] | true | | openivm_compiled_sql_retention | maximum archived versions per view and operation | BIGINT | GLOBAL | [] | 10 | | openivm_cost_decay | decay factor for learned cost model regression (0.0-1.0, higher = slower adaptation) | DOUBLE | GLOBAL | [] | 0.9 | | openivm_daemon_wake_seconds | seconds between the refresh daemon's checks for due views | BIGINT | GLOBAL | [] | 30 | | openivm_disable_daemon | disable this database's refresh daemon (for shadow/compile-only DBs); PRAGMA refresh_start_daemon starts one anyway | BOOLEAN | GLOBAL | [] | false | | openivm_distinct_aux_state | use auxiliary count state for inner DISTINCT under aggregate (DBSP distinct(R)=sgn(R[t]) — emit ±1 only on count transitions across zero) instead of GROUP_RECOMPUTE. Single-source views only in v0; multi-source views fall back to GROUP_RECOMPUTE. | BOOLEAN | GLOBAL | [] | false | | openivm_ducklake_nterm | use N-term telescoping for DuckLake joins (vs 2^N-1 inclusion-exclusion) | BOOLEAN | GLOBAL | [] | true | | openivm_emit_spark_hints | emit Spark optimizer hints in target_dialect=spark compiled refresh SQL | BOOLEAN | GLOBAL | [] | false | | openivm_enable_data_dependent_optimizers | optimize the finished incremental plan using current delta statistics | BOOLEAN | GLOBAL | [] | true | | openivm_enable_view_matching | enable smart view matching at query time (master flag) | BOOLEAN | GLOBAL | [] | false | | openivm_files_path | path for compiled SQL reference files | VARCHAR | GLOBAL | [] | NULL | | openivm_fk_pruning | prune inclusion-exclusion join terms using FK constraints | BOOLEAN | GLOBAL | [] | true | | openivm_full_outer_merge | use incremental MERGE for FULL OUTER JOIN aggregates (Zhang & Larson) instead of group-recompute | BOOLEAN | GLOBAL | [] | true | | openivm_having_merge | use MERGE for HAVING views (store all groups, VIEW filters) instead of group-recompute | BOOLEAN | GLOBAL | [] | true | | openivm_input_dialect | SQL dialect materialized-view bodies are written in: duckdb (default) or spark | VARCHAR | GLOBAL | [] | duckdb | | openivm_internal_schema | schema for OpenIVM internal maintenance tables within each data catalog; empty keeps them beside the materialized view and its sources | VARCHAR | GLOBAL | [] | | | openivm_late_append_window_trim | opt in to pruning strictly older changed rows from eligible rank-1 lookup refresh keys | BOOLEAN | GLOBAL | [] | false | | openivm_left_join_merge | use incremental MERGE for LEFT JOIN aggregates (Larson & Zhou) instead of group-recompute | BOOLEAN | GLOBAL | [] | true | | openivm_match_estimate_ttl_ms | max staleness (ms) for cached pending-delta-row estimate before refresh | BIGINT | GLOBAL | [] | 5000 | | openivm_match_log_decisions | log per-query matcher decisions to openivm_match_log | BOOLEAN | GLOBAL | [] | false | | openivm_match_log_retention | max rows per query_hash retained in openivm_match_log | BIGINT | GLOBAL | [] | 50 | | openivm_match_strategies | allowed strategies (csv): 'tier1','tier2','tier3','partial','full' or 'all' | VARCHAR | GLOBAL | [] | all | | openivm_metadata_catalog | attached catalog that stores OpenIVM metadata (empty: each native view catalog, or the default database for external catalogs) | VARCHAR | GLOBAL | [] | | | openivm_metadata_lease_seconds | seconds a client of a remote metadata catalog owns a view's refresh before another client may take it over (renewed while the refresh runs) | BIGINT | GLOBAL | [] | 600 | | openivm_metadata_schema | schema that stores OpenIVM metadata; empty retains its existing schema | VARCHAR | GLOBAL | [] | | | openivm_minmax_incremental | use GREATEST/LEAST for MIN/MAX when deltas are insert-only | BOOLEAN | GLOBAL | [] | true | | openivm_predicate_oracle | predicate implication oracle: 'syntactic', 'interval' (default), or 'sat' (stub) | VARCHAR | GLOBAL | [] | interval | | openivm_profile_refresh | record per-step materialized view refresh timings | BOOLEAN | GLOBAL | [] | false | | openivm_profile_retention_days | delete refresh profile rows older than this many days when profiling is written | BIGINT | GLOBAL | [] | 31 | | openivm_refresh_mode | refresh strategy: incremental, full, or auto (auto never forces full; see openivm_adaptive_refresh) | VARCHAR | GLOBAL | [] | incremental | | openivm_regular_nterm | use N-term telescoping for compile-only regular inner joins | BOOLEAN | GLOBAL | [] | true | | openivm_regular_nterm_left | extend compile-only N-term telescoping to LEFT-join projection views | BOOLEAN | GLOBAL | [] | true | | openivm_running_window_incremental | extend cumulative running window aggregates for append-only suffix batches | BOOLEAN | GLOBAL | [] | false | | openivm_shared_native_publication | share storage for unordered native projection materialized views | BOOLEAN | GLOBAL | [] | false | | openivm_skip_aggregate_delete | skip zero-row DELETE for grouped aggregates when deltas are insert-only | BOOLEAN | GLOBAL | [] | true | | openivm_skip_empty_deltas | skip refresh or join terms when deltas are empty | BOOLEAN | GLOBAL | [] | true | | openivm_skip_projection_delete | skip DELETE and consolidation for projections when deltas are insert-only | BOOLEAN | GLOBAL | [] | true | | openivm_snapshot_publication | publish unordered DuckLake materialized views through retained snapshots | BOOLEAN | GLOBAL | [] | false | | openivm_spark_expression_markers | enable compiler-only opaque Spark expression markers | BOOLEAN | GLOBAL | [] | false | | openivm_stateful_auxstate | use persisted auxiliary state for stateful operators such as COUNT(DISTINCT) instead of GROUP_RECOMPUTE | BOOLEAN | GLOBAL | [] | false | | openivm_test_concurrent_sql | testing only: SQL that a concurrent_commit_* fail point commits from another connection during the first refresh attempt | VARCHAR | GLOBAL | [] | | | openivm_test_fail_point | testing only: simulate a crash at a refresh protocol step (after_intent, after_view_delta, before_data_commit, after_data_commit), a failing data statement (data_statement_error), a lease takeover (lease_lost_before_data, lease_lost_mid_data, lease_lost_before_watermark) or a concurrent commit (concurrent_commit_before_data, concurrent_commit_after_data, concurrent_commit_then_data_error after the interruption marker, followed by a failing data statement, or concurrent_commit_before_create between planning and running a CREATE MATERIALIZED VIEW program) | VARCHAR | GLOBAL | [] | | | temp_directory | Set the directory to which temporary files are written. | VARCHAR | GLOBAL | [] | post.db.tmp |