Skip to content

Commit e34e572

Browse files
Backport #90557 to 25.10: Fix logical error caused by type mismatch in equals function
1 parent 3a87302 commit e34e572

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

src/Functions/FunctionsComparison.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,7 @@ class FunctionComparison : public IFunction
12321232

12331233
bool has_nullable = false;
12341234
bool has_null = false;
1235+
bool has_nothing = false;
12351236

12361237
const DataTypeTuple * any_tuple = left_tuple ? left_tuple : right_tuple;
12371238
size_t size = any_tuple->getElements().size();
@@ -1245,9 +1246,17 @@ class FunctionComparison : public IFunction
12451246
element_type = func->build(args)->getResultType();
12461247
}
12471248
has_nullable = has_nullable || element_type->isNullable() || isDynamic(element_type);
1249+
1250+
/// Nullable(Nothing)
12481251
has_null = has_null || element_type->onlyNull();
1252+
1253+
/// Nothing
1254+
has_nothing = has_nothing || isNothing(element_type);
12491255
}
12501256

1257+
if (has_nothing)
1258+
return std::make_shared<DataTypeNothing>();
1259+
12511260
/// If any element comparison is nullable, return type will also be nullable.
12521261
/// We useDefaultImplementationForNulls, but it doesn't work for tuples.
12531262
if (has_null)

tests/queries/0_stateless/03724_filter_assume_not_null_materialize.reference

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
SET allow_not_comparable_types_in_comparison_functions = 0;
2+
3+
SELECT (assumeNotNull((NULL)), 1); -- { serverError ILLEGAL_COLUMN }
4+
5+
SELECT (assumeNotNull(materialize(NULL)), 1); -- { serverError ILLEGAL_COLUMN }
6+
7+
SELECT 1 WHERE (assumeNotNull(NULL), 1) = (1, 1); -- { serverError ILLEGAL_COLUMN }
8+
9+
SELECT 1 WHERE (assumeNotNull(materialize(NULL)), 1) = (1, 1); -- { serverError ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER }
10+
11+
SET allow_not_comparable_types_in_comparison_functions = 1;
12+
13+
SELECT (assumeNotNull((NULL)), 1); -- { serverError ILLEGAL_COLUMN }
14+
15+
SELECT (assumeNotNull(materialize(NULL)), 1); -- { serverError ILLEGAL_COLUMN }
16+
17+
SELECT 1 WHERE (assumeNotNull(NULL), 1) = (1, 1); -- { serverError ILLEGAL_COLUMN }
18+
19+
SELECT 1 WHERE (assumeNotNull(materialize(NULL)), 1) = (1, 1); -- { serverError ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
()
2+
\N 1.1
3+
\N 2.2
4+
1 3.3
5+
2 4.4
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
SELECT () ORDER BY 1 LIMIT 1 WITH TIES;
2+
3+
DROP TABLE IF EXISTS t0;
4+
5+
CREATE TABLE t0 (v1 Nullable(Int8), v2 Decimal(18,4)) ENGINE = MergeTree() ORDER BY tuple();
6+
SELECT DISTINCT TOP 1 WITH TIES * FROM t0 ORDER BY tuple();
7+
8+
INSERT INTO t0 VALUES (NULL, 1.1), (NULL, 2.2), (1, 3.3), (2, 4.4);
9+
SELECT DISTINCT TOP 1 WITH TIES * FROM t0 ORDER BY tuple();

0 commit comments

Comments
 (0)