Merge pull request #50177 from amosbird/fix_50094

Fix broken index analysis when binary operator contains a null constant argument
This commit is contained in:
Alexey Milovidov 2023-06-02 01:29:03 +03:00 committed by GitHub
commit 60dccff77c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -1334,6 +1334,10 @@ bool KeyCondition::isKeyPossiblyWrappedByMonotonicFunctions(
arguments.push_back(const_arg);
kind = FunctionWithOptionalConstArg::Kind::RIGHT_CONST;
}
/// If constant arg of binary operator is NULL, there will be no monotonicity.
if (const_arg.column->isNullAt(0))
return false;
}
else
arguments.push_back({ nullptr, key_column_type, "" });

View File

@ -0,0 +1,12 @@
drop table if exists tab;
create table tab (x DateTime) engine MergeTree order by x;
SELECT toDateTime(65537, toDateTime(NULL), NULL)
FROM tab
WHERE ((x + CAST('1', 'Nullable(UInt8)')) <= 2) AND ((x + CAST('', 'Nullable(UInt8)')) <= 256)
ORDER BY
toDateTime(toDateTime(-2, NULL, NULL) + 100.0001, NULL, -2, NULL) DESC NULLS LAST,
x ASC NULLS LAST;
drop table tab;