MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / ExpressionAnalysisResult

Method ExpressionAnalysisResult

src/Interpreters/ExpressionAnalyzer.cpp:1989–2343  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1987}
1988
1989ExpressionAnalysisResult::ExpressionAnalysisResult(
1990 SelectQueryExpressionAnalyzer & query_analyzer,
1991 const StorageMetadataPtr & metadata_snapshot,
1992 bool first_stage_,
1993 bool second_stage_,
1994 bool only_types,
1995 const FilterDAGInfoPtr & row_policy_info_,
1996 const FilterDAGInfoPtr & additional_filter,
1997 const Block & source_header)
1998 : first_stage(first_stage_)
1999 , second_stage(second_stage_)
2000 , need_aggregate(query_analyzer.hasAggregation())
2001 , has_window(query_analyzer.hasWindow())
2002 , use_grouping_set_key(query_analyzer.useGroupingSetKey())
2003{
2004 /// first_stage: Do I need to perform the first part of the pipeline - running on remote servers during distributed processing.
2005 /// second_stage: Do I need to execute the second part of the pipeline - running on the initiating server during distributed processing.
2006
2007 /** First we compose a chain of actions and remember the necessary steps from it.
2008 * Regardless of from_stage and to_stage, we will compose a complete sequence of actions to perform optimization and
2009 * throw out unnecessary columns based on the entire query. In unnecessary parts of the query, we will not execute subqueries.
2010 */
2011
2012 const ASTSelectQuery & query = *query_analyzer.getSelectQuery();
2013 auto context = query_analyzer.getContext();
2014 const Settings & settings = context->getSettingsRef();
2015 const ConstStoragePtr & storage = query_analyzer.storage();
2016
2017 Names additional_required_columns_after_prewhere;
2018 ssize_t prewhere_step_num = -1;
2019 ssize_t where_step_num = -1;
2020 ssize_t having_step_num = -1;
2021
2022 ActionsAndProjectInputsFlagPtr prewhere_dag_and_flags;
2023
2024 auto finalize_chain = [&](ExpressionActionsChain & chain) -> ColumnsWithTypeAndName
2025 {
2026 if (prewhere_step_num >= 0)
2027 {
2028 ExpressionActionsChainSteps::Step & step = *chain.steps.at(prewhere_step_num);
2029
2030 auto prewhere_required_columns = prewhere_dag_and_flags->dag.getRequiredColumnsNames();
2031 NameSet required_source_columns(prewhere_required_columns.begin(), prewhere_required_columns.end());
2032 /// Add required columns to required output in order not to remove them after prewhere execution.
2033 /// TODO: add sampling and final execution to common chain.
2034 for (const auto & column : additional_required_columns_after_prewhere)
2035 {
2036 if (required_source_columns.contains(column))
2037 step.addRequiredOutput(column);
2038 }
2039 }
2040
2041 chain.finalize();
2042
2043 if (prewhere_dag_and_flags)
2044 {
2045 prewhere_info = std::make_shared<PrewhereInfo>(std::move(prewhere_dag_and_flags->dag), query.prewhere()->getColumnName());
2046 prewhere_dag_and_flags.reset();

Callers

nothing calls this directly

Calls 15

sanitizeBlockFunction · 0.85
getHeaderFunction · 0.85
blocksHaveEqualStructureFunction · 0.85
useGroupingSetKeyMethod · 0.80
addRequiredOutputMethod · 0.80
prewhereMethod · 0.80
getLastStepMethod · 0.80
sampleSizeMethod · 0.80

Tested by

no test coverage detected