-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Initial version of DuckDB engine for MariaDB based on DuckDB 1.5.2. #4903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
114 commits
Select commit
Hold shift + click to select a range
34f4099
Port AliSQL DuckDB engine basics to MariaDB part 2
drrtuy 2416e4d
fix(dml,duckdb): Set table->write_set bitmap in rnd_next to convert t…
drrtuy 31e62e9
feat(dml): direct UPDATE and DELETE support
drrtuy ac02354
feat(duckdb): migrate DuckDB-specific variables.
drrtuy a25bbd2
feat(DDL): Various DDL fixes, e.g. RENAME TABLE and ALTER TABLE engin…
drrtuy 8e4316e
fix(dml): various type-related fixes for batch processing + initial M…
drrtuy fedcf04
fix(ddl): various ALTER fixes for duckdb.
drrtuy 7757681
chore(mtr): disable.def to streamline MTR tests verification.
drrtuy c6fa229
chore(duckdb): use upstream DuckDB 1.2.1
drrtuy 732e2c9
feat(duckdb): switch to upstream DuckDB 1.2.1.
drrtuy 77834dc
fix(duckdb): LENGTH() over VARCHAR canonical name is strlen that brea…
drrtuy 8064f34
chore(duckdb): update to upstream duckdb 1.3.2.
drrtuy 07e0c43
chore(packaging): initial version of DEB and RPM packaging for DuckDB…
drrtuy e4b5892
chore(duckdb): use duckdb fork with patches applied.
drrtuy ea9d564
chore(duckdb): Add drrtuy/duckdb (mdb-v.1.3.2) as nested submodule
drrtuy 9a84811
chore(build): fix paths to server modules.
drrtuy b4a85a5
fix(): use original query b/c query printer does not use DuckDB-suppo…
drrtuy c57f845
chore(deb): deb packaging utilities.
drrtuy e72782c
fix(): a number of review fixes.
drrtuy a893a05
chore(): remove dead yet code.
drrtuy bbb54a5
chore(): MariaDB Foundation copyright stanza.
drrtuy ea26665
chore(license): add extra GPL v2 license text.
drrtuy a2e5582
chore(): README
drrtuy 641743a
chore(license): add extra GPL v2 license text.
drrtuy 9858982
feat(collations): support collate stanzas for CREATE TABLE.
drrtuy 0806d8f
feat(collations): fixes for collations tests.
drrtuy 1cf07f1
fix(test): fixes 1 hour off issue caused by DST and a number of colla…
drrtuy ccb2345
feat(CEJ): in-memory CEJ algo.
drrtuy b0c0751
feat(): UNION SELECT_LEX pushdown.
drrtuy 4f8f129
fix(ddl,tests): specialize CREATE TABLE error.
drrtuy 9039d53
chore(): use upstream DuckDB.
drrtuy 7f16343
feat(cte): r-/CTE with CEJ support.
drrtuy 97a3ad6
chore(): compilation fixes for MDB 11.4
drrtuy 92a1304
chore(mtr): use deterministic charset in tests.
drrtuy c6e35b3
fix(mtr): MTR passes with CS MDB 11.4
drrtuy 3877bc1
chore(mtr): take default utf8mb4 collation difference difference b/w …
drrtuy 489fb8b
chore(build): add -Werror option.
drrtuy 0c1ac40
chore(): various compilation warnings fixes.
drrtuy 93cd438
chore(build): ninja build error fix.
drrtuy dccccef
chore(build): Debug build fixes.
drrtuy 2169034
chore(deb): packaging fixes.
drrtuy 37ea03d
cleaner build output
LaGrunge 752ace6
run_mtr.sh: MTR runnner
LaGrunge 0ee00ee
fix(mtr): make 11 tests extern compatible
LaGrunge 0326139
fix(run_mtr.sh): fix noextern mode
LaGrunge f9abca2
feat(tests): fuzzy search for menu
LaGrunge db8f551
fix(mtr): disabled warnings and fixed timezone in two MTR tests.
drrtuy 20e646a
fix(mtr): add missing test includes and fix charset for disabled tests
LaGrunge 2733543
feat(errors): add DuckDB-specific error codes with codegen
LaGrunge 42e99f3
fix(mtr): enable truncate_and_maintenance and duckdb_set_operation tests
LaGrunge 8f5792b
fix(mtr): enable duckdb_monitor test
LaGrunge c43c4eb
fix(monitor): count rows in direct_delete/update, adapt monitor test
LaGrunge 8690e5f
fix(mtr): enable duckdb_db_table_strconvert test
LaGrunge ff83c84
Merge pull request #2 from drrtuy/better1
drrtuy 41959e6
Initial Claude.md
LaGrunge cbd59be
fix(build): adapt to MariaDB 11.4 API changes
LaGrunge 52f8320
Revert "fix(build): adapt to MariaDB 11.4 API changes"
drrtuy ebb6d68
chore(build): fix custom command target dependencies.
drrtuy 83b43c3
chore(mtr): added an explicit database to the tests so that MDB does …
drrtuy 2c8b969
chore(): README path update and conf file development leftovers cleanup.
drrtuy c928b6c
docs: add detailed analysis and work plan for 31 disabled tests
LaGrunge 4fbda0b
fix(errors): use ER_DUCKDB_TABLE_STRUCT_INVALID for ALTER structural
LaGrunge ac238c9
fix(mtr): update rename_duckdb_table result for new error codes
LaGrunge de56472
docs: update disabled tests plan — 17/47 enabled, item 3 done
LaGrunge b6b1066
fix(ddl): reject ALTER TABLE on tables without PK when require_primar…
LaGrunge 1a2db4f
fix(mtr): enable create_table_constraint test
LaGrunge 5388866
fix(mtr): add test cleanup to restore database charset after tests
LaGrunge 96de594
docs: update plan — 19/47 enabled, add DuckDB upstream upgrade item
LaGrunge 07e708d
feat(upstream): upgrade DuckDB submodule v1.3.2 → v1.5.2
LaGrunge c7f1c9b
docs: update plan — DuckDB v1.5.2 done, add compound ALTER regression
LaGrunge 1761f62
fix(ddl): execute compound ALTER operations separately for DuckDB v1.5
LaGrunge 667999f
fix(config): propagate appender_allocator_flush_threshold to DuckDB v1.5
LaGrunge 1a65c21
feat(pushdown): add MariaDB SQL compatibility macros and WITH ROLLUP …
LaGrunge 3b080be
feat(pushdown): add more MariaDB SQL compatibility macros
LaGrunge e65f2ee
fix(decimal): map DECIMAL(>38) to DOUBLE, default use_double_for_deci…
LaGrunge 1cbee60
fix(mtr): add have_duckdb.inc and max_allowed_packet to feature_duckd…
LaGrunge 0158ce8
feat(udf): register native DuckDB scalar function overloads for Maria…
LaGrunge af85291
feat(compat): improve bin/oct for string args, add hex(numeric), loca…
LaGrunge 33cff77
feat(compat): port full hex/oct/bin from AliSQL, add locate C++ UDF
LaGrunge d1973fb
feat(compat): add mid() UDF, CONVERT→CAST rewrite in pushdown
LaGrunge 872b6d9
feat(pushdown): add CROSS JOIN, REGEXP, NOT REGEXP rewrites + mid UDF
LaGrunge 529c890
feat(compat): implement regexp_instr, regexp_replace, regexp_substr,
LaGrunge 15fd9e2
feat(compat): add strcmp, substring_index, to_base64 macros, RLIKE
LaGrunge a6649b1
feat(compat): override length(VARCHAR) and ascii(VARCHAR) for MariaDB
LaGrunge 4725234
feat(compat): addtime/subtime C++ UDFs, convert_tz macro, LIMIT and
LaGrunge cdca05b
feat(compat): curdate/curtime macros, STRAIGHT_JOIN/index hints/LIMIT
LaGrunge cadef8b
feat(compat): CURRENT_TIME(N)/CURRENT_DATE()/CURRENT_TIMESTAMP() rewr…
LaGrunge 4078135
fix(rebase issues): Some tests are broken now, a big thanx
LaGrunge 26bbf60
fix(mtr): trim couple tests to pass on U24.04.
drrtuy 55a6ac2
chore(build): install build dependencies in build.sh.
drrtuy a174928
chore(): docs updates based on the recent changes.
drrtuy 433ae89
fix(build): now DuckDB core extensions are statically linked instead …
drrtuy 4928b46
fix(pushdown): skip-list of all escaped strings to avoid SQL expressi…
drrtuy 19b7c8b
fix(pushdown): fix for STRAIGHT_JOIN, various JOIN re-write cases and…
drrtuy bf703f9
chore(build) preparation for code refactoring.
drrtuy a541453
chore(build): refactor code breaking it into separate modules.
drrtuy ca6a30e
feat(runtime): fiber runtime based on ASM borrowed from libmariadb + …
drrtuy 15fd76b
feat(cej): MDB tables scan now uses mysql_execute_command to to lever…
drrtuy 2b59dea
fix(cej): WHERE predicate now does not contain alias or table name in…
drrtuy e663297
fix(cej): escape column names, remove bin objects from the repo, add …
drrtuy eff6113
chore(test): fix flacky cross_join_where test.
drrtuy fc00787
chore(): avoid compilation error for the fiber test TU.
drrtuy 1639aeb
fix(build):thread local maps with default TLS model got broken with M…
drrtuy 612480e
chore(): update documentation.
drrtuy fe39d73
Merge https://github.com/drrtuy/duckdb-engine into 11.4
vuvova ac9ae6a
Merge https://github.com/mariadb/duckdb-engine into 11.4
vuvova a699575
add submodule, most-merge fixes
vuvova 2b941ae
don't modify server's error messages
vuvova 2be1c96
Expose static symbols leveraged in DuckDB to stringify WHERE conditio…
drrtuy a9dd99f
improve ExternalProject
vuvova d010dca
class != struct
vuvova 36ba420
correct duckdb engine maturity for a first release
vuvova 71cafa8
duckdb-engine rpm/deb fixes
vuvova cc40fe5
change duckdb_query_udf to run_in_duckdb function plugin
vuvova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## What This Is | ||
|
|
||
| DuckDB storage engine plugin for MariaDB. Creates tables with `ENGINE=DuckDB` that store data in DuckDB's columnar format and execute analytical queries through DuckDB's vectorized engine. Lives under `storage/duckdb/` in the MariaDB server tree. | ||
|
|
||
| ## Build | ||
|
|
||
| ```bash | ||
| # Build + install + start MariaDB (most common during development) | ||
| ./build.sh -S -t Debug | ||
|
|
||
| # CI mode (build only, no install) | ||
| ./build.sh -c -t Debug | ||
|
|
||
| # Build with packages | ||
| ./build.sh -p -t RelWithDebInfo | ||
| ``` | ||
|
|
||
| The build directory is created as a sibling: `../DuckdbBuildOf_<source_dir_name>/`. DuckDB itself is built from source at `third_parties/duckdb/` via `ExternalProject_Add` and merged into a single `libduckdb_bundle.a`. | ||
|
|
||
| ## Tests (MTR) | ||
|
|
||
| Tests use MariaDB's MTR (MySQL Test Runner) framework. Test files live in `mysql-test/duckdb/t/` with expected results in `mysql-test/duckdb/r/`. | ||
|
|
||
| ```bash | ||
| # Run a single test | ||
| ./run_mtr.sh create_table_column | ||
|
|
||
| # Run and record new expected output | ||
| ./run_mtr.sh -r create_table_column | ||
|
|
||
| # Run all tests | ||
| ./run_mtr.sh -a | ||
|
|
||
| # Run against an externally running MariaDB | ||
| ./run_mtr.sh -e create_table_column | ||
|
|
||
| # Run all against extern server | ||
| ./run_mtr.sh -a -e | ||
| ``` | ||
|
|
||
| ## Architecture | ||
|
|
||
| All engine code is in the `myduck` namespace (except `ha_duckdb` which is in global scope per MariaDB handler convention). | ||
|
|
||
| ### Key components | ||
|
|
||
| - **`ha_duckdb`** (`ha_duckdb.cc/h`) — MariaDB `handler` subclass. Entry point for all storage engine operations (open, close, read, write, DDL). Implements row-at-a-time interface for MariaDB, translating to DuckDB batch operations. | ||
|
|
||
| - **`DuckdbManager`** (`duckdb_manager.cc/h`) — Singleton owning the `duckdb::DuckDB` instance. Created once at plugin init, creates connections for each thread. Database file stored as `duckdb.db` in MariaDB data directory. | ||
|
|
||
| - **`DuckdbThdContext`** (`duckdb_context.cc/h`) — Per-thread context holding a `duckdb::Connection`, transaction state, and appenders. Attached to MariaDB's THD. Manages BEGIN/COMMIT/ROLLBACK lifecycle and session variable propagation (timezone, optimizer flags, collation). | ||
|
|
||
| - **DDL/DML Convertors** (`ddl_convertor.cc/h`, `dml_convertor.cc/h`) — Translate MariaDB SQL structures (TABLE, Field, Alter_info) into DuckDB-compatible SQL strings. Handle identifier quoting differences (MariaDB backticks → DuckDB double quotes) and type mapping. | ||
|
|
||
| - **`DeltaAppender`** (`delta_appender.cc/h`) — Batched write path. Accumulates INSERT/UPDATE/DELETE rows using DuckDB's Appender API into a temporary buffer table, then flushes as a single DuckDB DML statement at commit time. `DeltaAppenders` manages per-table appender instances. | ||
|
|
||
| - **Select handler / Query pushdown** (`ha_duckdb_pushdown.cc/h`) — Implements MariaDB's `select_handler` interface to push entire SELECT queries down to DuckDB. Registered via `hton->create_select` and `hton->create_unit`. Supports pure-DuckDB queries and cross-engine joins. | ||
|
|
||
| - **Cross-engine scan** (`cross_engine_scan.cc/h`) — Enables DuckDB to read from non-DuckDB tables (e.g. InnoDB) during cross-engine joins. Registers a `_mdb_scan` table function and a replacement scan callback in DuckDB. Uses a thread-local registry of external tables. | ||
|
|
||
| - **Type mapping** (`duckdb_types.cc/h`) — Converts between MariaDB field types and DuckDB types. `store_duckdb_field_in_mysql_format()` reads DuckDB values back into MariaDB row format. | ||
|
|
||
| ### SQL generation conventions | ||
|
|
||
| All generated SQL must use **double quotes** for identifiers (DuckDB follows SQL standard), not backticks. The `SELECT_LEX::print()` output from MariaDB uses backticks and must be post-processed. See `docs/mariadb-duckdb-incompatibilities.md` for known function name rewrites and type mapping issues. | ||
|
|
||
| ### DuckDB source and patches | ||
|
|
||
| DuckDB source is at `third_parties/duckdb/` (git submodule). No patches are applied — all compatibility is handled at runtime via `duckdb_mysql_compat.cc`. The build produces a static library; `_GLIBCXX_DEBUG` is explicitly undefined in CMakeLists.txt to avoid ABI mismatch with MariaDB's debug build. | ||
|
|
||
| ### Configuration | ||
|
|
||
| `duckdb.cnf` — MariaDB config snippet that loads `ha_duckdb.so`. Installed to `/etc/my.cnf.d/`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| IF("NO" STREQUAL "${PLUGIN_DUCKDB}") | ||
| return() | ||
| ENDIF() | ||
|
vuvova marked this conversation as resolved.
vuvova marked this conversation as resolved.
|
||
|
|
||
| IF(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux") | ||
| MESSAGE_ONCE(duckdb "DuckDB: not Linux, skipping") | ||
| return() | ||
| ENDIF() | ||
|
|
||
| IF(NOT (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR | ||
| CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")) | ||
| MESSAGE_ONCE(duckdb "DuckDB: not x86_64 or aarch64, skipping") | ||
| return() | ||
| ENDIF() | ||
|
vuvova marked this conversation as resolved.
|
||
|
|
||
| # Check C++17 compiler support | ||
| MY_CHECK_CXX_COMPILER_FLAG("-std=c++17") | ||
| IF(NOT have_CXX__std_c__17) | ||
| MESSAGE_ONCE(duckdb "DuckDB: C++ compiler does not support -std=c++17, skipping") | ||
| RETURN() | ||
| ENDIF() | ||
|
|
||
| # libduckdb_bundle.a is built without debug STL wrappers. | ||
| # Mismatched _GLIBCXX_DEBUG changes sizeof(std::vector) → SIGSEGV. | ||
| SET(CMAKE_CXX_FLAGS_DEBUG | ||
| "${CMAKE_CXX_FLAGS_DEBUG} -U_GLIBCXX_DEBUG -U_GLIBCXX_ASSERTIONS") | ||
|
|
||
| INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/duckdb.cmake) | ||
| INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/duckdb_target_setup.cmake) | ||
|
|
||
| # Provide MariaDB server include paths to sub-libraries. | ||
| # MYSQL_ADD_PLUGIN normally does this, but it runs after ADD_SUBDIRECTORY. | ||
| INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include | ||
| ${CMAKE_SOURCE_DIR}/sql | ||
| ${CMAKE_BINARY_DIR}/include | ||
| ${PCRE_INCLUDE_DIRS} | ||
| ${SSL_INCLUDE_DIRS} | ||
| ${ZLIB_INCLUDE_DIRS}) | ||
|
|
||
| # Build sub-libraries. | ||
| ADD_SUBDIRECTORY(common) | ||
| ADD_SUBDIRECTORY(convertor) | ||
| ADD_SUBDIRECTORY(runtime) | ||
|
|
||
| # Plugin sources (handler layer + UDFs whose extern "C" symbols must be | ||
| # in the final .so for dlsym() loading). | ||
| SET(DUCKDB_PLUGIN_SOURCES | ||
| ha_duckdb.cc | ||
| ha_duckdb_pushdown.cc | ||
| duckdb_udf.cc | ||
| ) | ||
|
|
||
| MYSQL_ADD_PLUGIN(duckdb ${DUCKDB_PLUGIN_SOURCES} | ||
| STORAGE_ENGINE | ||
| MODULE_ONLY | ||
| LINK_LIBRARIES duckdb_runtime duckdb_convertor duckdb_common ${DUCKDB_LIBRARY} | ||
| ) | ||
|
|
||
| IF(TARGET duckdb) | ||
| duckdb_setup_target(duckdb) | ||
| TARGET_INCLUDE_DIRECTORIES(duckdb PRIVATE | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/common | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/convertor | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/runtime | ||
| ) | ||
| ENDIF() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.