OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PlanState.cpp
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 #include "PlanState.h"
18 #include "Execute.h"
19 
20 bool PlanState::isLazyFetchColumn(const Analyzer::Expr* target_expr) const {
21  if (!allow_lazy_fetch_) {
22  return false;
23  }
24  const auto do_not_fetch_column = dynamic_cast<const Analyzer::ColumnVar*>(target_expr);
25  if (!do_not_fetch_column || dynamic_cast<const Analyzer::Var*>(do_not_fetch_column)) {
26  return false;
27  }
28  const auto& column_key = do_not_fetch_column->getColumnKey();
29  if (column_key.table_id > 0) {
30  const auto cd = get_column_descriptor(column_key);
31  if (cd->isVirtualCol) {
32  return false;
33  }
34  }
35  std::set<shared::ColumnKey> intersect;
36  std::set_intersection(columns_to_fetch_.begin(),
37  columns_to_fetch_.end(),
38  columns_to_not_fetch_.begin(),
40  std::inserter(intersect, intersect.begin()));
41  if (!intersect.empty()) {
43  }
44  return columns_to_fetch_.find(column_key) == columns_to_fetch_.end();
45 }
46 
48  const std::list<std::shared_ptr<const InputColDescriptor>>& global_col_ids) {
49  for (const auto& col_id : global_col_ids) {
50  CHECK(col_id);
51  const auto local_col_id = global_to_local_col_ids_.size();
52  const auto it_ok =
53  global_to_local_col_ids_.insert(std::make_pair(*col_id, local_col_id));
54  // enforce uniqueness of the column ids in the scan plan
55  CHECK(it_ok.second);
56  }
57 }
58 
60  const bool fetch_column) {
61  CHECK(col_var);
62  const auto& global_col_key = col_var->getColumnKey();
63  const int scan_idx = col_var->get_rte_idx();
64  InputColDescriptor scan_col_desc(
65  global_col_key.column_id, global_col_key.table_id, global_col_key.db_id, scan_idx);
66  const auto it = global_to_local_col_ids_.find(scan_col_desc);
67  CHECK(it != global_to_local_col_ids_.end()) << "Expected to find " << scan_col_desc;
68  if (fetch_column) {
69  columns_to_fetch_.insert(global_col_key);
70  }
71  return it->second;
72 }
73 
75  std::shared_ptr<Analyzer::Expr> expr) {
76  auto it = left_join_non_hashtable_quals_.find(idx);
77  if (it == left_join_non_hashtable_quals_.end()) {
78  std::vector<std::shared_ptr<Analyzer::Expr>> expr_vec{expr};
79  left_join_non_hashtable_quals_.emplace(idx, std::move(expr_vec));
80  } else {
81  it->second.emplace_back(expr);
82  }
83 }
std::unordered_map< size_t, std::vector< std::shared_ptr< Analyzer::Expr > > > left_join_non_hashtable_quals_
Definition: PlanState.h:63
std::unordered_map< InputColDescriptor, size_t > global_to_local_col_ids_
Definition: PlanState.h:59
bool allow_lazy_fetch_
Definition: PlanState.h:64
void addNonHashtableQualForLeftJoin(size_t idx, std::shared_ptr< Analyzer::Expr > expr)
Definition: PlanState.cpp:74
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
const ColumnDescriptor * get_column_descriptor(const shared::ColumnKey &column_key)
Definition: Execute.h:192
std::set< shared::ColumnKey > columns_to_not_fetch_
Definition: PlanState.h:61
void allocateLocalColumnIds(const std::list< std::shared_ptr< const InputColDescriptor >> &global_col_ids)
Definition: PlanState.cpp:47
const shared::ColumnKey & getColumnKey() const
Definition: Analyzer.h:198
#define CHECK(condition)
Definition: Logger.h:291
std::set< shared::ColumnKey > columns_to_fetch_
Definition: PlanState.h:60
int32_t get_rte_idx() const
Definition: Analyzer.h:202