Skip to content

fix(clickhouse): TLPDistinct and TLPSetOp treat -0 and 0 as the same value - #37

Open
groeneai wants to merge 1 commit into
ClickHouse:mainfrom
groeneai:fix-clickhouse-signed-zero-set-compare
Open

groeneai wants to merge 1 commit into
ClickHouse:mainfrom
groeneai:fix-clickhouse-signed-zero-set-compare

Conversation

@groeneai

Copy link
Copy Markdown

The 2026-11-28 master nightly (SQLancer (arm_asan_ubsan), SQLancer (arm_release)) reported 9 TLPDistinct / TLPSetOp findings, all about -0 vs 0.

Since ClickHouse/ClickHouse#130054, DISTINCT treats -0. and 0. as one key and keeps the first row it sees, so which zero a query prints depends on row order. UNION DISTINCT is a DISTINCT over the union. TLPDistinct and the UNION_DISTINCT and INTERSECT checks of TLPSetOp compared the printed values as strings, so {0} on one side and {-0} on the other became a finding. In database4, SELECT DISTINCT ... printed 0, 0 and the partitioned query printed -0, 0 for the same two rows.

This maps -0 to 0 with ComparatorHelper.canonicalizeResultValue before these comparisons, as the DuckDB, Databend and Doris DISTINCT testers already do.

INTERSECT ALL and EXCEPT ALL still compare the zeros bitwise on master (SELECT -0. INTERSECT ALL SELECT 0. is empty, while INTERSECT DISTINCT, now a join, returns -0). The other 4 findings of that nightly (checkIntersect dropping the zero, checkExcept leaving -0) come from that server-side difference and are still reported.

Checked against master 26.12.1.1 (debug build, .claude/clickhouse-config/ overrides):

check before with this PR
database4 table replayed, the CI's two TLPDistinct queries, comparator call, 10 runs fails 10/10 passes 10/10
TLPDistinct,SetOpTLP, 10 threads, 10 min 23 findings: 9 zero-representative (UNION_DISTINCT 6, INTERSECT 3), 14 INTERSECT ALL / EXCEPT ALL 10 findings, all INTERSECT ALL / EXCEPT ALL

mvn verify -DskipTests=true -Djacoco.skip=true passes with 0 Checkstyle violations.

Related: ClickHouse/ClickHouse#128538

🤖 Generated with Claude Code

…value

Since ClickHouse #130054, DISTINCT (and UNION DISTINCT, which is a DISTINCT
over the union) treats -0. and 0. as one key and keeps the first row it sees,
so which of the two zeros a query prints depends on row order. TLPDistinct and
the UNION DISTINCT and INTERSECT checks of TLPSetOp compared the printed values
as strings, so the same set of values printed as {0} on one side and {-0} on
the other was reported as a mismatch.

Map -0 to 0 with ComparatorHelper.canonicalizeResultValue before these set
comparisons, as the DuckDB, Databend and Doris DISTINCT testers already do.
INTERSECT ALL and EXCEPT ALL still compare the zeros bitwise on master, so a
mismatch caused by that is still reported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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