Skip to content

After one error through a callback or promise(), a compiled statement is parsed and compiled again on every run #2875

Closed

Description

@mathiasrw

After a single error through a callback or promise(), a statement made with alasql.compile() is parsed and compiled again on every later run, for good.

alasql.fn.BOOM = x => { if (x === 99) throw new Error('boom'); return x; };
alasql('CREATE TABLE z (a INT); INSERT INTO z VALUES (1)');
var st = alasql.compile('SELECT BOOM(?) AS v FROM z');
// 5000 runs of st([1]): 11 ms
await st.promise([99]).catch(() => {});
// 5000 runs of st([1]): 571 ms (4.20.0: 4 ms)

Since #2747 (in 4.21.0). runStatement (src/engine/core.js) counts a run up in statement.running and counts it down when the run finishes or calls back. When the statement throws synchronously and a callback was given, neither happens, so running stays above 0, and every later call is treated as overlapping and gets a fresh parse and compile. promise() always passes a callback, so one rejected promise is enough. The fix: catch the synchronous throw, call finish(), rethrow; and a test that rejects once and then checks that the next run reuses the compiled statement.

The same counter in the dexec statement cache (#2465) probably has the same problem; not checked.

Breaking?

No.

Activity

  1. added this to the v4.x Focus milestone on Nov 15, 2026
  2. added a commit that references this issue on Nov 16, 2026
    6f00897
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions