Repository navigation
Closed
Description
We are running this in test. We are getting results like 7.82 ops/s where most other tests we are doing are things like 2.40K ops/s or 8.36K ops/s
It indicates there is something terribly wrong. Very wrong. I understand that we got no indexes on, but can this really be right?
look into if index adding in the example is really the only thing we can do or if there are some clear performance improvements we can do in the code that would spit up such a scenario. Or in worst case: can we log a warning if we detect that a massive workload seems to be entering the pipeliens and no indexes on the right things, basically warning the user this will take a long time and probably could improve from indexes on x, y, z to improve performance.
// Test 5: Subqueries
{
name: 'Subquery Operation',
description: 'SELECT with subquery for filtering',
setup: (alasql) => {
alasql('CREATE TABLE IF NOT EXISTS users (id INT, name STRING, age INT, department STRING, salary NUMBER)');
alasql('CREATE TABLE IF NOT EXISTS orders (id INT, userId INT, product STRING, amount NUMBER, date STRING)');
const users = generateUsers(1000);
const orders = generateOrders(3000, 1000);
alasql('DELETE FROM users');
alasql('DELETE FROM orders');
users.forEach(u => alasql('INSERT INTO users VALUES (?, ?, ?, ?, ?)', [u.id, u.name, u.age, u.department, u.salary]));
orders.forEach(o => alasql('INSERT INTO orders VALUES (?, ?, ?, ?, ?)', [o.id, o.userId, o.product, o.amount, o.date]));
},
run: (alasql) => {
return alasql('SELECT * FROM users WHERE id IN (SELECT userId FROM orders WHERE amount > 800)');
},
teardown: (alasql) => {
alasql('DROP TABLE IF EXISTS users');
alasql('DROP TABLE IF EXISTS orders');
},
},
Reacted by Copilot
Metadata
Metadata
Assignees
Labels
No labels
Activity
mathiasrw commentedon Nov 30, 2025
Problem
IN (SELECT ...)andNOT IN (SELECT ...)subqueries were re-executed for every row in the outer table, resulting in O(n×m) complexity. This caused ~7.82 ops/s for 1000 users × 3000 orders scenario—orders of magnitude slower than expected.Solution
subqueryCacheobject on the queryindexOf()withSet.has()for constant-time membership checkssubqueryCache = {}at start ofqueryfn()to ensure fresh data on each query runChanges
src/50expression.js: Lazy-cache subquery results as Set for IN/NOT IN operatorssrc/38query.js: Reset singlesubqueryCacheobject at query execution starttest/test2987.js: Tests for correctness and cache isolationPerformance
Use subquery caching with correlation check to fix #2280 (#2281)
mathiasrw commentedon Dec 6, 2025
Fix released in v4.11.0