Skip to content

Rules that differ between dialects become named rules chosen when a statement is compiled #3170

Backlog

Description

@mathiasrw

What happens today

alasql.options has six dialect flags (tsql, mysql, postgres, oracle, sqlite, orientdb), all true by default (src/engine/core.js). The files in src/dialects/ read them once at start-up, so changing a flag later does nothing. mysql.js adds TIMESTAMPDIFF and INFORMATION_SCHEMA, src/data/database.js adds tempdb for tsql, and the other files are empty.

The statement cache key is the SQL text plus joinstar (alasql.dexec in src/engine/core.js). The code generator has no named rule to read, so a step that switches a rule has no place to keep the old one.

What to change

  1. Add a rule set on the engine. The defaults are today's behaviour.

    alasql.rules = {
      compare: 'fast',
      nullOrder: 'v4',
      setOperationOrder: 'v4',
      ambiguousColumn: 'first',
      groupByName: 'alias',
    };

    The code generator reads alasql.rules while it compiles. Nothing reads it while rows run.

  2. A behaviour module sets rules or replaces functions. A dialect module is a list of behaviour modules and nothing else.

    const timestampdiff = {name: 'timestampdiff', fn: {TIMESTAMPDIFF: (u, a, b) => alasql.stdfn.DATEDIFF(u, a, b)}};
    const mysql = {name: 'mysql', modules: [timestampdiff, informationSchema]};
    alasql.load(mysql);

    alasql.load applies the modules in order and bumps a counter. The counter is part of the statement cache key.

  3. Add modules at alasql/dialect/<name> for sqlite, postgres, mysql and mssql, and an empty alasql/dialect/v4. Move the code of src/dialects/*.js into them. TIMESTAMPDIFF, INFORMATION_SCHEMA and tempdb stay in the default.

  4. Remove the six flags from alasql.options and their reads.

What stays the same

  • With no module loaded, every query gives the same result as before.
  • Only code that sets one of the six removed options changes.

Done when

  • A new test file named after this issue checks that the default rules give today's results, that loading a module with another rule value makes the same SQL text compile again with that rule, and that TIMESTAMPDIFF, INFORMATION_SCHEMA and tempdb work without loading anything.
  • The dialect test in test/dialect/ runs once for the default and once with the sqlite module loaded.
  • 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

#2652

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions