perf(sql): parallel execution of ORDER BY + LIMIT queries (up to 10x speed-up)#5957
perf(sql): parallel execution of ORDER BY + LIMIT queries (up to 10x speed-up)#5957bluestreak01 merged 18 commits intomasterfrom
Conversation
|
great job @puzpuzpuz ! what is your machine? |
Ryzen 7900x (12c/24t), 64GB RAM, Ubuntu 22.04. |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing Touches🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
core/src/main/java/io/questdb/griffin/engine/table/AsyncTopKRecordCursor.java
Show resolved
Hide resolved
core/src/main/java/io/questdb/cairo/sql/async/PageFrameReduceTask.java
Outdated
Show resolved
Hide resolved
core/src/test/java/io/questdb/test/griffin/OrderByTimeoutTest.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/questdb/griffin/engine/table/AsyncTopKRecordCursorFactory.java
Show resolved
Hide resolved
[PR Coverage check]😍 pass : 428 / 467 (91.65%) file detail
|
|
@bluestreak01 thanks for the review! |


Closes #4133
Adds new factory for parallel execution of SQL queries with ORDER BY and LIMIT combination (a.k.a. top K), e.g.
The parallel execution can be disabled by setting the new
cairo.sql.parallel.topk.enabled=falseconfig property value.Also fixes query cache clean-up on HTTP and PGWire connection close. Freeing all factories in the global query cache when a connection is closed was hurting cache efficiency in case of short-lived connections.
Design
Instead of gathering top K records on a single threads, the new factory calculates top K records on each worker thread. Once that's done, the gathered top K tree chains are merged into a single one which is used to return the result set.
So, the pipeline is the following:
Benchmarks
Results for ClickBench Q25 on my machine: