dbms: more sound solution for backtracking for-loop. [#METR-12108]

This commit is contained in:
Andrey Mironov 2014-08-08 10:08:17 +04:00
parent beca178f2f
commit e8fe836a1b

View File

@ -463,13 +463,16 @@ void ExpressionAnalyzer::optimizeGroupBy()
};
/// iterate over each GROUP BY expression, eliminate injective function calls and literals
for (size_t i = 0; i < group_exprs.size(); ++i)
for (size_t i = 0; i < group_exprs.size();)
{
if (const auto function = typeid_cast<ASTFunction*>(group_exprs[i].get()))
{
/// assert function is injective
if (!injectiveFunctionNames.count(function->name))
{
++i;
continue;
}
/// copy shared pointer to args in order to ensure lifetime
auto args_ast = function->arguments;
@ -478,7 +481,6 @@ void ExpressionAnalyzer::optimizeGroupBy()
* next iteration does not skip not yet processed data
*/
remove_expr_at_index(i);
i -= 1;
/// copy non-literal arguments
std::remove_copy_if(
@ -489,7 +491,11 @@ void ExpressionAnalyzer::optimizeGroupBy()
else if (is_literal(group_exprs[i]))
{
remove_expr_at_index(i);
i -= 1;
}
else
{
/// if neither a function nor literal - advance to next expression
++i;
}
}