Repository navigation
bech32Encode is not injective - #117239
Conversation
On any encoding error - most easily, data too long for a valid Bech32 string - the function returns an empty string rather than NULL, so arbitrarily many distinct inputs collapse onto that one result. The default-on `optimize_injective_functions_in_group_by` and `optimize_injective_functions_in_limit_by` trusted the claim and grouped or limited by the raw argument, returning one group (or row) per distinct argument instead of one. Closes: #117201
|
Workflow [PR], commit [ed954df] Summary: ✅
AI ReviewSummaryThis PR corrects the Final Verdict✅ No findings. LLVM Coverage ReportMeasured on commit ed954df.
Changed lines: Changed C/C++ lines covered: 1/3 (33.33%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 6 s compile time in total, 7 of them have a recent master baseline. |
The AI review pointed out that the `bech32Encode` injectivity claim is consumed by more than the `GROUP BY` and `LIMIT BY` key rewrites: `TruncateOrderByAfterGroupByKeysPass` drops the `ORDER BY` tiebreakers after an injective function of the keys, and `isPartitionKeyFunctionOfKeys` strips injective functions off the aggregation keys to aggregate each partition on its own. Both returned wrong results before the fix: the tiebreaker was truncated away, and eight partitions whose values all encode to an empty string produced eight groups instead of one.
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=117239&sha=727930f0556a9e89930f9d76881839790a3aaf52&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%205%2F6%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. Three |
|
🕵 Addressed the AI review's finding: the new test now also covers the other two default-on planner paths that trust
Both were verified to fail before the fix and pass after it with a local build. |
|
Not PR-caused, and all three shards resolve to fixes that are already merged: the tree that produced them predates both. Three shards fired at The kernel records in the job logs name the breaching leaf and the victim:
Neither fix was in that tree. The run's base is master Your After both merged the residual is one shard only. Distinct trees per shard carrying the So 2/6 and 5/6 need nothing further. The 6/6 residual is a container leak: three leaf test files declare No separate pull request is needed from me here: every shard at that sha is owned by #117202, #117412 or #117564. |
`EXPLAIN QUERY TREE` and the two planner passes the test covers exist in the analyzer only, so the test failed in the old-analyzer CI runs with `EXPLAIN QUERY TREE is only supported with the analyzer`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117239&sha=55fe16cd971c29fccd00631618cfc1952210039a&name_0=PR&name_1=Stateless%20tests%20(amd_llvm_coverage,%20old%20analyzer,%20s3%20storage,%20DBReplicated,%20parallel,%202/3) #117239
…the `bech32Encode` test `StorageDistributed::getOptimizedQueryProcessingStageAnalyzer` strips injective functions off the `GROUP BY`, `DISTINCT` and `LIMIT BY` keys and, when the sharding key remains, lets every shard complete the query on its own. With `bech32Encode` wrongly marked injective, each shard emitted its own group of the inputs that encode to an empty string. Both shards of `test_cluster_two_shards` read the same local table, so the test asserts one group, distinct value and limited row rather than two, with the `optimize_distributed_group_by_sharding_key = 0` controls next to it.
Closes: #117201
Related: #117210
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix wrong results for
GROUP BYandLIMIT n BYoverbech32Encode. The function declared itselfinjective, but it returns an empty string on any encoding error, so distinct inputs that collapse
onto that result were grouped and limited as if they were distinct.
Description
bech32Encodereturns an emptyString(not NULL) whenever encoding fails — most easily reachedwith data longer than a valid Bech32 string permits — so arbitrarily many distinct inputs share that
one output. The default-on
optimize_injective_functions_in_group_byandoptimize_injective_functions_in_limit_bytrusted the claim and grouped/limited by the raw argument,returning one group (or row) per distinct argument instead of one.
bech32Decodealready answersfalsefor the analogous reason.The same claim is also trusted by
TruncateOrderByAfterGroupByKeysPass, which drops theORDER BYtiebreakers after an injective function of the
GROUP BYkeys, and byisPartitionKeyFunctionOfKeys,which strips injective functions off the aggregation keys to aggregate each partition on its own.
Both returned wrong results too. So did
StorageDistributed::getOptimizedQueryProcessingStageAnalyzer,which strips injective functions off the
GROUP BY,DISTINCTandLIMIT BYkeys and, when thesharding key remains, lets every shard complete the query on its own without a merge on the initiator.
Test
05065_bech32_encode_not_injectivecovers all five paths, and also checks that valid datastill round-trips.
Workflow [PR]
Sync PR [sync-upstream/pr/117239]