OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PlanState.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019 OmniSci, 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) {
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  if (do_not_fetch_column->get_table_id() > 0) {
29  auto cd = get_column_descriptor(do_not_fetch_column->get_column_id(),
30  do_not_fetch_column->get_table_id(),
31  *executor_->getCatalog());
32  if (cd->isVirtualCol) {
33  return false;
34  }
35  }
36  std::set<std::pair<int, int>> intersect;
37  std::set_intersection(columns_to_fetch_.begin(),
38  columns_to_fetch_.end(),
39  columns_to_not_fetch_.begin(),
41  std::inserter(intersect, intersect.begin()));
42  if (!intersect.empty()) {
44  }
45  return columns_to_fetch_.find(std::make_pair(do_not_fetch_column->get_table_id(),
46  do_not_fetch_column->get_column_id())) ==
47  columns_to_fetch_.end();
48 }
49 
51  const std::list<std::shared_ptr<const InputColDescriptor>>& global_col_ids) {
52  for (const auto& col_id : global_col_ids) {
53  CHECK(col_id);
54  const auto local_col_id = global_to_local_col_ids_.size();
55  const auto it_ok =
56  global_to_local_col_ids_.insert(std::make_pair(*col_id, local_col_id));
57  // enforce uniqueness of the column ids in the scan plan
58  CHECK(it_ok.second);
59  }
60 }
61 
63  const bool fetch_column) {
64  CHECK(col_var);
65  const int table_id = col_var->get_table_id();
66  int global_col_id = col_var->get_column_id();
67  const int scan_idx = col_var->get_rte_idx();
68  InputColDescriptor scan_col_desc(global_col_id, table_id, scan_idx);
69  const auto it = global_to_local_col_ids_.find(scan_col_desc);
70  CHECK(it != global_to_local_col_ids_.end());
71  if (fetch_column) {
72  columns_to_fetch_.insert(std::make_pair(table_id, global_col_id));
73  }
74  return it->second;
75 }
int get_table_id() const
Definition: Analyzer.h:194
std::unordered_map< InputColDescriptor, size_t > global_to_local_col_ids_
Definition: PlanState.h:52
bool allow_lazy_fetch_
Definition: PlanState.h:55
std::set< std::pair< TableId, ColumnId > > columns_to_fetch_
Definition: PlanState.h:53
const Executor * executor_
Definition: PlanState.h:57
std::set< std::pair< TableId, ColumnId > > columns_to_not_fetch_
Definition: PlanState.h:54
int getLocalColumnId(const Analyzer::ColumnVar *col_var, const bool fetch_column)
Definition: PlanState.cpp:62
CHECK(cgen_state)
void allocateLocalColumnIds(const std::list< std::shared_ptr< const InputColDescriptor >> &global_col_ids)
Definition: PlanState.cpp:50
int get_rte_idx() const
Definition: Analyzer.h:196
int get_column_id() const
Definition: Analyzer.h:195
bool isLazyFetchColumn(const Analyzer::Expr *target_expr)
Definition: PlanState.cpp:20
const ColumnDescriptor * get_column_descriptor(const int col_id, const int table_id, const Catalog_Namespace::Catalog &cat)
Definition: Execute.h:142