Skip to content

Slow query performance when dealing with a subquery #937

Open

Description

@webdori882

Hi,

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

Activity

  1. hkmoon commented on Sep 7, 2017

    @hkmoon

    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.

  2. webdori882 commented on Sep 7, 2017

    @webdori882
    Author

    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.

  3. mathiasrw commented on Sep 7, 2017

    @mathiasrw
    Member

    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.

  4. webdori882 commented on Sep 12, 2017

    @webdori882
    Author

    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!

  5. hunharibo commented on Mar 6, 2018

    @hunharibo

    I noticed a large delay in subquery performance as well. How did you solve this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions