You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Slow query performance when dealing with a subquery #937
We have been using alasql for a while now and recently noticed that the query performance degrades significantly when subquery is introduced. Given a table with 1000 records getting the full set of records using the
SELECT
...
FROM `Person`
But when we introduce a subquery to perform pagination the query to get the first 100 records without ordering takes about 20 seconds:
SELECT
...
FROM `Person`
WHERE
EXISTS( SELECT
1
FROM
(SELECT
CONCAT_WS('.', COALESCE(CONCAT_WS(':','Person', `Person.__pk`), '_')) AS __pk
FROM `Person`
GROUP BY `Person.__pk`
LIMIT 100) x
WHERE
x.__pk = CONCAT_WS('.', COALESCE(CONCAT_WS(':','Person', `Person`.`Person.__pk`), '_')))
```
Is there any current work being done to improve query performance that we can contribute to or any tools we can use to identify the slow portion of the alasql query code? Any help is appreciated.
Thanks in advance, - J
I think EXISTS operation seems quite expensive as I experienced. I recommend to reduce the search space by INNER or LEFT JOIN and WHERE if possible and try it again.
hkmoon, thanks for your comment. We do realize the query is not optimal but the performance degradation when subquery with "Exists" is used in alasql is far greater compared to mysql. Our query generator happened to use "Exists" subqueries a lot and optimizing them will be a big win for us.
At this moment I am not aware of any initiatives on this area.
If this is of great importance to you you might be able to buy some focused development from @agershun
I have a feeling that a lot can be done regarding query planning - and I must admit that I am not sure we cash subqueries = not really awesome performance.
Building each sub into a table and joining them will encreese your performance - as @hkmoon states.
mathiasrw, thanks for your comment. We are currently weighing different options which could give us the most bang for the buck. Working with other contributors on improving alasql subquery is certainly an option but not the only one. Will report back with what we end up going with. Thanks!
Activity
hkmoon commentedon Sep 7, 2017
I think EXISTS operation seems quite expensive as I experienced. I recommend to reduce the search space by INNER or LEFT JOIN and WHERE if possible and try it again.
webdori882 commentedon Sep 7, 2017
hkmoon, thanks for your comment. We do realize the query is not optimal but the performance degradation when subquery with "Exists" is used in alasql is far greater compared to mysql. Our query generator happened to use "Exists" subqueries a lot and optimizing them will be a big win for us.
mathiasrw commentedon Sep 7, 2017
Hi @webdori882 - thank you for your input
At this moment I am not aware of any initiatives on this area.
If this is of great importance to you you might be able to buy some focused development from @agershun
I have a feeling that a lot can be done regarding query planning - and I must admit that I am not sure we cash subqueries = not really awesome performance.
Building each sub into a table and joining them will encreese your performance - as @hkmoon states.
webdori882 commentedon Sep 12, 2017
mathiasrw, thanks for your comment. We are currently weighing different options which could give us the most bang for the buck. Working with other contributors on improving alasql subquery is certainly an option but not the only one. Will report back with what we end up going with. Thanks!
hunharibo commentedon Mar 6, 2018
I noticed a large delay in subquery performance as well. How did you solve this?