OmniSciDB  8fa3bf436f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Execute.h
Go to the documentation of this file.
1 /*
2  * Copyright 2020 OmniSci, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #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 <stack>
31 #include <unordered_map>
32 #include <unordered_set>
33 
34 #include <llvm/IR/Function.h>
35 #include <llvm/IR/Value.h>
36 #include <llvm/Linker/Linker.h>
37 #include <llvm/Transforms/Utils/ValueMapper.h>
38 #include <rapidjson/document.h>
39 
43 #include "QueryEngine/CgenState.h"
44 #include "QueryEngine/CodeCache.h"
55 #include "QueryEngine/PlanState.h"
62 
63 #include "DataMgr/Chunk/Chunk.h"
64 #include "Logger/Logger.h"
66 #include "Shared/funcannotations.h"
68 #include "Shared/measure.h"
69 #include "Shared/thread_count.h"
70 #include "Shared/toString.h"
75 
76 using QueryCompilationDescriptorOwned = std::unique_ptr<QueryCompilationDescriptor>;
78 using QueryMemoryDescriptorOwned = std::unique_ptr<QueryMemoryDescriptor>;
79 using QuerySessionId = std::string;
80 using CurrentQueryStatus = std::pair<QuerySessionId, std::string>;
81 using InterruptFlagMap = std::map<QuerySessionId, bool>;
83  // A class that is used to describe the query session's info
84  public:
85  /* todo(yoonmin): support more query status
86  * i.e., RUNNING_SORT, RUNNING_CARD_EST, CLEANUP, ... */
87  enum QueryStatus {
88  UNDEFINED = 0,
93  };
94 
95  QuerySessionStatus(const QuerySessionId& query_session,
96  const std::string& query_str,
97  const std::string& submitted_time)
98  : query_session_(query_session)
99  , executor_id_(0)
100  , query_str_(query_str)
101  , submitted_time_(submitted_time)
103  QuerySessionStatus(const QuerySessionId& query_session,
104  const size_t executor_id,
105  const std::string& query_str,
106  const std::string& submitted_time)
107  : query_session_(query_session)
108  , executor_id_(executor_id)
109  , query_str_(query_str)
110  , submitted_time_(submitted_time)
112  QuerySessionStatus(const QuerySessionId& query_session,
113  const size_t executor_id,
114  const std::string& query_str,
115  const std::string& submitted_time,
116  const QuerySessionStatus::QueryStatus& query_status)
117  : query_session_(query_session)
118  , executor_id_(executor_id)
119  , query_str_(query_str)
120  , submitted_time_(submitted_time)
121  , query_status_(query_status) {}
122 
124  const std::string getQueryStr() { return query_str_; }
125  const size_t getExecutorId() { return executor_id_; }
126  const std::string& getQuerySubmittedTime() { return submitted_time_; }
129  query_status_ = status;
130  }
131  void setExecutorId(const size_t executor_id) { executor_id_ = executor_id; }
133  query_status_ = QuerySessionStatus::QueryStatus::RUNNING;
134  }
135 
136  private:
138  size_t executor_id_;
139  const std::string query_str_;
140  const std::string submitted_time_;
141  // Currently we use three query status:
142  // 1) PENDING_IN_QUEUE: a task is submitted to the dispatch_queue but hangs due to no
143  // existing worker (= executor) 2) PENDING_IN_EXECUTOR: a task is assigned to the
144  // specific executor but waits to get the resource to run 3) RUNNING: a task is assigned
145  // to the specific executor and its execution has been successfully started
146  // 4) RUNNING_REDUCTION: a task is in the reduction phase
148 };
149 using QuerySessionMap =
150  std::map<const QuerySessionId, std::map<std::string, QuerySessionStatus>>;
151 extern void read_udf_gpu_module(const std::string& udf_ir_filename);
152 extern void read_udf_cpu_module(const std::string& udf_ir_filename);
153 extern bool is_udf_module_present(bool cpu_only = false);
154 extern void read_rt_udf_gpu_module(const std::string& udf_ir);
155 extern void read_rt_udf_cpu_module(const std::string& udf_ir);
156 extern bool is_rt_udf_module_present(bool cpu_only = false);
157 
158 class ColumnFetcher;
159 
160 class WatchdogException : public std::runtime_error {
161  public:
162  WatchdogException(const std::string& cause) : std::runtime_error(cause) {}
163 };
164 
165 class Executor;
166 
167 inline llvm::Value* get_arg_by_name(llvm::Function* func, const std::string& name) {
168  for (auto& arg : func->args()) {
169  if (arg.getName() == name) {
170  return &arg;
171  }
172  }
173  CHECK(false);
174  return nullptr;
175 }
176 
177 inline uint32_t log2_bytes(const uint32_t bytes) {
178  switch (bytes) {
179  case 1:
180  return 0;
181  case 2:
182  return 1;
183  case 4:
184  return 2;
185  case 8:
186  return 3;
187  default:
188  abort();
189  }
190 }
191 
193  const int col_id,
194  const int table_id,
196  CHECK_GT(table_id, 0);
197  const auto col_desc = cat.getMetadataForColumn(table_id, col_id);
198  CHECK(col_desc);
199  return col_desc;
200 }
201 
202 inline const Analyzer::Expr* extract_cast_arg(const Analyzer::Expr* expr) {
203  const auto cast_expr = dynamic_cast<const Analyzer::UOper*>(expr);
204  if (!cast_expr || cast_expr->get_optype() != kCAST) {
205  return expr;
206  }
207  return cast_expr->get_operand();
208 }
209 
210 inline std::string numeric_type_name(const SQLTypeInfo& ti) {
211  CHECK(ti.is_integer() || ti.is_decimal() || ti.is_boolean() || ti.is_time() ||
212  ti.is_fp() || (ti.is_string() && ti.get_compression() == kENCODING_DICT) ||
213  ti.is_timeinterval());
214  if (ti.is_integer() || ti.is_decimal() || ti.is_boolean() || ti.is_time() ||
215  ti.is_string() || ti.is_timeinterval()) {
216  return "int" + std::to_string(ti.get_logical_size() * 8) + "_t";
217  }
218  return ti.get_type() == kDOUBLE ? "double" : "float";
219 }
220 
222  const int col_id,
223  const int table_id,
225  CHECK(table_id);
226  return table_id > 0 ? get_column_descriptor(col_id, table_id, cat) : nullptr;
227 }
228 
229 inline const ResultSetPtr& get_temporary_table(const TemporaryTables* temporary_tables,
230  const int table_id) {
231  CHECK_LT(table_id, 0);
232  const auto it = temporary_tables->find(table_id);
233  CHECK(it != temporary_tables->end());
234  return it->second;
235 }
236 
237 inline const SQLTypeInfo get_column_type(const int col_id,
238  const int table_id,
239  const ColumnDescriptor* cd,
240  const TemporaryTables* temporary_tables) {
241  CHECK(cd || temporary_tables);
242  if (cd) {
243  CHECK_EQ(col_id, cd->columnId);
244  CHECK_EQ(table_id, cd->tableId);
245  return cd->columnType;
246  }
247  const auto& temp = get_temporary_table(temporary_tables, table_id);
248  return temp->getColType(col_id);
249 }
250 
251 // TODO(alex): Adjust interfaces downstream and make this not needed.
252 inline std::vector<Analyzer::Expr*> get_exprs_not_owned(
253  const std::vector<std::shared_ptr<Analyzer::Expr>>& exprs) {
254  std::vector<Analyzer::Expr*> exprs_not_owned;
255  for (const auto& expr : exprs) {
256  exprs_not_owned.push_back(expr.get());
257  }
258  return exprs_not_owned;
259 }
260 
261 class CompilationRetryNoLazyFetch : public std::runtime_error {
262  public:
264  : std::runtime_error("Retry query compilation with no GPU lazy fetch.") {}
265 };
266 
267 class CompilationRetryNewScanLimit : public std::runtime_error {
268  public:
269  CompilationRetryNewScanLimit(const size_t new_scan_limit)
270  : std::runtime_error("Retry query compilation with new scan limit.")
271  , new_scan_limit_(new_scan_limit) {}
272 
274 };
275 
276 class TooManyLiterals : public std::runtime_error {
277  public:
278  TooManyLiterals() : std::runtime_error("Too many literals in the query") {}
279 };
280 
281 class CompilationRetryNoCompaction : public std::runtime_error {
282  public:
284  : std::runtime_error("Retry query compilation with no compaction.") {}
285 };
286 
287 class QueryMustRunOnCpu : public std::runtime_error {
288  public:
289  QueryMustRunOnCpu() : std::runtime_error("Query must run in cpu mode.") {}
290 };
291 
292 class ParseIRError : public std::runtime_error {
293  public:
294  ParseIRError(const std::string message) : std::runtime_error(message) {}
295 };
296 
297 class StringConstInResultSet : public std::runtime_error {
298  public:
300  : std::runtime_error(
301  "NONE ENCODED String types are not supported as input result set.") {}
302 };
303 
304 class ExtensionFunction;
305 
307 using ColumnToFragmentsMap = std::map<const ColumnDescriptor*, std::set<int32_t>>;
308 using TableToFragmentIds = std::map<int32_t, std::set<int32_t>>;
309 
313 };
314 
316  public:
318 
319  UpdateLogForFragment(FragmentInfoType const& fragment_info,
320  size_t const,
321  const std::shared_ptr<ResultSet>& rs);
322 
323  std::vector<TargetValue> getEntryAt(const size_t index) const override;
324  std::vector<TargetValue> getTranslatedEntryAt(const size_t index) const override;
325 
326  size_t const getRowCount() const override;
328  return rs_->getRowSetMemOwner()->getLiteralStringDictProxy();
329  }
330  size_t const getEntryCount() const override;
331  size_t const getFragmentIndex() const;
332  FragmentInfoType const& getFragmentInfo() const;
335  }
337  return fragment_info_.fragmentId;
338  }
339 
340  SQLTypeInfo getColumnType(const size_t col_idx) const;
341 
342  using Callback = std::function<void(const UpdateLogForFragment&, TableUpdateMetadata&)>;
343 
344  auto getResultSet() const { return rs_; }
345 
346  private:
349  std::shared_ptr<ResultSet> rs_;
350 };
351 
352 using LLVMValueVector = std::vector<llvm::Value*>;
353 
355 
356 std::ostream& operator<<(std::ostream&, FetchResult const&);
357 
358 class Executor {
359  static_assert(sizeof(float) == 4 && sizeof(double) == 8,
360  "Host hardware not supported, unexpected size of float / double.");
361  static_assert(sizeof(time_t) == 8,
362  "Host hardware not supported, 64-bit time support is required.");
363 
364  public:
365  using ExecutorId = size_t;
366  static const ExecutorId UNITARY_EXECUTOR_ID = 0;
367 
368  Executor(const ExecutorId id,
369  const size_t block_size_x,
370  const size_t grid_size_x,
371  const size_t max_gpu_slab_size,
372  const std::string& debug_dir,
373  const std::string& debug_file);
374 
375  static std::shared_ptr<Executor> getExecutor(
376  const ExecutorId id,
377  const std::string& debug_dir = "",
378  const std::string& debug_file = "",
379  const SystemParameters& system_parameters = SystemParameters());
380 
381  static void nukeCacheOfExecutors() {
382  mapd_unique_lock<mapd_shared_mutex> flush_lock(
383  execute_mutex_); // don't want native code to vanish while executing
384  mapd_unique_lock<mapd_shared_mutex> lock(executors_cache_mutex_);
385  (decltype(executors_){}).swap(executors_);
386  }
387 
388  static void clearMemory(const Data_Namespace::MemoryLevel memory_level);
389 
390  static size_t getArenaBlockSize();
391 
396 
401  const bool with_generation) const {
403  return getStringDictionaryProxy(dict_id, row_set_mem_owner_, with_generation);
404  }
405 
407  const int dictId,
408  const std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
409  const bool with_generation) const;
410 
411  bool isCPUOnly() const;
412 
413  bool isArchMaxwell(const ExecutorDeviceType dt) const;
414 
416  return cgen_state_->contains_left_deep_outer_join_;
417  }
418 
420 
422  int) const;
423 
424  const Catalog_Namespace::Catalog* getCatalog() const;
425  void setCatalog(const Catalog_Namespace::Catalog* catalog);
426 
427  const std::shared_ptr<RowSetMemoryOwner> getRowSetMemoryOwner() const;
428 
429  const TemporaryTables* getTemporaryTables() const;
430 
431  Fragmenter_Namespace::TableInfo getTableInfo(const int table_id) const;
432 
433  const TableGeneration& getTableGeneration(const int table_id) const;
434 
436 
437  size_t getNumBytesForFetchedRow(const std::set<int>& table_ids_to_fetch) const;
438 
439  std::vector<ColumnLazyFetchInfo> getColLazyFetchInfo(
440  const std::vector<Analyzer::Expr*>& target_exprs) const;
441 
442  void registerActiveModule(void* module, const int device_id) const;
443  void unregisterActiveModule(void* module, const int device_id) const;
444  void interrupt(const QuerySessionId& query_session = "",
445  const QuerySessionId& interrupt_session = "");
446  void resetInterrupt();
447 
448  // only for testing usage
449  void enableRuntimeQueryInterrupt(const double runtime_query_check_freq,
450  const unsigned pending_query_check_freq) const;
451 
452  static const size_t high_scan_limit{32000000};
453 
454  int8_t warpSize() const;
455  unsigned gridSize() const;
456  unsigned numBlocksPerMP() const;
457  unsigned blockSize() const;
458  size_t maxGpuSlabSize() const;
459 
460  ResultSetPtr executeWorkUnit(size_t& max_groups_buffer_entry_guess,
461  const bool is_agg,
462  const std::vector<InputTableInfo>&,
463  const RelAlgExecutionUnit&,
464  const CompilationOptions&,
465  const ExecutionOptions& options,
467  RenderInfo* render_info,
468  const bool has_cardinality_estimation,
469  ColumnCacheMap& column_cache);
470 
472  const std::vector<InputTableInfo>& table_infos,
473  const CompilationOptions& co,
474  const ExecutionOptions& eo,
476  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
478  const bool is_agg);
479 
480  private:
481  void clearMetaInfoCache();
482 
483  int deviceCount(const ExecutorDeviceType) const;
484  int deviceCountForMemoryLevel(const Data_Namespace::MemoryLevel memory_level) const;
485 
486  // Generate code for a window function target.
487  llvm::Value* codegenWindowFunction(const size_t target_index,
488  const CompilationOptions& co);
489 
490  // Generate code for an aggregate window function target.
491  llvm::Value* codegenWindowFunctionAggregate(const CompilationOptions& co);
492 
493  // The aggregate state requires a state reset when starting a new partition. Generate
494  // the new partition check and return the continuation basic block.
495  llvm::BasicBlock* codegenWindowResetStateControlFlow();
496 
497  // Generate code for initializing the state of a window aggregate.
498  void codegenWindowFunctionStateInit(llvm::Value* aggregate_state);
499 
500  // Generates the required calls for an aggregate window function and returns the final
501  // result.
502  llvm::Value* codegenWindowFunctionAggregateCalls(llvm::Value* aggregate_state,
503  const CompilationOptions& co);
504 
505  // The AVG window function requires some post-processing: the sum is divided by count
506  // and the result is stored back for the current row.
507  void codegenWindowAvgEpilogue(llvm::Value* crt_val,
508  llvm::Value* window_func_null_val,
509  llvm::Value* multiplicity_lv);
510 
511  // Generates code which loads the current aggregate value for the window context.
512  llvm::Value* codegenAggregateWindowState();
513 
514  llvm::Value* aggregateWindowStatePtr();
515 
517  if (dt == ExecutorDeviceType::GPU) {
518  const auto cuda_mgr = catalog_->getDataMgr().getCudaMgr();
519  LOG_IF(FATAL, cuda_mgr == nullptr)
520  << "No CudaMgr instantiated, unable to check device architecture";
521  return cuda_mgr->isArchPascalOrLater();
522  }
523  return false;
524  }
525 
526  bool needFetchAllFragments(const InputColDescriptor& col_desc,
527  const RelAlgExecutionUnit& ra_exe_unit,
528  const FragmentsList& selected_fragments) const;
529 
531  const InputColDescriptor& inner_col_desc,
532  const RelAlgExecutionUnit& ra_exe_unit,
533  const FragmentsList& selected_fragments,
534  const Data_Namespace::MemoryLevel memory_level) const;
535 
536  using PerFragmentCallBack =
537  std::function<void(ResultSetPtr, const Fragmenter_Namespace::FragmentInfo&)>;
538 
544  void executeWorkUnitPerFragment(const RelAlgExecutionUnit& ra_exe_unit,
545  const InputTableInfo& table_info,
546  const CompilationOptions& co,
547  const ExecutionOptions& eo,
550  const std::set<size_t>& fragment_indexes_param);
551 
553 
560  const std::vector<InputTableInfo>& table_infos,
561  const CompilationOptions& co,
562  const ExecutionOptions& eo,
564 
566  const RelAlgExecutionUnit& ra_exe_unit,
567  const ExecutorDeviceType requested_device_type);
568 
570  SharedKernelContext& shared_context,
571  const RelAlgExecutionUnit& ra_exe_unit,
573  const ExecutorDeviceType device_type,
574  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner);
575 
577  SharedKernelContext& shared_context,
578  const RelAlgExecutionUnit& ra_exe_unit) const;
579 
580  std::unordered_map<int, const Analyzer::BinOper*> getInnerTabIdToJoinCond() const;
581 
586  std::vector<std::unique_ptr<ExecutionKernel>> createKernels(
587  SharedKernelContext& shared_context,
588  const RelAlgExecutionUnit& ra_exe_unit,
589  ColumnFetcher& column_fetcher,
590  const std::vector<InputTableInfo>& table_infos,
591  const ExecutionOptions& eo,
592  const bool is_agg,
593  const bool allow_single_frag_table_opt,
594  const size_t context_count,
595  const QueryCompilationDescriptor& query_comp_desc,
597  RenderInfo* render_info,
598  std::unordered_set<int>& available_gpus,
599  int& available_cpus);
600 
605  template <typename THREAD_POOL>
606  void launchKernels(SharedKernelContext& shared_context,
607  std::vector<std::unique_ptr<ExecutionKernel>>&& kernels);
608 
609  std::vector<size_t> getTableFragmentIndices(
610  const RelAlgExecutionUnit& ra_exe_unit,
611  const ExecutorDeviceType device_type,
612  const size_t table_idx,
613  const size_t outer_frag_idx,
614  std::map<int, const TableFragments*>& selected_tables_fragments,
615  const std::unordered_map<int, const Analyzer::BinOper*>&
616  inner_table_id_to_join_condition);
617 
618  bool skipFragmentPair(const Fragmenter_Namespace::FragmentInfo& outer_fragment_info,
619  const Fragmenter_Namespace::FragmentInfo& inner_fragment_info,
620  const int inner_table_id,
621  const std::unordered_map<int, const Analyzer::BinOper*>&
622  inner_table_id_to_join_condition,
623  const RelAlgExecutionUnit& ra_exe_unit,
624  const ExecutorDeviceType device_type);
625 
627  const RelAlgExecutionUnit& ra_exe_unit,
628  const int device_id,
630  const std::map<int, const TableFragments*>&,
631  const FragmentsList& selected_fragments,
633  std::list<ChunkIter>&,
634  std::list<std::shared_ptr<Chunk_NS::Chunk>>&,
635  DeviceAllocator* device_allocator,
636  const size_t thread_idx,
637  const bool allow_runtime_interrupt);
638 
640  const RelAlgExecutionUnit& ra_exe_unit,
641  const int device_id,
643  const std::map<int, const TableFragments*>&,
644  const FragmentsList& selected_fragments,
646  std::list<ChunkIter>&,
647  std::list<std::shared_ptr<Chunk_NS::Chunk>>&,
648  DeviceAllocator* device_allocator,
649  const size_t thread_idx,
650  const bool allow_runtime_interrupt);
651 
652  std::pair<std::vector<std::vector<int64_t>>, std::vector<std::vector<uint64_t>>>
654  const RelAlgExecutionUnit& ra_exe_unit,
655  const CartesianProduct<std::vector<std::vector<size_t>>>& frag_ids_crossjoin,
656  const std::vector<InputDescriptor>& input_descs,
657  const std::map<int, const TableFragments*>& all_tables_fragments);
658 
660  std::vector<std::vector<size_t>>& selected_fragments_crossjoin,
661  std::vector<size_t>& local_col_to_frag_pos,
662  const std::list<std::shared_ptr<const InputColDescriptor>>& col_global_ids,
663  const FragmentsList& selected_fragments,
664  const RelAlgExecutionUnit& ra_exe_unit);
665 
667  std::vector<std::vector<size_t>>& selected_fragments_crossjoin,
668  std::vector<size_t>& local_col_to_frag_pos,
669  const std::list<std::shared_ptr<const InputColDescriptor>>& col_global_ids,
670  const FragmentsList& selected_fragments,
671  const RelAlgExecutionUnit& ra_exe_unit);
672 
673  std::vector<size_t> getFragmentCount(const FragmentsList& selected_fragments,
674  const size_t scan_idx,
675  const RelAlgExecutionUnit& ra_exe_unit);
676 
677  int32_t executePlanWithGroupBy(const RelAlgExecutionUnit& ra_exe_unit,
678  const CompilationResult&,
679  const bool hoist_literals,
680  ResultSetPtr& results,
681  const ExecutorDeviceType device_type,
682  std::vector<std::vector<const int8_t*>>& col_buffers,
683  const std::vector<size_t> outer_tab_frag_ids,
685  const std::vector<std::vector<int64_t>>& num_rows,
686  const std::vector<std::vector<uint64_t>>& frag_offsets,
688  const int device_id,
689  const int outer_table_id,
690  const int64_t limit,
691  const uint32_t start_rowid,
692  const uint32_t num_tables,
693  const bool allow_runtime_interrupt,
694  RenderInfo* render_info);
696  const RelAlgExecutionUnit& ra_exe_unit,
697  const CompilationResult&,
698  const bool hoist_literals,
699  ResultSetPtr& results,
700  const std::vector<Analyzer::Expr*>& target_exprs,
701  const ExecutorDeviceType device_type,
702  std::vector<std::vector<const int8_t*>>& col_buffers,
703  QueryExecutionContext* query_exe_context,
704  const std::vector<std::vector<int64_t>>& num_rows,
705  const std::vector<std::vector<uint64_t>>& frag_offsets,
706  Data_Namespace::DataMgr* data_mgr,
707  const int device_id,
708  const uint32_t start_rowid,
709  const uint32_t num_tables,
710  const bool allow_runtime_interrupt,
711  RenderInfo* render_info);
712 
713  public: // Temporary, ask saman about this
714  static std::pair<int64_t, int32_t> reduceResults(const SQLAgg agg,
715  const SQLTypeInfo& ti,
716  const int64_t agg_init_val,
717  const int8_t out_byte_width,
718  const int64_t* out_vec,
719  const size_t out_vec_sz,
720  const bool is_group_by,
721  const bool float_argument_input);
722 
723  static void addCodeToCache(const CodeCacheKey&,
724  std::shared_ptr<CompilationContext>,
725  llvm::Module*,
726  CodeCache&);
727 
728  private:
730  const RelAlgExecutionUnit& ra_exe_unit);
731  std::vector<int64_t> getJoinHashTablePtrs(const ExecutorDeviceType device_type,
732  const int device_id);
734  const RelAlgExecutionUnit&,
735  std::vector<std::pair<ResultSetPtr, std::vector<size_t>>>& all_fragment_results,
736  std::shared_ptr<RowSetMemoryOwner>,
737  const QueryMemoryDescriptor&) const;
739  std::vector<std::pair<ResultSetPtr, std::vector<size_t>>>& all_fragment_results,
740  std::shared_ptr<RowSetMemoryOwner>,
741  const QueryMemoryDescriptor&) const;
743  const RelAlgExecutionUnit&,
744  std::vector<std::pair<ResultSetPtr, std::vector<size_t>>>& all_fragment_results,
745  std::shared_ptr<RowSetMemoryOwner>,
746  const QueryMemoryDescriptor&) const;
747 
748  ResultSetPtr executeWorkUnitImpl(size_t& max_groups_buffer_entry_guess,
749  const bool is_agg,
750  const bool allow_single_frag_table_opt,
751  const std::vector<InputTableInfo>&,
752  const RelAlgExecutionUnit&,
753  const CompilationOptions&,
754  const ExecutionOptions& options,
756  std::shared_ptr<RowSetMemoryOwner>,
757  RenderInfo* render_info,
758  const bool has_cardinality_estimation,
759  ColumnCacheMap& column_cache);
760 
761  std::vector<llvm::Value*> inlineHoistedLiterals();
762 
763  std::tuple<CompilationResult, std::unique_ptr<QueryMemoryDescriptor>> compileWorkUnit(
764  const std::vector<InputTableInfo>& query_infos,
765  const PlanState::DeletedColumnsMap& deleted_cols_map,
766  const RelAlgExecutionUnit& ra_exe_unit,
767  const CompilationOptions& co,
768  const ExecutionOptions& eo,
769  const CudaMgr_Namespace::CudaMgr* cuda_mgr,
770  const bool allow_lazy_fetch,
771  std::shared_ptr<RowSetMemoryOwner>,
772  const size_t max_groups_buffer_entry_count,
773  const int8_t crt_min_byte_width,
774  const bool has_cardinality_estimation,
775  ColumnCacheMap& column_cache,
776  RenderInfo* render_info = nullptr);
777  // Generate code to skip the deleted rows in the outermost table.
778  llvm::BasicBlock* codegenSkipDeletedOuterTableRow(
779  const RelAlgExecutionUnit& ra_exe_unit,
780  const CompilationOptions& co);
781  std::vector<JoinLoop> buildJoinLoops(RelAlgExecutionUnit& ra_exe_unit,
782  const CompilationOptions& co,
783  const ExecutionOptions& eo,
784  const std::vector<InputTableInfo>& query_infos,
785  ColumnCacheMap& column_cache);
786  // Create a callback which hoists left hand side filters above the join for left joins,
787  // eliminating extra computation of the probe and matches if the row does not pass the
788  // filters
790  const RelAlgExecutionUnit& ra_exe_unit,
791  const size_t level_idx,
792  const int inner_table_id,
793  const CompilationOptions& co);
794  // Create a callback which generates code which returns true iff the row on the given
795  // level is deleted.
796  std::function<llvm::Value*(const std::vector<llvm::Value*>&, llvm::Value*)>
797  buildIsDeletedCb(const RelAlgExecutionUnit& ra_exe_unit,
798  const size_t level_idx,
799  const CompilationOptions& co);
800  // Builds a join hash table for the provided conditions on the current level.
801  // Returns null iff on failure and provides the reasons in `fail_reasons`.
802  std::shared_ptr<HashJoin> buildCurrentLevelHashTable(
803  const JoinCondition& current_level_join_conditions,
804  RelAlgExecutionUnit& ra_exe_unit,
805  const CompilationOptions& co,
806  const std::vector<InputTableInfo>& query_infos,
807  ColumnCacheMap& column_cache,
808  std::vector<std::string>& fail_reasons);
810  llvm::Value* addJoinLoopIterator(const std::vector<llvm::Value*>& prev_iters,
811  const size_t level_idx);
812  void codegenJoinLoops(const std::vector<JoinLoop>& join_loops,
813  const RelAlgExecutionUnit& ra_exe_unit,
814  GroupByAndAggregate& group_by_and_aggregate,
815  llvm::Function* query_func,
816  llvm::BasicBlock* entry_bb,
818  const CompilationOptions& co,
819  const ExecutionOptions& eo);
820  bool compileBody(const RelAlgExecutionUnit& ra_exe_unit,
821  GroupByAndAggregate& group_by_and_aggregate,
823  const CompilationOptions& co,
824  const GpuSharedMemoryContext& gpu_smem_context = {});
825 
826  void createErrorCheckControlFlow(llvm::Function* query_func,
827  bool run_with_dynamic_watchdog,
828  bool run_with_allowing_runtime_interrupt,
829  ExecutorDeviceType device_type,
830  const std::vector<InputTableInfo>& input_table_infos);
831 
832  void insertErrorCodeChecker(llvm::Function* query_func,
833  bool hoist_literals,
834  bool allow_runtime_query_interrupt);
835 
836  void preloadFragOffsets(const std::vector<InputDescriptor>& input_descs,
837  const std::vector<InputTableInfo>& query_infos);
838 
840  std::shared_ptr<HashJoin> hash_table;
841  std::string fail_reason;
842  };
843 
845  const std::shared_ptr<Analyzer::BinOper>& qual_bin_oper,
846  const std::vector<InputTableInfo>& query_infos,
847  const MemoryLevel memory_level,
848  const HashType preferred_hash_type,
849  ColumnCacheMap& column_cache,
850  const RegisteredQueryHint& query_hint);
851  void nukeOldState(const bool allow_lazy_fetch,
852  const std::vector<InputTableInfo>& query_infos,
853  const PlanState::DeletedColumnsMap& deleted_cols_map,
854  const RelAlgExecutionUnit* ra_exe_unit);
855 
856  std::shared_ptr<CompilationContext> optimizeAndCodegenCPU(
857  llvm::Function*,
858  llvm::Function*,
859  const std::unordered_set<llvm::Function*>&,
860  const CompilationOptions&);
861  std::shared_ptr<CompilationContext> optimizeAndCodegenGPU(
862  llvm::Function*,
863  llvm::Function*,
864  std::unordered_set<llvm::Function*>&,
865  const bool no_inline,
866  const CudaMgr_Namespace::CudaMgr* cuda_mgr,
867  const CompilationOptions&);
868  std::string generatePTX(const std::string&) const;
869  void initializeNVPTXBackend() const;
870 
871  int64_t deviceCycles(int milliseconds) const;
872 
874  llvm::Value* translated_value;
875  llvm::Value* original_value;
876  };
877 
879  const size_t col_width,
880  const CompilationOptions&,
881  const bool translate_null_val,
882  const int64_t translated_null_val,
884  std::stack<llvm::BasicBlock*>&,
885  const bool thread_mem_shared);
886 
887  llvm::Value* castToFP(llvm::Value*,
888  SQLTypeInfo const& from_ti,
889  SQLTypeInfo const& to_ti);
890  llvm::Value* castToIntPtrTyIn(llvm::Value* val, const size_t bit_width);
891 
892  std::tuple<RelAlgExecutionUnit, PlanState::DeletedColumnsMap> addDeletedColumn(
893  const RelAlgExecutionUnit& ra_exe_unit,
894  const CompilationOptions& co);
895 
896  bool isFragmentFullyDeleted(const int table_id,
897  const Fragmenter_Namespace::FragmentInfo& fragment);
898 
899  std::pair<bool, int64_t> skipFragment(
900  const InputDescriptor& table_desc,
901  const Fragmenter_Namespace::FragmentInfo& frag_info,
902  const std::list<std::shared_ptr<Analyzer::Expr>>& simple_quals,
903  const std::vector<uint64_t>& frag_offsets,
904  const size_t frag_idx);
905 
906  std::pair<bool, int64_t> skipFragmentInnerJoins(
907  const InputDescriptor& table_desc,
908  const RelAlgExecutionUnit& ra_exe_unit,
909  const Fragmenter_Namespace::FragmentInfo& fragment,
910  const std::vector<uint64_t>& frag_offsets,
911  const size_t frag_idx);
912 
914  const std::unordered_set<PhysicalInput>& phys_inputs);
916  const std::unordered_set<PhysicalInput>& phys_inputs);
917  TableGenerations computeTableGenerations(std::unordered_set<int> phys_table_ids);
918 
919  public:
920  void setupCaching(const std::unordered_set<PhysicalInput>& phys_inputs,
921  const std::unordered_set<int>& phys_table_ids);
922  void setColRangeCache(const AggregatedColRange& aggregated_col_range) {
923  agg_col_range_cache_ = aggregated_col_range;
924  }
925 
926  QuerySessionId& getCurrentQuerySession(mapd_shared_lock<mapd_shared_mutex>& read_lock);
927  size_t getRunningExecutorId(mapd_shared_lock<mapd_shared_mutex>& read_lock);
928  void setCurrentQuerySession(const QuerySessionId& query_session,
929  mapd_unique_lock<mapd_shared_mutex>& write_lock);
930  void setRunningExecutorId(const size_t id,
931  mapd_unique_lock<mapd_shared_mutex>& write_lock);
932  bool checkCurrentQuerySession(const std::string& candidate_query_session,
933  mapd_shared_lock<mapd_shared_mutex>& read_lock);
934  void invalidateRunningQuerySession(mapd_unique_lock<mapd_shared_mutex>& write_lock);
935  bool addToQuerySessionList(const QuerySessionId& query_session,
936  const std::string& query_str,
937  const std::string& submitted,
938  const size_t executor_id,
939  const QuerySessionStatus::QueryStatus query_status,
940  mapd_unique_lock<mapd_shared_mutex>& write_lock);
941  bool removeFromQuerySessionList(const QuerySessionId& query_session,
942  const std::string& submitted_time_str,
943  mapd_unique_lock<mapd_shared_mutex>& write_lock);
944  void setQuerySessionAsInterrupted(const QuerySessionId& query_session,
945  mapd_unique_lock<mapd_shared_mutex>& write_lock);
946  void resetQuerySessionInterruptFlag(const std::string& query_session,
947  mapd_unique_lock<mapd_shared_mutex>& write_lock);
948  bool checkIsQuerySessionInterrupted(const std::string& query_session,
949  mapd_shared_lock<mapd_shared_mutex>& read_lock);
951  bool checkIsQuerySessionEnrolled(const QuerySessionId& query_session,
952  mapd_shared_lock<mapd_shared_mutex>& read_lock);
954  const QuerySessionId& query_session,
955  const std::string& submitted_time_str,
956  const QuerySessionStatus::QueryStatus updated_query_status,
957  mapd_unique_lock<mapd_shared_mutex>& write_lock);
959  const QuerySessionId& query_session,
960  const std::string& submitted_time_str,
961  const size_t executor_id,
962  mapd_unique_lock<mapd_shared_mutex>& write_lock);
963  std::vector<QuerySessionStatus> getQuerySessionInfo(
964  const QuerySessionId& query_session,
965  mapd_shared_lock<mapd_shared_mutex>& read_lock);
966 
969  const QuerySessionId& query_session_id,
970  const std::string& query_str,
971  const std::string& query_submitted_time);
972  void checkPendingQueryStatus(const QuerySessionId& query_session);
973  void clearQuerySessionStatus(const QuerySessionId& query_session,
974  const std::string& submitted_time_str,
975  const bool acquire_spin_lock);
977  std::shared_ptr<const query_state::QueryState>& query_state,
978  const QuerySessionStatus::QueryStatus new_query_status);
979  void updateQuerySessionStatus(const QuerySessionId& query_session,
980  const std::string& submitted_time_str,
981  const QuerySessionStatus::QueryStatus new_query_status);
982  void enrollQuerySession(const QuerySessionId& query_session,
983  const std::string& query_str,
984  const std::string& submitted_time_str,
985  const size_t executor_id,
986  const QuerySessionStatus::QueryStatus query_session_status);
987 
988  // true when we have matched cardinality, and false otherwise
989  using CachedCardinality = std::pair<bool, size_t>;
990  void addToCardinalityCache(const std::string& cache_key, const size_t cache_value);
991  CachedCardinality getCachedCardinality(const std::string& cache_key);
992 
993  private:
994  std::shared_ptr<CompilationContext> getCodeFromCache(const CodeCacheKey&,
995  const CodeCache&);
996 
997  std::vector<int8_t> serializeLiterals(
998  const std::unordered_map<int, CgenState::LiteralValues>& literals,
999  const int device_id);
1000 
1001  static size_t align(const size_t off_in, const size_t alignment) {
1002  size_t off = off_in;
1003  if (off % alignment != 0) {
1004  off += (alignment - off % alignment);
1005  }
1006  return off;
1007  }
1008 
1009  std::unique_ptr<CgenState> cgen_state_;
1010 
1012  public:
1014  : cgen_state_(cgen_state), saved_fetch_cache(cgen_state_->fetch_cache_) {}
1016 
1017  private:
1019  std::unordered_map<int, std::vector<llvm::Value*>> saved_fetch_cache;
1020  };
1021 
1022  llvm::Value* spillDoubleElement(llvm::Value* elem_val, llvm::Type* elem_ty);
1023 
1024  std::unique_ptr<PlanState> plan_state_;
1025  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner_;
1026 
1027  static const int max_gpu_count{16};
1029 
1030  static std::mutex gpu_active_modules_mutex_;
1033  static std::atomic<bool> interrupted_;
1034 
1035  mutable std::mutex str_dict_mutex_;
1036 
1037  mutable std::unique_ptr<llvm::TargetMachine> nvptx_target_machine_;
1038 
1041 
1042  static const size_t baseline_threshold{
1043  1000000}; // if a perfect hash needs more entries, use baseline
1044  static const size_t code_cache_size{1000};
1045 
1046  const unsigned block_size_x_;
1047  const unsigned grid_size_x_;
1048  const size_t max_gpu_slab_size_;
1049  const std::string debug_dir_;
1050  const std::string debug_file_;
1051 
1055 
1058 
1059  // Singleton instance used for an execution unit which is a project with window
1060  // functions.
1061  std::unique_ptr<WindowProjectNodeContext> window_project_node_context_owned_;
1062  // The active window function.
1064 
1069  // a query session that currently is running
1071  // an executor's id that executes the running query
1073  // a pair of <QuerySessionId, interrupted_flag>
1075  // a pair of <QuerySessionId, query_session_status>
1077 
1078  static std::map<int, std::shared_ptr<Executor>> executors_;
1079  static std::atomic_flag execute_spin_lock_;
1080 
1081  // SQL queries take a shared lock, exclusive options (cache clear, memory clear) take a
1082  // write lock
1084 
1086  mapd_shared_lock<mapd_shared_mutex> shared_lock;
1087  mapd_unique_lock<mapd_shared_mutex> unique_lock;
1088  };
1090  ExecutorMutexHolder ret;
1092  // Only one unitary executor can run at a time
1093  ret.unique_lock = mapd_unique_lock<mapd_shared_mutex>(execute_mutex_);
1094  } else {
1095  ret.shared_lock = mapd_shared_lock<mapd_shared_mutex>(execute_mutex_);
1096  }
1097  return ret;
1098  }
1099 
1101 
1102  // for now we use recycler_mutex only for cardinality_cache_
1103  // and will expand its coverage for more interesting caches for query execution
1105  static std::unordered_map<std::string, size_t> cardinality_cache_;
1106 
1107  public:
1108  static const int32_t ERR_DIV_BY_ZERO{1};
1109  static const int32_t ERR_OUT_OF_GPU_MEM{2};
1110  static const int32_t ERR_OUT_OF_SLOTS{3};
1111  static const int32_t ERR_UNSUPPORTED_SELF_JOIN{4};
1112  static const int32_t ERR_OUT_OF_RENDER_MEM{5};
1113  static const int32_t ERR_OUT_OF_CPU_MEM{6};
1114  static const int32_t ERR_OVERFLOW_OR_UNDERFLOW{7};
1115  static const int32_t ERR_OUT_OF_TIME{9};
1116  static const int32_t ERR_INTERRUPTED{10};
1117  static const int32_t ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED{11};
1118  static const int32_t ERR_TOO_MANY_LITERALS{12};
1119  static const int32_t ERR_STRING_CONST_IN_RESULTSET{13};
1121  static const int32_t ERR_SINGLE_VALUE_FOUND_MULTIPLE_VALUES{15};
1122  static const int32_t ERR_GEOS{16};
1123 
1124  static std::mutex compilation_mutex_;
1125  static std::mutex kernel_mutex_;
1126 
1128  friend class CodeGenerator;
1129  friend class ColumnFetcher;
1130  friend struct DiamondCodegen; // cgen_state_
1131  friend class ExecutionKernel;
1132  friend class HashJoin; // cgen_state_
1134  friend class GroupByAndAggregate;
1140  friend class ResultSet;
1141  friend class InValuesBitmap;
1142  friend class LeafAggregator;
1143  friend class PerfectJoinHashTable;
1144  friend class QueryRewriter;
1146  friend class RelAlgExecutor;
1147  friend class TableOptimizer;
1151  friend struct TargetExprCodegen;
1153 };
1154 
1155 inline std::string get_null_check_suffix(const SQLTypeInfo& lhs_ti,
1156  const SQLTypeInfo& rhs_ti) {
1157  if (lhs_ti.get_notnull() && rhs_ti.get_notnull()) {
1158  return "";
1159  }
1160  std::string null_check_suffix{"_nullable"};
1161  if (lhs_ti.get_notnull()) {
1162  CHECK(!rhs_ti.get_notnull());
1163  null_check_suffix += "_rhs";
1164  } else if (rhs_ti.get_notnull()) {
1165  CHECK(!lhs_ti.get_notnull());
1166  null_check_suffix += "_lhs";
1167  }
1168  return null_check_suffix;
1169 }
1170 
1171 inline bool is_unnest(const Analyzer::Expr* expr) {
1172  return dynamic_cast<const Analyzer::UOper*>(expr) &&
1173  static_cast<const Analyzer::UOper*>(expr)->get_optype() == kUNNEST;
1174 }
1175 
1176 inline bool is_constructed_point(const Analyzer::Expr* expr) {
1177  auto uoper = dynamic_cast<const Analyzer::UOper*>(expr);
1178  auto oper = (uoper && uoper->get_optype() == kCAST) ? uoper->get_operand() : expr;
1179  auto arr = dynamic_cast<const Analyzer::ArrayExpr*>(oper);
1180  return (arr && arr->isLocalAlloc() && arr->get_type_info().is_fixlen_array());
1181 }
1182 
1183 bool is_trivial_loop_join(const std::vector<InputTableInfo>& query_infos,
1184  const RelAlgExecutionUnit& ra_exe_unit);
1185 
1186 std::unordered_set<int> get_available_gpus(const Catalog_Namespace::Catalog& cat);
1187 
1188 size_t get_context_count(const ExecutorDeviceType device_type,
1189  const size_t cpu_count,
1190  const size_t gpu_count);
1191 
1192 extern "C" RUNTIME_EXPORT void register_buffer_with_executor_rsm(int64_t exec,
1193  int8_t* buffer);
1194 
1196 
1197 #endif // QUERYENGINE_EXECUTE_H
bool updateQuerySessionStatusWithLock(const QuerySessionId &query_session, const std::string &submitted_time_str, const QuerySessionStatus::QueryStatus updated_query_status, mapd_unique_lock< mapd_shared_mutex > &write_lock)
Definition: Execute.cpp:4021
void read_rt_udf_gpu_module(const std::string &udf_ir)
SQLTypeInfo getColumnType(const size_t col_idx) const
CudaMgr_Namespace::CudaMgr * getCudaMgr() const
Definition: DataMgr.h:207
const std::string debug_dir_
Definition: Execute.h:1049
QuerySessionId & getCurrentQuerySession(mapd_shared_lock< mapd_shared_mutex > &read_lock)
Definition: Execute.cpp:3819
llvm::Value * translated_value
Definition: Execute.h:874
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:1597
bool is_agg(const Analyzer::Expr *expr)
static mapd_shared_mutex executor_session_mutex_
Definition: Execute.h:1068
AggregatedColRange computeColRangesCache(const std::unordered_set< PhysicalInput > &phys_inputs)
Definition: Execute.cpp:3745
std::shared_ptr< HashJoin > buildCurrentLevelHashTable(const JoinCondition &current_level_join_conditions, 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:659
void enableRuntimeQueryInterrupt(const double runtime_query_check_freq, const unsigned pending_query_check_freq) const
Definition: Execute.cpp:4152
SQLAgg
Definition: sqldefs.h:71
#define CHECK_EQ(x, y)
Definition: Logger.h:211
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:2046
void resetQuerySessionInterruptFlag(const std::string &query_session, mapd_unique_lock< mapd_shared_mutex > &write_lock)
Definition: Execute.cpp:4118
static QuerySessionMap queries_session_map_
Definition: Execute.h:1076
static mapd_shared_mutex execute_mutex_
Definition: Execute.h:1083
std::unique_ptr< llvm::TargetMachine > nvptx_target_machine_
Definition: Execute.h:1037
int64_t kernel_queue_time_ms_
Definition: Execute.h:1056
size_t maxGpuSlabSize() const
Definition: Execute.cpp:3351
ExecutorMutexHolder acquireExecuteMutex()
Definition: Execute.h:1089
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)
Definition: Execute.cpp:3054
int64_t compilation_queue_time_ms_
Definition: Execute.h:1057
const std::string & getQuerySubmittedTime()
Definition: Execute.h:126
friend class ResultSet
Definition: Execute.h:1140
std::map< const ColumnDescriptor *, std::set< int32_t >> ColumnToFragmentsMap
Definition: Execute.h:307
std::string cat(Ts &&...args)
void invalidateRunningQuerySession(mapd_unique_lock< mapd_shared_mutex > &write_lock)
Definition: Execute.cpp:3848
void checkPendingQueryStatus(const QuerySessionId &query_session)
Definition: Execute.cpp:3871
static const int32_t ERR_INTERRUPTED
Definition: Execute.h:1116
const Analyzer::Expr * remove_cast_to_int(const Analyzer::Expr *expr)
Definition: ColumnIR.cpp:537
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:102
bool is_trivial_loop_join(const std::vector< InputTableInfo > &query_infos, const RelAlgExecutionUnit &ra_exe_unit)
Definition: Execute.cpp:1154
FetchCacheAnchor(CgenState *cgen_state)
Definition: Execute.h:1013
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, const QueryMemoryDescriptor &query_mem_desc, const CompilationOptions &co, const ExecutionOptions &eo)
Definition: IRCodegen.cpp:824
const std::shared_ptr< RowSetMemoryOwner > getRowSetMemoryOwner() const
Definition: Execute.cpp:286
StringDictionaryProxy * getLiteralDictionary() const override
Definition: Execute.h:327
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:2205
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:1680
void read_rt_udf_cpu_module(const std::string &udf_ir)
Fragmenter_Namespace::RowDataProvider RowDataProvider
Definition: Execute.h:306
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:223
std::unordered_set< int > get_available_gpus(const Catalog_Namespace::Catalog &cat)
Definition: Execute.cpp:1034
static const int max_gpu_count
Definition: Execute.h:1027
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:875
std::map< const QuerySessionId, std::map< std::string, QuerySessionStatus >> QuerySessionMap
Definition: Execute.h:150
#define const
size_t const getFragmentIndex() const
static const size_t code_cache_size
Definition: Execute.h:1044
void setQueryStatusAsRunning()
Definition: Execute.h:132
bool isArchPascalOrLater(const ExecutorDeviceType dt) const
Definition: Execute.h:516
std::ostream & operator<<(std::ostream &os, const SessionInfo &session_info)
Definition: SessionInfo.cpp:53
static std::atomic_flag execute_spin_lock_
Definition: Execute.h:1079
TableUpdateMetadata executeUpdate(const RelAlgExecutionUnit &ra_exe_unit, const std::vector< InputTableInfo > &table_infos, const CompilationOptions &co, const ExecutionOptions &eo, const Catalog_Namespace::Catalog &cat, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner, const UpdateLogForFragment::Callback &cb, const bool is_agg)
bool is_fp() const
Definition: sqltypes.h:493
std::pair< QuerySessionId, std::string > CurrentQueryStatus
Definition: Execute.h:80
bool is_constructed_point(const Analyzer::Expr *expr)
Definition: Execute.h:1176
static mapd_shared_mutex executors_cache_mutex_
Definition: Execute.h:1100
bool is_udf_module_present(bool cpu_only=false)
std::function< llvm::BasicBlock *(llvm::BasicBlock *, llvm::BasicBlock *, const std::string &, llvm::Function *, CgenState *)> HoistedFiltersCallback
Definition: JoinLoop.h:60
std::vector< ColumnLazyFetchInfo > getColLazyFetchInfo(const std::vector< Analyzer::Expr * > &target_exprs) const
Definition: Execute.cpp:336
static const size_t baseline_threshold
Definition: Execute.h:1042
void registerActiveModule(void *module, const int device_id) const
string name
Definition: setup.in.py:72
std::tuple< RelAlgExecutionUnit, PlanState::DeletedColumnsMap > addDeletedColumn(const RelAlgExecutionUnit &ra_exe_unit, const CompilationOptions &co)
Definition: Execute.cpp:3434
TableGenerations computeTableGenerations(std::unordered_set< int > phys_table_ids)
Definition: Execute.cpp:3792
TableToFragmentIds fragments_with_deleted_rows
Definition: Execute.h:312
const SQLTypeInfo get_column_type(const int col_id, const int table_id, const ColumnDescriptor *cd, const TemporaryTables *temporary_tables)
Definition: Execute.h:237
llvm::Value * aggregateWindowStatePtr()
void read_udf_cpu_module(const std::string &udf_ir_filename)
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:662
void read_udf_gpu_module(const std::string &udf_ir_filename)
Definition: sqldefs.h:49
std::vector< std::string > CodeCacheKey
Definition: CodeCache.h:25
const Analyzer::Expr * extract_cast_arg(const Analyzer::Expr *expr)
Definition: Execute.h:202
bool checkCurrentQuerySession(const std::string &candidate_query_session, mapd_shared_lock< mapd_shared_mutex > &read_lock)
Definition: Execute.cpp:3840
void setRunningExecutorId(const size_t id, mapd_unique_lock< mapd_shared_mutex > &write_lock)
Definition: Execute.cpp:3831
const QuerySessionStatus::QueryStatus getQueryStatus()
Definition: Execute.h:127
static const int32_t ERR_GEOS
Definition: Execute.h:1122
const std::string query_str_
Definition: Execute.h:139
QuerySessionStatus(const QuerySessionId &query_session, const std::string &query_str, const std::string &submitted_time)
Definition: Execute.h:95
AggregatedColRange agg_col_range_cache_
Definition: Execute.h:1066
std::shared_ptr< ResultSet > ResultSetPtr
static void * gpu_active_modules_[max_gpu_count]
Definition: Execute.h:1032
std::unique_ptr< CgenState > cgen_state_
Definition: Execute.h:1009
static const int32_t ERR_TOO_MANY_LITERALS
Definition: Execute.h:1118
llvm::Value * original_value
Definition: Execute.h:875
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:3959
ParseIRError(const std::string message)
Definition: Execute.h:294
std::vector< Analyzer::Expr * > get_exprs_not_owned(const std::vector< std::shared_ptr< Analyzer::Expr >> &exprs)
Definition: Execute.h:252
static uint32_t gpu_active_modules_device_mask_
Definition: Execute.h:1031
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
void buildSelectedFragsMappingForUnion(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:2789
int deviceCount(const ExecutorDeviceType) const
Definition: Execute.cpp:645
llvm::Value * castToIntPtrTyIn(llvm::Value *val, const size_t bit_width)
Definition: Execute.cpp:3390
size_t getNumBytesForFetchedRow(const std::set< int > &table_ids_to_fetch) const
Definition: Execute.cpp:306
static std::mutex kernel_mutex_
Definition: Execute.h:1125
unsigned numBlocksPerMP() const
Definition: Execute.cpp:3333
#define CHECK_GT(x, y)
Definition: Logger.h:215
Container for compilation results and assorted options for a single execution unit.
bool isCPUOnly() const
Definition: Execute.cpp:256
std::unique_ptr< WindowProjectNodeContext > window_project_node_context_owned_
Definition: Execute.h:1061
std::vector< QuerySessionStatus > getQuerySessionInfo(const QuerySessionId &query_session, mapd_shared_lock< mapd_shared_mutex > &read_lock)
Definition: Execute.cpp:4186
std::vector< FragmentsPerTable > FragmentsList
bool is_time() const
Definition: sqltypes.h:495
bool needFetchAllFragments(const InputColDescriptor &col_desc, const RelAlgExecutionUnit &ra_exe_unit, const FragmentsList &selected_fragments) const
Definition: Execute.cpp:2386
const QuerySessionId query_session_
Definition: Execute.h:137
std::shared_ptr< HashJoin > hash_table
Definition: Execute.h:840
std::string to_string(char const *&&v)
bool checkIsQuerySessionInterrupted(const std::string &query_session, mapd_shared_lock< mapd_shared_mutex > &read_lock)
Definition: Execute.cpp:4127
mapd_shared_mutex & getSessionLock()
Definition: Execute.cpp:3815
#define LOG_IF(severity, condition)
Definition: Logger.h:293
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:185
QuerySessionStatus(const QuerySessionId &query_session, const size_t executor_id, const std::string &query_str, const std::string &submitted_time)
Definition: Execute.h:103
std::function< void(const UpdateLogForFragment &, TableUpdateMetadata &)> Callback
Definition: Execute.h:342
Fragmenter_Namespace::TableInfo getTableInfo(const int table_id) const
Definition: Execute.cpp:294
RUNTIME_EXPORT void register_buffer_with_executor_rsm(int64_t exec, int8_t *buffer)
std::shared_ptr< CompilationContext > getCodeFromCache(const CodeCacheKey &, const CodeCache &)
static const size_t high_scan_limit
Definition: Execute.h:452
CodeCache gpu_code_cache_
Definition: Execute.h:1040
static const int32_t ERR_STRING_CONST_IN_RESULTSET
Definition: Execute.h:1119
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:163
std::vector< int64_t > getJoinHashTablePtrs(const ExecutorDeviceType device_type, const int device_id)
Definition: Execute.cpp:3232
void preloadFragOffsets(const std::vector< InputDescriptor > &input_descs, const std::vector< InputTableInfo > &query_infos)
Definition: Execute.cpp:3266
bool isFragmentFullyDeleted(const int table_id, const Fragmenter_Namespace::FragmentInfo &fragment)
Definition: Execute.cpp:3513
bool checkIsRunningQuerySessionInterrupted()
Definition: Execute.cpp:4138
bool checkIsQuerySessionEnrolled(const QuerySessionId &query_session, mapd_shared_lock< mapd_shared_mutex > &read_lock)
Definition: Execute.cpp:4143
void setQueryStatus(const QuerySessionStatus::QueryStatus &status)
Definition: Execute.h:128
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:2566
static const int32_t ERR_STREAMING_TOP_N_NOT_SUPPORTED_IN_RENDER_QUERY
Definition: Execute.h:1120
const ExecutorId executor_id_
Definition: Execute.h:1052
static const int32_t ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED
Definition: Execute.h:1117
const ResultSetPtr & get_temporary_table(const TemporaryTables *temporary_tables, const int table_id)
Definition: Execute.h:229
int8_t warpSize() const
Definition: Execute.cpp:3315
std::map< QuerySessionId, bool > InterruptFlagMap
Definition: Execute.h:81
const size_t max_gpu_slab_size_
Definition: Execute.h:1048
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:1007
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:1855
const ColumnDescriptor * getPhysicalColumnDescriptor(const Analyzer::ColumnVar *, int) const
Definition: Execute.cpp:267
bool compileBody(const RelAlgExecutionUnit &ra_exe_unit, GroupByAndAggregate &group_by_and_aggregate, const QueryMemoryDescriptor &query_mem_desc, const CompilationOptions &co, const GpuSharedMemoryContext &gpu_smem_context={})
static const int32_t ERR_DIV_BY_ZERO
Definition: Execute.h:1108
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)
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, mapd_unique_lock< mapd_shared_mutex > &write_lock)
Definition: Execute.cpp:3984
llvm::Value * get_arg_by_name(llvm::Function *func, const std::string &name)
Definition: Execute.h:167
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 CompilationOptions &)
std::vector< llvm::Value * > LLVMValueVector
Definition: Execute.h:352
size_t get_context_count(const ExecutorDeviceType device_type, const size_t cpu_count, const size_t gpu_count)
Definition: Execute.cpp:1046
const ColumnDescriptor * get_column_descriptor_maybe(const int col_id, const int table_id, const Catalog_Namespace::Catalog &cat)
Definition: Execute.h:221
std::vector< TargetValue > getEntryAt(const size_t index) const override
int get_logical_size() const
Definition: sqltypes.h:325
std::unordered_map< int, std::vector< llvm::Value * > > fetch_cache_
Definition: CgenState.h:330
decltype(FragmentInfoType::fragmentId) const getFragmentId() const
Definition: Execute.h:336
int64_t deviceCycles(int milliseconds) const
Definition: Execute.cpp:3355
std::string generatePTX(const std::string &) const
std::mutex str_dict_mutex_
Definition: Execute.h:1035
bool is_integer() const
Definition: sqltypes.h:491
const Catalog_Namespace::Catalog * catalog_
Definition: Execute.h:1053
friend class PendingExecutionClosure
Definition: Execute.h:1145
void setQuerySessionAsInterrupted(const QuerySessionId &query_session, mapd_unique_lock< mapd_shared_mutex > &write_lock)
Definition: Execute.cpp:4107
static const int32_t ERR_OUT_OF_RENDER_MEM
Definition: Execute.h:1112
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:900
std::shared_timed_mutex mapd_shared_mutex
const std::string debug_file_
Definition: Execute.h:1050
ResultSetPtr collectAllDeviceShardedTopResults(SharedKernelContext &shared_context, const RelAlgExecutionUnit &ra_exe_unit) const
Definition: Execute.cpp:1970
CachedCardinality getCachedCardinality(const std::string &cache_key)
Definition: Execute.cpp:4176
decltype(FragmentInfoType::physicalTableId) const getPhysicalTableId() const
Definition: Execute.h:333
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: Execute.h:1025
Used by Fragmenter classes to store info about each fragment - the fragment id and number of tuples(r...
Definition: Fragmenter.h:77
void setColRangeCache(const AggregatedColRange &aggregated_col_range)
Definition: Execute.h:922
bool containsLeftDeepOuterJoin() const
Definition: Execute.h:415
void setCatalog(const Catalog_Namespace::Catalog *catalog)
Definition: Execute.cpp:282
StringDictionaryProxy * getStringDictionaryProxy(const int dict_id, const bool with_generation) const
Definition: Execute.h:400
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:1114
bool is_timeinterval() const
Definition: sqltypes.h:500
static std::unordered_map< std::string, size_t > cardinality_cache_
Definition: Execute.h:1105
static InterruptFlagMap queries_interrupt_flag_
Definition: Execute.h:1074
FragmentInfoType const & getFragmentInfo() const
std::unique_ptr< PlanState > plan_state_
Definition: Execute.h:1024
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:1115
void initializeNVPTXBackend() const
mapd_unique_lock< mapd_shared_mutex > unique_lock
Definition: Execute.h:1087
std::map< int32_t, std::set< int32_t >> TableToFragmentIds
Definition: Execute.h:308
const std::string submitted_time_
Definition: Execute.h:140
const TableGeneration & getTableGeneration(const int table_id) const
Definition: Execute.cpp:298
llvm::Value * castToFP(llvm::Value *, SQLTypeInfo const &from_ti, SQLTypeInfo const &to_ti)
Definition: Execute.cpp:3363
size_t fragment_index_
Definition: Execute.h:348
std::pair< bool, size_t > CachedCardinality
Definition: Execute.h:989
const ColumnDescriptor * getColumnDescriptor(const Analyzer::ColumnVar *) const
Definition: Execute.cpp:261
static const int32_t ERR_UNSUPPORTED_SELF_JOIN
Definition: Execute.h:1111
const unsigned block_size_x_
Definition: Execute.h:1046
const unsigned grid_size_x_
Definition: Execute.h:1047
specifies the content in-memory of a row in the column metadata table
bool is_boolean() const
Definition: sqltypes.h:496
std::vector< TargetValue > getTranslatedEntryAt(const size_t index) const override
static const int32_t ERR_SINGLE_VALUE_FOUND_MULTIPLE_VALUES
Definition: Execute.h:1121
static std::map< int, std::shared_ptr< Executor > > executors_
Definition: Execute.h:1078
static const int32_t ERR_OUT_OF_GPU_MEM
Definition: Execute.h:1109
const TemporaryTables * getTemporaryTables()
Definition: Execute.h:395
std::string get_null_check_suffix(const SQLTypeInfo &lhs_ti, const SQLTypeInfo &rhs_ti)
Definition: Execute.h:1155
JoinHashTableOrError buildHashTableForQualifier(const std::shared_ptr< Analyzer::BinOper > &qual_bin_oper, const std::vector< InputTableInfo > &query_infos, const MemoryLevel memory_level, const HashType preferred_hash_type, ColumnCacheMap &column_cache, const RegisteredQueryHint &query_hint)
Definition: Execute.cpp:3287
static void addCodeToCache(const CodeCacheKey &, std::shared_ptr< CompilationContext >, llvm::Module *, CodeCache &)
const Catalog_Namespace::Catalog * getCatalog() const
Definition: Execute.cpp:278
#define RUNTIME_EXPORT
std::unordered_map< int, std::unordered_map< int, std::shared_ptr< const ColumnarResults >>> ColumnCacheMap
bool updateQuerySessionExecutorAssignment(const QuerySessionId &query_session, const std::string &submitted_time_str, const size_t executor_id, mapd_unique_lock< mapd_shared_mutex > &write_lock)
Definition: Execute.cpp:4047
ColumnToFragmentsMap columns_for_metadata_update
Definition: Execute.h:311
#define CHECK_LT(x, y)
Definition: Logger.h:213
ResultSetPtr resultsUnion(SharedKernelContext &shared_context, const RelAlgExecutionUnit &ra_exe_unit)
Definition: Execute.cpp:872
static QuerySessionId current_query_session_
Definition: Execute.h:1070
std::shared_ptr< ResultSet > rs_
Definition: Execute.h:349
std::vector< size_t > getFragmentCount(const FragmentsList &selected_fragments, const size_t scan_idx, const RelAlgExecutionUnit &ra_exe_unit)
Definition: Execute.cpp:2744
llvm::BasicBlock * codegenSkipDeletedOuterTableRow(const RelAlgExecutionUnit &ra_exe_unit, const CompilationOptions &co)
std::unique_ptr< QueryCompilationDescriptor > QueryCompilationDescriptorOwned
Definition: Execute.h:76
size_t ExecutorId
Definition: Execute.h:365
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:322
std::vector< int8_t > serializeLiterals(const std::unordered_map< int, CgenState::LiteralValues > &literals, const int device_id)
Definition: Execute.cpp:383
InputTableInfoCache input_table_info_cache_
Definition: Execute.h:1065
const Expr * get_operand() const
Definition: Analyzer.h:371
void codegenWindowFunctionStateInit(llvm::Value *aggregate_state)
void launchKernels(SharedKernelContext &shared_context, std::vector< std::unique_ptr< ExecutionKernel >> &&kernels)
CodeCache cpu_code_cache_
Definition: Execute.h:1039
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:3546
unsigned gridSize() const
Definition: Execute.cpp:3324
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:2337
StringDictionaryGenerations computeStringDictionaryGenerations(const std::unordered_set< PhysicalInput > &phys_inputs)
Definition: Execute.cpp:3771
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:2405
void updateQuerySessionStatus(std::shared_ptr< const query_state::QueryState > &query_state, const QuerySessionStatus::QueryStatus new_query_status)
Definition: Execute.cpp:3921
void setExecutorId(const size_t executor_id)
Definition: Execute.h:131
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)
Definition: Execute.cpp:2842
FragmentInfoType const & fragment_info_
Definition: Execute.h:347
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:3247
const std::string getQueryStr()
Definition: Execute.h:124
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:3712
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:2758
llvm::Value * codegenAggregateWindowState()
TableGenerations table_generations_
Definition: Execute.h:1067
void unregisterActiveModule(void *module, const int device_id) const
std::function< void(ResultSetPtr, const Fragmenter_Namespace::FragmentInfo &)> PerFragmentCallBack
Definition: Execute.h:537
void resetInterrupt()
mapd_shared_lock< mapd_shared_mutex > read_lock
const size_t getExecutorId()
Definition: Execute.h:125
size_t executor_id_
Definition: Execute.h:138
size_t getRunningExecutorId(mapd_shared_lock< mapd_shared_mutex > &read_lock)
Definition: Execute.cpp:3836
bool removeFromQuerySessionList(const QuerySessionId &query_session, const std::string &submitted_time_str, mapd_unique_lock< mapd_shared_mutex > &write_lock)
Definition: Execute.cpp:4072
std::string QuerySessionId
Definition: Execute.h:79
llvm::Value * addJoinLoopIterator(const std::vector< llvm::Value * > &prev_iters, const size_t level_idx)
Definition: IRCodegen.cpp:806
ResultSetPtr reduceMultiDeviceResultSets(std::vector< std::pair< ResultSetPtr, std::vector< size_t >>> &all_fragment_results, std::shared_ptr< RowSetMemoryOwner >, const QueryMemoryDescriptor &) const
Definition: Execute.cpp:947
llvm::Value * codegenWindowFunctionAggregate(const CompilationOptions &co)
void addToCardinalityCache(const std::string &cache_key, const size_t cache_value)
Definition: Execute.cpp:4167
static std::atomic< bool > interrupted_
Definition: Execute.h:1033
#define CHECK(condition)
Definition: Logger.h:203
static const int32_t ERR_OUT_OF_SLOTS
Definition: Execute.h:1110
void clearQuerySessionStatus(const QuerySessionId &query_session, const std::string &submitted_time_str, const bool acquire_spin_lock)
Definition: Execute.cpp:3897
static std::mutex compilation_mutex_
Definition: Execute.h:1124
void interrupt(const QuerySessionId &query_session="", const QuerySessionId &interrupt_session="")
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:2431
mapd_shared_lock< mapd_shared_mutex > shared_lock
Definition: Execute.h:1086
static size_t running_query_executor_id_
Definition: Execute.h:1072
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:1417
std::unordered_map< int, const Analyzer::BinOper * > getInnerTabIdToJoinCond() const
Definition: Execute.cpp:2020
ExecutorDeviceType getDeviceTypeForTargets(const RelAlgExecutionUnit &ra_exe_unit, const ExecutorDeviceType requested_device_type)
Definition: Execute.cpp:1722
JoinLoop::HoistedFiltersCallback buildHoistLeftHandSideFiltersCb(const RelAlgExecutionUnit &ra_exe_unit, const size_t level_idx, const int inner_table_id, const CompilationOptions &co)
Definition: IRCodegen.cpp:492
Executor(const ExecutorId id, 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:144
uint32_t log2_bytes(const uint32_t bytes)
Definition: Execute.h:177
ExpressionRange getColRange(const PhysicalInput &) const
Definition: Execute.cpp:302
std::string numeric_type_name(const SQLTypeInfo &ti)
Definition: Execute.h:210
CurrentQueryStatus attachExecutorToQuerySession(const QuerySessionId &query_session_id, const std::string &query_str, const std::string &query_submitted_time)
Definition: Execute.cpp:3854
mapd_unique_lock< mapd_shared_mutex > write_lock
void redeclareFilterFunction()
Definition: IRCodegen.cpp:708
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:112
UpdateLogForFragment(FragmentInfoType const &fragment_info, size_t const, const std::shared_ptr< ResultSet > &rs)
bool is_unnest(const Analyzer::Expr *expr)
Definition: Execute.h:1171
bool is_string() const
Definition: sqltypes.h:489
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:279
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:600
auto getResultSet() const
Definition: Execute.h:344
unsigned blockSize() const
Definition: Execute.cpp:3341
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:321
std::unordered_map< int, std::vector< llvm::Value * > > saved_fetch_cache
Definition: Execute.h:1019
static size_t align(const size_t off_in, const size_t alignment)
Definition: Execute.h:1001
std::unique_ptr< QueryMemoryDescriptor > QueryMemoryDescriptorOwned
Definition: Execute.h:78
size_t const getRowCount() const override
const QuerySessionId getQuerySession()
Definition: Execute.h:123
static const int32_t ERR_OUT_OF_CPU_MEM
Definition: Execute.h:1113
QuerySessionStatus::QueryStatus query_status_
Definition: Execute.h:147
bool is_decimal() const
Definition: sqltypes.h:492
int deviceCountForMemoryLevel(const Data_Namespace::MemoryLevel memory_level) const
Definition: Execute.cpp:655
void setCurrentQuerySession(const QuerySessionId &query_session, mapd_unique_lock< mapd_shared_mutex > &write_lock)
Definition: Execute.cpp:3824
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:317
bool is_rt_udf_module_present(bool cpu_only=false)
static size_t getArenaBlockSize()
Definition: Execute.cpp:210
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:1350
std::mutex gpu_exec_mutex_[max_gpu_count]
Definition: Execute.h:1028
HashType
Definition: HashTable.h:19
DEVICE void swap(ARGS &&...args)
Definition: gpu_enabled.h:114
static mapd_shared_mutex recycler_mutex_
Definition: Execute.h:1104
llvm::Value * codegenWindowFunction(const size_t target_index, const CompilationOptions &co)
SQLOps get_optype() const
Definition: Analyzer.h:370
WindowFunctionContext * active_window_function_
Definition: Execute.h:1063
static std::mutex gpu_active_modules_mutex_
Definition: Execute.h:1030
void setupCaching(const std::unordered_set< PhysicalInput > &phys_inputs, const std::unordered_set< int > &phys_table_ids)
Definition: Execute.cpp:3804
static void nukeCacheOfExecutors()
Definition: Execute.h:381
void clearMetaInfoCache()
Definition: Execute.cpp:377
const ColumnDescriptor * get_column_descriptor(const int col_id, const int table_id, const Catalog_Namespace::Catalog &cat)
Definition: Execute.h:192
void createErrorCheckControlFlow(llvm::Function *query_func, bool run_with_dynamic_watchdog, bool run_with_allowing_runtime_interrupt, ExecutorDeviceType device_type, const std::vector< InputTableInfo > &input_table_infos)
size_t const getEntryCount() const override
llvm::BasicBlock * codegenWindowResetStateControlFlow()
const TemporaryTables * temporary_tables_
Definition: Execute.h:1054
CompilationRetryNewScanLimit(const size_t new_scan_limit)
Definition: Execute.h:269
WatchdogException(const std::string &cause)
Definition: Execute.h:162
static const ExecutorId UNITARY_EXECUTOR_ID
Definition: Execute.h:366
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:2247
ResultSetPtr executeExplain(const QueryCompilationDescriptor &)
Definition: Execute.cpp:1718