Skip to content

ENG-30396: VoltDB provider, milestone 5: TLP DISTINCT, HAVING and AGGREGATE - #5

Closed
jwiebema1 wants to merge 4 commits into
ENG-30396-sqlancer-m4from
ENG-30396-sqlancer-m5
Closed

jwiebema1 wants to merge 4 commits into
ENG-30396-sqlancer-m4from
ENG-30396-sqlancer-m5

Conversation

@jwiebema1

@jwiebema1 jwiebema1 commented Nov 3, 2026 •

Copy link
Copy Markdown

Milestone 5 of ENG-30396: the TLP aggregate, HAVING and DISTINCT oracles, which the plan lists third, "once the first two are stable". Stacked on #4 (milestone 4), which is stacked on #3, #2 and #1; review those first.

What it adds

Each oracle partitions a query by a random predicate p being TRUE, FALSE or NULL, then checks that the three partitions together give the original query's result.

  • TLP_DISTINCT:
    • The original query is a SELECT DISTINCT of some columns or, half the time, the same columns with GROUP BY.
    • The partitions add WHERE p, WHERE NOT p and WHERE p IS NULL.
    • Their rows, without duplicates, must equal the original's, which must have none.
  • TLP_HAVING:
    • The original query groups by some columns and selects some of them, plus 1 to 3 aggregates. Some originals have a WHERE clause.
    • The partitions add HAVING p, HAVING NOT p and HAVING p IS NULL. Here p mixes the grouping columns with MIN, MAX, SUM and COUNT of expressions.
    • Their rows together must equal the original's.
  • TLP_AGGREGATE:
    • The original query computes 1 to 3 of MIN, MAX, SUM, COUNT(x) and COUNT(*) over all rows.
    • The partitions compute the same with WHERE p, WHERE NOT p and WHERE p IS NULL.
    • Combined, they must give the original's values.
    • The shared oracles combine partitions in SQL, as an outer aggregate over a UNION ALL. VoltDB rejects that over partitioned tables, so this oracle combines them in Java.
    • Integer and DECIMAL sums are added exactly. FLOAT sums are allowed a relative difference of 1e-9.
    • AVG can't be combined, so it is left out. So are MIN and MAX of BOOLEAN (ENG-30493).

Structure

  • VoltDBTLPWhereOracle becomes VoltDBTLPOracle, with a mode for each of WHERE, DISTINCT and HAVING.
  • The aggregate oracle is VoltDBTLPAggregateOracle.
  • All of them support --use-reducer.

Other changes

  • New AST classes: an aggregate node and an alias node.
  • VoltDBSelect: now prints DISTINCT, GROUP BY and HAVING.
  • Row comparison: compares FLOAT values to 12 significant digits. A FLOAT SUM in a HAVING query's output can differ in its last digit between queries.
  • Generator: builds aggregates, grouping columns and HAVING predicates.
  • Expected errors: adds has more than 38 digits of precision, VoltDB's message when a DECIMAL overflows in an expression of constants.
  • Join generation for TLP DISTINCT and HAVING: with FULL JOINs gone, a LEFT JOIN of a replicated table after a partitioned join could be "not plannable" (the milestone 3 limitation). These two oracles keep replicated tables in the FROM list in that case.
  • ENG-4643: the connection's result-set wrapper now returns null for a NULL from getObject(), as it already did from getString().
  • Shared code: SQLancerResultSet gains getObject().

Bugs found

Each has a minimal reproduction and is linked to ENG-30396. Each is worked around while --avoid-known-bugs is on, the default.

Ticket What Workaround
ENG-30529 (Major, wrong rows) A multi-partition GROUP BY or DISTINCT groups by only one of two columns with the same name, such as t0.c0 and t1.c0. Found while checking the SQL these oracles generate. Every SQLancer table names its columns c0, c1, ..., so almost every join hits it. TLP HAVING later found that aliases don't help when the grouped columns aren't selected (added as a comment). Grouping columns have distinct names, and every output column has its own alias.
ENG-30530 (Major, wrong rows) GROUP BY or DISTINCT on the partitioning column of a table that an outer join null-extends returns one NULL group per partition. The plan has no coordinator aggregation. Found by TLP DISTINCT. With an outer join, partitioning columns are not grouped by.
ENG-30531 (Major, wrong rows) GROUP BY or DISTINCT on an indexed column, inlined into a FULL JOIN as a serial aggregation, returns the NULL group twice: the null-extended rows come after the index-ordered ones. Replicated tables alone are enough. Found by TLP DISTINCT in the first 30-minute runs: all 8 of their failures, each reduced to 3 to 6 statements. Related to the closed ENG-13603. TLP DISTINCT and TLP HAVING make no FULL JOINs.
ENG-30533 (Major, wrong result) MIN or MAX of a column without GROUP BY, through a multi-column index range on that column, skips rows whose next index column is NULL. With an index on (a, b) and the row (5, NULL), MIN(a) WHERE a = 5 is NULL. Found by TLP AGGREGATE in the second 30-minute runs, and reduced by SQLancer to 3 statements. TLP AGGREGATE writes MIN and MAX of a bare column as (c + 0) or (c || ''), which the shortcut doesn't apply to. MIN and MAX of VARBINARY and temporal values are left out of that oracle.
ENG-30534 (Minor, error) Aggregates of x'' and of '' in a GROUP BY join whose ON condition holds x'' fail with "Type VARCHAR can't be cast as VARBINARY", as if the two were one expression. Found by TLP HAVING in the third 30-minute runs. VARBINARY constants inside an aggregate are never empty.
ENG-30504 (comment added) In HAVING, NOT (a OR b) fails with the BOOLEAN cast error even as the whole clause. Found by TLP HAVING. The NOT partition pushes the NOT down (De Morgan).

Also seen: an aggregate query whose WHERE clause folds to FALSE returns no row. This is the existing ENG-19957 (the planner adds LIMIT 0), which was closed as won't fix. The README lists it as an intentional difference, and TLP AGGREGATE treats such a partition as the empty aggregate.

Testing

  • mvn verify -DskipTests passes: formatter, checkstyle, PMD and SpotBugs.

  • 3-minute trials of each oracle, 1 node: 4,578 DISTINCT checks, 3,604 HAVING checks and 4,004 AGGREGATE checks, none failing.

  • With --avoid-known-bugs false: the known bugs fail the run as expected.

  • Acceptance, 30 minutes each: 8 sites per host, with TLP_DISTINCT, TLP_HAVING and TLP_AGGREGATE together and --use-reducer. Both runs on head c29ce77:

    Cluster Seed Checks Result
    3 nodes, k=1 20261112 147,391 PASS, no FATAL lines
    1 node 20261113 225,976 PASS, no FATAL lines
  • Earlier acceptance runs failed and found bugs. Three earlier pairs of runs each failed, and each failure was a real VoltDB bug, worked around in the next commit:

    • First pair: ENG-30531.
    • Second pair: ENG-30533 on 1 node. The 3-node run, seed 20261108, passed with 151,277 checks.
    • Third pair: ENG-30534 on 3 nodes. The 1-node run, seed 20261111, passed with 225,085 checks.
    • Also fixed along the way: two harness gaps, FLOAT digits in HAVING output and a new DECIMAL error message.
  • TestVoltDB gains a test for the three oracles. Like the others, it runs only with VOLTDB_AVAILABLE=true against localhost:21212, so it was not run here.

…REGATE

Three more oracles. TLP_DISTINCT and TLP_HAVING are modes of the TLP oracle
(VoltDBTLPWhereOracle becomes VoltDBTLPOracle); TLP_AGGREGATE combines MIN,
MAX, SUM and COUNT over the three WHERE partitions in Java, since VoltDB
rejects the shared oracles' UNION ALL over partitioned tables.

The generator gains aggregates, grouping columns and HAVING predicates, and
works around ENG-30529 (aliases on grouped output), ENG-30530 (no grouping on
partitioning columns with an outer join) and ENG-30504 in HAVING (NOT pushed
down). A partition that returns no row is the empty aggregate (ENG-19957).
getObject() now returns null for a NULL value too (ENG-4643).
…output to 12 digits

The 30-minute runs found ENG-30531: GROUP BY or DISTINCT on an indexed
column, inlined into a FULL JOIN as a serial aggregation, returns the NULL
group twice. TLP DISTINCT and HAVING now make no FULL JOINs while
--avoid-known-bugs is on. A FLOAT SUM in a HAVING query's output can differ
in its last digit between queries, so FLOAT values compare to 12 digits.
…CIMAL precision errors

The second 30-minute runs found ENG-30533: MIN of a column without GROUP BY,
through a multi-column index whose next column is NULL, skips the row. TLP
AGGREGATE now writes MIN and MAX of a bare column as (c + 0) or (c || ''),
which the shortcut does not apply to.

Trials found ENG-30529 again where the grouped columns are not selected, so
grouping columns now have distinct names. With FULL JOINs gone from TLP
DISTINCT and HAVING, a LEFT JOIN of a replicated table after partitioned
joins could become "not plannable"; those generators keep replicated tables
in the FROM list there. "has more than 38 digits of precision" is DECIMAL
overflow in folded constants, an expected error.
…gates

The third 30-minute runs found ENG-30534: aggregates of x'' and of '' in a
GROUP BY join whose ON condition holds x'' fail with a cast error.
@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-m5 branch November 25, 2026 13:45
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