Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport #50177 to 23.4: Fix broken index analysis when binary operator contains a null constant argument #50517

Merged
merged 1 commit into from Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Storages/MergeTree/KeyCondition.cpp
Expand Up @@ -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, "" });
Expand Down
@@ -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;