Materialize column in header for not isSuitableForConstantFolding

This commit is contained in:
vdimir 2023-09-04 15:30:57 +00:00
parent 50fb2d996c
commit e438eff93c
No known key found for this signature in database
GPG Key ID: 6EE4CE2BEDC51862

View File

@ -539,6 +539,16 @@ static ColumnWithTypeAndName executeActionForHeader(const ActionsDAG::Node * nod
case ActionsDAG::ActionType::FUNCTION:
{
res_column.column = node->function->execute(arguments, res_column.type, 0, true);
/**
* In header, we only need const columns if they are used for constant folding.
* Constants in headers are used for query analysis and optimization.
* Therefore, if the function is not suitable for constant folding, the constant shouldn't be in the header.
* For example, function hostName() is not suitable for constant folding in distributed queries.
* In the new analyzer, we'd like to have a non-constant hostName() in the header.
* For the old analyzer, we take a header from DAG, and it's not constant because of a check inside ActionsDAG::addFunctionImpl.
*/
if (!node->function_base->isSuitableForConstantFolding() && res_column.column && isColumnConst(*res_column.column))
res_column.column = res_column.column->convertToFullColumnIfConst();
break;
}