Skip to content

Support comparing arrays on bigger sizes with no supertype conversion(64, 128, 256 bits) operators( =, !=, >, >=, <, <=, IS DISTINCT FROM, IS NOT DISTINCT FROM) - #110245

Merged
diegomestre2 merged 55 commits into
ClickHouse:masterfrom
diegomestre2:array_bigger_sizes
Aug 5, 2026

Conversation

@diegomestre2

@diegomestre2 diegomestre2 commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Comparing two arrays whose element types have no least common supertype would previously threw ILLEGAL_TYPE_OF_ARGUMENT.

Reproduced on mixed signed/unsigned integers wider than 32 bits, such as Array(Int64) vs Array(UInt64) or Array(Int256) vs Array(UInt256). This happened because the array comparison path relied on getLeastSupertype to bring both sides to a common bigger element type, and no such type exists for those combinations.

This change adds executeArray path. Additionally, there is a templated version of executeArray for each operator and it calls the specific executeArrayLexicographicImpl.

Closes: #33897

At execution time executeArray compares the arrays lexicographically:

  • The aligned common prefix of each row's two arrays is gathered into two flat, equally-sized element columns, and the accurate element-wise equals (and, for ordering operators, less/greater) comparisons are run once over all gathered elements at once.
  • Per row, the first differing element decides the result; if the common prefixes are equal, the shorter array is treated as "less".

The path works for constant and non-constant columns, empty arrays, and nested arrays (Array(Array(...))).

Tests

Added 04509_array_comparison_bigger_types and 04538_null_safe_cmp_bigger_types covering all six comparison operators, IS DISTINCT FROM and IS NOT DISTINCT FROM, mixed signed/unsigned 64-bit and 256-bit element types, length tie-breaking, empty arrays, nested arrays, per-row offsets via a table, incomparable element types still throw.

Changelog category (leave one):

  • Bug Fix

Changelog entry:

Fixes comparisons that previously threw ILLEGAL_TYPE_OF_ARGUMENT when the operands have no least common supertype. Arrays such as Array(Int64) vs Array(UInt64) and Array(Int256) vs Array(UInt256) can now be compared lexicographically with =, !=, <, <=, >, >=, IS DISTINCT FROM, and IS NOT DISTINCT FROM. Null-safe comparisons such as isDistinctFrom / isNotDistinctFrom now also compare supported non-array numeric or decimal pairs by value instead of throwing.` Array comparison with nested type = Tuple(Nullable(...)) works for equality.

Version info

  • Merged into: 26.8.1.817 (included in 26.8 and later)

@CLAassistant

CLAassistant commented Jul 13, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@clickhouse-gh

clickhouse-gh Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3d91f77]

Summary: ✅


AI Review

Summary

This PR adds a lexicographic fallback for array comparisons whose element types have no least common supertype, extends the same family of no-supertype handling to the null-safe comparison wrappers, and adds focused regressions for wide signed/unsigned integers, nested nullability, and the FixedString(16)/IPv6 path. I re-checked the current head against the full thread history and did not find a remaining correctness issue or a new regression; the previously raised array/null-safe gaps appear addressed in the current code, and the current Praktika report for PR #110245 is all green.

Missing context / blind spots
  • ⚠️ I did not run the new queries locally because this workspace does not have a built clickhouse binary or build directory; confidence here comes from source inspection plus the current green Praktika report.
Final Verdict

✅ No blocking issues found in the current head.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.40% 86.50% +0.10%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.70% +0.00%

Changed lines: Changed C/C++ lines covered: 325/326 (99.69%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Jul 13, 2026
@diegomestre2
diegomestre2 force-pushed the array_bigger_sizes branch 2 times, most recently from 11c6cca to 0c7b370 Compare July 13, 2026 11:27
@diegomestre2 diegomestre2 added the can be tested Allows running workflows for external contributors label Jul 13, 2026
Comment thread src/Functions/FunctionsComparison.h Resolved
@Manerone Manerone self-assigned this Jul 14, 2026
Comment thread src/Functions/FunctionsComparison.h Resolved
…r arrayExecute since previous implementation did not build on amd_binary and arm_binary
Comment thread src/Functions/isDistinctFrom.cpp Resolved
Comment thread src/Functions/isNotDistinctFrom.cpp Resolved
@diegomestre2 diegomestre2 changed the title Support comparing arrays on bigger sizes with no supertype conversion(64, 128, 256 bits) operators( =, !=, >, >=, <, <=) Support comparing arrays on bigger sizes with no supertype conversion(64, 128, 256 bits) operators( =, !=, >, >=, <, <=, IS DISTINCT FROM, IS NOT DISTINCT FROM) Jul 16, 2026
Comment thread src/Functions/FunctionsComparison.h Resolved
Comment thread src/Functions/FunctionsNullSafeCmp.h Resolved
@diegomestre2 diegomestre2 removed their assignment Jul 27, 2026

@Fgrtue Fgrtue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the implementation of the algorithm is good and I have no questions to it. The code is understandable and easy to read, the comments also help.

I have one suggestion in terms of the design, and I also have a test case that seemed not to work for me:

SELECT [tuple(1::Nullable(Int64))] <  [tuple(1::Nullable(UInt64))];

However the version without arrays works fine:

SELECT tuple(1::Nullable(Int64)) <  tuple(1::Nullable(UInt64))

Comment thread src/Functions/FunctionsComparison.h Resolved
Comment thread src/Functions/FunctionsComparison.h Resolved
Comment thread src/Functions/FunctionsComparison.h Resolved
@diegomestre2

Copy link
Copy Markdown
Contributor Author

I think the implementation of the algorithm is good and I have no questions to it. The code is understandable and easy to read, the comments also help.

I have one suggestion in terms of the design, and I also have a test case that seemed not to work for me:

SELECT [tuple(1::Nullable(Int64))] <  [tuple(1::Nullable(UInt64))];

However the version without arrays works fine:

SELECT tuple(1::Nullable(Int64)) <  tuple(1::Nullable(UInt64))

Good catch! At some point I tried to discuss this with claude and checked the code. It would be difficult to allow this query to work because the null-safe code on NullSafeCmp only allow comparisons without order, The equality comparison works like in the query below:

SELECT [tuple(1::Nullable(Int64))] =  [tuple(1::Nullable(UInt64))];

It works because it uses the code from FunctionComparison<EqualsOp, NameEquals, true>::executeTupleImpl which composes tuple fields with FunctionIsNotDistinctFrom that propagate null-safety through the recursion. To support the comparison query it would require changes as big as this PR, because once you do it, you have to guarantee order between NULLs. We could maybe leave this as an issue for a future PR.

@diegomestre2

Copy link
Copy Markdown
Contributor Author

The failure in Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) is a known flaky signature, not a deterministic test assertion from this PR:

Server crash: Logical error: Got read request from replica A for unknown stream B. (STID: 5217-5b3d)
This exact signature is already tracked and auto-matched in CI to #110518
01666_merge_tree_max_query_limit appears as UNKNOWN after the server died (cascade), not as primary root cause

Job link: https://github.com/ClickHouse/ClickHouse/actions/runs/30459583353/job/90868375171?pr=110245
Tracking issue: #110518

@clickhouse-gh

clickhouse-gh Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.40% 86.50% +0.10%
Functions 91.90% 91.90% +0.00%
Branches 78.60% 78.70% +0.10%

Changed lines: Changed C/C++ lines covered: 342/343 (99.71%) · Uncovered code

Full report · Diff report

@Fgrtue Fgrtue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really liked reading through the code. Everything looks modular and is was easy to decouple the logic. I made just two suggestions about using constexpr. Other than that I don't have any more suggestion that I find in any way significant. If you decide to make those changes and decide to keep the current implementation without any other changes -- please feel free to merge, because green mark from me would be just a formality after all (:

Comment thread src/Functions/FunctionsComparison.h Resolved
Comment thread src/Functions/FunctionsComparison.h Resolved
Comment thread src/Functions/FunctionsComparison.h Resolved
Comment thread src/Functions/equals.cpp Resolved
Comment thread src/Functions/isDistinctFrom.cpp Resolved
@diegomestre2
diegomestre2 added this pull request to the merge queue Aug 5, 2026
Merged via the queue into ClickHouse:master with commit 4b1308e Aug 5, 2026
522 of 527 checks passed
@diegomestre2
diegomestre2 deleted the array_bigger_sizes branch August 5, 2026 10:55
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 5, 2026
pull Bot pushed a commit to Dream-hu/ClickHouse that referenced this pull request Aug 13, 2026
Comparing two arrays whose element types have no least supertype takes the
element-wise lexicographic path added by ClickHouse#110245. When a position holds a bare
`Nothing`, `getReturnTypeImpl` declared a plain `UInt8` while the executing
element comparator declared `Nothing`, so the unconditional
`assert_cast<const ColumnUInt8 &>` on the element result received a
`ColumnNothing` and killed the server:

    SELECT CAST([], 'Array(Nullable(Nothing))') > [[1]];
    Logical error: 'Bad cast from type DB::ColumnNothing to DB::ColumnVector<char8_t>'

The divergence exists because validation recurses into `getReturnTypeImpl`
directly, which has no `Nothing` handling, while execution goes through the
overload resolver, which short-circuits to `DataTypeNothing`. It is reachable
from ordinary SQL, both during constant folding and at runtime over a table,
and through `Tuple` members at any array depth.

Close it from both ends. Validation now rejects a position that nothing can
decide: a bare `Nothing`, directly or through a `Tuple` member. Two `Nothing`
shapes stay decidable and keep answering as they do today -- `Nullable(Nothing)`
is decided by its own all-set null map, and `Array(Nothing)` shares a supertype
with `Array(T)` so it never reaches this branch. Each side is classified
independently, because one side's null map never decides a position on the
other side. `Array` and `Map` are not descended, matching
`FunctionsNullSafeCmp::containsNothing`; depth is still covered because the
array branch recurses once per level and is only consulted where that level has
no supertype.

Execution answers what validation accepted and fails closed otherwise: a result
is synthesised only where a direct `Nothing` argument is paired with its own
all-set null map, and any other `Nothing` element type throws instead of
fabricating a `false`. The direct-recursion optimisation is kept.

An untyped NULL or empty array against a non-supertypable partner now answers
instead of aborting, matching the supertype path. The regression never shipped
in a release.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exception when comparing Array(Int64) and Array(UInt64)

7 participants