Skip to content

ENG-30396: SETOPS and DERIVED oracles: set operations, derived tables and WITH (milestone 16) - #16

Closed
jwiebema1 wants to merge 3 commits into
ENG-30396-sqlancer-m15from
ENG-30396-sqlancer-m16
Closed

jwiebema1 wants to merge 3 commits into
ENG-30396-sqlancer-m15from
ENG-30396-sqlancer-m16

Conversation

@jwiebema1

@jwiebema1 jwiebema1 commented Nov 8, 2026 •

Copy link
Copy Markdown

Milestone 16 of ENG-30396 (tracked in ENG-30581, epic ENG-30580 "SQL Housekeeping"): set operations, derived tables and WITH. Stacked on #15 (milestone 15), which is stacked on #14 to #1; review those first.

The nightly job runs the new oracles once VoltDB/internal#6356 is merged; VoltDB/pro#7102 adds them to run-jenkins-sqlancer-test.sh's default.

Why

No oracle exercised UNION, INTERSECT or EXCEPT, a derived table, or a common table expression; the planner rewrites all three (pushing a WHERE clause into a derived table, distributing a set operation across partitions), and a wrong rewrite gives a wrong result without an error.

What it changes

  • SETOPS (oracle/VoltDBSetOperationOracle): UNION, INTERSECT and EXCEPT, each with and without ALL, as A op B or (A op B) op C, sometimes inside SELECT * FROM (...) AS u (not when an output is a string, ENG-30607, or an operand is partitioned, ENG-30604), checked against the same operation done in Java on each operand's rows. Rows are compared as multisets with NULLs equal and exact numbers by value (VoltDBRows.key), since a set operation's type may widen. The oracle follows VoltDB's rules: one type per position (an operand without a column of it outputs a constant such as CAST(2 AS TINYINT)), and at most one partitioned operand.
  • DERIVED (oracle/VoltDBDerivedTableOracle), three modes:
    • WRAP: a query against SELECT * FROM (query) AS d.
    • PUSH: a query against the same query with every FROM column selected under an alias in a derived table and its fetch list and WHERE clause outside it, so that VoltDB pushes the WHERE clause back down; over replicated tables, sometimes as WITH D AS (...).
    • RECURSIVE: WITH RECURSIVE over an integer column of a replicated table against the closure computed in Java (closures over 5,000 rows are skipped).
  • Queries that don't start with SELECT (WITH ..., (SELECT ...) EXCEPT ...) go through {call @AdHoc(?)}, since the JDBC driver rejects them in executeQuery (ENG-30603).
  • run-sqlancer.sh passes --num-statement-kind-retries 20. SQLancer retries a failed INSERT with new values up to 1,000 times; once a table's key had run out of values (a BOOLEAN or TINYINT primary key), every insert of that database spent 1,000 constraint violations, and the runs' "successful statements" fell to 70 to 81%. With 20, a local seed that had 54% has 90%.
  • The README: a section on both oracles, the status line, the option table, the nightly table, the bug table.

Bugs found

Ticket Issue Workaround while --avoid-known-bugs is true
ENG-30604 A set operation inside a derived table, with an operand pinned to one partition (WHERE k = 1 on the partitioning column), returns the replicated operands' rows once per site: 17 rows instead of 3 on 8 sites. Found by SETOPS. Wrong result. A set operation that reads a partitioned table is not wrapped in a derived table.
ENG-30605 String literals at one position of a set operation are padded to the longest: 'a' UNION ALL 'abc' gives 'a '. A VARCHAR column on either side is right. Found by SETOPS. Wrong result. String and VARBINARY constants in set operations have one character or byte.
ENG-30607 A set operation inside a derived table, SELECT * FROM (A UNION B) AS u, fails with "The size 17 of the value '...' exceeds the size of the VARCHAR(16) column" when A's column is VARCHAR(16) or wider and a value from B is longer; the bare set operation is right. Found by SETOPS in lab build #28. Wrong error. A set operation with a VARCHAR or VARBINARY output is not wrapped in a derived table.
ENG-30603 (JDBC, under ENG-30559) The driver takes a statement for a query only if it starts with SELECT: executeQuery rejects WITH ... SELECT and (SELECT ...) EXCEPT ..., and execute returns their first value as an update count. Such queries go through {call @AdHoc(?)}.

Testing

…, WITH)

SETOPS checks UNION, INTERSECT and EXCEPT, with and without ALL, against the
operation done in Java on the operands' rows. DERIVED checks a query against
itself in a derived table, with its WHERE clause outside a derived table or
common table, and a recursive WITH against its closure computed in Java.

Queries that do not start with SELECT go through @adhoc (ENG-30603). Avoids
ENG-30604 and ENG-30605.
@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-m16 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