ClickHouse/src/Interpreters/RewriteSumFunctionWithSumAndCountVisitor.h
Jiebin Sun b3f3a0c75c Rewrite the AST of sum(column + literal) function
Rewrite the following AST of `sum(column + literal)`
sum(column + literal)  ->  sum(column) + literal * count(column)
sum(literal + column)  ->  sum(column) + literal * count(column)

Test the patch on 2 x 80 vCPUs system, Q29 of ClickBench has got a huge
11.5x performance improvement.

Signed-off-by: Jiebin Sun <jiebin.sun@intel.com>
2023-12-15 01:28:47 +08:00

26 lines
613 B
C++

#pragma once
#include <Interpreters/DatabaseAndTableWithAlias.h>
#include <Interpreters/InDepthNodeVisitor.h>
namespace DB
{
class ASTFunction;
class RewriteSumFunctionWithSumAndCountMatcher
{
public:
struct Data
{
const TablesWithColumns & tables;
};
static void visit(ASTPtr & ast, const Data & data);
static void visit(const ASTFunction &, ASTPtr & ast, const Data & data);
static bool needChildVisit(const ASTPtr &, const ASTPtr &) { return true; }
};
using RewriteSumFunctionWithSumAndCountVisitor = InDepthNodeVisitor<RewriteSumFunctionWithSumAndCountMatcher, true>;
}