Avoid exception when negative or floating point constant is used in WHERE condition for indexed tables #11905

This commit is contained in:
Alexey Milovidov 2020-07-10 09:30:49 +03:00
parent c16d8e094b
commit 276b3a0215
3 changed files with 38 additions and 9 deletions

View File

@ -866,17 +866,23 @@ bool KeyCondition::tryParseAtomFromAST(const ASTPtr & node, const Context & cont
return atom_it->second(out, const_value); return atom_it->second(out, const_value);
} }
else if (getConstant(node, block_with_constants, const_value, const_type)) /// For cases where it says, for example, `WHERE 0 AND something` else if (getConstant(node, block_with_constants, const_value, const_type))
{ {
if (const_value.getType() == Field::Types::UInt64 /// For cases where it says, for example, `WHERE 0 AND something`
|| const_value.getType() == Field::Types::Int64
|| const_value.getType() == Field::Types::Float64)
{
/// Zero in all types is represented in memory the same way as in UInt64.
out.function = const_value.safeGet<UInt64>()
? RPNElement::ALWAYS_TRUE
: RPNElement::ALWAYS_FALSE;
if (const_value.getType() == Field::Types::UInt64)
{
out.function = const_value.safeGet<UInt64>() ? RPNElement::ALWAYS_TRUE : RPNElement::ALWAYS_FALSE;
return true;
}
else if (const_value.getType() == Field::Types::Int64)
{
out.function = const_value.safeGet<Int64>() ? RPNElement::ALWAYS_TRUE : RPNElement::ALWAYS_FALSE;
return true;
}
else if (const_value.getType() == Field::Types::Float64)
{
out.function = const_value.safeGet<Float64>() ? RPNElement::ALWAYS_TRUE : RPNElement::ALWAYS_FALSE;
return true; return true;
} }
} }

View File

@ -0,0 +1,19 @@
DROP TABLE IF EXISTS t0;
CREATE TABLE t0
(
`c0` Int32,
`c1` Int32 CODEC(NONE)
)
ENGINE = MergeTree()
ORDER BY tuple()
SETTINGS index_granularity = 8192;
INSERT INTO t0 VALUES (0, 0);
SELECT t0.c1 FROM t0 WHERE NOT (t0.c1 OR (t0.c0 AND -1524532316));
SELECT t0.c1 FROM t0 WHERE NOT (t0.c1 OR (t0.c0 AND -1.0));
SELECT t0.c1 FROM t0 WHERE NOT (t0.c1 OR (t0.c0 AND inf));
SELECT t0.c1 FROM t0 WHERE NOT (t0.c1 OR (t0.c0 AND nan));
DROP TABLE t0;