Skip to content

How do parallel queries work when SQLite doesn't support them?ย #408

Open
@ColonelThirtyTwo

Description

@ColonelThirtyTwo

I'm a beginner at Node.js, but I'm familiar with SQLite.

SQLite has a synchronous interface; you call sqlite3_step(stmt), it blocks and fetches one result, then returns. There's no way to asynchronously fetch results, short of running all SQL queries on another thread, and one connection can only run one query at a time.

But node-sqlite3 claims that it can run queries in parallel, which shouldn't be possible with SQLite's API. This leads me to believe that one of the following is happening:

  • Queries aren't actually processed in parallel, but are simply queued up and eventually executed. Of course, if you're going to execute queries one-at-a-time, you may as well preserve the order. If that's the case, serialize has literally no purpose.

    From looking at the source code and issue db.parallelize() needs to run queries in parallelย #394, this seems the most likely.

  • Database isn't one connection, but a pool of several connections, each with their own worker thread. But this leads to other issues; temporary tables and certain PRAGMA settings are per-connection, and each query would have to wait for the main thread to call the callback after each row or statement.

Maybe there is a different technique for running SQLite queries in parallel that I can't think of, but to me, this is a major deign smell, and I'm skeptical about using this library until this issue is explained and documented.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions