DuckDB is an analytical in-process SQL database management system http://www.duckdb.org
  • C++ 77.9%
  • sql 16%
  • Python 2.6%
  • C 2.5%
  • Swift 0.4%
  • Other 0.4%
Find a file
Hannes Mühleisen 30c64e17ec
MATCH_RECOGNIZE: Bound match attempt steps (#26028)
MATCH_RECOGNIZE contains a complexity
[boobytrap](https://youtu.be/aDoorU4X6Jk?t=2051) as specified by ISO
with exponential(!) complexity.

Consider this query:
```SQL
SELECT count(*) FROM (VALUES(1),(2),(3),(4),(5),(6),(7),(8),(9),(10)) x(y)
MATCH_RECOGNIZE (
  ORDER BY y
  MEASURES 1 AS m
  PATTERN ((CALM | DOG | SIPS | TEA | HIS | SMALL | HOME | BURNS | QUITE)* HOT)
  DEFINE HOT AS HOT.y < avg(CALM.y) - avg(DOG.y)
);
```

with only 10 rows of input, this takes more than 5 mins to finish on
DBMS X & Trino (and DuckDB, before this PR). The computational
complexity is `O(m^n)` where `n` is the number of rows(!) and `m` is the
number of pattern variables in the inner parens. This PR adds a new
setting `match_recognize_max_states` that limits the matching steps. If
exceeded, the following message is now shown:

> MATCH_RECOGNIZE gave up on a match after exploring 1000000 states. A
DEFINE condition here reads the match itself and not only the row it
tests, so the matcher has to keep the different ways of matching the
same row apart, and their number grows quickly with the size of the
partition. Narrow the PATTERN or the DEFINE conditions so that fewer
ways reach the same row, or raise match_recognize_max_states.
2026-09-23 14:55:39 +00:00
.github add SUBMODULES database-connector to sqlite_scanner.cmake 2026-09-11 15:01:26 +02:00
api_spec Capi make set target optional (#25806) 2026-09-18 11:23:03 +00:00
benchmark Count a filtered window frame with a segment tree (#25935) 2026-09-19 19:06:45 +00:00
data Merge origin/main into match-recognize 2026-09-14 14:40:51 +02:00
examples tidy 2026-06-19 15:09:34 +02:00
extension Parquet: avoid a branch in the dictionary filter loop 2026-09-22 10:13:17 +02:00
logo
scripts Merge origin/main into match-recognize 2026-09-15 16:02:57 +02:00
src MATCH_RECOGNIZE: Bound match attempt steps (#26028) 2026-09-23 14:55:39 +00:00
test MATCH_RECOGNIZE: Bound match attempt steps (#26028) 2026-09-23 14:55:39 +00:00
third_party Experiment: Remove manually unrolled memory routines (#25380) 2026-09-08 09:36:20 +00:00
tools Capi make set target optional (#25806) 2026-09-18 11:23:03 +00:00
.clang-format remove empty lines at the start of blocks 2025-10-28 09:00:51 +01:00
.clang-tidy Make clang-tidy checks easier to read 2026-04-20 10:49:45 +02:00
.clangd Disable clang-tidy checks for some excluded dirs 2026-04-20 10:49:19 +02:00
.codecov.yml
.editorconfig
.gitattributes Let GitHub render *.test files as SQL 2025-03-06 10:10:24 +01:00
.gitignore rework task scheduler, split into multiple pools and queues 2026-05-28 17:03:48 +02:00
.sanitizer-leak-suppressions.txt And text pool 2025-01-27 12:57:06 +01:00
.sanitizer-thread-suppressions.txt remove AddToEvictionQueue tsan suppression 2026-06-15 13:57:19 +02:00
AGENTS.md Fix outdated paths in AGENTS.md 2026-09-11 00:50:57 -04:00
AI_POLICY.md add ai policy 2026-06-03 11:21:13 +02:00
CITATION.cff
CLAUDE.md create AGENTS.md and link CLAUDE.md 2026-06-04 22:41:26 -04:00
CMakeLists.txt Move SQL identity certification into core registration 2026-09-11 09:24:10 +02:00
CODE_OF_CONDUCT.md
CONTRIBUTING.md Add note on enums 2026-06-26 08:34:29 +02:00
Doxyfile Fix typos in errors and comments 2026-04-22 08:53:31 +02:00
DuckDBConfig.cmake.in Remove the ICU dependency 2026-08-01 15:21:31 +02:00
DuckDBConfigVersion.cmake.in Normalize version number in CMake version config 2026-05-28 23:18:43 +08:00
LICENSE Update copyright year 2026-01-26 18:01:34 +01:00
Makefile Use consistent naming for static/shared libs 2026-09-08 07:21:53 +02:00
README.md Update Labs URL 2026-05-27 13:28:57 +02:00
SECURITY.md update security.md 2026-08-17 13:13:31 +02:00

DuckDB logo

Github Actions Badge discord Latest Release

DuckDB

DuckDB is a high-performance analytical database system. It is designed to be fast, reliable, portable, and easy to use. DuckDB provides a rich SQL dialect with support far beyond basic SQL. DuckDB supports arbitrary and nested correlated subqueries, window functions, collations, complex types (arrays, structs, maps), and several extensions designed to make SQL easier to use.

DuckDB is available as a standalone CLI application and has clients for Python, R, Java, Wasm, etc., with deep integrations with packages such as pandas and dplyr.

For more information on using DuckDB, please refer to the DuckDB documentation.

Installation

If you want to install DuckDB, please see our installation page for instructions.

Data Import

For CSV files and Parquet files, data import is as simple as referencing the file in the FROM clause:

SELECT * FROM 'myfile.csv';
SELECT * FROM 'myfile.parquet';

Refer to our Data Import section for more information.

SQL Reference

The documentation contains a SQL introduction and reference.

Development

For development, DuckDB requires CMake, Python 3 and a C++17 compliant compiler. In the root directory, run make to compile the sources. For development, use make debug to build a non-optimized debug version. You should run make unit and make allunit to verify that your version works properly after making changes. To test performance, you can run BUILD_BENCHMARK=1 BUILD_TPCH=1 make and then perform several standard benchmarks from the root directory by executing ./build/release/benchmark/benchmark_runner. The details of benchmarks are in our Benchmark Guide.

Please also refer to our Build Guide and Contribution Guide.

Support

See the Support Options page and the dedicated endoflife.date page.