Skip to content

Query runs: state of one run kept on the cached statement, and separate sync and async paths #2724

Open
1 of 4 issues completed

Description

@mathiasrw

Several bugs come from where a query keeps the state of one run and from having separate synchronous and asynchronous code paths. Values that belong to one run (parameters used as LIMIT, subquery caches) are written to the compiled statement that the cache shares between runs, and each kind of source (tables, ?, subqueries, files) reads its rows and reports its errors in its own way.

What this issue is about

This issue asks for a change in structure, not for a fix of each bug listed below. The bugs show where the current structure fails, and they serve as test cases. Three changes, in this order.

  1. A run context. A compiled statement does not change after it is compiled. Each run gets its own object that carries the parameters, the database, the outer row of a subquery, the caches of that run and the callback, and it is passed down instead of being written onto the statement.

    const ctx = {params, db, outer: null, caches: new Map(), cb};
    plan.run(ctx); // nothing is written to plan
  2. One source interface. Tables, ?, subqueries, files and table functions such as RANGE all give their rows the same way, and a file format only parses text into rows. Reading, errors and async handling are written once.

    interface Source {
      columns: Column[] | null; // null when known only once rows arrive
      open(ctx): Iterable<Row> | AsyncIterable<Row>;
    }
  3. One runner for sync and async. When every source is synchronous the runner iterates, otherwise it awaits, along the same path. An error always reaches the caller, so a promise always settles. The cache key is built from the SQL text and every option that affects compiling.

Before you start

#2596 (two runs of the same statement at once) is the first part of this issue and comes first. It has its own three steps: find every write to a cached statement with Object.freeze in a test build, give each run its own object, add the tests it lists.

Ground rules

Bugs traced to this

Sub-issues

Sub-issues

1 of 4 Issues completed
Loading 4 sub-issues

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions