diff --git a/dbms/src/Storages/MergeTree/KeyCondition.cpp b/dbms/src/Storages/MergeTree/KeyCondition.cpp index a2789fe3063..9450d41b794 100644 --- a/dbms/src/Storages/MergeTree/KeyCondition.cpp +++ b/dbms/src/Storages/MergeTree/KeyCondition.cpp @@ -16,6 +16,8 @@ #include #include +#include + namespace DB { @@ -1095,10 +1097,14 @@ bool KeyCondition::mayBeTrueInParallelogram(const std::vector & parallelo } else if (element.function == RPNElement::FUNCTION_NOT) { + assert(!rpn_stack.empty()); + rpn_stack.back() = !rpn_stack.back(); } else if (element.function == RPNElement::FUNCTION_AND) { + assert(!rpn_stack.empty()); + auto arg1 = rpn_stack.back(); rpn_stack.pop_back(); auto arg2 = rpn_stack.back(); @@ -1106,6 +1112,8 @@ bool KeyCondition::mayBeTrueInParallelogram(const std::vector & parallelo } else if (element.function == RPNElement::FUNCTION_OR) { + assert(!rpn_stack.empty()); + auto arg1 = rpn_stack.back(); rpn_stack.pop_back(); auto arg2 = rpn_stack.back(); @@ -1124,7 +1132,7 @@ bool KeyCondition::mayBeTrueInParallelogram(const std::vector & parallelo } if (rpn_stack.size() != 1) - throw Exception("Unexpected stack size in KeyCondition::mayBeTrueInRange", ErrorCodes::LOGICAL_ERROR); + throw Exception("Unexpected stack size in KeyCondition::mayBeTrueInParallelogram", ErrorCodes::LOGICAL_ERROR); return rpn_stack[0].can_be_true; } @@ -1223,6 +1231,8 @@ bool KeyCondition::alwaysUnknownOrTrue() const } else if (element.function == RPNElement::FUNCTION_AND) { + assert(!rpn_stack.empty()); + auto arg1 = rpn_stack.back(); rpn_stack.pop_back(); auto arg2 = rpn_stack.back(); @@ -1230,6 +1240,8 @@ bool KeyCondition::alwaysUnknownOrTrue() const } else if (element.function == RPNElement::FUNCTION_OR) { + assert(!rpn_stack.empty()); + auto arg1 = rpn_stack.back(); rpn_stack.pop_back(); auto arg2 = rpn_stack.back(); @@ -1239,6 +1251,9 @@ bool KeyCondition::alwaysUnknownOrTrue() const throw Exception("Unexpected function type in KeyCondition::RPNElement", ErrorCodes::LOGICAL_ERROR); } + if (rpn_stack.size() != 1) + throw Exception("Unexpected stack size in KeyCondition::alwaysUnknownOrTrue", ErrorCodes::LOGICAL_ERROR); + return rpn_stack[0]; }