Skip to content

Pass the rows of INSERT, UPDATE and DELETE through one write pipeline #2650

Open

Description

@mathiasrw

What happens today

Each statement writes rows its own way, and the rules are split between the statement and the table closures from src/statements/createtable.js.

  • INSERT VALUES (src/statements/insert.js) generates per-row code with the defaults spliced in (line 246) and calls table.insert(a, orreplace, ignore). INSERT SELECT (line 380) does the same in JavaScript. INSERT ... DEFAULT VALUES (line 425) pushes into table.data and skips every rule.
  • UPDATE (src/statements/update.js, line 93) applies onupdatefns and the SET list through assignfn and calls table.update(assignfn, i, params).
  • DELETE (src/statements/delete.js) calls table.delete(i) and runs the AFTER DELETE triggers itself (line 113).
  • OUTPUT rows are built five times (insert.js lines 312 and 398, update.js line 154, delete.js lines 131 and 208).

What to change

  1. Add writeRows(table, op, rows, ctx) in src/statements/write.js with op one of 'insert', 'update', 'delete'. Per row and in today's order it runs defaults and identity (insert), ON UPDATE and the SET list (update), BEFORE and INSTEAD OF triggers, checks and keys from src/statements/tablerules.js (Move the key and check rules of a table into one module #2716), the write to table.data, the key and other indexes, and AFTER triggers. Defaults, identity and triggers come from table.schema (Keep the definition of a table as data in table.schema and build its rules from it #3169). It returns {count, output} with {inserted, deleted} pairs when the statement has OUTPUT.

    const {count, output} = writeRows(table, 'update', matches, ctx);
    return self.output ? outputRows(self.output, output) : count;
  2. Add outputRows(spec, pairs) in the same file, the only place that builds OUTPUT rows (*, plain columns, INSERTED.x, DELETED.x, aliases).

  3. INSERT VALUES and INSERT SELECT build plain value rows (generated code keeps only the column expressions and type conversion) and hand them to writeRows. INSERT ... DEFAULT VALUES uses writeRows with a flag that skips the rules.

  4. UPDATE and DELETE find rows with wherefn as today and hand them to writeRows. AFTER DELETE triggers move into the pipeline.

  5. table.insert, table.update and table.delete become thin wrappers over writeRows for one row.

  6. Triggers are called through alasql.executeTrigger as today.

What stays the same

  • Every result for memory tables, including counts with IGNORE and OR REPLACE, the return value of INSERT into a class table, OUTPUT rows, trigger order and arguments, and every error text.
  • Storage engines take their current path.
  • alasql.options.nocount keeps its effect.
  • No result changes.

Done when

  • A new test file named after this issue runs INSERT VALUES, INSERT SELECT, INSERT SET, INSERT DEFAULT VALUES, UPDATE and DELETE with and without OUTPUT, OR REPLACE and IGNORE, and BEFORE, INSTEAD OF and AFTER triggers of each kind, and pins the results and the trigger order.
  • OUTPUT rows are built only in outputRows.
  • The full test suite and the CI checks (dialect test, parity check, run-state check, binding check) pass, and the pull request lists every parity difference.

Depends on

#3169

Activity

  1. added this to the v4.x Focus milestone on Nov 26, 2026
  2. changed the title [-]Review #2302 for code improvements: OUTPUT rows built by hand in each statement[/-] [+]Pass the rows of INSERT, UPDATE and DELETE through one write pipeline[/+] on Nov 26, 2026
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