OmniSciDB  ca0c39ec8f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Execute.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 #ifndef QUERYENGINE_EXECUTE_H
18 #define QUERYENGINE_EXECUTE_H
19 
20 #include <algorithm>
21 #include <atomic>
22 #include <condition_variable>
23 #include <cstddef>
24 #include <cstdlib>
25 #include <deque>
26 #include <functional>
27 #include <limits>
28 #include <map>
29 #include <mutex>
30 #include <queue>
31 #include <stack>
32 #include <unordered_map>
33 #include <unordered_set>
34 
35 #include <llvm/IR/Function.h>
36 #include <llvm/IR/Value.h>
37 #include <llvm/Linker/Linker.h>
38 #include <llvm/Transforms/Utils/ValueMapper.h>
39 #include <rapidjson/document.h>
40 
44 #include "QueryEngine/CgenState.h"
45 #include "QueryEngine/CodeCache.h"
58 #include "QueryEngine/PlanState.h"
67 
68 #include "DataMgr/Chunk/Chunk.h"
69 #include "Logger/Logger.h"
71 #include "Shared/funcannotations.h"
73 #include "Shared/measure.h"
74 #include "Shared/thread_count.h"
75 #include "Shared/toString.h"
80 
81 using QueryCompilationDescriptorOwned = std::unique_ptr<QueryCompilationDescriptor>;
83 using QueryMemoryDescriptorOwned = std::unique_ptr<QueryMemoryDescriptor>;
84 using QuerySessionId = std::string;
85 using CurrentQueryStatus = std::pair<QuerySessionId, std::string>;
86 using InterruptFlagMap = std::map<QuerySessionId, bool>;
88  // A class that is used to describe the query session's info
89  public:
90  /* todo(yoonmin): support more query status
91  * i.e., RUNNING_SORT, RUNNING_CARD_EST, CLEANUP, ... */
92  enum QueryStatus {
93  UNDEFINED = 0,
99  };
100 
101  QuerySessionStatus(const QuerySessionId& query_session,
102  const std::string& query_str,
103  const std::string& submitted_time)
104  : query_session_(query_session)
105  , executor_id_(0)
106  , query_str_(query_str)
107  , submitted_time_(submitted_time)
109  QuerySessionStatus(const QuerySessionId& query_session,
110  const size_t executor_id,
111  const std::string& query_str,
112  const std::string& submitted_time)
113  : query_session_(query_session)
114  , executor_id_(executor_id)
115  , query_str_(query_str)
116  , submitted_time_(submitted_time)
118  QuerySessionStatus(const QuerySessionId& query_session,
119  const size_t executor_id,
120  const std::string& query_str,
121  const std::string& submitted_time,
122  const QuerySessionStatus::QueryStatus& query_status)
123  : query_session_(query_session)
124  , executor_id_(executor_id)
125  , query_str_(query_str)
126  , submitted_time_(submitted_time)
127  , query_status_(query_status) {}
128 
130  const std::string getQueryStr() { return query_str_; }
131  const size_t getExecutorId() { return executor_id_; }
132  const std::string& getQuerySubmittedTime() { return submitted_time_; }
135  query_status_ = status;
136  }
137  void setExecutorId(const size_t executor_id) { executor_id_ = executor_id; }
138 
139  private:
141  size_t executor_id_;
142  const std::string query_str_;
143  const std::string submitted_time_;
144  // Currently we use three query status:
145  // 1) PENDING_IN_QUEUE: a task is submitted to the dispatch_queue but hangs due to no
146  // existing worker (= executor) 2) PENDING_IN_EXECUTOR: a task is assigned to the
147  // specific executor but waits to get the resource to run 3) RUNNING: a task is assigned
148  // to the specific executor and its execution has been successfully started
149  // 4) RUNNING_REDUCTION: a task is in the reduction phase
151 };
152 using QuerySessionMap =
153  std::map<const QuerySessionId, std::map<std::string, QuerySessionStatus>>;
154 
155 class ColumnFetcher;
156 
157 class WatchdogException : public std::runtime_error {
158  public:
159  WatchdogException(const std::string& cause) : std::runtime_error(cause) {}
160 };
161 
163 
164 class Executor;
165 
166 inline llvm::Value* get_arg_by_name(llvm::Function* func, const std::string& name) {
167  for (auto& arg : func->args()) {
168  if (arg.getName() == name) {
169  return &arg;
170  }
171  }
172  CHECK(false);
173  return nullptr;
174 }
175 
176 inline uint32_t log2_bytes(const uint32_t bytes) {
177  switch (bytes) {
178  case 1:
179  return 0;
180  case 2:
181  return 1;
182  case 4:
183  return 2;
184  case 8:
185  return 3;
186  default:
187  abort();
188  }
189 }
190 
192  const int col_id,
193  const int table_id,
195  CHECK_GT(table_id, 0);
196  const auto col_desc = cat.getMetadataForColumn(table_id, col_id);
197  CHECK(col_desc);
198  return col_desc;
199 }
200 
201 inline const Analyzer::Expr* extract_cast_arg(const Analyzer::Expr* expr) {
202  const auto cast_expr = dynamic_cast<const Analyzer::UOper*>(expr);
203  if (!cast_expr || cast_expr->get_optype() != kCAST) {
204  return expr;
205  }
206  return cast_expr->get_operand();
207 }
208 
209 inline std::string numeric_type_name(const SQLTypeInfo& ti) {
210  CHECK(ti.is_integer() || ti.is_decimal() || ti.is_boolean() || ti.is_time() ||
211  ti.is_fp() || (ti.is_string() && ti.get_compression() == kENCODING_DICT) ||
212  ti.is_timeinterval());
213  if (ti.is_integer() || ti.is_decimal() || ti.is_boolean() || ti.is_time() ||
214  ti.is_string() || ti.is_timeinterval()) {
215  return "int" + std::to_string(ti.get_logical_size() * 8) + "_t";
216  }
217  return ti.get_type() == kDOUBLE ? "double" : "float";
218 }
219 
221  const int col_id,
222  const int table_id,
224  CHECK(table_id);
225  return table_id > 0 ? get_column_descriptor(col_id, table_id, cat) : nullptr;
226 }
227 
228 inline const ResultSetPtr& get_temporary_table(const TemporaryTables* temporary_tables,
229  const int table_id) {
230  CHECK_LT(table_id, 0);
231  const auto it = temporary_tables->find(table_id);
232  CHECK(it != temporary_tables->end());
233  return it->second;
234 }
235 
236 inline const SQLTypeInfo get_column_type(const int col_id,
237  const int table_id,
238  const ColumnDescriptor* cd,
239  const TemporaryTables* temporary_tables) {
240  CHECK(cd || temporary_tables);
241  if (cd) {
242  CHECK_EQ(col_id, cd->columnId);
243  CHECK_EQ(table_id, cd->tableId);
244  return cd->columnType;
245  }
246  const auto& temp = get_temporary_table(temporary_tables, table_id);
247  return temp->getColType(col_id);
248 }
249 
250 class CompilationRetryNoLazyFetch : public std::runtime_error {
251  public:
253  : std::runtime_error("Retry query compilation with no GPU lazy fetch.") {}
254 };
255 
256 class CompilationRetryNewScanLimit : public std::runtime_error {
257  public:
258  CompilationRetryNewScanLimit(const size_t new_scan_limit)
259  : std::runtime_error("Retry query compilation with new scan limit.")
260  , new_scan_limit_(new_scan_limit) {}
261 
263 };
264 
265 class TooManyLiterals : public std::runtime_error {
266  public:
267  TooManyLiterals() : std::runtime_error("Too many literals in the query") {}
268 };
269 
270 class CompilationRetryNoCompaction : public std::runtime_error {
271  public:
273  : std::runtime_error("Retry query compilation with no compaction.") {}
274 };
275 
276 // Throwing QueryMustRunOnCpu allows us retry a query step on CPU if
277 // g_allow_query_step_cpu_retry is true (on by default) by catching
278 // the exception at the query step execution level in RelAlgExecutor,
279 // or if g_allow_query_step_cpu_retry is false but g_allow_cpu_retry is true,
280 // by retrying the entire query on CPU (if both flags are false, we return an
281 // error). This flag is thrown for the following broad categories of conditions:
282 // 1) we have not implemented an operator on GPU and so cannot codegen for GPU
283 // 2) we catch an unexpected GPU compilation/linking error (perhaps due
284 // to an outdated driver/CUDA installation not allowing a modern operator)
285 // 3) when we detect up front that we will not have enough GPU memory to execute
286 // a query.
287 // There is a fourth scenerio where our pre-flight GPU memory check passed but for
288 // whatever reason we still run out of memory. In those cases we go down the
289 // handleOutOfMemoryRetry path, which will first try per-fragment execution on GPU,
290 // and if that fails, CPU execution.
291 // Note that for distributed execution failures on leaves, we do not retry queries
292 // TODO(todd): See if CPU retry of individual steps can be turned on safely for
293 // distributed
294 
295 class QueryMustRunOnCpu : public std::runtime_error {
296  public:
297  QueryMustRunOnCpu() : std::runtime_error("Query must run in cpu mode.") {}
298 
299  QueryMustRunOnCpu(const std::string& err) : std::runtime_error(err) {}
300 };
301 
302 class ParseIRError : public std::runtime_error {
303  public:
304  ParseIRError(const std::string message) : std::runtime_error(message) {}
305 };
306 
307 class StringConstInResultSet : public std::runtime_error {
308  public:
310  : std::runtime_error(
311  "NONE ENCODED String types are not supported as input result set.") {}
312 };
313 
314 class ExtensionFunction;
315 
317 using ColumnToFragmentsMap = std::map<const ColumnDescriptor*, std::set<int32_t>>;
318 using TableToFragmentIds = std::map<int32_t, std::set<int32_t>>;
319 
323 };
324 
326  public:
328 
329  UpdateLogForFragment(FragmentInfoType const& fragment_info,
330  size_t const,
331  const std::shared_ptr<ResultSet>& rs);
332 
333  std::vector<TargetValue> getEntryAt(const size_t index) const override;
334  std::vector<TargetValue> getTranslatedEntryAt(const size_t index) const override;
335 
336  size_t const getRowCount() const override;
338  return rs_->getRowSetMemOwner()->getLiteralStringDictProxy();
339  }
340  size_t const getEntryCount() const override;
341  size_t const getFragmentIndex() const;
342  FragmentInfoType const& getFragmentInfo() const;
345  }
346  decltype(FragmentInfoType::fragmentId) const getFragmentId() const {
347  return fragment_info_.fragmentId;
348  }
349 
350  SQLTypeInfo getColumnType(const size_t col_idx) const;
351 
352  using Callback = std::function<void(const UpdateLogForFragment&, TableUpdateMetadata&)>;
353 
354  auto getResultSet() const { return rs_; }
355 
356  private:
359  std::shared_ptr<ResultSet> rs_;
360 };
361 
362 using LLVMValueVector = std::vector<llvm::Value*>;
363 
365 
366 std::ostream& operator<<(std::ostream&, FetchResult const&);
367 
368 class Executor {
369  static_assert(sizeof(float) == 4 && sizeof(double) == 8,
370  "Host hardware not supported, unexpected size of float / double.");
371  static_assert(sizeof(time_t) == 8,
372  "Host hardware not supported, 64-bit time support is required.");
373 
374  public:
375  using ExecutorId = size_t;
376  static const ExecutorId UNITARY_EXECUTOR_ID = 0;
377  static const ExecutorId INVALID_EXECUTOR_ID = SIZE_MAX;
378 
379  Executor(const ExecutorId id,
380  Data_Namespace::DataMgr* data_mgr,
381  const size_t block_size_x,
382  const size_t grid_size_x,
383  const size_t max_gpu_slab_size,
384  const std::string& debug_dir,
385  const std::string& debug_file);
386 
387  void clearCaches(bool runtime_only = false);
388 
389  std::string dumpCache() const;
390 
391  static void clearExternalCaches(bool for_update,
392  const TableDescriptor* td,
393  const int current_db_id) {
394  bool clearEntireCache = true;
395  if (td) {
396  const auto& table_chunk_key_prefix = td->getTableChunkKey(current_db_id);
397  if (!table_chunk_key_prefix.empty()) {
398  auto table_key = boost::hash_value(table_chunk_key_prefix);
400  if (for_update) {
402  } else {
404  }
405  clearEntireCache = false;
406  }
407  }
408  if (clearEntireCache) {
410  if (for_update) {
412  } else {
414  }
415  }
416  }
417 
418  void reset(bool discard_runtime_modules_only = false);
419 
420  template <typename F>
421  static void registerExtensionFunctions(F register_extension_functions) {
422  // Don't want native code to vanish while executing:
424  // Blocks Executor::getExecutor:
426  // Lock registration to avoid
427  // java.util.ConcurrentModificationException from calcite server
428  // when client registrations arrive too fast. Also blocks
429  // Executor::get_rt_udf_module for retrieving runtime UDF/UDTF
430  // module until this registration has rebuild it via
431  // Executor::update_after_registration:
432  std::lock_guard<std::mutex> register_lock(
434 
435  // Reset all executors:
436  for (auto& executor_item : Executor::executors_) {
437  executor_item.second->reset(/*discard_runtime_modules_only=*/true);
438  }
439  // Call registration worker, see
440  // DBHandler::register_runtime_extension_functions for details. In
441  // short, updates Executor::extension_module_sources,
442  // table_functions::TableFunctionsFactory, and registers runtime
443  // extension functions with Calcite:
444  register_extension_functions();
445 
446  // Update executors with registered LLVM modules:
447  update_after_registration(/*update_runtime_modules_only=*/true);
448  }
449 
450  static std::shared_ptr<Executor> getExecutor(
451  const ExecutorId id,
452  const std::string& debug_dir = "",
453  const std::string& debug_file = "",
454  const SystemParameters& system_parameters = SystemParameters());
455 
456  static void nukeCacheOfExecutors() {
458  execute_mutex_); // don't want native code to vanish while executing
460  executors_.clear();
461  }
462 
463  static void clearMemory(const Data_Namespace::MemoryLevel memory_level);
464 
465  static size_t getArenaBlockSize();
466 
467  static void addUdfIrToModule(const std::string& udf_ir_filename, const bool is_cuda_ir);
468 
469  enum class ExtModuleKinds {
470  template_module, // RuntimeFunctions.bc
471  udf_cpu_module, // Load-time UDFs for CPU execution
472  udf_gpu_module, // Load-time UDFs for GPU execution
473  rt_udf_cpu_module, // Run-time UDF/UDTFs for CPU execution
474  rt_udf_gpu_module, // Run-time UDF/UDTFs for GPU execution
475  rt_geos_module, // geos functions
476  rt_libdevice_module // math library functions for GPU execution
477  };
478  // Globally available mapping of extension module sources. Not thread-safe.
479  static std::map<ExtModuleKinds, std::string> extension_module_sources;
481 
482  // Convenience functions for retrieving executor-local extension modules, thread-safe:
483  const std::unique_ptr<llvm::Module>& get_rt_module() const {
485  }
486  const std::unique_ptr<llvm::Module>& get_udf_module(bool is_gpu = false) const {
487  return get_extension_module(
489  }
490  const std::unique_ptr<llvm::Module>& get_rt_udf_module(bool is_gpu = false) const {
491  std::lock_guard<std::mutex> lock(
493  return get_extension_module(
495  }
496  const std::unique_ptr<llvm::Module>& get_geos_module() const {
498  }
499  const std::unique_ptr<llvm::Module>& get_libdevice_module() const {
501  }
502 
503  bool has_rt_module() const {
505  }
506  bool has_udf_module(bool is_gpu = false) const {
507  return has_extension_module(
509  }
510  bool has_rt_udf_module(bool is_gpu = false) const {
511  return has_extension_module(
513  }
514  bool has_geos_module() const {
516  }
517  bool has_libdevice_module() const {
519  }
520 
525 
530  const bool with_generation) const {
532  return getStringDictionaryProxy(dict_id, row_set_mem_owner_, with_generation);
533  }
534 
536  const int dictId,
537  const std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
538  const bool with_generation) const;
539 
541  const int source_dict_id,
542  const int dest_dict_id,
543  const RowSetMemoryOwner::StringTranslationType translation_type,
544  const std::vector<StringOps_Namespace::StringOpInfo>& string_op_infos,
545  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
546  const bool with_generation) const;
547 
549  const StringDictionaryProxy* source_proxy,
550  StringDictionaryProxy* dest_proxy,
551  const std::vector<StringOps_Namespace::StringOpInfo>& source_string_op_infos,
552  const std::vector<StringOps_Namespace::StringOpInfo>& dest_source_string_op_infos,
553  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner) const;
554 
556  const int source_dict_id,
557  const std::vector<StringOps_Namespace::StringOpInfo>& string_op_infos,
558  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
559  const bool with_generation) const;
560 
561  bool isCPUOnly() const;
562 
563  bool isArchMaxwell(const ExecutorDeviceType dt) const;
564 
566  return cgen_state_->contains_left_deep_outer_join_;
567  }
568 
570 
572  int) const;
573 
574  const Catalog_Namespace::Catalog* getCatalog() const;
575  void setCatalog(const Catalog_Namespace::Catalog* catalog);
576 
578  CHECK(data_mgr_);
579  return data_mgr_;
580  }
581 
582  const std::shared_ptr<RowSetMemoryOwner> getRowSetMemoryOwner() const;
583 
584  const TemporaryTables* getTemporaryTables() const;
585 
586  Fragmenter_Namespace::TableInfo getTableInfo(const int table_id) const;
587 
588  const TableGeneration& getTableGeneration(const int table_id) const;
589 
591 
592  size_t getNumBytesForFetchedRow(const std::set<int>& table_ids_to_fetch) const;
593 
594  bool hasLazyFetchColumns(const std::vector<Analyzer::Expr*>& target_exprs) const;
595  std::vector<ColumnLazyFetchInfo> getColLazyFetchInfo(
596  const std::vector<Analyzer::Expr*>& target_exprs) const;
597 
598  static void registerActiveModule(void* module, const int device_id);
599  static void unregisterActiveModule(const int device_id);
600  void interrupt(const QuerySessionId& query_session = "",
601  const QuerySessionId& interrupt_session = "");
602  void resetInterrupt();
603 
604  // only for testing usage
605  void enableRuntimeQueryInterrupt(const double runtime_query_check_freq,
606  const unsigned pending_query_check_freq) const;
607 
608  static const size_t high_scan_limit{128000000};
609 
610  int8_t warpSize() const;
611  unsigned gridSize() const;
612  void setGridSize(unsigned grid_size);
613  void resetGridSize();
614  unsigned numBlocksPerMP() const;
615  unsigned blockSize() const;
616  void setBlockSize(unsigned block_size);
617  void resetBlockSize();
618  size_t maxGpuSlabSize() const;
619 
620  ResultSetPtr executeWorkUnit(size_t& max_groups_buffer_entry_guess,
621  const bool is_agg,
622  const std::vector<InputTableInfo>&,
623  const RelAlgExecutionUnit&,
624  const CompilationOptions&,
625  const ExecutionOptions& options,
627  RenderInfo* render_info,
628  const bool has_cardinality_estimation,
629  ColumnCacheMap& column_cache);
630 
632  const std::vector<InputTableInfo>& table_infos,
633  const TableDescriptor* updated_table_desc,
634  const CompilationOptions& co,
635  const ExecutionOptions& eo,
637  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
639  const bool is_agg);
640 
642  const RelAlgExecutionUnit& ra_exe_unit,
643  const std::shared_ptr<RowSetMemoryOwner>& row_set_mem_owner);
644 
645  int deviceCount(const ExecutorDeviceType) const;
646 
647  private:
648  void clearMetaInfoCache();
649 
650  int deviceCountForMemoryLevel(const Data_Namespace::MemoryLevel memory_level) const;
651 
652  // Generate code for a window function target.
653  llvm::Value* codegenWindowFunction(const size_t target_index,
654  const CompilationOptions& co);
655 
656  // Generate code for an aggregate window function target.
657  llvm::Value* codegenWindowFunctionAggregate(const CompilationOptions& co);
658 
659  // The aggregate state requires a state reset when starting a new partition. Generate
660  // the new partition check and return the continuation basic block.
661  llvm::BasicBlock* codegenWindowResetStateControlFlow();
662 
663  // Generate code for initializing the state of a window aggregate.
664  void codegenWindowFunctionStateInit(llvm::Value* aggregate_state);
665 
666  // Generates the required calls for an aggregate window function and returns the final
667  // result.
668  llvm::Value* codegenWindowFunctionAggregateCalls(llvm::Value* aggregate_state,
669  const CompilationOptions& co);
670 
671  // Generate code for computing window function on frame
672  llvm::Value* codegenWindowFunctionOnFrame(const CompilationOptions& co);
673 
674  // Generate code for computing current partition index from a given row_pos
675  llvm::Value* codegenCurrentPartitionIndex(
676  const WindowFunctionContext* window_func_context,
677  llvm::Value* current_row_pos_lv);
678 
679  // Generate code to analyze user-given window frame bound expr
680  llvm::Value* codegenFrameBoundExpr(const Analyzer::WindowFunction* window_func,
681  const Analyzer::WindowFrame* frame_bound,
682  CodeGenerator& code_generator,
683  const CompilationOptions& co);
684 
685  // Generate code for computing window frame bounds
686  std::pair<llvm::Value*, llvm::Value*> codegenWindowFrameBound(
687  WindowFunctionContext* window_func_context,
688  const Analyzer::WindowFrame* frame_start_bound,
689  const Analyzer::WindowFrame* frame_end_bound,
690  llvm::Value* current_row_pos_lv,
691  llvm::Value* current_partition_start_offset_lv,
692  llvm::Value* order_key_buf_ptr_lv,
693  llvm::Value* order_key_col_null_val_lv,
694  llvm::Value* frame_start_bound_expr_lv,
695  llvm::Value* frame_end_bound_expr_lv,
696  llvm::Value* num_elem_current_partition_lv,
697  llvm::Value* target_partition_rowid_ptr_lv,
698  llvm::Value* target_partition_sorted_rowid_ptr_lv,
699  llvm::Value* null_start_pos_lv,
700  llvm::Value* null_end_pos_lv,
701  CodeGenerator& code_generator);
702 
703  // The AVG window function requires some post-processing: the sum is divided by count
704  // and the result is stored back for the current row.
705  void codegenWindowAvgEpilogue(llvm::Value* crt_val,
706  llvm::Value* window_func_null_val,
707  llvm::Value* multiplicity_lv);
708 
709  // Generates code which loads the current aggregate value for the window context.
710  llvm::Value* codegenAggregateWindowState();
711 
712  llvm::Value* aggregateWindowStatePtr();
713 
715  CHECK(data_mgr_);
716  auto cuda_mgr = data_mgr_->getCudaMgr();
717  CHECK(cuda_mgr);
718  return cuda_mgr;
719  }
720 
722  if (dt == ExecutorDeviceType::GPU) {
723  return cudaMgr()->isArchPascalOrLater();
724  }
725  return false;
726  }
727 
728  bool needFetchAllFragments(const InputColDescriptor& col_desc,
729  const RelAlgExecutionUnit& ra_exe_unit,
730  const FragmentsList& selected_fragments) const;
731 
733  const InputColDescriptor& inner_col_desc,
734  const RelAlgExecutionUnit& ra_exe_unit,
735  const FragmentsList& selected_fragments,
736  const Data_Namespace::MemoryLevel memory_level) const;
737 
738  using PerFragmentCallBack =
739  std::function<void(ResultSetPtr, const Fragmenter_Namespace::FragmentInfo&)>;
740 
746  void executeWorkUnitPerFragment(const RelAlgExecutionUnit& ra_exe_unit,
747  const InputTableInfo& table_info,
748  const CompilationOptions& co,
749  const ExecutionOptions& eo,
752  const std::set<size_t>& fragment_indexes_param);
753 
755 
762  const std::vector<InputTableInfo>& table_infos,
763  const CompilationOptions& co,
764  const ExecutionOptions& eo,
766 
768  const RelAlgExecutionUnit& ra_exe_unit,
769  const ExecutorDeviceType requested_device_type);
770 
772  SharedKernelContext& shared_context,
773  const RelAlgExecutionUnit& ra_exe_unit,
775  const ExecutorDeviceType device_type,
776  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner);
777 
779  SharedKernelContext& shared_context,
780  const RelAlgExecutionUnit& ra_exe_unit) const;
781 
782  std::unordered_map<int, const Analyzer::BinOper*> getInnerTabIdToJoinCond() const;
783 
788  std::vector<std::unique_ptr<ExecutionKernel>> createKernels(
789  SharedKernelContext& shared_context,
790  const RelAlgExecutionUnit& ra_exe_unit,
791  ColumnFetcher& column_fetcher,
792  const std::vector<InputTableInfo>& table_infos,
793  const ExecutionOptions& eo,
794  const bool is_agg,
795  const bool allow_single_frag_table_opt,
796  const size_t context_count,
797  const QueryCompilationDescriptor& query_comp_desc,
799  RenderInfo* render_info,
800  std::unordered_set<int>& available_gpus,
801  int& available_cpus);
802 
807  void launchKernels(SharedKernelContext& shared_context,
808  std::vector<std::unique_ptr<ExecutionKernel>>&& kernels,
809  const ExecutorDeviceType device_type);
810 
811  std::vector<size_t> getTableFragmentIndices(
812  const RelAlgExecutionUnit& ra_exe_unit,
813  const ExecutorDeviceType device_type,
814  const size_t table_idx,
815  const size_t outer_frag_idx,
816  std::map<int, const TableFragments*>& selected_tables_fragments,
817  const std::unordered_map<int, const Analyzer::BinOper*>&
818  inner_table_id_to_join_condition);
819 
820  bool skipFragmentPair(const Fragmenter_Namespace::FragmentInfo& outer_fragment_info,
821  const Fragmenter_Namespace::FragmentInfo& inner_fragment_info,
822  const int inner_table_id,
823  const std::unordered_map<int, const Analyzer::BinOper*>&
824  inner_table_id_to_join_condition,
825  const RelAlgExecutionUnit& ra_exe_unit,
826  const ExecutorDeviceType device_type);
827 
829  const RelAlgExecutionUnit& ra_exe_unit,
830  const int device_id,
832  const std::map<int, const TableFragments*>&,
833  const FragmentsList& selected_fragments,
835  std::list<ChunkIter>&,
836  std::list<std::shared_ptr<Chunk_NS::Chunk>>&,
837  DeviceAllocator* device_allocator,
838  const size_t thread_idx,
839  const bool allow_runtime_interrupt);
840 
842  const RelAlgExecutionUnit& ra_exe_unit,
843  const int device_id,
845  const std::map<int, const TableFragments*>&,
846  const FragmentsList& selected_fragments,
848  std::list<ChunkIter>&,
849  std::list<std::shared_ptr<Chunk_NS::Chunk>>&,
850  DeviceAllocator* device_allocator,
851  const size_t thread_idx,
852  const bool allow_runtime_interrupt);
853 
854  std::pair<std::vector<std::vector<int64_t>>, std::vector<std::vector<uint64_t>>>
856  const RelAlgExecutionUnit& ra_exe_unit,
857  const CartesianProduct<std::vector<std::vector<size_t>>>& frag_ids_crossjoin,
858  const std::vector<InputDescriptor>& input_descs,
859  const std::map<int, const TableFragments*>& all_tables_fragments);
860 
862  std::vector<std::vector<size_t>>& selected_fragments_crossjoin,
863  std::vector<size_t>& local_col_to_frag_pos,
864  const std::list<std::shared_ptr<const InputColDescriptor>>& col_global_ids,
865  const FragmentsList& selected_fragments,
866  const RelAlgExecutionUnit& ra_exe_unit);
867 
869  std::vector<std::vector<size_t>>& selected_fragments_crossjoin,
870  const FragmentsList& selected_fragments,
871  const RelAlgExecutionUnit& ra_exe_unit);
872 
873  std::vector<size_t> getFragmentCount(const FragmentsList& selected_fragments,
874  const size_t scan_idx,
875  const RelAlgExecutionUnit& ra_exe_unit);
876 
877  // pass nullptr to results if it shouldn't be extracted from the execution context
878  int32_t executePlanWithGroupBy(const RelAlgExecutionUnit& ra_exe_unit,
879  const CompilationResult&,
880  const bool hoist_literals,
881  ResultSetPtr* results,
882  const ExecutorDeviceType device_type,
883  std::vector<std::vector<const int8_t*>>& col_buffers,
884  const std::vector<size_t> outer_tab_frag_ids,
886  const std::vector<std::vector<int64_t>>& num_rows,
887  const std::vector<std::vector<uint64_t>>& frag_offsets,
889  const int device_id,
890  const int outer_table_id,
891  const int64_t limit,
892  const uint32_t start_rowid,
893  const uint32_t num_tables,
894  const bool allow_runtime_interrupt,
895  RenderInfo* render_info,
896  const int64_t rows_to_process = -1);
897  // pass nullptr to results if it shouldn't be extracted from the execution context
899  const RelAlgExecutionUnit& ra_exe_unit,
900  const CompilationResult&,
901  const bool hoist_literals,
902  ResultSetPtr* results,
903  const std::vector<Analyzer::Expr*>& target_exprs,
904  const ExecutorDeviceType device_type,
905  std::vector<std::vector<const int8_t*>>& col_buffers,
906  QueryExecutionContext* query_exe_context,
907  const std::vector<std::vector<int64_t>>& num_rows,
908  const std::vector<std::vector<uint64_t>>& frag_offsets,
909  Data_Namespace::DataMgr* data_mgr,
910  const int device_id,
911  const uint32_t start_rowid,
912  const uint32_t num_tables,
913  const bool allow_runtime_interrupt,
914  RenderInfo* render_info,
915  const int64_t rows_to_process = -1);
916 
917  public: // Temporary, ask saman about this
918  static std::pair<int64_t, int32_t> reduceResults(const SQLAgg agg,
919  const SQLTypeInfo& ti,
920  const int64_t agg_init_val,
921  const int8_t out_byte_width,
922  const int64_t* out_vec,
923  const size_t out_vec_sz,
924  const bool is_group_by,
925  const bool float_argument_input);
926 
927  private:
929  const RelAlgExecutionUnit& ra_exe_unit);
930  std::vector<int8_t*> getJoinHashTablePtrs(const ExecutorDeviceType device_type,
931  const int device_id);
933  const RelAlgExecutionUnit&,
934  std::vector<std::pair<ResultSetPtr, std::vector<size_t>>>& all_fragment_results,
935  std::shared_ptr<RowSetMemoryOwner>,
936  const QueryMemoryDescriptor&) const;
938  std::vector<std::pair<ResultSetPtr, std::vector<size_t>>>& all_fragment_results,
939  std::shared_ptr<RowSetMemoryOwner>,
940  const QueryMemoryDescriptor&) const;
942  const RelAlgExecutionUnit&,
943  std::vector<std::pair<ResultSetPtr, std::vector<size_t>>>& all_fragment_results,
944  std::shared_ptr<RowSetMemoryOwner>,
945  const QueryMemoryDescriptor&) const;
946 
947  ResultSetPtr executeWorkUnitImpl(size_t& max_groups_buffer_entry_guess,
948  const bool is_agg,
949  const bool allow_single_frag_table_opt,
950  const std::vector<InputTableInfo>&,
951  const RelAlgExecutionUnit&,
952  const CompilationOptions&,
953  const ExecutionOptions& options,
955  std::shared_ptr<RowSetMemoryOwner>,
956  RenderInfo* render_info,
957  const bool has_cardinality_estimation,
958  ColumnCacheMap& column_cache);
959 
960  std::vector<llvm::Value*> inlineHoistedLiterals();
961 
963 
964  std::tuple<CompilationResult, std::unique_ptr<QueryMemoryDescriptor>> compileWorkUnit(
965  const std::vector<InputTableInfo>& query_infos,
966  const PlanState::DeletedColumnsMap& deleted_cols_map,
967  const RelAlgExecutionUnit& ra_exe_unit,
968  const CompilationOptions& co,
969  const ExecutionOptions& eo,
970  const CudaMgr_Namespace::CudaMgr* cuda_mgr,
971  const bool allow_lazy_fetch,
972  std::shared_ptr<RowSetMemoryOwner>,
973  const size_t max_groups_buffer_entry_count,
974  const int8_t crt_min_byte_width,
975  const bool has_cardinality_estimation,
976  ColumnCacheMap& column_cache,
977  RenderInfo* render_info = nullptr);
978  // Generate code to skip the deleted rows in the outermost table.
979  llvm::BasicBlock* codegenSkipDeletedOuterTableRow(
980  const RelAlgExecutionUnit& ra_exe_unit,
981  const CompilationOptions& co);
982  std::vector<JoinLoop> buildJoinLoops(RelAlgExecutionUnit& ra_exe_unit,
983  const CompilationOptions& co,
984  const ExecutionOptions& eo,
985  const std::vector<InputTableInfo>& query_infos,
986  ColumnCacheMap& column_cache);
987  // Create a callback which hoists left hand side filters above the join for left joins,
988  // eliminating extra computation of the probe and matches if the row does not pass the
989  // filters
991  const RelAlgExecutionUnit& ra_exe_unit,
992  const size_t level_idx,
993  const int inner_table_id,
994  const CompilationOptions& co);
995  // Create a callback which generates code which returns true iff the row on the given
996  // level is deleted.
997  std::function<llvm::Value*(const std::vector<llvm::Value*>&, llvm::Value*)>
998  buildIsDeletedCb(const RelAlgExecutionUnit& ra_exe_unit,
999  const size_t level_idx,
1000  const CompilationOptions& co);
1001  // Builds a join hash table for the provided conditions on the current level.
1002  // Returns null iff on failure and provides the reasons in `fail_reasons`.
1003  std::shared_ptr<HashJoin> buildCurrentLevelHashTable(
1004  const JoinCondition& current_level_join_conditions,
1005  size_t level_idx,
1006  RelAlgExecutionUnit& ra_exe_unit,
1007  const CompilationOptions& co,
1008  const std::vector<InputTableInfo>& query_infos,
1009  ColumnCacheMap& column_cache,
1010  std::vector<std::string>& fail_reasons);
1011  void redeclareFilterFunction();
1012  llvm::Value* addJoinLoopIterator(const std::vector<llvm::Value*>& prev_iters,
1013  const size_t level_idx);
1014  void codegenJoinLoops(const std::vector<JoinLoop>& join_loops,
1015  const RelAlgExecutionUnit& ra_exe_unit,
1016  GroupByAndAggregate& group_by_and_aggregate,
1017  llvm::Function* query_func,
1018  llvm::BasicBlock* entry_bb,
1020  const CompilationOptions& co,
1021  const ExecutionOptions& eo);
1022  bool compileBody(const RelAlgExecutionUnit& ra_exe_unit,
1023  GroupByAndAggregate& group_by_and_aggregate,
1025  const CompilationOptions& co,
1026  const GpuSharedMemoryContext& gpu_smem_context = {});
1027 
1028  void createErrorCheckControlFlow(llvm::Function* query_func,
1029  bool run_with_dynamic_watchdog,
1030  bool run_with_allowing_runtime_interrupt,
1031  const std::vector<JoinLoop>& join_loops,
1032  ExecutorDeviceType device_type,
1033  const std::vector<InputTableInfo>& input_table_infos);
1034 
1035  void insertErrorCodeChecker(llvm::Function* query_func,
1036  bool hoist_literals,
1037  bool allow_runtime_query_interrupt);
1038 
1039  void preloadFragOffsets(const std::vector<InputDescriptor>& input_descs,
1040  const std::vector<InputTableInfo>& query_infos);
1041 
1043  std::shared_ptr<HashJoin> hash_table;
1044  std::string fail_reason;
1045  };
1046 
1048  const std::shared_ptr<Analyzer::BinOper>& qual_bin_oper,
1049  const std::vector<InputTableInfo>& query_infos,
1050  const MemoryLevel memory_level,
1051  const JoinType join_type,
1052  const HashType preferred_hash_type,
1053  ColumnCacheMap& column_cache,
1054  const HashTableBuildDagMap& hashtable_build_dag_map,
1055  const RegisteredQueryHint& query_hint,
1056  const TableIdToNodeMap& table_id_to_node_map);
1057  void nukeOldState(const bool allow_lazy_fetch,
1058  const std::vector<InputTableInfo>& query_infos,
1059  const PlanState::DeletedColumnsMap& deleted_cols_map,
1060  const RelAlgExecutionUnit* ra_exe_unit);
1061 
1062  std::shared_ptr<CompilationContext> optimizeAndCodegenCPU(
1063  llvm::Function*,
1064  llvm::Function*,
1065  const std::unordered_set<llvm::Function*>&,
1066  const CompilationOptions&);
1067  std::shared_ptr<CompilationContext> optimizeAndCodegenGPU(
1068  llvm::Function*,
1069  llvm::Function*,
1070  std::unordered_set<llvm::Function*>&,
1071  const bool no_inline,
1072  const CudaMgr_Namespace::CudaMgr* cuda_mgr,
1073  const bool is_gpu_smem_used,
1074  const CompilationOptions&);
1075  std::string generatePTX(const std::string&) const;
1076  void initializeNVPTXBackend() const;
1077 
1078  int64_t deviceCycles(int milliseconds) const;
1079 
1081  llvm::Value* translated_value;
1082  llvm::Value* original_value;
1083  };
1084 
1086  const size_t col_width,
1087  const CompilationOptions&,
1088  const bool translate_null_val,
1089  const int64_t translated_null_val,
1090  DiamondCodegen&,
1091  std::stack<llvm::BasicBlock*>&,
1092  const bool thread_mem_shared);
1093 
1094  llvm::Value* castToFP(llvm::Value*,
1095  SQLTypeInfo const& from_ti,
1096  SQLTypeInfo const& to_ti);
1097  llvm::Value* castToIntPtrTyIn(llvm::Value* val, const size_t bit_width);
1098 
1099  std::tuple<RelAlgExecutionUnit, PlanState::DeletedColumnsMap> addDeletedColumn(
1100  const RelAlgExecutionUnit& ra_exe_unit,
1101  const CompilationOptions& co);
1102 
1103  bool isFragmentFullyDeleted(const int table_id,
1104  const Fragmenter_Namespace::FragmentInfo& fragment);
1105 
1107  const Analyzer::BinOper* comp_expr,
1108  const Analyzer::ColumnVar* lhs_col,
1109  const Fragmenter_Namespace::FragmentInfo& fragment,
1110  const Analyzer::Constant* rhs_const) const;
1111 
1112  std::pair<bool, int64_t> skipFragment(
1113  const InputDescriptor& table_desc,
1114  const Fragmenter_Namespace::FragmentInfo& frag_info,
1115  const std::list<std::shared_ptr<Analyzer::Expr>>& simple_quals,
1116  const std::vector<uint64_t>& frag_offsets,
1117  const size_t frag_idx);
1118 
1119  std::pair<bool, int64_t> skipFragmentInnerJoins(
1120  const InputDescriptor& table_desc,
1121  const RelAlgExecutionUnit& ra_exe_unit,
1122  const Fragmenter_Namespace::FragmentInfo& fragment,
1123  const std::vector<uint64_t>& frag_offsets,
1124  const size_t frag_idx);
1125 
1127  const std::unordered_set<PhysicalInput>& phys_inputs);
1129  const std::unordered_set<PhysicalInput>& phys_inputs);
1130  TableGenerations computeTableGenerations(std::unordered_set<int> phys_table_ids);
1131 
1132  public:
1133  void setupCaching(const std::unordered_set<PhysicalInput>& phys_inputs,
1134  const std::unordered_set<int>& phys_table_ids);
1135  void setColRangeCache(const AggregatedColRange& aggregated_col_range) {
1136  agg_col_range_cache_ = aggregated_col_range;
1137  }
1142  const QuerySessionId& candidate_query_session,
1144  bool checkCurrentQuerySession(const std::string& candidate_query_session,
1148  bool addToQuerySessionList(const QuerySessionId& query_session,
1149  const std::string& query_str,
1150  const std::string& submitted,
1151  const size_t executor_id,
1152  const QuerySessionStatus::QueryStatus query_status,
1155  const QuerySessionId& query_session,
1156  const std::string& submitted_time_str,
1159  const QuerySessionId& query_session,
1162  const std::string& query_session,
1165  const QuerySessionId& query_session,
1168  const QuerySessionId& query_session,
1169  const std::string& submitted_time_str,
1170  const QuerySessionStatus::QueryStatus updated_query_status,
1173  const QuerySessionId& query_session,
1174  const std::string& submitted_time_str,
1175  const size_t executor_id,
1177  std::vector<QuerySessionStatus> getQuerySessionInfo(
1178  const QuerySessionId& query_session,
1180 
1183  const QuerySessionId& query_session_id,
1184  const std::string& query_str,
1185  const std::string& query_submitted_time);
1186  void checkPendingQueryStatus(const QuerySessionId& query_session);
1187  void clearQuerySessionStatus(const QuerySessionId& query_session,
1188  const std::string& submitted_time_str);
1189  void updateQuerySessionStatus(const QuerySessionId& query_session,
1190  const std::string& submitted_time_str,
1191  const QuerySessionStatus::QueryStatus new_query_status);
1192  void enrollQuerySession(const QuerySessionId& query_session,
1193  const std::string& query_str,
1194  const std::string& submitted_time_str,
1195  const size_t executor_id,
1196  const QuerySessionStatus::QueryStatus query_session_status);
1197  size_t getNumCurentSessionsEnrolled() const;
1198  // get a set of executor ids that a given session has fired regardless of
1199  // each executor's status: pending or running
1200  const std::vector<size_t> getExecutorIdsRunningQuery(
1201  const QuerySessionId& interrupt_session) const;
1202  // check whether the current session that this executor manages is interrupted
1203  // while performing non-kernel time task
1204  bool checkNonKernelTimeInterrupted() const;
1205  void registerExtractedQueryPlanDag(const QueryPlanDAG& query_plan_dag);
1207 
1208  // true when we have matched cardinality, and false otherwise
1209  using CachedCardinality = std::pair<bool, size_t>;
1210  void addToCardinalityCache(const std::string& cache_key, const size_t cache_value);
1211  CachedCardinality getCachedCardinality(const std::string& cache_key);
1212 
1216 
1217  CgenState* getCgenStatePtr() const { return cgen_state_.get(); }
1218  PlanState* getPlanStatePtr() const { return plan_state_.get(); }
1219 
1220  llvm::LLVMContext& getContext() { return *context_.get(); }
1221  void update_extension_modules(bool update_runtime_modules_only = false);
1222 
1223  static void update_after_registration(bool update_runtime_modules_only = false) {
1224  for (auto executor_item : Executor::executors_) {
1225  executor_item.second->update_extension_modules(update_runtime_modules_only);
1226  }
1227  }
1228 
1229  private:
1230  std::vector<int8_t> serializeLiterals(
1231  const std::unordered_map<int, CgenState::LiteralValues>& literals,
1232  const int device_id);
1233 
1234  static size_t align(const size_t off_in, const size_t alignment) {
1235  size_t off = off_in;
1236  if (off % alignment != 0) {
1237  off += (alignment - off % alignment);
1238  }
1239  return off;
1240  }
1241 
1243  std::unique_ptr<llvm::LLVMContext> context_;
1244 
1245  public:
1246  // CgenStateManager uses RAII pattern to ensure that recursive code
1247  // generation (e.g. as in multi-step multi-subqueries) uses a new
1248  // CgenState instance for each recursion depth while restoring the
1249  // old CgenState instances when returning from recursion.
1251  public:
1252  CgenStateManager(Executor& executor);
1253  CgenStateManager(Executor& executor,
1254  const bool allow_lazy_fetch,
1255  const std::vector<InputTableInfo>& query_infos,
1256  const PlanState::DeletedColumnsMap& deleted_cols_map,
1257  const RelAlgExecutionUnit* ra_exe_unit);
1259 
1260  private:
1262  std::chrono::steady_clock::time_point lock_queue_clock_;
1263  std::lock_guard<std::mutex> lock_;
1264  std::unique_ptr<CgenState> cgen_state_;
1265  };
1266 
1267  private:
1268  std::unique_ptr<CgenState> cgen_state_;
1269 
1270  const std::unique_ptr<llvm::Module>& get_extension_module(ExtModuleKinds kind) const {
1271  auto it = extension_modules_.find(kind);
1272  if (it != extension_modules_.end()) {
1273  return it->second;
1274  }
1275  static const std::unique_ptr<llvm::Module> empty;
1276  return empty;
1277  }
1278 
1280  return extension_modules_.find(kind) != extension_modules_.end();
1281  }
1282 
1283  std::map<ExtModuleKinds, std::unique_ptr<llvm::Module>> extension_modules_;
1284 
1286  public:
1288  : cgen_state_(cgen_state), saved_fetch_cache(cgen_state_->fetch_cache_) {}
1290 
1291  private:
1293  std::unordered_map<size_t, std::vector<llvm::Value*>> saved_fetch_cache;
1294  };
1295 
1296  llvm::Value* spillDoubleElement(llvm::Value* elem_val, llvm::Type* elem_ty);
1297 
1298  std::unique_ptr<PlanState> plan_state_;
1299  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner_;
1300 
1301  static const int max_gpu_count{16};
1303 
1304  static std::mutex gpu_active_modules_mutex_;
1307  // indicates whether this executor has been interrupted
1308  std::atomic<bool> interrupted_;
1309 
1310  mutable std::mutex str_dict_mutex_;
1311 
1312  mutable std::unique_ptr<llvm::TargetMachine> nvptx_target_machine_;
1313 
1314  static const size_t baseline_threshold{
1315  1000000}; // if a perfect hash needs more entries, use baseline
1316 
1317  unsigned block_size_x_;
1318  unsigned grid_size_x_;
1319  const size_t max_gpu_slab_size_;
1320  const std::string debug_dir_;
1321  const std::string debug_file_;
1322 
1327 
1330 
1331  // Singleton instance used for an execution unit which is a project with window
1332  // functions.
1333  std::unique_ptr<WindowProjectNodeContext> window_project_node_context_owned_;
1334  // The active window function.
1336 
1341  // a query session that this executor manages
1343  // a pair of <QuerySessionId, interrupted_flag>
1345  // a pair of <QuerySessionId, query_session_status>
1347  static std::map<int, std::shared_ptr<Executor>> executors_;
1348 
1349  // SQL queries take a shared lock, exclusive options (cache clear, memory clear) take a
1350  // write lock
1352 
1356  };
1358  ExecutorMutexHolder ret;
1360  // Only one unitary executor can run at a time
1362  } else {
1364  }
1365  return ret;
1366  }
1367 
1369 
1372  static std::unordered_map<std::string, size_t> cardinality_cache_;
1374 
1375  // a variable used for testing query plan DAG extractor when a query has a table
1376  // function
1378 
1379  public:
1380  static const int32_t ERR_DIV_BY_ZERO{1};
1381  static const int32_t ERR_OUT_OF_GPU_MEM{2};
1382  static const int32_t ERR_OUT_OF_SLOTS{3};
1383  static const int32_t ERR_UNSUPPORTED_SELF_JOIN{4};
1384  static const int32_t ERR_OUT_OF_RENDER_MEM{5};
1385  static const int32_t ERR_OUT_OF_CPU_MEM{6};
1386  static const int32_t ERR_OVERFLOW_OR_UNDERFLOW{7};
1387  static const int32_t ERR_OUT_OF_TIME{9};
1388  static const int32_t ERR_INTERRUPTED{10};
1389  static const int32_t ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED{11};
1390  static const int32_t ERR_TOO_MANY_LITERALS{12};
1391  static const int32_t ERR_STRING_CONST_IN_RESULTSET{13};
1393  static const int32_t ERR_SINGLE_VALUE_FOUND_MULTIPLE_VALUES{15};
1394  static const int32_t ERR_GEOS{16};
1395  static const int32_t ERR_WIDTH_BUCKET_INVALID_ARGUMENT{17};
1396 
1397  // Although compilation is Executor-local, an executor may trigger
1398  // threaded compilations (see executeWorkUnitPerFragment) that share
1399  // executor cgen_state and LLVM context, for instance.
1400  //
1401  // Rule of thumb: when `executor->thread_id_ != logger::thread_id()`
1402  // and executor LLVM Context is being modified (modules are cloned,
1403  // etc), one should protect such a code with
1404  //
1405  // std::lock_guard<std::mutex> compilation_lock(executor->compilation_mutex_);
1406  //
1407  // to ensure thread safety.
1410 
1411  // Runtime extension function registration updates
1412  // extension_modules_ that needs to be kept blocked from codegen
1413  // until the update is complete.
1415  static std::mutex kernel_mutex_; // TODO: should this be executor-local mutex?
1416 
1418  friend class CodeGenerator;
1419  friend class ColumnFetcher;
1420  friend struct DiamondCodegen; // cgen_state_
1421  friend class ExecutionKernel;
1422  friend class KernelSubtask;
1423  friend class HashJoin; // cgen_state_
1425  friend class RangeJoinHashTable;
1426  friend class GroupByAndAggregate;
1432  friend class ResultSet;
1433  friend class InValuesBitmap;
1435  friend class LeafAggregator;
1436  friend class PerfectJoinHashTable;
1437  friend class QueryRewriter;
1439  friend class RelAlgExecutor;
1440  friend class TableOptimizer;
1444  friend struct TargetExprCodegen;
1446 };
1447 
1448 inline std::string get_null_check_suffix(const SQLTypeInfo& lhs_ti,
1449  const SQLTypeInfo& rhs_ti) {
1450  if (lhs_ti.get_notnull() && rhs_ti.get_notnull()) {
1451  return "";
1452  }
1453  std::string null_check_suffix{"_nullable"};
1454  if (lhs_ti.get_notnull()) {
1455  CHECK(!rhs_ti.get_notnull());
1456  null_check_suffix += "_rhs";
1457  } else if (rhs_ti.get_notnull()) {
1458  CHECK(!lhs_ti.get_notnull());
1459  null_check_suffix += "_lhs";
1460  }
1461  return null_check_suffix;
1462 }
1463 
1464 inline bool is_unnest(const Analyzer::Expr* expr) {
1465  return dynamic_cast<const Analyzer::UOper*>(expr) &&
1466  static_cast<const Analyzer::UOper*>(expr)->get_optype() == kUNNEST;
1467 }
1468 
1469 inline bool is_constructed_point(const Analyzer::Expr* expr) {
1470  auto uoper = dynamic_cast<const Analyzer::UOper*>(expr);
1471  auto oper = (uoper && uoper->get_optype() == kCAST) ? uoper->get_operand() : expr;
1472  auto arr = dynamic_cast<const Analyzer::ArrayExpr*>(oper);
1473  return (arr && arr->isLocalAlloc() && arr->get_type_info().is_fixlen_array());
1474 }
1475 
1476 bool is_trivial_loop_join(const std::vector<InputTableInfo>& query_infos,
1477  const RelAlgExecutionUnit& ra_exe_unit);
1478 
1479 std::unordered_set<int> get_available_gpus(const Catalog_Namespace::Catalog& cat);
1480 
1481 size_t get_context_count(const ExecutorDeviceType device_type,
1482  const size_t cpu_count,
1483  const size_t gpu_count);
1484 
1485 extern "C" RUNTIME_EXPORT void register_buffer_with_executor_rsm(int64_t exec,
1486  int8_t* buffer);
1487 
1489 
1490 inline std::string toString(const Executor::ExtModuleKinds& kind) {
1491  switch (kind) {
1493  return "template_module";
1495  return "rt_geos_module";
1497  return "rt_libdevice_module";
1499  return "udf_cpu_module";
1501  return "udf_gpu_module";
1503  return "rt_udf_cpu_module";
1505  return "rt_udf_gpu_module";
1506  }
1507  LOG(FATAL) << "Invalid LLVM module kind.";
1508  return "";
1509 }
1510 
1511 namespace foreign_storage {
1512 void populate_string_dictionary(const int32_t table_id,
1513  const int32_t col_id,
1515 }
1516 
1517 #endif // QUERYENGINE_EXECUTE_H
void createErrorCheckControlFlow(llvm::Function *query_func, bool run_with_dynamic_watchdog, bool run_with_allowing_runtime_interrupt, const std::vector< JoinLoop > &join_loops, ExecutorDeviceType device_type, const std::vector< InputTableInfo > &input_table_infos)
SQLTypeInfo getColumnType(const size_t col_idx) const
CudaMgr_Namespace::CudaMgr * getCudaMgr() const
Definition: DataMgr.h:224
const std::string debug_dir_
Definition: Execute.h:1320
llvm::Value * translated_value
Definition: Execute.h:1081
void executeWorkUnitPerFragment(const RelAlgExecutionUnit &ra_exe_unit, const InputTableInfo &table_info, const CompilationOptions &co, const ExecutionOptions &eo, const Catalog_Namespace::Catalog &cat, PerFragmentCallBack &cb, const std::set< size_t > &fragment_indexes_param)
Compiles and dispatches a work unit per fragment processing results with the per fragment callback...
Definition: Execute.cpp:2001
bool is_agg(const Analyzer::Expr *expr)
static void invalidateCachesByTable(size_t table_key)
AggregatedColRange computeColRangesCache(const std::unordered_set< PhysicalInput > &phys_inputs)
Definition: Execute.cpp:4367
void enableRuntimeQueryInterrupt(const double runtime_query_check_freq, const unsigned pending_query_check_freq) const
Definition: Execute.cpp:4745
SQLAgg
Definition: sqldefs.h:72
#define CHECK_EQ(x, y)
Definition: Logger.h:230
const QueryPlanDAG getLatestQueryPlanDagExtracted() const
Definition: Execute.cpp:4832
std::vector< std::unique_ptr< ExecutionKernel > > createKernels(SharedKernelContext &shared_context, const RelAlgExecutionUnit &ra_exe_unit, ColumnFetcher &column_fetcher, const std::vector< InputTableInfo > &table_infos, const ExecutionOptions &eo, const bool is_agg, const bool allow_single_frag_table_opt, const size_t context_count, const QueryCompilationDescriptor &query_comp_desc, const QueryMemoryDescriptor &query_mem_desc, RenderInfo *render_info, std::unordered_set< int > &available_gpus, int &available_cpus)
Definition: Execute.cpp:2538
ExtModuleKinds
Definition: Execute.h:469
void codegenJoinLoops(const std::vector< JoinLoop > &join_loops, const RelAlgExecutionUnit &ra_exe_unit, GroupByAndAggregate &group_by_and_aggregate, llvm::Function *query_func, llvm::BasicBlock *entry_bb, QueryMemoryDescriptor &query_mem_desc, const CompilationOptions &co, const ExecutionOptions &eo)
Definition: IRCodegen.cpp:1112
static heavyai::shared_mutex execute_mutex_
Definition: Execute.h:1351
const std::unique_ptr< llvm::Module > & get_udf_module(bool is_gpu=false) const
Definition: Execute.h:486
static QuerySessionMap queries_session_map_
Definition: Execute.h:1346
CudaMgr_Namespace::CudaMgr * cudaMgr() const
Definition: Execute.h:714
int32_t executePlanWithGroupBy(const RelAlgExecutionUnit &ra_exe_unit, const CompilationResult &, const bool hoist_literals, ResultSetPtr *results, const ExecutorDeviceType device_type, std::vector< std::vector< const int8_t * >> &col_buffers, const std::vector< size_t > outer_tab_frag_ids, QueryExecutionContext *, const std::vector< std::vector< int64_t >> &num_rows, const std::vector< std::vector< uint64_t >> &frag_offsets, Data_Namespace::DataMgr *, const int device_id, const int outer_table_id, const int64_t limit, const uint32_t start_rowid, const uint32_t num_tables, const bool allow_runtime_interrupt, RenderInfo *render_info, const int64_t rows_to_process=-1)
Definition: Execute.cpp:3550
std::unique_ptr< llvm::TargetMachine > nvptx_target_machine_
Definition: Execute.h:1312
bool checkIsQuerySessionInterrupted(const std::string &query_session, heavyai::shared_lock< heavyai::shared_mutex > &read_lock)
Definition: Execute.cpp:4725
bool has_libdevice_module() const
Definition: Execute.h:517
int64_t kernel_queue_time_ms_
Definition: Execute.h:1328
JoinType
Definition: sqldefs.h:157
size_t maxGpuSlabSize() const
Definition: Execute.cpp:3876
ExecutorMutexHolder acquireExecuteMutex()
Definition: Execute.h:1357
Data_Namespace::DataMgr * data_mgr_
Definition: Execute.h:1324
int64_t compilation_queue_time_ms_
Definition: Execute.h:1329
const std::string & getQuerySubmittedTime()
Definition: Execute.h:132
friend class ResultSet
Definition: Execute.h:1432
std::map< const ColumnDescriptor *, std::set< int32_t >> ColumnToFragmentsMap
Definition: Execute.h:317
const std::unique_ptr< llvm::Module > & get_geos_module() const
Definition: Execute.h:496
std::string cat(Ts &&...args)
llvm::Value * codegenCurrentPartitionIndex(const WindowFunctionContext *window_func_context, llvm::Value *current_row_pos_lv)
static void initialize_extension_module_sources()
Definition: Execute.cpp:268
void checkPendingQueryStatus(const QuerySessionId &query_session)
Definition: Execute.cpp:4506
const StringDictionaryProxy::IdMap * getJoinIntersectionStringProxyTranslationMap(const StringDictionaryProxy *source_proxy, StringDictionaryProxy *dest_proxy, const std::vector< StringOps_Namespace::StringOpInfo > &source_string_op_infos, const std::vector< StringOps_Namespace::StringOpInfo > &dest_source_string_op_infos, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner) const
Definition: Execute.cpp:586
static void registerActiveModule(void *module, const int device_id)
static const int32_t ERR_INTERRUPTED
Definition: Execute.h:1388
const Analyzer::Expr * remove_cast_to_int(const Analyzer::Expr *expr)
Definition: ColumnIR.cpp:576
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:132
std::unordered_map< size_t, std::vector< llvm::Value * > > fetch_cache_
Definition: CgenState.h:442
std::vector< int8_t * > getJoinHashTablePtrs(const ExecutorDeviceType device_type, const int device_id)
Definition: Execute.cpp:3738
bool is_trivial_loop_join(const std::vector< InputTableInfo > &query_infos, const RelAlgExecutionUnit &ra_exe_unit)
Definition: Execute.cpp:1578
FetchCacheAnchor(CgenState *cgen_state)
Definition: Execute.h:1287
heavyai::shared_lock< heavyai::shared_mutex > read_lock
const std::unique_ptr< llvm::Module > & get_extension_module(ExtModuleKinds kind) const
Definition: Execute.h:1270
const std::shared_ptr< RowSetMemoryOwner > getRowSetMemoryOwner() const
Definition: Execute.cpp:684
StringDictionaryProxy * getLiteralDictionary() const override
Definition: Execute.h:337
std::atomic< bool > interrupted_
Definition: Execute.h:1308
static ResultSetRecyclerHolder resultset_recycler_holder_
Definition: Execute.h:1373
std::vector< size_t > getTableFragmentIndices(const RelAlgExecutionUnit &ra_exe_unit, const ExecutorDeviceType device_type, const size_t table_idx, const size_t outer_frag_idx, std::map< int, const TableFragments * > &selected_tables_fragments, const std::unordered_map< int, const Analyzer::BinOper * > &inner_table_id_to_join_condition)
Definition: Execute.cpp:2724
ExecutorDeviceType
ResultSetPtr executeTableFunction(const TableFunctionExecutionUnit exe_unit, const std::vector< InputTableInfo > &table_infos, const CompilationOptions &co, const ExecutionOptions &eo, const Catalog_Namespace::Catalog &cat)
Compiles and dispatches a table function; that is, a function that takes as input one or more columns...
Definition: Execute.cpp:2081
Fragmenter_Namespace::RowDataProvider RowDataProvider
Definition: Execute.h:316
static const int max_gpu_count
Definition: Execute.h:1301
GroupColLLVMValue groupByColumnCodegen(Analyzer::Expr *group_by_col, const size_t col_width, const CompilationOptions &, const bool translate_null_val, const int64_t translated_null_val, DiamondCodegen &, std::stack< llvm::BasicBlock * > &, const bool thread_mem_shared)
Definition: IRCodegen.cpp:1292
std::map< const QuerySessionId, std::map< std::string, QuerySessionStatus >> QuerySessionMap
Definition: Execute.h:153
size_t const getFragmentIndex() const
#define LOG(tag)
Definition: Logger.h:216
std::string QueryPlanDAG
bool isArchPascalOrLater(const ExecutorDeviceType dt) const
Definition: Execute.h:721
void AutoTrackBuffersInRuntimeIR()
std::ostream & operator<<(std::ostream &os, const SessionInfo &session_info)
Definition: SessionInfo.cpp:57
bool is_fp() const
Definition: sqltypes.h:579
Cache for physical column ranges. Set by the aggregator on the leaves.
std::pair< QuerySessionId, std::string > CurrentQueryStatus
Definition: Execute.h:85
bool is_constructed_point(const Analyzer::Expr *expr)
Definition: Execute.h:1469
heavyai::unique_lock< heavyai::shared_mutex > unique_lock
Definition: Execute.h:1355
std::function< llvm::BasicBlock *(llvm::BasicBlock *, llvm::BasicBlock *, const std::string &, llvm::Function *, CgenState *)> HoistedFiltersCallback
Definition: JoinLoop.h:61
std::vector< ColumnLazyFetchInfo > getColLazyFetchInfo(const std::vector< Analyzer::Expr * > &target_exprs) const
Definition: Execute.cpp:747
static const size_t baseline_threshold
Definition: Execute.h:1314
void updateQuerySessionStatus(const QuerySessionId &query_session, const std::string &submitted_time_str, const QuerySessionStatus::QueryStatus new_query_status)
Definition: Execute.cpp:4546
const std::unique_ptr< llvm::Module > & get_rt_udf_module(bool is_gpu=false) const
Definition: Execute.h:490
std::unordered_set< int > get_available_gpus(const Data_Namespace::DataMgr *data_mgr)
Definition: Execute.cpp:1456
std::unordered_map< size_t, std::vector< llvm::Value * > > saved_fetch_cache
Definition: Execute.h:1293
std::tuple< RelAlgExecutionUnit, PlanState::DeletedColumnsMap > addDeletedColumn(const RelAlgExecutionUnit &ra_exe_unit, const CompilationOptions &co)
Definition: Execute.cpp:3958
TableGenerations computeTableGenerations(std::unordered_set< int > phys_table_ids)
Definition: Execute.cpp:4418
bool isArchPascalOrLater() const
Definition: CudaMgr.h:150
TableToFragmentIds fragments_with_deleted_rows
Definition: Execute.h:322
bool hasLazyFetchColumns(const std::vector< Analyzer::Expr * > &target_exprs) const
Definition: Execute.cpp:736
const SQLTypeInfo get_column_type(const int col_id, const int table_id, const ColumnDescriptor *cd, const TemporaryTables *temporary_tables)
Definition: Execute.h:236
llvm::Value * aggregateWindowStatePtr()
llvm::Value * codegenWindowFunctionOnFrame(const CompilationOptions &co)
Driver for running cleanup processes on a table. TableOptimizer provides functions for various cleanu...
static std::pair< int64_t, int32_t > reduceResults(const SQLAgg agg, const SQLTypeInfo &ti, const int64_t agg_init_val, const int8_t out_byte_width, const int64_t *out_vec, const size_t out_vec_sz, const bool is_group_by, const bool float_argument_input)
Definition: Execute.cpp:1071
Definition: sqldefs.h:48
Macros and functions for groupby buffer compaction.
const StringDictionaryProxy::TranslationMap< Datum > * getStringProxyNumericTranslationMap(const int source_dict_id, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner, const bool with_generation) const
Definition: Execute.cpp:605
QuerySessionId current_query_session_
Definition: Execute.h:1342
const Analyzer::Expr * extract_cast_arg(const Analyzer::Expr *expr)
Definition: Execute.h:201
int32_t executePlanWithoutGroupBy(const RelAlgExecutionUnit &ra_exe_unit, const CompilationResult &, const bool hoist_literals, ResultSetPtr *results, const std::vector< Analyzer::Expr * > &target_exprs, const ExecutorDeviceType device_type, std::vector< std::vector< const int8_t * >> &col_buffers, QueryExecutionContext *query_exe_context, const std::vector< std::vector< int64_t >> &num_rows, const std::vector< std::vector< uint64_t >> &frag_offsets, Data_Namespace::DataMgr *data_mgr, const int device_id, const uint32_t start_rowid, const uint32_t num_tables, const bool allow_runtime_interrupt, RenderInfo *render_info, const int64_t rows_to_process=-1)
Definition: Execute.cpp:3329
heavyai::shared_mutex & getSessionLock()
Definition: Execute.cpp:4453
const QuerySessionStatus::QueryStatus getQueryStatus()
Definition: Execute.h:133
static const int32_t ERR_GEOS
Definition: Execute.h:1394
const std::string query_str_
Definition: Execute.h:142
QuerySessionStatus(const QuerySessionId &query_session, const std::string &query_str, const std::string &submitted_time)
Definition: Execute.h:101
AggregatedColRange agg_col_range_cache_
Definition: Execute.h:1338
std::shared_ptr< ResultSet > ResultSetPtr
static void * gpu_active_modules_[max_gpu_count]
Definition: Execute.h:1306
heavyai::unique_lock< heavyai::shared_mutex > write_lock
std::unique_ptr< CgenState > cgen_state_
Definition: Execute.h:1268
static const int32_t ERR_TOO_MANY_LITERALS
Definition: Execute.h:1390
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
llvm::Value * original_value
Definition: Execute.h:1082
void enrollQuerySession(const QuerySessionId &query_session, const std::string &query_str, const std::string &submitted_time_str, const size_t executor_id, const QuerySessionStatus::QueryStatus query_session_status)
Definition: Execute.cpp:4562
ParseIRError(const std::string message)
Definition: Execute.h:304
static uint32_t gpu_active_modules_device_mask_
Definition: Execute.h:1305
void launchKernels(SharedKernelContext &shared_context, std::vector< std::unique_ptr< ExecutionKernel >> &&kernels, const ExecutorDeviceType device_type)
Definition: Execute.cpp:2672
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:379
FragmentSkipStatus canSkipFragmentForFpQual(const Analyzer::BinOper *comp_expr, const Analyzer::ColumnVar *lhs_col, const Fragmenter_Namespace::FragmentInfo &fragment, const Analyzer::Constant *rhs_const) const
Definition: Execute.cpp:4070
static void invalidateCaches()
int deviceCount(const ExecutorDeviceType) const
Definition: Execute.cpp:1056
llvm::Value * castToIntPtrTyIn(llvm::Value *val, const size_t bit_width)
Definition: Execute.cpp:3912
size_t getNumBytesForFetchedRow(const std::set< int > &table_ids_to_fetch) const
Definition: Execute.cpp:704
void reset(bool discard_runtime_modules_only=false)
Definition: Execute.cpp:297
static std::mutex kernel_mutex_
Definition: Execute.h:1415
unsigned numBlocksPerMP() const
Definition: Execute.cpp:3845
std::unique_ptr< CgenState > cgen_state_
Definition: Execute.h:1264
#define CHECK_GT(x, y)
Definition: Logger.h:234
Container for compilation results and assorted options for a single execution unit.
bool isCPUOnly() const
Definition: Execute.cpp:654
void resetGridSize()
Definition: Execute.cpp:3864
bool checkCurrentQuerySession(const std::string &candidate_query_session, heavyai::shared_lock< heavyai::shared_mutex > &read_lock)
Definition: Execute.cpp:4462
void clearCaches(bool runtime_only=false)
std::unique_ptr< WindowProjectNodeContext > window_project_node_context_owned_
Definition: Execute.h:1333
void addTransientStringLiterals(const RelAlgExecutionUnit &ra_exe_unit, const std::shared_ptr< RowSetMemoryOwner > &row_set_mem_owner)
Definition: Execute.cpp:2163
std::vector< FragmentsPerTable > FragmentsList
bool is_time() const
Definition: sqltypes.h:581
bool needFetchAllFragments(const InputColDescriptor &col_desc, const RelAlgExecutionUnit &ra_exe_unit, const FragmentsList &selected_fragments) const
Definition: Execute.cpp:2906
const QuerySessionId query_session_
Definition: Execute.h:140
std::shared_ptr< HashJoin > hash_table
Definition: Execute.h:1043
std::string to_string(char const *&&v)
bool updateQuerySessionStatusWithLock(const QuerySessionId &query_session, const std::string &submitted_time_str, const QuerySessionStatus::QueryStatus updated_query_status, heavyai::unique_lock< heavyai::shared_mutex > &write_lock)
Definition: Execute.cpp:4629
const StringDictionaryProxy::IdMap * getStringProxyTranslationMap(const int source_dict_id, const int dest_dict_id, const RowSetMemoryOwner::StringTranslationType translation_type, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner, const bool with_generation) const
Definition: Execute.cpp:567
bool checkNonKernelTimeInterrupted() const
Definition: Execute.cpp:4813
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:501
QuerySessionStatus(const QuerySessionId &query_session, const size_t executor_id, const std::string &query_str, const std::string &submitted_time)
Definition: Execute.h:109
std::function< void(const UpdateLogForFragment &, TableUpdateMetadata &)> Callback
Definition: Execute.h:352
bool removeFromQuerySessionList(const QuerySessionId &query_session, const std::string &submitted_time_str, heavyai::unique_lock< heavyai::shared_mutex > &write_lock)
Definition: Execute.cpp:4680
void populate_string_dictionary(const int32_t table_id, const int32_t col_id, const Catalog_Namespace::Catalog &catalog)
Definition: Execute.cpp:205
Fragmenter_Namespace::TableInfo getTableInfo(const int table_id) const
Definition: Execute.cpp:692
RUNTIME_EXPORT void register_buffer_with_executor_rsm(int64_t exec, int8_t *buffer)
static const size_t high_scan_limit
Definition: Execute.h:608
const std::unique_ptr< llvm::Module > & get_libdevice_module() const
Definition: Execute.h:499
QueryMustRunOnCpu(const std::string &err)
Definition: Execute.h:299
static const int32_t ERR_STRING_CONST_IN_RESULTSET
Definition: Execute.h:1391
std::shared_lock< T > shared_lock
void codegenWindowAvgEpilogue(llvm::Value *crt_val, llvm::Value *window_func_null_val, llvm::Value *multiplicity_lv)
static std::shared_ptr< Executor > getExecutor(const ExecutorId id, const std::string &debug_dir="", const std::string &debug_file="", const SystemParameters &system_parameters=SystemParameters())
Definition: Execute.cpp:477
void preloadFragOffsets(const std::vector< InputDescriptor > &input_descs, const std::vector< InputTableInfo > &query_infos)
Definition: Execute.cpp:3773
bool isFragmentFullyDeleted(const int table_id, const Fragmenter_Namespace::FragmentInfo &fragment)
Definition: Execute.cpp:4037
void setQueryStatus(const QuerySessionStatus::QueryStatus &status)
Definition: Execute.h:134
std::unordered_map< int, const ResultSetPtr & > TemporaryTables
Definition: InputMetadata.h:31
FetchResult fetchUnionChunks(const ColumnFetcher &, const RelAlgExecutionUnit &ra_exe_unit, const int device_id, const Data_Namespace::MemoryLevel, const std::map< int, const TableFragments * > &, const FragmentsList &selected_fragments, const Catalog_Namespace::Catalog &, std::list< ChunkIter > &, std::list< std::shared_ptr< Chunk_NS::Chunk >> &, DeviceAllocator *device_allocator, const size_t thread_idx, const bool allow_runtime_interrupt)
Definition: Execute.cpp:3135
static const int32_t ERR_STREAMING_TOP_N_NOT_SUPPORTED_IN_RENDER_QUERY
Definition: Execute.h:1392
const ExecutorId executor_id_
Definition: Execute.h:1242
bool updateQuerySessionExecutorAssignment(const QuerySessionId &query_session, const std::string &submitted_time_str, const size_t executor_id, heavyai::unique_lock< heavyai::shared_mutex > &write_lock)
Definition: Execute.cpp:4655
static const int32_t ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED
Definition: Execute.h:1389
const ResultSetPtr & get_temporary_table(const TemporaryTables *temporary_tables, const int table_id)
Definition: Execute.h:228
int8_t warpSize() const
Definition: Execute.cpp:3828
std::map< QuerySessionId, bool > InterruptFlagMap
Definition: Execute.h:86
const size_t max_gpu_slab_size_
Definition: Execute.h:1319
ResultSetPtr reduceSpeculativeTopN(const RelAlgExecutionUnit &, std::vector< std::pair< ResultSetPtr, std::vector< size_t >>> &all_fragment_results, std::shared_ptr< RowSetMemoryOwner >, const QueryMemoryDescriptor &) const
Definition: Execute.cpp:1429
ResultSetPtr collectAllDeviceResults(SharedKernelContext &shared_context, const RelAlgExecutionUnit &ra_exe_unit, const QueryMemoryDescriptor &query_mem_desc, const ExecutorDeviceType device_type, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner)
Definition: Execute.cpp:2347
const ColumnDescriptor * getPhysicalColumnDescriptor(const Analyzer::ColumnVar *, int) const
Definition: Execute.cpp:665
std::lock_guard< std::mutex > lock_
Definition: Execute.h:1263
static void unregisterActiveModule(const int device_id)
static const int32_t ERR_DIV_BY_ZERO
Definition: Execute.h:1380
std::tuple< CompilationResult, std::unique_ptr< QueryMemoryDescriptor > > compileWorkUnit(const std::vector< InputTableInfo > &query_infos, const PlanState::DeletedColumnsMap &deleted_cols_map, const RelAlgExecutionUnit &ra_exe_unit, const CompilationOptions &co, const ExecutionOptions &eo, const CudaMgr_Namespace::CudaMgr *cuda_mgr, const bool allow_lazy_fetch, std::shared_ptr< RowSetMemoryOwner >, const size_t max_groups_buffer_entry_count, const int8_t crt_min_byte_width, const bool has_cardinality_estimation, ColumnCacheMap &column_cache, RenderInfo *render_info=nullptr)
TableIdToNodeMap table_id_to_node_map_
Definition: Execute.h:1326
bool compileBody(const RelAlgExecutionUnit &ra_exe_unit, GroupByAndAggregate &group_by_and_aggregate, QueryMemoryDescriptor &query_mem_desc, const CompilationOptions &co, const GpuSharedMemoryContext &gpu_smem_context={})
std::unordered_map< size_t, HashTableBuildDag > HashTableBuildDagMap
llvm::Value * get_arg_by_name(llvm::Function *func, const std::string &name)
Definition: Execute.h:166
std::vector< llvm::Value * > LLVMValueVector
Definition: Execute.h:362
size_t get_context_count(const ExecutorDeviceType device_type, const size_t cpu_count, const size_t gpu_count)
Definition: Execute.cpp:1470
const ColumnDescriptor * get_column_descriptor_maybe(const int col_id, const int table_id, const Catalog_Namespace::Catalog &cat)
Definition: Execute.h:220
std::vector< TargetValue > getEntryAt(const size_t index) const override
int get_logical_size() const
Definition: sqltypes.h:399
decltype(FragmentInfoType::fragmentId) const getFragmentId() const
Definition: Execute.h:346
int64_t deviceCycles(int milliseconds) const
Definition: Execute.cpp:3880
std::string generatePTX(const std::string &) const
std::mutex str_dict_mutex_
Definition: Execute.h:1310
bool is_integer() const
Definition: sqltypes.h:577
const Catalog_Namespace::Catalog * catalog_
Definition: Execute.h:1323
friend class PendingExecutionClosure
Definition: Execute.h:1438
static const int32_t ERR_OUT_OF_RENDER_MEM
Definition: Execute.h:1384
std::unordered_map< TableId, const ColumnDescriptor * > DeletedColumnsMap
Definition: PlanState.h:44
ResultSetPtr reduceMultiDeviceResults(const RelAlgExecutionUnit &, std::vector< std::pair< ResultSetPtr, std::vector< size_t >>> &all_fragment_results, std::shared_ptr< RowSetMemoryOwner >, const QueryMemoryDescriptor &) const
Definition: Execute.cpp:1322
const std::string debug_file_
Definition: Execute.h:1321
ResultSetPtr collectAllDeviceShardedTopResults(SharedKernelContext &shared_context, const RelAlgExecutionUnit &ra_exe_unit) const
Definition: Execute.cpp:2462
CachedCardinality getCachedCardinality(const std::string &cache_key)
Definition: Execute.cpp:4769
decltype(FragmentInfoType::physicalTableId) const getPhysicalTableId() const
Definition: Execute.h:343
std::unordered_map< int, const RelAlgNode * > TableIdToNodeMap
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: Execute.h:1299
Used by Fragmenter classes to store info about each fragment - the fragment id and number of tuples(r...
Definition: Fragmenter.h:86
void setColRangeCache(const AggregatedColRange &aggregated_col_range)
Definition: Execute.h:1135
bool containsLeftDeepOuterJoin() const
Definition: Execute.h:565
static QueryPlanDAG latest_query_plan_extracted_
Definition: Execute.h:1377
void setCatalog(const Catalog_Namespace::Catalog *catalog)
Definition: Execute.cpp:680
size_t getNumCurentSessionsEnrolled() const
Definition: Execute.cpp:4586
bool has_rt_module() const
Definition: Execute.h:503
StringDictionaryProxy * getStringDictionaryProxy(const int dict_id, const bool with_generation) const
Definition: Execute.h:529
std::shared_ptr< CompilationContext > optimizeAndCodegenCPU(llvm::Function *, llvm::Function *, const std::unordered_set< llvm::Function * > &, const CompilationOptions &)
static const int32_t ERR_OVERFLOW_OR_UNDERFLOW
Definition: Execute.h:1386
bool is_timeinterval() const
Definition: sqltypes.h:586
static std::unordered_map< std::string, size_t > cardinality_cache_
Definition: Execute.h:1372
static InterruptFlagMap queries_interrupt_flag_
Definition: Execute.h:1344
FragmentInfoType const & getFragmentInfo() const
const logger::ThreadId thread_id_
Definition: Execute.h:1409
std::unique_lock< T > unique_lock
std::unique_ptr< PlanState > plan_state_
Definition: Execute.h:1298
void insertErrorCodeChecker(llvm::Function *query_func, bool hoist_literals, bool allow_runtime_query_interrupt)
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
static const int32_t ERR_OUT_OF_TIME
Definition: Execute.h:1387
void initializeNVPTXBackend() const
std::map< int32_t, std::set< int32_t >> TableToFragmentIds
Definition: Execute.h:318
const std::string submitted_time_
Definition: Execute.h:143
const TableGeneration & getTableGeneration(const int table_id) const
Definition: Execute.cpp:696
llvm::Value * castToFP(llvm::Value *, SQLTypeInfo const &from_ti, SQLTypeInfo const &to_ti)
Definition: Execute.cpp:3885
size_t fragment_index_
Definition: Execute.h:358
std::pair< bool, size_t > CachedCardinality
Definition: Execute.h:1209
const ColumnDescriptor * getColumnDescriptor(const Analyzer::ColumnVar *) const
Definition: Execute.cpp:659
static const int32_t ERR_UNSUPPORTED_SELF_JOIN
Definition: Execute.h:1383
bool checkIsQuerySessionEnrolled(const QuerySessionId &query_session, heavyai::shared_lock< heavyai::shared_mutex > &read_lock)
Definition: Execute.cpp:4736
specifies the content in-memory of a row in the column metadata table
bool is_boolean() const
Definition: sqltypes.h:582
std::vector< TargetValue > getTranslatedEntryAt(const size_t index) const override
static const int32_t ERR_SINGLE_VALUE_FOUND_MULTIPLE_VALUES
Definition: Execute.h:1393
static std::map< int, std::shared_ptr< Executor > > executors_
Definition: Execute.h:1347
unsigned grid_size_x_
Definition: Execute.h:1318
QuerySessionStatus::QueryStatus getQuerySessionStatus(const QuerySessionId &candidate_query_session, heavyai::shared_lock< heavyai::shared_mutex > &read_lock)
Definition: Execute.cpp:4472
static const int32_t ERR_OUT_OF_GPU_MEM
Definition: Execute.h:1381
const TemporaryTables * getTemporaryTables()
Definition: Execute.h:524
std::string get_null_check_suffix(const SQLTypeInfo &lhs_ti, const SQLTypeInfo &rhs_ti)
Definition: Execute.h:1448
const std::unique_ptr< llvm::Module > & get_rt_module() const
Definition: Execute.h:483
static const ExecutorId INVALID_EXECUTOR_ID
Definition: Execute.h:377
const Catalog_Namespace::Catalog * getCatalog() const
Definition: Execute.cpp:676
#define RUNTIME_EXPORT
std::unordered_map< int, std::unordered_map< int, std::shared_ptr< const ColumnarResults >>> ColumnCacheMap
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
std::string dumpCache() const
Definition: Execute.cpp:4865
ColumnToFragmentsMap columns_for_metadata_update
Definition: Execute.h:321
const std::vector< size_t > getExecutorIdsRunningQuery(const QuerySessionId &interrupt_session) const
Definition: Execute.cpp:4797
#define CHECK_LT(x, y)
Definition: Logger.h:232
ResultSetPtr resultsUnion(SharedKernelContext &shared_context, const RelAlgExecutionUnit &ra_exe_unit)
Definition: Execute.cpp:1295
void registerExtractedQueryPlanDag(const QueryPlanDAG &query_plan_dag)
Definition: Execute.cpp:4826
std::shared_ptr< ResultSet > rs_
Definition: Execute.h:359
JoinHashTableOrError buildHashTableForQualifier(const std::shared_ptr< Analyzer::BinOper > &qual_bin_oper, const std::vector< InputTableInfo > &query_infos, const MemoryLevel memory_level, const JoinType join_type, const HashType preferred_hash_type, ColumnCacheMap &column_cache, const HashTableBuildDagMap &hashtable_build_dag_map, const RegisteredQueryHint &query_hint, const TableIdToNodeMap &table_id_to_node_map)
Definition: Execute.cpp:3794
QuerySessionId & getCurrentQuerySession(heavyai::shared_lock< heavyai::shared_mutex > &read_lock)
Definition: Execute.cpp:4457
std::vector< size_t > getFragmentCount(const FragmentsList &selected_fragments, const size_t scan_idx, const RelAlgExecutionUnit &ra_exe_unit)
Definition: Execute.cpp:3255
static void addUdfIrToModule(const std::string &udf_ir_filename, const bool is_cuda_ir)
llvm::BasicBlock * codegenSkipDeletedOuterTableRow(const RelAlgExecutionUnit &ra_exe_unit, const CompilationOptions &co)
std::unique_ptr< QueryCompilationDescriptor > QueryCompilationDescriptorOwned
Definition: Execute.h:81
size_t ExecutorId
Definition: Execute.h:375
void setGridSize(unsigned grid_size)
Definition: Execute.cpp:3860
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:387
TableUpdateMetadata executeUpdate(const RelAlgExecutionUnit &ra_exe_unit, const std::vector< InputTableInfo > &table_infos, const TableDescriptor *updated_table_desc, const CompilationOptions &co, const ExecutionOptions &eo, Catalog_Namespace::Catalog &cat, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner, const UpdateLogForFragment::Callback &cb, const bool is_agg)
std::shared_ptr< HashJoin > buildCurrentLevelHashTable(const JoinCondition &current_level_join_conditions, size_t level_idx, RelAlgExecutionUnit &ra_exe_unit, const CompilationOptions &co, const std::vector< InputTableInfo > &query_infos, ColumnCacheMap &column_cache, std::vector< std::string > &fail_reasons)
Definition: IRCodegen.cpp:935
static heavyai::shared_mutex recycler_mutex_
Definition: Execute.h:1371
static void update_after_registration(bool update_runtime_modules_only=false)
Definition: Execute.h:1223
std::vector< int8_t > serializeLiterals(const std::unordered_map< int, CgenState::LiteralValues > &literals, const int device_id)
Definition: Execute.cpp:794
std::shared_ptr< CompilationContext > optimizeAndCodegenGPU(llvm::Function *, llvm::Function *, std::unordered_set< llvm::Function * > &, const bool no_inline, const CudaMgr_Namespace::CudaMgr *cuda_mgr, const bool is_gpu_smem_used, const CompilationOptions &)
std::pair< llvm::Value *, llvm::Value * > codegenWindowFrameBound(WindowFunctionContext *window_func_context, const Analyzer::WindowFrame *frame_start_bound, const Analyzer::WindowFrame *frame_end_bound, llvm::Value *current_row_pos_lv, llvm::Value *current_partition_start_offset_lv, llvm::Value *order_key_buf_ptr_lv, llvm::Value *order_key_col_null_val_lv, llvm::Value *frame_start_bound_expr_lv, llvm::Value *frame_end_bound_expr_lv, llvm::Value *num_elem_current_partition_lv, llvm::Value *target_partition_rowid_ptr_lv, llvm::Value *target_partition_sorted_rowid_ptr_lv, llvm::Value *null_start_pos_lv, llvm::Value *null_end_pos_lv, CodeGenerator &code_generator)
InputTableInfoCache input_table_info_cache_
Definition: Execute.h:1337
void setBlockSize(unsigned block_size)
Definition: Execute.cpp:3868
const Expr * get_operand() const
Definition: Analyzer.h:379
std::chrono::steady_clock::time_point lock_queue_clock_
Definition: Execute.h:1262
void codegenWindowFunctionStateInit(llvm::Value *aggregate_state)
std::pair< bool, int64_t > skipFragment(const InputDescriptor &table_desc, const Fragmenter_Namespace::FragmentInfo &frag_info, const std::list< std::shared_ptr< Analyzer::Expr >> &simple_quals, const std::vector< uint64_t > &frag_offsets, const size_t frag_idx)
Definition: Execute.cpp:4130
unsigned gridSize() const
Definition: Execute.cpp:3836
llvm::Value * spillDoubleElement(llvm::Value *elem_val, llvm::Type *elem_ty)
std::pair< std::vector< std::vector< int64_t > >, std::vector< std::vector< uint64_t > > > getRowCountAndOffsetForAllFrags(const RelAlgExecutionUnit &ra_exe_unit, const CartesianProduct< std::vector< std::vector< size_t >>> &frag_ids_crossjoin, const std::vector< InputDescriptor > &input_descs, const std::map< int, const TableFragments * > &all_tables_fragments)
Definition: Execute.cpp:2857
friend class KernelSubtask
Definition: Execute.h:1422
PlanState * getPlanStatePtr() const
Definition: Execute.h:1218
uint64_t ThreadId
Definition: Logger.h:364
static std::map< ExtModuleKinds, std::string > extension_module_sources
Definition: Execute.h:479
StringDictionaryGenerations computeStringDictionaryGenerations(const std::unordered_set< PhysicalInput > &phys_inputs)
Definition: Execute.cpp:4393
unsigned block_size_x_
Definition: Execute.h:1317
bool has_udf_module(bool is_gpu=false) const
Definition: Execute.h:506
static const int32_t ERR_WIDTH_BUCKET_INVALID_ARGUMENT
Definition: Execute.h:1395
Data_Namespace::DataMgr * getDataMgr() const
Definition: Execute.h:577
bool needLinearizeAllFragments(const ColumnDescriptor *cd, const InputColDescriptor &inner_col_desc, const RelAlgExecutionUnit &ra_exe_unit, const FragmentsList &selected_fragments, const Data_Namespace::MemoryLevel memory_level) const
Definition: Execute.cpp:2925
void setExecutorId(const size_t executor_id)
Definition: Execute.h:137
std::unique_ptr< llvm::LLVMContext > context_
Definition: Execute.h:1243
CgenState * getCgenStatePtr() const
Definition: Execute.h:1217
FragmentInfoType const & fragment_info_
Definition: Execute.h:357
void nukeOldState(const bool allow_lazy_fetch, const std::vector< InputTableInfo > &query_infos, const PlanState::DeletedColumnsMap &deleted_cols_map, const RelAlgExecutionUnit *ra_exe_unit)
Definition: Execute.cpp:3753
static heavyai::shared_mutex executor_session_mutex_
Definition: Execute.h:1340
const std::string getQueryStr()
Definition: Execute.h:130
std::pair< bool, int64_t > skipFragmentInnerJoins(const InputDescriptor &table_desc, const RelAlgExecutionUnit &ra_exe_unit, const Fragmenter_Namespace::FragmentInfo &fragment, const std::vector< uint64_t > &frag_offsets, const size_t frag_idx)
Definition: Execute.cpp:4334
void buildSelectedFragsMapping(std::vector< std::vector< size_t >> &selected_fragments_crossjoin, std::vector< size_t > &local_col_to_frag_pos, const std::list< std::shared_ptr< const InputColDescriptor >> &col_global_ids, const FragmentsList &selected_fragments, const RelAlgExecutionUnit &ra_exe_unit)
Definition: Execute.cpp:3269
llvm::Value * codegenAggregateWindowState()
TableGenerations table_generations_
Definition: Execute.h:1339
std::function< void(ResultSetPtr, const Fragmenter_Namespace::FragmentInfo &)> PerFragmentCallBack
Definition: Execute.h:739
void resetInterrupt()
const size_t getExecutorId()
Definition: Execute.h:131
size_t executor_id_
Definition: Execute.h:141
llvm::Value * codegenFrameBoundExpr(const Analyzer::WindowFunction *window_func, const Analyzer::WindowFrame *frame_bound, CodeGenerator &code_generator, const CompilationOptions &co)
void buildSelectedFragsMappingForUnion(std::vector< std::vector< size_t >> &selected_fragments_crossjoin, const FragmentsList &selected_fragments, const RelAlgExecutionUnit &ra_exe_unit)
Definition: Execute.cpp:3300
static void registerExtensionFunctions(F register_extension_functions)
Definition: Execute.h:421
std::string QuerySessionId
Definition: Execute.h:84
llvm::Value * addJoinLoopIterator(const std::vector< llvm::Value * > &prev_iters, const size_t level_idx)
Definition: IRCodegen.cpp:1094
ResultSetPtr reduceMultiDeviceResultSets(std::vector< std::pair< ResultSetPtr, std::vector< size_t >>> &all_fragment_results, std::shared_ptr< RowSetMemoryOwner >, const QueryMemoryDescriptor &) const
Definition: Execute.cpp:1369
llvm::Value * codegenWindowFunctionAggregate(const CompilationOptions &co)
void addToCardinalityCache(const std::string &cache_key, const size_t cache_value)
Definition: Execute.cpp:4760
#define CHECK(condition)
Definition: Logger.h:222
QueryPlanDagCache & getQueryPlanDagCache()
Definition: Execute.cpp:4445
bool has_extension_module(ExtModuleKinds kind) const
Definition: Execute.h:1279
static const int32_t ERR_OUT_OF_SLOTS
Definition: Execute.h:1382
void resetBlockSize()
Definition: Execute.cpp:3872
heavyai::shared_lock< heavyai::shared_mutex > shared_lock
Definition: Execute.h:1354
static void clearExternalCaches(bool for_update, const TableDescriptor *td, const int current_db_id)
Definition: Execute.h:391
CgenStateManager(Executor &executor)
Definition: Execute.cpp:408
std::mutex compilation_mutex_
Definition: Execute.h:1408
void interrupt(const QuerySessionId &query_session="", const QuerySessionId &interrupt_session="")
heavyai::shared_mutex & getDataRecyclerLock()
Definition: Execute.cpp:4441
bool has_rt_udf_module(bool is_gpu=false) const
Definition: Execute.h:510
std::vector< llvm::Value * > inlineHoistedLiterals()
FetchResult fetchChunks(const ColumnFetcher &, const RelAlgExecutionUnit &ra_exe_unit, const int device_id, const Data_Namespace::MemoryLevel, const std::map< int, const TableFragments * > &, const FragmentsList &selected_fragments, const Catalog_Namespace::Catalog &, std::list< ChunkIter > &, std::list< std::shared_ptr< Chunk_NS::Chunk >> &, DeviceAllocator *device_allocator, const size_t thread_idx, const bool allow_runtime_interrupt)
Definition: Execute.cpp:2948
ResultSetPtr executeWorkUnitImpl(size_t &max_groups_buffer_entry_guess, const bool is_agg, const bool allow_single_frag_table_opt, const std::vector< InputTableInfo > &, const RelAlgExecutionUnit &, const CompilationOptions &, const ExecutionOptions &options, const Catalog_Namespace::Catalog &, std::shared_ptr< RowSetMemoryOwner >, RenderInfo *render_info, const bool has_cardinality_estimation, ColumnCacheMap &column_cache)
Definition: Execute.cpp:1833
std::unordered_map< int, const Analyzer::BinOper * > getInnerTabIdToJoinCond() const
Definition: Execute.cpp:2512
ExecutorDeviceType getDeviceTypeForTargets(const RelAlgExecutionUnit &ra_exe_unit, const ExecutorDeviceType requested_device_type)
Definition: Execute.cpp:2214
void invalidateRunningQuerySession(heavyai::unique_lock< heavyai::shared_mutex > &write_lock)
Definition: Execute.cpp:4484
JoinLoop::HoistedFiltersCallback buildHoistLeftHandSideFiltersCb(const RelAlgExecutionUnit &ra_exe_unit, const size_t level_idx, const int inner_table_id, const CompilationOptions &co)
Definition: IRCodegen.cpp:768
uint32_t log2_bytes(const uint32_t bytes)
Definition: Execute.h:176
ExpressionRange getColRange(const PhysicalInput &) const
Definition: Execute.cpp:700
std::string numeric_type_name(const SQLTypeInfo &ti)
Definition: Execute.h:209
CurrentQueryStatus attachExecutorToQuerySession(const QuerySessionId &query_session_id, const std::string &query_str, const std::string &query_submitted_time)
Definition: Execute.cpp:4489
void redeclareFilterFunction()
Definition: IRCodegen.cpp:995
SQLTypeInfo columnType
QuerySessionStatus(const QuerySessionId &query_session, const size_t executor_id, const std::string &query_str, const std::string &submitted_time, const QuerySessionStatus::QueryStatus &query_status)
Definition: Execute.h:118
UpdateLogForFragment(FragmentInfoType const &fragment_info, size_t const, const std::shared_ptr< ResultSet > &rs)
bool is_unnest(const Analyzer::Expr *expr)
Definition: Execute.h:1464
bool is_string() const
Definition: sqltypes.h:575
std::vector< JoinLoop > buildJoinLoops(RelAlgExecutionUnit &ra_exe_unit, const CompilationOptions &co, const ExecutionOptions &eo, const std::vector< InputTableInfo > &query_infos, ColumnCacheMap &column_cache)
Definition: IRCodegen.cpp:523
std::function< llvm::Value *(const std::vector< llvm::Value * > &, llvm::Value *)> buildIsDeletedCb(const RelAlgExecutionUnit &ra_exe_unit, const size_t level_idx, const CompilationOptions &co)
Definition: IRCodegen.cpp:876
auto getResultSet() const
Definition: Execute.h:354
unsigned blockSize() const
Definition: Execute.cpp:3850
string name
Definition: setup.in.py:72
std::shared_timed_mutex shared_mutex
static std::mutex register_runtime_extension_functions_mutex_
Definition: Execute.h:1414
Execution unit for relational algebra. It&#39;s a low-level description of any relational algebra operati...
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:386
ExecutorId getExecutorId() const
Definition: Execute.h:1138
static size_t align(const size_t off_in, const size_t alignment)
Definition: Execute.h:1234
static heavyai::shared_mutex executors_cache_mutex_
Definition: Execute.h:1368
std::unique_ptr< QueryMemoryDescriptor > QueryMemoryDescriptorOwned
Definition: Execute.h:83
size_t const getRowCount() const override
const QuerySessionId getQuerySession()
Definition: Execute.h:129
void clearQuerySessionStatus(const QuerySessionId &query_session, const std::string &submitted_time_str)
Definition: Execute.cpp:4532
static const int32_t ERR_OUT_OF_CPU_MEM
Definition: Execute.h:1385
QuerySessionStatus::QueryStatus query_status_
Definition: Execute.h:150
bool is_decimal() const
Definition: sqltypes.h:578
void setQuerySessionAsInterrupted(const QuerySessionId &query_session, heavyai::unique_lock< heavyai::shared_mutex > &write_lock)
Definition: Execute.cpp:4714
int deviceCountForMemoryLevel(const Data_Namespace::MemoryLevel memory_level) const
Definition: Execute.cpp:1064
std::vector< QuerySessionStatus > getQuerySessionInfo(const QuerySessionId &query_session, heavyai::shared_lock< heavyai::shared_mutex > &read_lock)
Definition: Execute.cpp:4779
Descriptor for the fragments required for an execution kernel.
llvm::Value * codegenWindowFunctionAggregateCalls(llvm::Value *aggregate_state, const CompilationOptions &co)
Fragmenter_Namespace::FragmentInfo FragmentInfoType
Definition: Execute.h:327
static size_t getArenaBlockSize()
Definition: Execute.cpp:527
ResultSetPtr executeWorkUnit(size_t &max_groups_buffer_entry_guess, const bool is_agg, const std::vector< InputTableInfo > &, const RelAlgExecutionUnit &, const CompilationOptions &, const ExecutionOptions &options, const Catalog_Namespace::Catalog &, RenderInfo *render_info, const bool has_cardinality_estimation, ColumnCacheMap &column_cache)
Definition: Execute.cpp:1765
std::mutex gpu_exec_mutex_[max_gpu_count]
Definition: Execute.h:1302
HashType
Definition: HashTable.h:19
llvm::LLVMContext & getContext()
Definition: Execute.h:1220
llvm::Value * codegenWindowFunction(const size_t target_index, const CompilationOptions &co)
std::vector< int > getTableChunkKey(const int getCurrentDBId) const
bool addToQuerySessionList(const QuerySessionId &query_session, const std::string &query_str, const std::string &submitted, const size_t executor_id, const QuerySessionStatus::QueryStatus query_status, heavyai::unique_lock< heavyai::shared_mutex > &write_lock)
Definition: Execute.cpp:4591
SQLOps get_optype() const
Definition: Analyzer.h:378
static QueryPlanDagCache query_plan_dag_cache_
Definition: Execute.h:1370
WindowFunctionContext * active_window_function_
Definition: Execute.h:1335
static std::mutex gpu_active_modules_mutex_
Definition: Execute.h:1304
void setupCaching(const std::unordered_set< PhysicalInput > &phys_inputs, const std::unordered_set< int > &phys_table_ids)
Definition: Execute.cpp:4430
static void nukeCacheOfExecutors()
Definition: Execute.h:456
void clearMetaInfoCache()
Definition: Execute.cpp:788
FragmentSkipStatus
Definition: Execute.h:162
const ColumnDescriptor * get_column_descriptor(const int col_id, const int table_id, const Catalog_Namespace::Catalog &cat)
Definition: Execute.h:191
size_t const getEntryCount() const override
llvm::BasicBlock * codegenWindowResetStateControlFlow()
const TemporaryTables * temporary_tables_
Definition: Execute.h:1325
CompilationRetryNewScanLimit(const size_t new_scan_limit)
Definition: Execute.h:258
WatchdogException(const std::string &cause)
Definition: Execute.h:159
static const ExecutorId UNITARY_EXECUTOR_ID
Definition: Execute.h:376
bool has_geos_module() const
Definition: Execute.h:514
void update_extension_modules(bool update_runtime_modules_only=false)
Definition: Execute.cpp:320
ResultSetRecyclerHolder & getRecultSetRecyclerHolder()
Definition: Execute.cpp:4449
bool isArchMaxwell(const ExecutorDeviceType dt) const
bool skipFragmentPair(const Fragmenter_Namespace::FragmentInfo &outer_fragment_info, const Fragmenter_Namespace::FragmentInfo &inner_fragment_info, const int inner_table_id, const std::unordered_map< int, const Analyzer::BinOper * > &inner_table_id_to_join_condition, const RelAlgExecutionUnit &ra_exe_unit, const ExecutorDeviceType device_type)
Definition: Execute.cpp:2766
ResultSetPtr executeExplain(const QueryCompilationDescriptor &)
Definition: Execute.cpp:2159
std::map< ExtModuleKinds, std::unique_ptr< llvm::Module > > extension_modules_
Definition: Execute.h:1283