OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PlanState.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <unordered_set>
20 
21 #include "Analyzer/Analyzer.h"
24 #include "Shared/DbObjectKeys.h"
25 
26 class Executor;
27 
28 struct JoinInfo {
29  JoinInfo(const std::vector<std::shared_ptr<Analyzer::BinOper>>& equi_join_tautologies,
30  const std::vector<std::shared_ptr<HashJoin>>& join_hash_tables)
31  : equi_join_tautologies_(equi_join_tautologies)
32  , join_hash_tables_(join_hash_tables) {}
33 
34  std::vector<std::shared_ptr<Analyzer::BinOper>>
35  equi_join_tautologies_; // expressions we equi-join on are true by
36  // definition when using a hash join; we'll
37  // fold them to true during code generation
38  std::vector<std::shared_ptr<HashJoin>> join_hash_tables_;
39  std::unordered_set<size_t> sharded_range_table_indices_;
40 };
41 
42 struct PlanState {
43  using DeletedColumnsMap = std::unordered_map<shared::TableKey, const ColumnDescriptor*>;
44  using HoistedFiltersSet = std::unordered_set<std::shared_ptr<Analyzer::Expr>>;
45 
46  PlanState(const bool allow_lazy_fetch,
47  const std::vector<InputTableInfo>& query_infos,
48  const DeletedColumnsMap& deleted_columns,
49  const Executor* executor)
50  : allow_lazy_fetch_(allow_lazy_fetch)
51  , join_info_({std::vector<std::shared_ptr<Analyzer::BinOper>>{}, {}})
52  , deleted_columns_(deleted_columns)
53  , query_infos_(query_infos)
54  , executor_(executor) {}
55 
56  std::vector<int64_t> init_agg_vals_;
57  std::vector<Analyzer::Expr*> target_exprs_;
59  std::unordered_map<InputColDescriptor, size_t> global_to_local_col_ids_;
60  std::set<shared::ColumnKey> columns_to_fetch_;
61  std::set<shared::ColumnKey> columns_to_not_fetch_;
62  std::unordered_map<size_t, std::vector<std::shared_ptr<Analyzer::Expr>>>
65  JoinInfo join_info_;
67  const std::vector<InputTableInfo>& query_infos_;
68  std::list<std::shared_ptr<Analyzer::Expr>> simple_quals_;
69  const Executor* executor_;
70 
72  const std::list<std::shared_ptr<const InputColDescriptor>>& global_col_ids);
73 
74  int getLocalColumnId(const Analyzer::ColumnVar* col_var, const bool fetch_column);
75 
76  bool isLazyFetchColumn(const Analyzer::Expr* target_expr) const;
77 
78  bool isLazyFetchColumn(const InputColDescriptor& col_desc) {
79  Analyzer::ColumnVar column(
80  SQLTypeInfo(),
81  {col_desc.getScanDesc().getTableKey(), col_desc.getColId()},
82  col_desc.getScanDesc().getNestLevel());
83  return isLazyFetchColumn(&column);
84  }
85 
87  auto deleted_cols_it = deleted_columns_.find(table_key);
88  if (deleted_cols_it != deleted_columns_.end()) {
89  return deleted_cols_it->second;
90  }
91  return nullptr;
92  }
93 
94  void addSimpleQual(std::shared_ptr<Analyzer::Expr> simple_qual) {
95  simple_quals_.push_back(simple_qual);
96  }
97 
98  std::list<std::shared_ptr<Analyzer::Expr>> getSimpleQuals() const {
99  return simple_quals_;
100  }
101 
102  void addNonHashtableQualForLeftJoin(size_t idx, std::shared_ptr<Analyzer::Expr> expr);
103 };
Defines data structures for the semantic analysis phase of query processing.
JoinInfo join_info_
Definition: PlanState.h:65
int32_t getNestLevel() const
std::list< std::shared_ptr< Analyzer::Expr > > simple_quals_
Definition: PlanState.h:68
std::unordered_map< size_t, std::vector< std::shared_ptr< Analyzer::Expr > > > left_join_non_hashtable_quals_
Definition: PlanState.h:63
std::unordered_map< shared::TableKey, const ColumnDescriptor * > DeletedColumnsMap
Definition: PlanState.h:43
std::unordered_map< InputColDescriptor, size_t > global_to_local_col_ids_
Definition: PlanState.h:59
bool allow_lazy_fetch_
Definition: PlanState.h:64
std::unordered_set< std::shared_ptr< Analyzer::Expr >> HoistedFiltersSet
Definition: PlanState.h:44
JoinInfo(const std::vector< std::shared_ptr< Analyzer::BinOper >> &equi_join_tautologies, const std::vector< std::shared_ptr< HashJoin >> &join_hash_tables)
Definition: PlanState.h:29
void addNonHashtableQualForLeftJoin(size_t idx, std::shared_ptr< Analyzer::Expr > expr)
Definition: PlanState.cpp:74
std::unordered_set< size_t > sharded_range_table_indices_
Definition: PlanState.h:39
const Executor * executor_
Definition: PlanState.h:69
std::vector< int64_t > init_agg_vals_
Definition: PlanState.h:56
executor_(executor)
Definition: PlanState.h:54
std::vector< std::shared_ptr< Analyzer::BinOper > > equi_join_tautologies_
Definition: PlanState.h:35
int getLocalColumnId(const Analyzer::ColumnVar *col_var, const bool fetch_column)
Definition: PlanState.cpp:59
bool isLazyFetchColumn(const Analyzer::Expr *target_expr) const
Definition: PlanState.cpp:20
int getColId() const
bool isLazyFetchColumn(const InputColDescriptor &col_desc)
Definition: PlanState.h:78
PlanState(const bool allow_lazy_fetch, const std::vector< InputTableInfo > &query_infos, const DeletedColumnsMap &deleted_columns, const Executor *executor)
Definition: PlanState.h:46
std::set< shared::ColumnKey > columns_to_not_fetch_
Definition: PlanState.h:61
const std::vector< InputTableInfo > & query_infos_
Definition: PlanState.h:67
specifies the content in-memory of a row in the column metadata table
void allocateLocalColumnIds(const std::list< std::shared_ptr< const InputColDescriptor >> &global_col_ids)
Definition: PlanState.cpp:47
const ColumnDescriptor * getDeletedColForTable(const shared::TableKey &table_key)
Definition: PlanState.h:86
const shared::TableKey & getTableKey() const
Executor(const ExecutorId id, Data_Namespace::DataMgr *data_mgr, const size_t block_size_x, const size_t grid_size_x, const size_t max_gpu_slab_size, const std::string &debug_dir, const std::string &debug_file)
Definition: Execute.cpp:244
void addSimpleQual(std::shared_ptr< Analyzer::Expr > simple_qual)
Definition: PlanState.h:94
const DeletedColumnsMap deleted_columns_
Definition: PlanState.h:66
HoistedFiltersSet hoisted_filters_
Definition: PlanState.h:58
std::list< std::shared_ptr< Analyzer::Expr > > getSimpleQuals() const
Definition: PlanState.h:98
std::set< shared::ColumnKey > columns_to_fetch_
Definition: PlanState.h:60
std::vector< Analyzer::Expr * > target_exprs_
Definition: PlanState.h:57
std::vector< std::shared_ptr< HashJoin > > join_hash_tables_
Definition: PlanState.h:38
const InputDescriptor & getScanDesc() const