Skip to content

ENG-30396: SQLancer VoltDB provider, milestone 10: materialized views and the VIEWS oracle - #10

Closed
jwiebema1 wants to merge 3 commits into
ENG-30396-sqlancer-m9from
ENG-30396-sqlancer-m10
Closed

jwiebema1 wants to merge 3 commits into
ENG-30396-sqlancer-m9from
ENG-30396-sqlancer-m10

Conversation

@jwiebema1

@jwiebema1 jwiebema1 commented Nov 6, 2026 •

Copy link
Copy Markdown

Milestone 10 of ENG-30396 (tracked in ENG-30581, epic ENG-30580 "SQL Housekeeping"): the VIEWS oracle, materialized views against their defining queries. Stacked on #9 (milestone 9), which is stacked on #8 to #1; review those first.

The nightly job runs VIEWS once VoltDB/internal#6350 and VoltDB/pro#7095 merge. They pin this branch's head and add VIEWS to the default oracles.

Why

VoltDB keeps a materialized view up to date incrementally, as rows are inserted, updated and deleted, rather than computing it again. Its planner also answers matching GROUP BY queries on the table from the view: the view rewriter, MVQueryRewriter. Neither path was tested by the other oracles. This oracle found three new bugs in a few minutes, one of which gives wrong results to ordinary queries, and the first lab run found a fourth that crashes the server.

What it adds

  • gen/VoltDBViewGenerator: a view of one table.

    • It groups by zero to two non-BOOLEAN columns.
    • It has COUNT(*) and up to three more of COUNT, SUM, MIN and MAX, with no MIN or MAX of BOOLEAN (ENG-30493).
    • While --avoid-known-bugs is on, SUM is only of NOT NULL TINYINT, SMALLINT and INTEGER columns (ENG-30584, ENG-30588).
    • Half have a WHERE clause, but only while --avoid-known-bugs is false (ENG-30583).
    • Each database creates up to --max-num-views (default 2), right after its tables and before any rows. VoltDB can't create some views on a table that holds data, and a view made first is maintained through every insert, upsert, update and delete that follows.
  • oracle/VoltDBViewOracle, VIEWS: it picks a view. Half the time it first runs one more INSERT, UPDATE or DELETE on the view's table. It then compares three results, as multisets:

    1. SELECT * FROM v;
    2. the defining query with ORDER BY 1, which the rewriter skips, so it is computed from the table;
    3. the defining query as written, which the rewriter may answer from the view.

    The view and the query as written must both match the query computed from the table. A failure reports the three queries and the differing rows, and --use-reducer works.

  • Other changes:

    • The DML generators take a table, for the oracle's extra change.
    • TLP DISTINCT compares FLOAT values exactly, not to 12 digits (see Testing).
    • INSERT and UPSERT expect expression errors, since view maintenance evaluates a view's WHERE clause on each new row.
    • CREATE VIEW expects "with a LIMIT or OFFSET clause is not supported", which a WHERE clause that folds to FALSE produces (ENG-19957, closed as won't fix).
  • README: a VIEWS section, the status line, the option, the expected errors, and the milestone 10 bugs.

Bugs found

All are new, under ENG-30580, and avoided while --avoid-known-bugs is on.

Ticket What Workaround
ENG-30588 (Critical, node crash) An UPDATE of an indexed column fails when it overflows a view's DECIMAL or BIGINT SUM, as it should, but the row is left out of the index on that column. Lookups by the key miss it, and the next UPDATE of the row crashes the node: "Failed to remove tuple from index (during update)". A failed DELETE, or a failed UPDATE of other columns, leaves the index intact. Found by lab build #10's 1-node run. Views sum TINYINT, SMALLINT and INTEGER columns only, which VoltDB sums as BIGINT.
ENG-30584 (Major, wrong results) Deleting a group's last non-NULL value leaves 0 instead of NULL in a view's SUM. Ordinary queries the rewriter answers from the view return 0 too, such as SELECT g, SUM(x) FROM t GROUP BY g, so it reaches applications that never read the view. Views sum NOT NULL columns only.
ENG-30582 (Major) Once a table has a view, the rewriter fails to plan GROUP BY and aggregate queries on it that worked before. The same aggregate twice gives "Duplicate key", from a Collectors.toMap without a merge function in MVQueryRewriter.getViewColumnMaps. An aggregate of an expression, SUM(x + 0) or MIN(ABS(c)), gives a ClassCastException. The other oracles hit it at once. No duplicate aggregates in a view, and the other oracles' queries never read a table that has a view.
ENG-30583 (Major) A view's WHERE clause can block later DDL with "May not dynamically modify field 'predicate' of schema object 'MaterializedViewInfo{...}'". A FLOAT constant such as 12.5E0 blocks every later DDL in the database until the view is dropped. A predicate an index could serve (LIKE, or a TIMESTAMP BETWEEN) blocks an index on that column (two comments on the ticket). Views have no WHERE clause.

Testing

Each database creates up to --max-num-views views right after its
tables, so VoltDB keeps them up to date through every insert, upsert,
update and delete. VIEWS compares a view with its defining query
computed from the table (ORDER BY 1 keeps the view rewriter away) and
with the query as written, which the rewriter may answer from the view.
Its trials found ENG-30582 (the rewriter fails on duplicate aggregates
and aggregates of expressions), ENG-30583 (a view's WHERE clause blocks
later DDL) and ENG-30584 (a deleted group's SUM stays 0, not NULL);
each is avoided while --avoid-known-bugs is on.
Lab build #10 crashed its 1-node server: an UPDATE of an indexed column
failed when it overflowed a view's DECIMAL SUM, but left the row out of
the index, and the next UPDATE of the row hit "Failed to remove tuple
from index (during update)" (ENG-30588; BIGINT sums do the same). While
--avoid-known-bugs is on, a view sums TINYINT, SMALLINT and INTEGER
columns only, which VoltDB sums as BIGINT.
A local trial's UPDATE left two FLOATs, -32767.000000000004 and
-32766.999999999996, that GROUP BY rightly kept as two rows. The oracle
rounded both to 12 digits before removing the partitions' duplicates,
so the partitions had one row. Rounding is for HAVING's FLOAT SUMs;
DISTINCT has no aggregates, so it now keeps FLOATs exact.
@jwiebema1

Copy link
Copy Markdown
Author

Superseded by #51, which combines every ENG-30396 PR of this repo into one. This PR's branch is kept, and its description still has this milestone's details and lab results.

@jwiebema1 jwiebema1 closed this Nov 18, 2026
@jwiebema1
jwiebema1 deleted the ENG-30396-sqlancer-m10 branch November 25, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant