OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PlanState Struct Reference

#include <PlanState.h>

+ Collaboration diagram for PlanState:

Public Types

using DeletedColumnsMap = std::unordered_map< shared::TableKey, const ColumnDescriptor * >
 
using HoistedFiltersSet = std::unordered_set< std::shared_ptr< Analyzer::Expr >>
 

Public Member Functions

 PlanState (const bool allow_lazy_fetch, const std::vector< InputTableInfo > &query_infos, const DeletedColumnsMap &deleted_columns, const Executor *executor)
 
 deleted_columns_ (deleted_columns)
 
 query_infos_ (query_infos)
 
 executor_ (executor)
 
void allocateLocalColumnIds (const std::list< std::shared_ptr< const InputColDescriptor >> &global_col_ids)
 
int getLocalColumnId (const Analyzer::ColumnVar *col_var, const bool fetch_column)
 
bool isLazyFetchColumn (const Analyzer::Expr *target_expr) const
 
bool isLazyFetchColumn (const InputColDescriptor &col_desc)
 
const ColumnDescriptorgetDeletedColForTable (const shared::TableKey &table_key)
 
void addSimpleQual (std::shared_ptr< Analyzer::Expr > simple_qual)
 
std::list< std::shared_ptr
< Analyzer::Expr > > 
getSimpleQuals () const
 
void addNonHashtableQualForLeftJoin (size_t idx, std::shared_ptr< Analyzer::Expr > expr)
 
const std::unordered_set
< shared::ColumnKey > & 
getColumnsToFetch () const
 
const std::unordered_set
< shared::ColumnKey > & 
getColumnsToNotFetch () const
 
bool isColumnToFetch (const shared::ColumnKey &column_key) const
 
bool isColumnToNotFetch (const shared::ColumnKey &column_key) const
 
void addColumnToFetch (const shared::ColumnKey &column_key, bool unmark_lazy_fetch=false)
 
void addColumnToNotFetch (const shared::ColumnKey &column_key)
 
bool hasExpressionNeedsLazyFetch (const std::vector< TargetExprCodegen > &target_exprs_to_codegen) const
 
void registerNonLazyFetchExpression (const std::vector< TargetExprCodegen > &target_exprs_to_codegen)
 

Public Attributes

std::vector< int64_t > init_agg_vals_
 
HoistedFiltersSet hoisted_filters_
 
std::unordered_map
< InputColDescriptor, size_t > 
global_to_local_col_ids_
 
std::unordered_map< size_t,
std::vector< std::shared_ptr
< Analyzer::Expr > > > 
left_join_non_hashtable_quals_
 
bool allow_lazy_fetch_
 
JoinInfo join_info_
 
const DeletedColumnsMap deleted_columns_
 
const std::vector
< InputTableInfo > & 
query_infos_
 
std::list< std::shared_ptr
< Analyzer::Expr > > 
simple_quals_
 
const Executorexecutor_
 

Private Attributes

std::unordered_set
< shared::ColumnKey
columns_to_fetch_
 
std::unordered_set
< shared::ColumnKey
columns_to_not_fetch_
 

Detailed Description

Definition at line 43 of file PlanState.h.

Member Typedef Documentation

using PlanState::DeletedColumnsMap = std::unordered_map<shared::TableKey, const ColumnDescriptor*>

Definition at line 44 of file PlanState.h.

using PlanState::HoistedFiltersSet = std::unordered_set<std::shared_ptr<Analyzer::Expr>>

Definition at line 45 of file PlanState.h.

Constructor & Destructor Documentation

PlanState::PlanState ( const bool  allow_lazy_fetch,
const std::vector< InputTableInfo > &  query_infos,
const DeletedColumnsMap deleted_columns,
const Executor executor 
)
inline

Definition at line 47 of file PlanState.h.

51  : allow_lazy_fetch_(allow_lazy_fetch)
52  , join_info_({std::vector<std::shared_ptr<Analyzer::BinOper>>{}, {}})
JoinInfo join_info_
Definition: PlanState.h:63
bool allow_lazy_fetch_
Definition: PlanState.h:62

Member Function Documentation

void PlanState::addColumnToFetch ( const shared::ColumnKey column_key,
bool  unmark_lazy_fetch = false 
)

Definition at line 124 of file PlanState.cpp.

References CHECK, columns_to_fetch_, columns_to_not_fetch_, and isColumnToNotFetch().

Referenced by CodeGenerator::codegenColVar(), getLocalColumnId(), anonymous_namespace{GeoIR.cpp}::mark_logical_column_to_fetch(), and registerNonLazyFetchExpression().

125  {
126  if (unmark_lazy_fetch) {
127  // This column was previously marked for lazy fetch but we now intentionally
128  // mark it as non-lazy fetch column
129  auto it = columns_to_not_fetch_.find(column_key);
130  if (it != columns_to_not_fetch_.end()) {
131  columns_to_not_fetch_.erase(it);
132  }
133  } else {
134  if (columns_to_not_fetch_.count(column_key)) {
135  // this case represents a query w/ fetching expressions with the order of
136  // cv and an expression on it, i.e., SELECT col1, ST_NPoints(col1) FROM ...
137  // since we first touch the cv itself and we forcely mark it as lazy-fetch
138  // but to evaluate the expression, we must fetch the same cv;
139  // so let's fetch the cv to allow evaluating the expression using the same cv
141  }
142  }
143  CHECK(!isColumnToNotFetch(column_key)) << column_key;
144  columns_to_fetch_.emplace(column_key);
145 }
std::unordered_set< shared::ColumnKey > columns_to_not_fetch_
Definition: PlanState.h:117
bool isColumnToNotFetch(const shared::ColumnKey &column_key) const
Definition: PlanState.cpp:118
#define CHECK(condition)
Definition: Logger.h:291
std::unordered_set< shared::ColumnKey > columns_to_fetch_
Definition: PlanState.h:116

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void PlanState::addColumnToNotFetch ( const shared::ColumnKey column_key)

Definition at line 147 of file PlanState.cpp.

References CHECK, columns_to_not_fetch_, and isColumnToFetch().

Referenced by CodeGenerator::codegenColVar().

147  {
148  CHECK(!isColumnToFetch(column_key)) << column_key;
149  columns_to_not_fetch_.emplace(column_key);
150 }
std::unordered_set< shared::ColumnKey > columns_to_not_fetch_
Definition: PlanState.h:117
bool isColumnToFetch(const shared::ColumnKey &column_key) const
Definition: PlanState.cpp:114
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void PlanState::addNonHashtableQualForLeftJoin ( size_t  idx,
std::shared_ptr< Analyzer::Expr expr 
)

Definition at line 95 of file PlanState.cpp.

References left_join_non_hashtable_quals_.

96  {
97  auto it = left_join_non_hashtable_quals_.find(idx);
98  if (it == left_join_non_hashtable_quals_.end()) {
99  std::vector<std::shared_ptr<Analyzer::Expr>> expr_vec{expr};
100  left_join_non_hashtable_quals_.emplace(idx, std::move(expr_vec));
101  } else {
102  it->second.emplace_back(expr);
103  }
104 }
std::unordered_map< size_t, std::vector< std::shared_ptr< Analyzer::Expr > > > left_join_non_hashtable_quals_
Definition: PlanState.h:61
void PlanState::addSimpleQual ( std::shared_ptr< Analyzer::Expr simple_qual)
inline

Definition at line 93 of file PlanState.h.

References simple_quals_.

93  {
94  simple_quals_.push_back(simple_qual);
95  }
std::list< std::shared_ptr< Analyzer::Expr > > simple_quals_
Definition: PlanState.h:66
void PlanState::allocateLocalColumnIds ( const std::list< std::shared_ptr< const InputColDescriptor >> &  global_col_ids)

Definition at line 40 of file PlanState.cpp.

References CHECK, and global_to_local_col_ids_.

Referenced by ScalarCodeGenerator::prepare().

41  {
42  for (const auto& col_id : global_col_ids) {
43  CHECK(col_id);
44  const auto local_col_id = global_to_local_col_ids_.size();
45  const auto it_ok =
46  global_to_local_col_ids_.insert(std::make_pair(*col_id, local_col_id));
47  // enforce uniqueness of the column ids in the scan plan
48  CHECK(it_ok.second);
49  }
50 }
std::unordered_map< InputColDescriptor, size_t > global_to_local_col_ids_
Definition: PlanState.h:59
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

PlanState::deleted_columns_ ( deleted_columns  )
PlanState::executor_ ( executor  )
inline

Definition at line 55 of file PlanState.h.

55 {}
const std::unordered_set< shared::ColumnKey > & PlanState::getColumnsToFetch ( ) const

Definition at line 106 of file PlanState.cpp.

References columns_to_fetch_.

106  {
107  return columns_to_fetch_;
108 }
std::unordered_set< shared::ColumnKey > columns_to_fetch_
Definition: PlanState.h:116
const std::unordered_set< shared::ColumnKey > & PlanState::getColumnsToNotFetch ( ) const

Definition at line 110 of file PlanState.cpp.

References columns_to_not_fetch_.

110  {
111  return columns_to_not_fetch_;
112 }
std::unordered_set< shared::ColumnKey > columns_to_not_fetch_
Definition: PlanState.h:117
const ColumnDescriptor* PlanState::getDeletedColForTable ( const shared::TableKey table_key)
inline

Definition at line 85 of file PlanState.h.

References deleted_columns_.

85  {
86  auto deleted_cols_it = deleted_columns_.find(table_key);
87  if (deleted_cols_it != deleted_columns_.end()) {
88  return deleted_cols_it->second;
89  }
90  return nullptr;
91  }
const DeletedColumnsMap deleted_columns_
Definition: PlanState.h:64
int PlanState::getLocalColumnId ( const Analyzer::ColumnVar col_var,
const bool  fetch_column 
)

Definition at line 52 of file PlanState.cpp.

References addColumnToFetch(), CHECK, Analyzer::ColumnVar::get_rte_idx(), Analyzer::ColumnVar::getColumnKey(), and global_to_local_col_ids_.

Referenced by ScalarCodeGenerator::codegenColumn(), and CodeGenerator::colByteStream().

53  {
54  // Previously, we consider `rte_idx` of `col_var` w/ its column key together
55  // to specify columns in the `global_to_local_col_ids_`.
56  // But there is a case when the same col has multiple 'rte_idx's
57  // For instance, the same geometry col is used not only as input col of the geo join op,
58  // but also included as input col of filter predicate
59  // In such a case, the same geometry col has two rte_idxs (the one defined by the filter
60  // predicate and the other determined by the geo join operator)
61  // The previous logic cannot cover this case b/c it allows only one `rte_idx` per col
62  // But it is safe to share `rte_idx` of among all use cases of the same col
63  CHECK(col_var);
64  const auto& global_col_key = col_var->getColumnKey();
65  InputColDescriptor scan_col_desc(global_col_key.column_id,
66  global_col_key.table_id,
67  global_col_key.db_id,
68  col_var->get_rte_idx());
69  std::optional<int> col_id{std::nullopt};
70  // let's try to find col_id w/ considering `rte_idx`
71  const auto it = global_to_local_col_ids_.find(scan_col_desc);
72  if (it != global_to_local_col_ids_.end()) {
73  // we have a valid col_id
74  col_id = it->second;
75  } else {
76  // otherwise, let's try to find col_id for the same col
77  // (but have different 'rte_idx') to share it w/ `col_var`
78  for (auto const& kv : global_to_local_col_ids_) {
79  if (kv.first.getColumnKey() == global_col_key) {
80  col_id = kv.second;
81  break;
82  }
83  }
84  }
85  if (col_id && *col_id >= 0) {
86  if (fetch_column) {
87  addColumnToFetch(global_col_key);
88  }
89  return *col_id;
90  }
91  CHECK(false) << "Expected to find " << global_col_key;
92  return {};
93 }
std::unordered_map< InputColDescriptor, size_t > global_to_local_col_ids_
Definition: PlanState.h:59
void addColumnToFetch(const shared::ColumnKey &column_key, bool unmark_lazy_fetch=false)
Definition: PlanState.cpp:124
const shared::ColumnKey & getColumnKey() const
Definition: Analyzer.h:198
#define CHECK(condition)
Definition: Logger.h:291
int32_t get_rte_idx() const
Definition: Analyzer.h:202

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::list<std::shared_ptr<Analyzer::Expr> > PlanState::getSimpleQuals ( ) const
inline

Definition at line 97 of file PlanState.h.

References simple_quals_.

Referenced by CodeGenerator::codegen().

97  {
98  return simple_quals_;
99  }
std::list< std::shared_ptr< Analyzer::Expr > > simple_quals_
Definition: PlanState.h:66

+ Here is the caller graph for this function:

bool PlanState::hasExpressionNeedsLazyFetch ( const std::vector< TargetExprCodegen > &  target_exprs_to_codegen) const

Definition at line 152 of file PlanState.cpp.

References anonymous_namespace{QueryMemoryDescriptor.cpp}::any_of().

Referenced by registerNonLazyFetchExpression().

153  {
154  return std::any_of(target_exprs_to_codegen.begin(),
155  target_exprs_to_codegen.end(),
156  [](const TargetExprCodegen& target_expr) {
157  return target_expr.target_info.sql_type.usesFlatBuffer();
158  });
159 }
bool any_of(std::vector< Analyzer::Expr * > const &target_exprs)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool PlanState::isColumnToFetch ( const shared::ColumnKey column_key) const

Definition at line 114 of file PlanState.cpp.

References columns_to_fetch_, and shared::contains().

Referenced by addColumnToNotFetch(), and CodeGenerator::codegenColVar().

114  {
115  return shared::contains(columns_to_fetch_, column_key);
116 }
bool contains(const T &container, const U &element)
Definition: misc.h:195
std::unordered_set< shared::ColumnKey > columns_to_fetch_
Definition: PlanState.h:116

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool PlanState::isColumnToNotFetch ( const shared::ColumnKey column_key) const

Definition at line 118 of file PlanState.cpp.

References columns_to_not_fetch_, and shared::contains().

Referenced by addColumnToFetch().

118  {
119  return shared::contains(columns_to_not_fetch_, column_key);
120 }
bool contains(const T &container, const U &element)
Definition: misc.h:195
std::unordered_set< shared::ColumnKey > columns_to_not_fetch_
Definition: PlanState.h:117

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool PlanState::isLazyFetchColumn ( const Analyzer::Expr target_expr) const

Definition at line 22 of file PlanState.cpp.

References allow_lazy_fetch_, columns_to_fetch_, get_column_descriptor(), and Analyzer::ColumnVar::getColumnKey().

Referenced by CodeGenerator::codegenColVar(), and isLazyFetchColumn().

22  {
23  if (!allow_lazy_fetch_) {
24  return false;
25  }
26  const auto do_not_fetch_column = dynamic_cast<const Analyzer::ColumnVar*>(target_expr);
27  if (!do_not_fetch_column || dynamic_cast<const Analyzer::Var*>(do_not_fetch_column)) {
28  return false;
29  }
30  const auto& column_key = do_not_fetch_column->getColumnKey();
31  if (column_key.table_id > 0) {
32  const auto cd = get_column_descriptor(column_key);
33  if (cd->isVirtualCol) {
34  return false;
35  }
36  }
37  return columns_to_fetch_.find(column_key) == columns_to_fetch_.end();
38 }
bool allow_lazy_fetch_
Definition: PlanState.h:62
const ColumnDescriptor * get_column_descriptor(const shared::ColumnKey &column_key)
Definition: Execute.h:213
const shared::ColumnKey & getColumnKey() const
Definition: Analyzer.h:198
std::unordered_set< shared::ColumnKey > columns_to_fetch_
Definition: PlanState.h:116

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool PlanState::isLazyFetchColumn ( const InputColDescriptor col_desc)
inline

Definition at line 77 of file PlanState.h.

References InputColDescriptor::getColId(), InputDescriptor::getNestLevel(), InputColDescriptor::getScanDesc(), InputDescriptor::getTableKey(), and isLazyFetchColumn().

77  {
78  Analyzer::ColumnVar column(
79  SQLTypeInfo(),
80  {col_desc.getScanDesc().getTableKey(), col_desc.getColId()},
81  col_desc.getScanDesc().getNestLevel());
82  return isLazyFetchColumn(&column);
83  }
int32_t getNestLevel() const
bool isLazyFetchColumn(const Analyzer::Expr *target_expr) const
Definition: PlanState.cpp:22
int getColId() const
const shared::TableKey & getTableKey() const
const InputDescriptor & getScanDesc() const

+ Here is the call graph for this function:

PlanState::query_infos_ ( query_infos  )
void PlanState::registerNonLazyFetchExpression ( const std::vector< TargetExprCodegen > &  target_exprs_to_codegen)

Definition at line 161 of file PlanState.cpp.

References addColumnToFetch(), and hasExpressionNeedsLazyFetch().

162  {
163  auto const needs_lazy_fetch = hasExpressionNeedsLazyFetch(target_exprs_to_codegen);
164  for (const auto& expr : target_exprs_to_codegen) {
165  if (needs_lazy_fetch && !expr.target_info.sql_type.usesFlatBuffer()) {
166  if (auto col_var = dynamic_cast<const Analyzer::ColumnVar*>(expr.target_expr)) {
167  // force non-lazy fetch on all other columns that don't support flatbuffer
168  addColumnToFetch(col_var->getColumnKey(), /*unmark_lazy_fetch=*/true);
169  }
170  }
171  }
172 }
void addColumnToFetch(const shared::ColumnKey &column_key, bool unmark_lazy_fetch=false)
Definition: PlanState.cpp:124
bool hasExpressionNeedsLazyFetch(const std::vector< TargetExprCodegen > &target_exprs_to_codegen) const
Definition: PlanState.cpp:152

+ Here is the call graph for this function:

Member Data Documentation

bool PlanState::allow_lazy_fetch_

Definition at line 62 of file PlanState.h.

Referenced by isLazyFetchColumn().

std::unordered_set<shared::ColumnKey> PlanState::columns_to_fetch_
private
std::unordered_set<shared::ColumnKey> PlanState::columns_to_not_fetch_
mutableprivate
const DeletedColumnsMap PlanState::deleted_columns_

Definition at line 64 of file PlanState.h.

Referenced by getDeletedColForTable().

const Executor* PlanState::executor_
std::unordered_map<InputColDescriptor, size_t> PlanState::global_to_local_col_ids_
HoistedFiltersSet PlanState::hoisted_filters_

Definition at line 58 of file PlanState.h.

std::vector<int64_t> PlanState::init_agg_vals_

Definition at line 57 of file PlanState.h.

JoinInfo PlanState::join_info_
std::unordered_map<size_t, std::vector<std::shared_ptr<Analyzer::Expr> > > PlanState::left_join_non_hashtable_quals_

Definition at line 61 of file PlanState.h.

Referenced by addNonHashtableQualForLeftJoin(), and Executor::buildJoinLoops().

const std::vector<InputTableInfo>& PlanState::query_infos_

Definition at line 65 of file PlanState.h.

Referenced by CodeGenerator::checkExpressionRanges(), and CodeGenerator::codegen().

std::list<std::shared_ptr<Analyzer::Expr> > PlanState::simple_quals_

Definition at line 66 of file PlanState.h.

Referenced by addSimpleQual(), and getSimpleQuals().


The documentation for this struct was generated from the following files: