2017-01-06 13:36:08 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DB/Parsers/IAST.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class Context;
|
|
|
|
class WriteBuffer;
|
2017-01-14 09:09:38 +00:00
|
|
|
struct TypeAndConstantInference;
|
2017-01-06 13:36:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
/** Transform GROUP BY, ORDER BY and LIMIT BY sections.
|
|
|
|
* (LIMIT BY is an extension to SQL language, do not be confused with ordinary LIMIT)
|
|
|
|
*
|
|
|
|
* Remove constant expressions (like ORDER BY concat('hello', 'world')).
|
|
|
|
* For GROUP BY, unwrap injective functions (like GROUP BY toString(x) -> GROUP BY x).
|
|
|
|
* For GROUP BY, remove deterministic functions of another keys (like GROUP BY x + 1, x -> GROUP BY x).
|
2017-01-06 22:54:05 +00:00
|
|
|
* TODO For ORDER BY, remove deterministic functions of previous keys (like ORDER BY num, toString(num) -> ORDER BY num),
|
|
|
|
* but only if no collation has specified.
|
2017-01-06 13:36:08 +00:00
|
|
|
* As a special case, remove duplicate keys.
|
|
|
|
* For LIMIT BY, apply all the same as for GROUP BY.
|
|
|
|
*
|
|
|
|
* TODO We should apply something similar for DISTINCT,
|
|
|
|
* but keys for DISTINCT are specified implicitly (as whole SELECT expression list).
|
|
|
|
*
|
|
|
|
* This should be run after CollectAliases, because some aliases will be lost from AST during this transformation.
|
2017-01-06 22:54:05 +00:00
|
|
|
* This should be run after TranslatePositionalArguments for positional arguments like ORDER BY 1, 2 not to be confused with constants.
|
2017-01-06 13:36:08 +00:00
|
|
|
*/
|
|
|
|
struct OptimizeGroupOrderLimitBy
|
|
|
|
{
|
|
|
|
void process(ASTPtr & ast, TypeAndConstantInference & expression_info);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|