OmniSciDB  b24e664e58
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LegacyExecute.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, 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 "Execute.h"
18 #include "QueryRewrite.h"
19 
20 #include "Shared/scope.h"
21 
22 // The legacy way of executing queries. Don't change it, it's going away.
23 
24 /*
25  * x64 benchmark: "SELECT COUNT(*) FROM test WHERE x > 41;"
26  * x = 42, 64-bit column, 1-byte encoding
27  * 3B rows in 1.2s on a i7-4870HQ core
28  *
29  * TODO(alex): check we haven't introduced a regression with the new translator.
30  */
31 
32 std::shared_ptr<ResultSet> Executor::execute(
33  const Planner::RootPlan* root_plan,
34  const Catalog_Namespace::SessionInfo& session,
35  const bool hoist_literals,
36  const ExecutorDeviceType device_type,
37  const ExecutorOptLevel opt_level,
38  const bool allow_multifrag,
39  const bool allow_loop_joins,
40  RenderInfo* render_info) {
41  catalog_ = &root_plan->getCatalog();
42  const auto stmt_type = root_plan->get_stmt_type();
43  // capture the lock acquistion time
44  auto clock_begin = timer_start();
45  std::lock_guard<std::mutex> lock(execute_mutex_);
47  resetInterrupt();
48  }
49  ScopeGuard restore_metainfo_cache = [this] { clearMetaInfoCache(); };
50  int64_t queue_time_ms = timer_stop(clock_begin);
51  ScopeGuard row_set_holder = [this] { row_set_mem_owner_ = nullptr; };
52  switch (stmt_type) {
53  case kSELECT: {
54  throw std::runtime_error("The legacy SELECT path has been fully deprecated.");
55  }
56  case kINSERT: {
57  if (root_plan->get_plan_dest() == Planner::RootPlan::kEXPLAIN) {
58  auto explanation_rs = std::make_shared<ResultSet>("No explanation available.");
59  explanation_rs->setQueueTime(queue_time_ms);
60  return explanation_rs;
61  }
62  auto& cat = session.getCatalog();
64  auto user_metadata = session.get_currentUser();
65  const int table_id = root_plan->get_result_table_id();
66  auto td = cat.getMetadataForTable(table_id);
67  DBObject dbObject(td->tableName, TableDBObjectType);
68  dbObject.loadKey(cat);
70  std::vector<DBObject> privObjects;
71  privObjects.push_back(dbObject);
72  if (!sys_cat.checkPrivileges(user_metadata, privObjects)) {
73  throw std::runtime_error(
74  "Violation of access privileges: user " + user_metadata.userName +
75  " has no insert privileges for table " + td->tableName + ".");
76  break;
77  }
78  executeSimpleInsert(root_plan);
79  auto empty_rs = std::make_shared<ResultSet>(std::vector<TargetInfo>{},
82  nullptr,
83  this);
84  empty_rs->setQueueTime(queue_time_ms);
85  return empty_rs;
86  }
87  default:
88  CHECK(false);
89  }
90  CHECK(false);
91  return nullptr;
92 }
catalog_(nullptr)
int get_result_table_id() const
Definition: Planner.h:291
std::shared_ptr< ResultSet > execute(const Planner::RootPlan *root_plan, const Catalog_Namespace::SessionInfo &session, const bool hoist_literals, const ExecutorDeviceType device_type, const ExecutorOptLevel, const bool allow_multifrag, const bool allow_loop_joins, RenderInfo *render_query_data=nullptr)
ExecutorDeviceType
SQLStmtType get_stmt_type() const
Definition: Planner.h:290
static const AccessPrivileges INSERT_INTO_TABLE
Definition: DBObject.h:154
TypeR::rep timer_stop(Type clock_begin)
Definition: measure.h:46
const Catalog_Namespace::Catalog & getCatalog() const
Definition: Planner.h:293
bool g_enable_dynamic_watchdog
Definition: Execute.cpp:72
void setPrivileges(const AccessPrivileges &privs)
Definition: DBObject.h:203
ExecutorOptLevel
static SysCatalog & instance()
Definition: SysCatalog.h:257
CHECK(cgen_state)
void loadKey()
Definition: DBObject.cpp:165
Catalog & getCatalog() const
Definition: SessionInfo.h:90
Dest get_plan_dest() const
Definition: Planner.h:299
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93
Type timer_start()
Definition: measure.h:40