Skip to content

performance drop from 2 to 3 tables (how to add indexes?) #1312

Open

Description

@darrencruse

New to alasql but we are considering using it on a project that joins data from multiple json apis for reporting purposes

In my initial test I was trying it out simply without creating any indexes just doing the basic:

const compiledStmt = alasql.compile(sqlStatement)
result = await compiledStmt.promise({ A: apiAResponseJson, B: apiBResponseJson, C: apiCResponseJson })

At the end I pasted some timings looking at execution times for the await compiledStmt.promise step

I notice a pretty severe drop in performance going from 2 to 3 tables

From looking at the alasql docs I'm assuming that drop is because I'm not using indexes does that sound right?

If so from the docs and googling I'm unsure how to create such indexes i.e. my code above is utterly simple right now but does creating indexes require that I change my approach completely actually using DDL statements i.e. similar to this example that I found in another issue?

CREATE TABLE t1( x INTEGER, y VARCHAR(8) );
CREATE INDEX tmp ON t1(x);
INSERT INTO t1 VALUES(1,'a'); 

Is there possibly a way to simply index my already "inserted" json data directly (maybe using an alasql function?). i.e. still using my simple code without the above DDL?

(note to change to the DDL way as above I will have thousands of insert statements that I would have to create from this json data I get from these apis I'm joining together)

I also wonder since my data and the indexes aren't persisting over time I'm just reading this api data, joining it together, then returning that to the client hitting my "join api" - and then throwing it all away

Might the overhead of creating the indexes take longer than the time saved running my selects?

Below I will paste what I was saying about the slow down I saw going from 2 to 3 tables (without any indexes though so maybe it's to be expected not sure).

Thanks,

Darren

Table A has 1008 records.
Table B has 252 records.
Table C has 252 records.

--------------------------------

select
 a.setId,
 b.treatmentId
from
  :A a, :B b
where
  a.entry_entryId = b.setEntryId

Execution time: 0s 26ms (0.026s)

--------------------------------

select
 b.treatmentId,
 c.experimentId
from
  :B b, :C c
where
  b.treatmentId = c.id

Execution time: 0s 15ms (0.015s)

--------------------------------

select
 a.setId,
 b.treatmentId,
 c.experimentId
from
  :A a, :B b, :C c
where
  a.entry_entryId = b.setEntryId
and
  b.treatmentId = c.id

Execution time: 4s 608ms (4.608s)

--------------------------------

Activity

  1. changed the title [-]performance drop from 2 to 3 tables[/-] [+]performance drop from 2 to 3 tables (how to add indexes?)[/+] on Mar 29, 2021
  2. darrencruse commented on Apr 1, 2021

    @darrencruse
    Author

    hello out there a little disappointed no reply on the above

    not to be pointed but does this mean the project has lost momentum?

    (I hate to use the phrase "dead project" :)

    From our looking we thought alasql was really filling a gap we'd not seen filled

    In the sense that our project is intentionally not a traditional ETL approach of loading api data into a data warehouse database and then running reports and such against the database

    it's been intentionally designed with the goal of hitting the apis in real time to give up to the minute results without anything stored (even temporarily) in a relational database

    And yet more and more we were realizing SQL does fill a gap that many of our users are not programmers but they are "data scientist" type people who are familiar with SQL (and spreadsheets - so with "tabular data" as opposed to the tree structured json data)

    So we thought alasql might have really helped us

    (from my brief playing with it so far I'm still thinking it might - but I also thought I was seeing some issues I couldn't quite explain my question above was meant to be just the first)

    Anyway if anybody reads this if it is the case that alasql has lost momentum

    Would anybody hazard a guess on the difficulty of my trying to do a PR to add a way to create indexes against the pure json data without having to do those explicit CREATE DATABASE/CREATE INDEX/INSERT statements?

    Or otherwise would anybody recommend an alternative to alasql (i.e. that provides sql and works in node and the browser and can query on the fly json data without it being a full blown "database"?)

    Thanks,

    Darren

  3. darrencruse commented on May 2, 2021

    @darrencruse
    Author

    never got any response about the above but just thought I'd record here that I did try more to address my performance issues and failed...

    I guess in retrospect I'm hitting the same bug that was already reported here:
    #1027

    But for the record what I found in the end was that I could get an example 3 table join to return in about 3-4 seconds

    But if I added my fourth table to the join the browser would simply freeze up and not respond at the point where I ran the select statement (where I was running it just using the synchronous db.exec call so that explains the freezing but not why it was taking so long to run the select).

    And what I wound up finding is that it didn't matter whether I added indexes or not the 3 table timings didn't change with/without the indexes and the 4 table select not returning wasn't helped with/without the indexes.

    Finally just for the record the above is where I'd ultimately beefed things up to do the full create table, create index, insert, then select statements

    i.e. originally I was trying to do some shortcuts e.g. just "inserting" my data by assigning my json like db.tables[tablename].data = jsonPayload, and not actually defining indexes etc.

    But now I'm doing all the sql statements just as one would by hand and the indexes just don't seem to be helping where the problem (at least for my 4 tables or above cases) means I won't be able to use Alasql.

    (though the lack of any response to my issue here was another reason I've decided not to use Alasql - looks to me like the project isn't active anymore but if I'm wrong in that please someone respond as I'd like to know - I might not have given up on it if I'd thought the project had some users and some community/support but the lack of any reply makes me think otherwise).

  4. mathiasrw commented on May 25, 2021

    @mathiasrw
    Member

    hello out there a little disappointed no reply on the above

    Please ask general questions like this on stack overflow or - if you think there is a clear problem - please include or link to code replicating the problem.

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