What the Duck? Speeding Up MySQL Analytics Without a Whole Second System.
In my career I have seen the same pattern many times.
A database grows without control, but not evenly. The live dataset, the rows the application really works on, stays relatively small.
Next to it, a few huge tables keep growing, kept only because someone needs them for reporting or just because they initially do not care to clean it up. Sometimes a single table holds 80% of the data or, trust me, even worse.
The worst case I met more than once is reporting run directly on the OLTP system.
A report that scans months of orders competes with the application for CPU, memory and I/O, and the buffer pool fills with old pages nobody else needs.
The application slows down, and the report is slow anyway, because InnoDB was never built to scan and aggregate hundreds of millions of rows.
There are several ways to act on this scenario, the most common answer to this impractical situation is my database is huge I must use sharding to be able to continue to grow.
What normally happens is that once there (sharding) the user discovers that, aside the obvious effort to maintain the sharded environment, one or two of his shards are still growing like crazy in some parts and he needs to shard again, and again … And they discover that being lazy, without checking whether they really need sharding or just need to clean up the data, is not a comfortable thing to do long term.
The most diligent accept the challenge and go for another answer which is separate analytical system: a data warehouse, an ETL pipeline, another product to run and pay for.
Very often this is more than people need. They do not need a new platform. They need to access the same data in a different way and get answers from large datasets in seconds instead of minutes or hours.
There is a second point I care about: how we get there.
I wanted a solution with the smallest possible impact on the MySQL core. This is not just a stylish decision but a very practical one. Changing the core brings a lot of hard work: maintaining the code, merging upstream changes and, not least, bug and CVE fixes.
This is why I rejected two common approaches from the start: writing a new storage engine and changing core server code.
Both are possible, others have done it, but both create a fork that must be carried release after release. If we can avoid touching the core, we should.
When and how it started
During Percona Live I had the opportunity to learn more about DuckDB.
DuckDB is an embedded analytical database: no server, just a library that runs inside the program using it.
It stores data by column, compresses it, and processes it in batches using all the CPU cores. In short, it is very good exactly where InnoDB struggles: large scans, aggregations and joins over many rows.
The question came naturally: what if DuckDB could live inside MySQL, next to InnoDB, and answer the heavy queries while InnoDB keeps doing what it does best?
At the time I was just wondering, will it work, can I do it? In situations like this for me the best way to answer is stop wondering and do it or at least try to do it.
When I say do it, I do not mean, talk about, or just write about it, but do it, put hands at work and build something I can use in one of the many cases I had experienced in the past. Not some abstract thing that could be usable or not, but something that is there to be used tomorrow on a customer site.
That is the moment when I started to talk with Clio Annali (the co-author), and we started to put down the idea and the plan.
Just to be clear, what we are presenting, is not a production ready version, it is still a proof of concept but built with the intent to become a real solution: tested, documented, and honest about its limits.
What: DUCKDB_SE
This is why DUCKDB_SE was born: DuckDB as a secondary engine for Percona Server for MySQL. It is a plugin, built on the secondary engine framework MySQL already has, with no change to the server code (only build integration).
The idea is simple. InnoDB stays the primary engine and receives every write, exactly as today. For the tables we choose, the plugin keeps a second, columnar copy in DuckDB. When a query is expensive enough, MySQL sends it to DuckDB instead of InnoDB. The application does not change: same SQL, same connection, same users and privileges.
The only visible difference is the time the query takes.
How it works, in four steps:
- One ALTER TABLE ... SECONDARY_LOAD copies the table into DuckDB. The copy is stored on disk next to the MySQL data, in a native DuckDB database file.
- After the load, every committed change on InnoDB reaches the copy. The plugin reads MySQL's own binary log, groups the changes in batches and applies them to DuckDB. Each batch also records how far it got, in the same commit, so after a crash nothing is lost and nothing is applied twice.
- When a query is expensive, or scans a large table, MySQL asks the plugin to run it. The plugin translates the query into DuckDB SQL, DuckDB runs it, and the rows come back through MySQL to the client.
- Refuse when unsure. A query that cannot be translated exactly is refused, and InnoDB answers it as usual. The rule is strict: DuckDB answers only when its result is exactly what InnoDB would return.
That last rule matters more than it seems. For example, MySQL compares text according to collations: under utf8mb4_0900_ai_ci, "José" and "jose" are equal. DuckDB has no such rules. DUCKDB_SE stores, next to each text column whose collation DuckDB cannot reproduce, MySQL's own sort key for every value, so grouping, sorting and joining in DuckDB give the same result as InnoDB, accents and case included.
Live data and full history
There is one more feature, and it goes back to the pattern we described at the start: small live data, huge history.
A table can be declared with history retention. Then a purge job can delete old rows from InnoDB, keeping InnoDB small and fast, while DuckDB keeps those rows as archived.
A normal delete still deletes everywhere. Only deletes done in a purge transaction, marked with a special GTID tag, are kept as history. History tables need sync_binlog = 1, and the purge job needs the TRANSACTION_GTID_TAG privilege.
Each session then chooses what a table name means, with duckdb_history_scope:
- LIVE (the default): only live rows, the same answer InnoDB gives.
- FULL: live and archived rows. Such queries run only in DuckDB and never fall back to InnoDB, because InnoDB does not have the archived rows. Reading the full history needs a dedicated privilege, DUCKDB_HISTORY_READER.
One MySQL table, two views of it: the live one for the application, and the full one for the reports.
History also needs care: obsolete records must go after some years, a legal erasure request must be honored, a historical flag must be corrected.
InnoDB no longer has those rows, so no DELETE or UPDATE can reach them.
The plugin adds functions for that: duckdb_history_delete and duckdb_history_update take the statement as text, evaluate it’s WHERE exactly as MySQL would, with the privileges of whoever calls them, and change only the archived rows; you can also use duckdb_history_count to identify first how many rows a statement would touch.
The change is made on the server where it runs, one server at a time, so a mistake can be caught after the first. A table can also ask for a safety net: with "history_undo_days": N, a request can be undone for N day(s).
What it looks like
The plugin is loaded from the configuration file. Two settings are mandatory, because DuckDB runs inside mysqld and we want its resources bounded:
[mysqld]plugin-load-add = ha_duckdb.soloose-duckdb_memory_limit = 8Gloose-duckdb_threads = 8
The copies follow InnoDB through the binary log, so it must be on, in ROW format with full row images and metadata, and with GTIDs.
Then we choose a table and load it:
-- We give the table a DuckDB copy that also keeps the historyALTER TABLE orders SECONDARY_ENGINE = duckdb, SECONDARY_ENGINE_ATTRIBUTE = '{"retain_history": true}';
-- We load the current data into the copyALTER TABLE orders SECONDARY_LOAD;
-- We let MySQL send expensive queries to DuckDBSET SESSION use_secondary_engine = ON;SELECT YEAR(created_at), SUM(amount)FROM ordersGROUP BY 1;
Nothing else changes for the application. EXPLAIN shows in secondary engine DUCKDB when a query runs there, and SHOW WARNINGS shows the SQL that DuckDB received.
The purge job and the history report look like this:
-- We purge old rows from InnoDB; DuckDB keeps them as archivedSET gtid_next = 'AUTOMATIC:duckdb_avoid_purge';DELETE FROM orders WHERE created_at < NOW() - INTERVAL 90 DAY;SET gtid_next = 'AUTOMATIC';
-- We report on five years of orders, not only the last 90 daysSELECT /*+ SET_VAR(duckdb_history_scope = 'FULL') */ YEAR(created_at), SUM(amount)FROM ordersGROUP BY 1;
And the maintenance of the history itself:
-- How many archived orders from before 2020 would goSELECT duckdb_history_count(“DELETE FROM orders WHERE created_at < '2020-01-01'”, FALSE);
-- Remove them from this server's copy (InnoDB no longer has them)SELECT duckdb_history_delete(“DELETE FROM orders WHERE created_at < '2020-01-01'”, FALSE);
-- Correct a flag on the archived rowsSELECT duckdb_history_update(“UPDATE orders SET obsolete = 1 WHERE created_at < '2021-01-01'”, FALSE);
Numbers
On a production-like workload, offloaded queries ran 54 to 574 times faster than on InnoDB, with identical results.
The workload simulates wind farm monitoring: 200 turbines sending a reading every 10 minutes for one year, 10.5 million readings, plus sites, regions, alarms and a maintenance history table. Every query runs on InnoDB and on DuckDB, and the results are compared.
These are the median times of the queries DuckDB answered, from one run on the release build on my test machine, on 14 November 2026, when the copies were still stored with DuckLake so not optimal given that the native storage adopted since then scans 2-3 times faster:
|
Query |
InnoDB (s) |
DuckDB (s) |
Speedup |
|
Two periods side by side (UNION ALL) |
35.73 |
0.062 |
574x |
|
Top 10 turbines by average power, one quarter |
17.88 |
0.041 |
439x |
|
Readings above each turbine's yearly average |
36.81 |
0.147 |
250x |
|
Quarter over quarter energy per region (CTE) |
21.76 |
0.108 |
201x |
|
Daily energy per site, one month |
5.25 |
0.049 |
107x |
|
Hourly profile over the year |
7.27 |
0.087 |
84x |
|
Whole table aggregate |
4.22 |
0.056 |
75x |
|
Turbines reporting per day with faults |
2.47 |
0.046 |
54x |
Just as important is what did not move. Point lookups by primary key and short index ranges stay on InnoDB, because that is where InnoDB is fast.
Queries using something not translated yet, such as window functions, also stay on InnoDB and return the same result as before, at the same speed.
To test coverage beyond my own queries, I used TPC-H in the form HammerDB sends it to MySQL.
All 22 TPC-H queries are offloaded and return exactly InnoDB's results. HammerDB's TPROC-H also runs offloaded at scale factor 100; there, query 21, one of the hardest, completes in about 2.2 seconds.
Other ways to bring DuckDB to MySQL
DUCKDB_SE is not the only attempt. Alibaba's AliSQL and MariaDB both added DuckDB as a storage engine, where the table lives only in DuckDB. AliSQL reached that by changing the MySQL SQL layer and maintaining its own DuckDB fork.
MariaDB maps its collations to DuckDB's own case rules, and its documentation warns that results can differ from InnoDB.
DUCKDB_SE takes the opposite path: InnoDB keeps the data, the plugin changes nothing in the server, DuckDB is used as released upstream, and a query either returns exactly InnoDB's result or goes back to InnoDB.
Being this strict could have cost speed.
On HammerDB’s TPROC-H at scale factor 100 it costs little: with one user DUCKDB_SE is within 6% of AliSQL’s total and 15% faster than MariaDB, and the fastest of the three on 12 of 21 queries; with 16 users it is 13% behind AliSQL and level with MariaDB.
One Vuser running:
Two Vuser running:
Four Vuser running:
Eight Vuser running:
Sixteen Vuser running:
As you can see we are not doing so bad are we?
What it does not do yet, and what is next
DUCKDB_SE is a proof of concept, and we prefer to be clear about where it stops today:
• Not every query is translated. Window functions, ROLLUP, GROUP_CONCAT and some string and date functions still run on InnoDB. They return correct results, only without the speedup.
• MySQL never uses a secondary engine inside a multi-statement transaction (BEGIN, or autocommit = 0). Reports must run with autocommit on.
• Tables need a primary key. DECIMAL columns with more than 38 digits, VECTOR columns and zero dates are not supported yet.
• The DuckDB file never shrinks (DuckDB reuses freed space), and its size under continuous updates is still to be measured. Encryption is designed, not built; backup works today only with the plugin stopped, and integration with XtraBackup is still to do.
• A DDL on a loaded table reloads the whole copy, which can take minutes on large tables, and the other tables wait meanwhile.
• Archived rows are deleted and corrected one server at a time (the functions above); doing it on every server at once, through the binary log, comes next.
The next steps are the ones that turn a POC into something customers can run: crash and consistency tests, storage compaction, backup, resource governance, and more translated SQL driven by real workloads.
The plugin targets Percona Server 9.7 today; building it on upstream MySQL 9.7 is a goal, and a port to 8.4 LTS is still to be decided.
The code and its documentation are public, in the 9.7-duckdb branch of my Percona Server fork: the plugin in storage/duckdb, and the design, how-to and tutorial in project_duckdb. A second, more technical post will follow, about how it is built without touching the core.
Where to start: the documentation, in reading order
Everything is in the repository, from the overview to the code. To understand the product, read it in this order, from the simplest to the most technical:
1. README (.github/README.md): what the plugin is, how it works, its status, a quick start, the performance numbers and what is not supported yet. Start here.
2. Tutorial (project_duckdb/TUTORIAL.md): a first session, step by step: build, configure, load a table, offload queries, keep the history.
3. HOWTO (project_duckdb/HOWTO.md): the reference: build options, configuration, every variable and status counter, what is offloaded, the limitations.
4. Design document (project_duckdb/duckdb-secondary-engine-design.md): goals, architecture, the decisions and why they were taken, the paths of a write and of a query through the code (with diagrams), risks, production readiness and the plan.
5. Worklogs (project_duckdb/worklog-index.md): the work item by item, in the style of MySQL worklogs: DWL-01 to DWL-08 are the proof of concept (requirements, design and tests of each function), DWL-09 to DWL-23 the plan towards beta and general availability.
6. TPC-H check (project_duckdb/tpch/README.md): the TPC-H queries one by one, the HammerDB setup and the memory and spill check script.
7. Monitoring (project_duckdb/monitoring/README.md): the PMM / Grafana dashboard, its custom queries and alert ideas.
8. Container image (project_duckdb/docker/README.md): build and run the server with the plugin in Docker, sized from the container’s memory and CPU limits.
9. Tests: the MTR suite test by test (storage/duckdb/mysql-test/duckdb/README.md) and the scenarios run by hand, with their results (project_duckdb/manual-test-plan.md).
10. Raw results (project_duckdb/perf): the performance runs behind the numbers in this post.
The code itself, in storage/duckdb, comes last: the “Paths through the code” section of the design document is its map.
If you recognize the pattern we described at the start, small live data and huge reporting tables, we would like to hear from you, and even more to see DUCKDB_SE on your queries.
In the meanwhile, please try it and let us know what you think participate to the discussion (https://github.com/Tusamarco/percona-server-duckdb-se/discussions/1) and if you find issues open one.
More to come...
Marco & Clio
Great MySQL to all!



















At Percona Live Europe 2026, Dmitry Lenev and I presented 

