Repository navigation
Optimize IN/NOT IN subquery performance with intelligent caching and correlated subquery detection - #2281
Conversation
Co-authored-by: mathiasrw <[email protected]>
Co-authored-by: mathiasrw <[email protected]>
Co-authored-by: mathiasrw <[email protected]>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
This comment has been minimized.
This comment has been minimized.
|
,,,............................................... 662 passing (2s)
error Command failed with exit code 1. |
…ements Co-authored-by: mathiasrw <[email protected]>
Fixed by initializing Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Co-authored-by: mathiasrw <[email protected]>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
Please proceed with
|
Co-authored-by: mathiasrw <[email protected]>
Implemented correlated subquery detection. The changes:
Correlated subqueries now work correctly (they were previously broken) and non-correlated subqueries still get the 100-160x performance boost. (b48c9a3) Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
Run yarn test-format-all |
Co-authored-by: mathiasrw <[email protected]>
Run yarn test-format-all |
|
@copilot Continue |
Co-authored-by: mathiasrw <[email protected]>
IN (SELECT ...)are executed once per row instead of being cachedsrc/50expression.jsSummary
This PR addresses the low performance issue when using subqueries with
IN (SELECT ...)orNOT IN (SELECT ...)operators.Problem
The original implementation re-executed the subquery for every row in the outer table being filtered, resulting in O(n*m) complexity where n is the number of outer rows and m is the subquery execution cost. This led to very poor performance (~7.82 ops/s for 1000 users x 3000 orders).
Solution
Changes
src/50expression.js: Modified IN/NOT IN with SELECT subquery to check if correlated and conditionally cachesrc/40select.js: AddedisCorrelateddetection incompileQueries()to mark subqueries that reference external tablessrc/38query.js: ResetsubqueryCache = {}at query start for clean statetest/test2280.js: Added comprehensive tests including correlated subquery testPerformance Improvement
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.