Skip to content

INSERT, UPDATE and DELETE: table rules checked in more than one place #2725

Open
0 of 6 issues completed
Open

Description

@mathiasrw

Several bugs come from INSERT, UPDATE and DELETE checking a table's rules in more than one place. Memory tables check keys, defaults, foreign keys and triggers inside table.insert, table.update and table.delete, while tables in a storage engine take a separate path, and each engine saves its own selection of the table's definition.

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.

  1. The table definition as data. Keys, foreign keys, checks, defaults, identity and triggers are plain objects on the table, not closures or code strings built in CREATE TABLE.

    table.schema = {columns, pk, uniques, foreignKeys, checks, defaults, identity, triggers};
  2. One write pipeline. INSERT, UPDATE and DELETE pass their rows through the same steps, whether the table lives in memory or in a storage engine, and OUTPUT is built in one place.

    writeRows(table, 'insert', rows, ctx)
      // defaults, identity, NOT NULL, checks, primary and unique keys, foreign keys,
      // triggers before, storage.insert(rows), key indexes, triggers after
      // returns {count, output}
  3. One storage interface that memory tables and each engine (IndexedDB, localStorage, FileStorage) implement, so every engine stores the whole definition and every engine is checked the same way.

    interface Storage {
      load(table); insert(table, rows); update(table, changes);
      delete(table, rows); truncate(table); saveSchema(table, schema);
    }

Key indexes belong to the table and are rebuilt when table.data is replaced. Triggers get the row as NEW and OLD from the pipeline.

Before you start

This issue does not depend on the other areas and can start now. Only UPDATE ? and DELETE FROM ? wait for the source interface of #2724, as they become a source plus this pipeline (#2682).

Ground rules

  • Results stay as in 4.x for memory tables. The one intended change is that tables in a storage engine enforce what memory tables already enforce (keys, checks, foreign keys). Only the bugs a pull request names may change results.
  • Small steps. A good first pull request moves the key and check logic out of table.insert into one function and calls it from both the memory path and the engine path of yy.Insert.compile. That fixes Give every storage engine one storage interface that saves the whole table definition and writes through the pipeline #2681 for INSERT.
  • Each pull request passes the full test suite and the parity check in test/parity/ against the build before it.
  • The code this touches moves to ES6 as part of the work, with constraints as objects.

Bugs traced to this

Sub-issues

Sub-issues

0 of 6 Issues completed
Loading 6 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