OmniSciDB  21ac014ffc
 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 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"
63 
64 #include "DataMgr/Chunk/Chunk.h"
65 #include "Logger/Logger.h"
67 #include "Shared/funcannotations.h"
69 #include "Shared/measure.h"
70 #include "Shared/thread_count.h"
71 #include "Shared/toString.h"
76 
77 using QueryCompilationDescriptorOwned = std::unique_ptr<QueryCompilationDescriptor>;
79 using QueryMemoryDescriptorOwned = std::unique_ptr<QueryMemoryDescriptor>;
80 using QuerySessionId = std::string;
81 using CurrentQueryStatus = std::pair<QuerySessionId, std::string>;
82 using InterruptFlagMap = std::map<QuerySessionId, bool>;
84  // A class that is used to describe the query session's info
85  public:
86  /* todo(yoonmin): support more query status
87  * i.e., RUNNING_SORT, RUNNING_CARD_EST, CLEANUP, ... */
88  enum QueryStatus {
89  UNDEFINED = 0,
94  };
95 
96  QuerySessionStatus(const QuerySessionId& query_session,
97  const std::string& query_str,
98  const std::string& submitted_time)
99  : query_session_(query_session)
100  , executor_id_(0)
101  , query_str_(query_str)
102  , submitted_time_(submitted_time)
104  QuerySessionStatus(const QuerySessionId& query_session,
105  const size_t executor_id,
106  const std::string& query_str,
107  const std::string& submitted_time)
108  : query_session_(query_session)
109  , executor_id_(executor_id)
110  , query_str_(query_str)
111  , submitted_time_(submitted_time)
113  QuerySessionStatus(const QuerySessionId& query_session,
114  const size_t executor_id,
115  const std::string& query_str,
116  const std::string& submitted_time,
117  const QuerySessionStatus::QueryStatus& query_status)
118  : query_session_(query_session)
119  , executor_id_(executor_id)
120  , query_str_(query_str)
121  , submitted_time_(submitted_time)
122  , query_status_(query_status) {}
123 
125  const std::string getQueryStr() { return query_str_; }
126  const size_t getExecutorId() { return executor_id_; }
127  const std::string& getQuerySubmittedTime() { return submitted_time_; }
130  query_status_ = status;
131  }
132  void setExecutorId(const size_t executor_id) { executor_id_ = executor_id; }
134  query_status_ = QuerySessionStatus::QueryStatus::RUNNING;
135  }
136 
137  private:
139  size_t executor_id_;
140  const std::string query_str_;
141  const std::string submitted_time_;
142  // Currently we use three query status:
143  // 1) PENDING_IN_QUEUE: a task is submitted to the dispatch_queue but hangs due to no
144  // existing worker (= executor) 2) PENDING_IN_EXECUTOR: a task is assigned to the
145  // specific executor but waits to get the resource to run 3) RUNNING: a task is assigned
146  // to the specific executor and its execution has been successfully started
147  // 4) RUNNING_REDUCTION: a task is in the reduction phase
149 };
150 using QuerySessionMap =
151  std::map<const QuerySessionId, std::map<std::string, QuerySessionStatus>>;
152 
153 extern void read_rt_udf_gpu_module(const std::string& udf_ir);
154 extern void read_rt_udf_cpu_module(const std::string& udf_ir);
155 extern bool is_rt_udf_module_present(bool cpu_only = false);
156 
157 class ColumnFetcher;
158 
159 class WatchdogException : public std::runtime_error {
160  public:
161  WatchdogException(const std::string& cause) : std::runtime_error(cause) {}
162 };
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 // TODO(alex): Adjust interfaces downstream and make this not needed.
251 inline std::vector<Analyzer::Expr*> get_exprs_not_owned(
252  const std::vector<std::shared_ptr<Analyzer::Expr>>& exprs) {
253  std::vector<Analyzer::Expr*> exprs_not_owned;
254  for (const auto& expr : exprs) {
255  exprs_not_owned.push_back(expr.get());
256  }
257  return exprs_not_owned;
258 }
259 
260 class CompilationRetryNoLazyFetch : public std::runtime_error {
261  public:
263  : std::runtime_error("Retry query compilation with no GPU lazy fetch.") {}
264 };
265 
266 class CompilationRetryNewScanLimit : public std::runtime_error {
267  public:
268  CompilationRetryNewScanLimit(const size_t new_scan_limit)
269  : std::runtime_error("Retry query compilation with new scan limit.")
270  , new_scan_limit_(new_scan_limit) {}
271 
273 };
274 
275 class TooManyLiterals : public std::runtime_error {
276  public:
277  TooManyLiterals() : std::runtime_error("Too many literals in the query") {}
278 };
279 
280 class CompilationRetryNoCompaction : public std::runtime_error {
281  public:
283  : std::runtime_error("Retry query compilation with no compaction.") {}
284 };
285 
286 class QueryMustRunOnCpu : public std::runtime_error {
287  public:
288  QueryMustRunOnCpu() : std::runtime_error("Query must run in cpu mode.") {}
289 
290  QueryMustRunOnCpu(const std::string& err) : std::runtime_error(err) {}
291 };
292 
293 class ParseIRError : public std::runtime_error {
294  public:
295  ParseIRError(const std::string message) : std::runtime_error(message) {}
296 };
297 
298 class StringConstInResultSet : public std::runtime_error {
299  public:
301  : std::runtime_error(
302  "NONE ENCODED String types are not supported as input result set.") {}
303 };
304 
305 class ExtensionFunction;
306 
308 using ColumnToFragmentsMap = std::map<const ColumnDescriptor*, std::set<int32_t>>;
309 using TableToFragmentIds = std::map<int32_t, std::set<int32_t>>;
310 
314 };
315 
317  public:
319 
320  UpdateLogForFragment(FragmentInfoType const& fragment_info,
321  size_t const,
322  const std::shared_ptr<ResultSet>& rs);
323 
324  std::vector<TargetValue> getEntryAt(const size_t index) const override;
325  std::vector<TargetValue> getTranslatedEntryAt(const size_t index) const override;
326 
327  size_t const getRowCount() const override;
329  return rs_->getRowSetMemOwner()->getLiteralStringDictProxy();
330  }
331  size_t const getEntryCount() const override;
332  size_t const getFragmentIndex() const;
333  FragmentInfoType const& getFragmentInfo() const;
336  }
338  return fragment_info_.fragmentId;
339  }
340 
341  SQLTypeInfo getColumnType(const size_t col_idx) const;
342 
343  using Callback = std::function<void(const UpdateLogForFragment&, TableUpdateMetadata&)>;
344 
345  auto getResultSet() const { return rs_; }
346 
347  private:
350  std::shared_ptr<ResultSet> rs_;
351 };
352 
353 using LLVMValueVector = std::vector<llvm::Value*>;
354 
356 
357 std::ostream& operator<<(std::ostream&, FetchResult const&);
358 
359 class Executor {
360  static_assert(sizeof(float) == 4 && sizeof(double) == 8,
361  "Host hardware not supported, unexpected size of float / double.");
362  static_assert(sizeof(time_t) == 8,
363  "Host hardware not supported, 64-bit time support is required.");
364 
365  public:
366  using ExecutorId = size_t;
367  static const ExecutorId UNITARY_EXECUTOR_ID = 0;
368 
369  Executor(const ExecutorId id,
370  Data_Namespace::DataMgr* data_mgr,
371  const size_t block_size_x,
372  const size_t grid_size_x,
373  const size_t max_gpu_slab_size,
374  const std::string& debug_dir,
375  const std::string& debug_file);
376 
377  static std::shared_ptr<Executor> getExecutor(
378  const ExecutorId id,
379  const std::string& debug_dir = "",
380  const std::string& debug_file = "",
381  const SystemParameters& system_parameters = SystemParameters());
382 
383  static void nukeCacheOfExecutors() {
384  mapd_unique_lock<mapd_shared_mutex> flush_lock(
385  execute_mutex_); // don't want native code to vanish while executing
386  mapd_unique_lock<mapd_shared_mutex> lock(executors_cache_mutex_);
387  (decltype(executors_){}).swap(executors_);
388  }
389 
390  static void clearMemory(const Data_Namespace::MemoryLevel memory_level);
391 
392  static size_t getArenaBlockSize();
393 
394  static void addUdfIrToModule(const std::string& udf_ir_filename, const bool is_cuda_ir);
395 
400 
405  const bool with_generation) const {
407  return getStringDictionaryProxy(dict_id, row_set_mem_owner_, with_generation);
408  }
409 
411  const int dictId,
412  const std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
413  const bool with_generation) const;
414 
415  bool isCPUOnly() const;
416 
417  bool isArchMaxwell(const ExecutorDeviceType dt) const;
418 
420  return cgen_state_->contains_left_deep_outer_join_;
421  }
422 
424 
426  int) const;
427 
428  const Catalog_Namespace::Catalog* getCatalog() const;
429  void setCatalog(const Catalog_Namespace::Catalog* catalog);
430 
432  CHECK(data_mgr_);
433  return data_mgr_;
434  }
435 
436  const std::shared_ptr<RowSetMemoryOwner> getRowSetMemoryOwner() const;
437 
438  const TemporaryTables* getTemporaryTables() const;
439 
440  Fragmenter_Namespace::TableInfo getTableInfo(const int table_id) const;
441 
442  const TableGeneration& getTableGeneration(const int table_id) const;
443 
445 
446  size_t getNumBytesForFetchedRow(const std::set<int>& table_ids_to_fetch) const;
447 
448  std::vector<ColumnLazyFetchInfo> getColLazyFetchInfo(
449  const std::vector<Analyzer::Expr*>& target_exprs) const;
450 
451  void registerActiveModule(void* module, const int device_id) const;
452  void unregisterActiveModule(void* module, const int device_id) const;
453  void interrupt(const QuerySessionId& query_session = "",
454  const QuerySessionId& interrupt_session = "");
455  void resetInterrupt();
456 
457  // only for testing usage
458  void enableRuntimeQueryInterrupt(const double runtime_query_check_freq,
459  const unsigned pending_query_check_freq) const;
460 
461  static const size_t high_scan_limit{32000000};
462 
463  int8_t warpSize() const;
464  unsigned gridSize() const;
465  unsigned numBlocksPerMP() const;
466  unsigned blockSize() const;
467  size_t maxGpuSlabSize() const;
468 
469  ResultSetPtr executeWorkUnit(size_t& max_groups_buffer_entry_guess,
470  const bool is_agg,
471  const std::vector<InputTableInfo>&,
472  const RelAlgExecutionUnit&,
473  const CompilationOptions&,
474  const ExecutionOptions& options,
476  RenderInfo* render_info,
477  const bool has_cardinality_estimation,
478  ColumnCacheMap& column_cache);
479 
481  const std::vector<InputTableInfo>& table_infos,
482  const TableDescriptor* updated_table_desc,
483  const CompilationOptions& co,
484  const ExecutionOptions& eo,
486  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
488  const bool is_agg);
489 
491  const RelAlgExecutionUnit& ra_exe_unit,
492  const std::shared_ptr<RowSetMemoryOwner>& row_set_mem_owner);
493 
494  private:
495  void clearMetaInfoCache();
496 
497  int deviceCount(const ExecutorDeviceType) const;
498  int deviceCountForMemoryLevel(const Data_Namespace::MemoryLevel memory_level) const;
499 
500  // Generate code for a window function target.
501  llvm::Value* codegenWindowFunction(const size_t target_index,
502  const CompilationOptions& co);
503 
504  // Generate code for an aggregate window function target.
505  llvm::Value* codegenWindowFunctionAggregate(const CompilationOptions& co);
506 
507  // The aggregate state requires a state reset when starting a new partition. Generate
508  // the new partition check and return the continuation basic block.
509  llvm::BasicBlock* codegenWindowResetStateControlFlow();
510 
511  // Generate code for initializing the state of a window aggregate.
512  void codegenWindowFunctionStateInit(llvm::Value* aggregate_state);
513 
514  // Generates the required calls for an aggregate window function and returns the final
515  // result.
516  llvm::Value* codegenWindowFunctionAggregateCalls(llvm::Value* aggregate_state,
517  const CompilationOptions& co);
518 
519  // The AVG window function requires some post-processing: the sum is divided by count
520  // and the result is stored back for the current row.
521  void codegenWindowAvgEpilogue(llvm::Value* crt_val,
522  llvm::Value* window_func_null_val,
523  llvm::Value* multiplicity_lv);
524 
525  // Generates code which loads the current aggregate value for the window context.
526  llvm::Value* codegenAggregateWindowState();
527 
528  llvm::Value* aggregateWindowStatePtr();
529 
531  CHECK(data_mgr_);
532  auto cuda_mgr = data_mgr_->getCudaMgr();
533  CHECK(cuda_mgr);
534  return cuda_mgr;
535  }
536 
538  if (dt == ExecutorDeviceType::GPU) {
539  return cudaMgr()->isArchPascalOrLater();
540  }
541  return false;
542  }
543 
544  bool needFetchAllFragments(const InputColDescriptor& col_desc,
545  const RelAlgExecutionUnit& ra_exe_unit,
546  const FragmentsList& selected_fragments) const;
547 
549  const InputColDescriptor& inner_col_desc,
550  const RelAlgExecutionUnit& ra_exe_unit,
551  const FragmentsList& selected_fragments,
552  const Data_Namespace::MemoryLevel memory_level) const;
553 
554  using PerFragmentCallBack =
555  std::function<void(ResultSetPtr, const Fragmenter_Namespace::FragmentInfo&)>;
556 
562  void executeWorkUnitPerFragment(const RelAlgExecutionUnit& ra_exe_unit,
563  const InputTableInfo& table_info,
564  const CompilationOptions& co,
565  const ExecutionOptions& eo,
568  const std::set<size_t>& fragment_indexes_param);
569 
571 
578  const std::vector<InputTableInfo>& table_infos,
579  const CompilationOptions& co,
580  const ExecutionOptions& eo,
582 
584  const RelAlgExecutionUnit& ra_exe_unit,
585  const ExecutorDeviceType requested_device_type);
586 
588  SharedKernelContext& shared_context,
589  const RelAlgExecutionUnit& ra_exe_unit,
591  const ExecutorDeviceType device_type,
592  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner);
593 
595  SharedKernelContext& shared_context,
596  const RelAlgExecutionUnit& ra_exe_unit) const;
597 
598  std::unordered_map<int, const Analyzer::BinOper*> getInnerTabIdToJoinCond() const;
599 
604  std::vector<std::unique_ptr<ExecutionKernel>> createKernels(
605  SharedKernelContext& shared_context,
606  const RelAlgExecutionUnit& ra_exe_unit,
607  ColumnFetcher& column_fetcher,
608  const std::vector<InputTableInfo>& table_infos,
609  const ExecutionOptions& eo,
610  const bool is_agg,
611  const bool allow_single_frag_table_opt,
612  const size_t context_count,
613  const QueryCompilationDescriptor& query_comp_desc,
615  RenderInfo* render_info,
616  std::unordered_set<int>& available_gpus,
617  int& available_cpus);
618 
623  template <typename THREAD_POOL>
624  void launchKernels(SharedKernelContext& shared_context,
625  std::vector<std::unique_ptr<ExecutionKernel>>&& kernels);
626 
627  std::vector<size_t> getTableFragmentIndices(
628  const RelAlgExecutionUnit& ra_exe_unit,
629  const ExecutorDeviceType device_type,
630  const size_t table_idx,
631  const size_t outer_frag_idx,
632  std::map<int, const TableFragments*>& selected_tables_fragments,
633  const std::unordered_map<int, const Analyzer::BinOper*>&
634  inner_table_id_to_join_condition);
635 
636  bool skipFragmentPair(const Fragmenter_Namespace::FragmentInfo& outer_fragment_info,
637  const Fragmenter_Namespace::FragmentInfo& inner_fragment_info,
638  const int inner_table_id,
639  const std::unordered_map<int, const Analyzer::BinOper*>&
640  inner_table_id_to_join_condition,
641  const RelAlgExecutionUnit& ra_exe_unit,
642  const ExecutorDeviceType device_type);
643 
645  const RelAlgExecutionUnit& ra_exe_unit,
646  const int device_id,
648  const std::map<int, const TableFragments*>&,
649  const FragmentsList& selected_fragments,
651  std::list<ChunkIter>&,
652  std::list<std::shared_ptr<Chunk_NS::Chunk>>&,
653  DeviceAllocator* device_allocator,
654  const size_t thread_idx,
655  const bool allow_runtime_interrupt);
656 
658  const RelAlgExecutionUnit& ra_exe_unit,
659  const int device_id,
661  const std::map<int, const TableFragments*>&,
662  const FragmentsList& selected_fragments,
664  std::list<ChunkIter>&,
665  std::list<std::shared_ptr<Chunk_NS::Chunk>>&,
666  DeviceAllocator* device_allocator,
667  const size_t thread_idx,
668  const bool allow_runtime_interrupt);
669 
670  std::pair<std::vector<std::vector<int64_t>>, std::vector<std::vector<uint64_t>>>
672  const RelAlgExecutionUnit& ra_exe_unit,
673  const CartesianProduct<std::vector<std::vector<size_t>>>& frag_ids_crossjoin,
674  const std::vector<InputDescriptor>& input_descs,
675  const std::map<int, const TableFragments*>& all_tables_fragments);
676 
678  std::vector<std::vector<size_t>>& selected_fragments_crossjoin,
679  std::vector<size_t>& local_col_to_frag_pos,
680  const std::list<std::shared_ptr<const InputColDescriptor>>& col_global_ids,
681  const FragmentsList& selected_fragments,
682  const RelAlgExecutionUnit& ra_exe_unit);
683 
685  std::vector<std::vector<size_t>>& selected_fragments_crossjoin,
686  std::vector<size_t>& local_col_to_frag_pos,
687  const std::list<std::shared_ptr<const InputColDescriptor>>& col_global_ids,
688  const FragmentsList& selected_fragments,
689  const RelAlgExecutionUnit& ra_exe_unit);
690 
691  std::vector<size_t> getFragmentCount(const FragmentsList& selected_fragments,
692  const size_t scan_idx,
693  const RelAlgExecutionUnit& ra_exe_unit);
694 
695  int32_t executePlanWithGroupBy(const RelAlgExecutionUnit& ra_exe_unit,
696  const CompilationResult&,
697  const bool hoist_literals,
698  ResultSetPtr& results,
699  const ExecutorDeviceType device_type,
700  std::vector<std::vector<const int8_t*>>& col_buffers,
701  const std::vector<size_t> outer_tab_frag_ids,
703  const std::vector<std::vector<int64_t>>& num_rows,
704  const std::vector<std::vector<uint64_t>>& frag_offsets,
706  const int device_id,
707  const int outer_table_id,
708  const int64_t limit,
709  const uint32_t start_rowid,
710  const uint32_t num_tables,
711  const bool allow_runtime_interrupt,
712  RenderInfo* render_info);
714  const RelAlgExecutionUnit& ra_exe_unit,
715  const CompilationResult&,
716  const bool hoist_literals,
717  ResultSetPtr& results,
718  const std::vector<Analyzer::Expr*>& target_exprs,
719  const ExecutorDeviceType device_type,
720  std::vector<std::vector<const int8_t*>>& col_buffers,
721  QueryExecutionContext* query_exe_context,
722  const std::vector<std::vector<int64_t>>& num_rows,
723  const std::vector<std::vector<uint64_t>>& frag_offsets,
724  Data_Namespace::DataMgr* data_mgr,
725  const int device_id,
726  const uint32_t start_rowid,
727  const uint32_t num_tables,
728  const bool allow_runtime_interrupt,
729  RenderInfo* render_info);
730 
731  public: // Temporary, ask saman about this
732  static std::pair<int64_t, int32_t> reduceResults(const SQLAgg agg,
733  const SQLTypeInfo& ti,
734  const int64_t agg_init_val,
735  const int8_t out_byte_width,
736  const int64_t* out_vec,
737  const size_t out_vec_sz,
738  const bool is_group_by,
739  const bool float_argument_input);
740 
741  static void addCodeToCache(const CodeCacheKey&,
742  std::shared_ptr<CompilationContext>,
743  llvm::Module*,
744  CodeCache&);
745 
746  private:
748  const RelAlgExecutionUnit& ra_exe_unit);
749  std::vector<int64_t> getJoinHashTablePtrs(const ExecutorDeviceType device_type,
750  const int device_id);
752  const RelAlgExecutionUnit&,
753  std::vector<std::pair<ResultSetPtr, std::vector<size_t>>>& all_fragment_results,
754  std::shared_ptr<RowSetMemoryOwner>,
755  const QueryMemoryDescriptor&) const;
757  std::vector<std::pair<ResultSetPtr, std::vector<size_t>>>& all_fragment_results,
758  std::shared_ptr<RowSetMemoryOwner>,
759  const QueryMemoryDescriptor&) const;
761  const RelAlgExecutionUnit&,
762  std::vector<std::pair<ResultSetPtr, std::vector<size_t>>>& all_fragment_results,
763  std::shared_ptr<RowSetMemoryOwner>,
764  const QueryMemoryDescriptor&) const;
765 
766  ResultSetPtr executeWorkUnitImpl(size_t& max_groups_buffer_entry_guess,
767  const bool is_agg,
768  const bool allow_single_frag_table_opt,
769  const std::vector<InputTableInfo>&,
770  const RelAlgExecutionUnit&,
771  const CompilationOptions&,
772  const ExecutionOptions& options,
774  std::shared_ptr<RowSetMemoryOwner>,
775  RenderInfo* render_info,
776  const bool has_cardinality_estimation,
777  ColumnCacheMap& column_cache);
778 
779  std::vector<llvm::Value*> inlineHoistedLiterals();
780 
781  std::tuple<CompilationResult, std::unique_ptr<QueryMemoryDescriptor>> compileWorkUnit(
782  const std::vector<InputTableInfo>& query_infos,
783  const PlanState::DeletedColumnsMap& deleted_cols_map,
784  const RelAlgExecutionUnit& ra_exe_unit,
785  const CompilationOptions& co,
786  const ExecutionOptions& eo,
787  const CudaMgr_Namespace::CudaMgr* cuda_mgr,
788  const bool allow_lazy_fetch,
789  std::shared_ptr<RowSetMemoryOwner>,
790  const size_t max_groups_buffer_entry_count,
791  const int8_t crt_min_byte_width,
792  const bool has_cardinality_estimation,
793  ColumnCacheMap& column_cache,
794  RenderInfo* render_info = nullptr);
795  // Generate code to skip the deleted rows in the outermost table.
796  llvm::BasicBlock* codegenSkipDeletedOuterTableRow(
797  const RelAlgExecutionUnit& ra_exe_unit,
798  const CompilationOptions& co);
799  std::vector<JoinLoop> buildJoinLoops(RelAlgExecutionUnit& ra_exe_unit,
800  const CompilationOptions& co,
801  const ExecutionOptions& eo,
802  const std::vector<InputTableInfo>& query_infos,
803  ColumnCacheMap& column_cache);
804  // Create a callback which hoists left hand side filters above the join for left joins,
805  // eliminating extra computation of the probe and matches if the row does not pass the
806  // filters
808  const RelAlgExecutionUnit& ra_exe_unit,
809  const size_t level_idx,
810  const int inner_table_id,
811  const CompilationOptions& co);
812  // Create a callback which generates code which returns true iff the row on the given
813  // level is deleted.
814  std::function<llvm::Value*(const std::vector<llvm::Value*>&, llvm::Value*)>
815  buildIsDeletedCb(const RelAlgExecutionUnit& ra_exe_unit,
816  const size_t level_idx,
817  const CompilationOptions& co);
818  // Builds a join hash table for the provided conditions on the current level.
819  // Returns null iff on failure and provides the reasons in `fail_reasons`.
820  std::shared_ptr<HashJoin> buildCurrentLevelHashTable(
821  const JoinCondition& current_level_join_conditions,
822  RelAlgExecutionUnit& ra_exe_unit,
823  const CompilationOptions& co,
824  const std::vector<InputTableInfo>& query_infos,
825  ColumnCacheMap& column_cache,
826  std::vector<std::string>& fail_reasons);
828  llvm::Value* addJoinLoopIterator(const std::vector<llvm::Value*>& prev_iters,
829  const size_t level_idx);
830  void codegenJoinLoops(const std::vector<JoinLoop>& join_loops,
831  const RelAlgExecutionUnit& ra_exe_unit,
832  GroupByAndAggregate& group_by_and_aggregate,
833  llvm::Function* query_func,
834  llvm::BasicBlock* entry_bb,
836  const CompilationOptions& co,
837  const ExecutionOptions& eo);
838  bool compileBody(const RelAlgExecutionUnit& ra_exe_unit,
839  GroupByAndAggregate& group_by_and_aggregate,
841  const CompilationOptions& co,
842  const GpuSharedMemoryContext& gpu_smem_context = {});
843 
844  void createErrorCheckControlFlow(llvm::Function* query_func,
845  bool run_with_dynamic_watchdog,
846  bool run_with_allowing_runtime_interrupt,
847  ExecutorDeviceType device_type,
848  const std::vector<InputTableInfo>& input_table_infos);
849 
850  void insertErrorCodeChecker(llvm::Function* query_func,
851  bool hoist_literals,
852  bool allow_runtime_query_interrupt);
853 
854  void preloadFragOffsets(const std::vector<InputDescriptor>& input_descs,
855  const std::vector<InputTableInfo>& query_infos);
856 
858  std::shared_ptr<HashJoin> hash_table;
859  std::string fail_reason;
860  };
861 
863  const std::shared_ptr<Analyzer::BinOper>& qual_bin_oper,
864  const std::vector<InputTableInfo>& query_infos,
865  const MemoryLevel memory_level,
866  const JoinType join_type,
867  const HashType preferred_hash_type,
868  ColumnCacheMap& column_cache,
869  const RegisteredQueryHint& query_hint);
870  void nukeOldState(const bool allow_lazy_fetch,
871  const std::vector<InputTableInfo>& query_infos,
872  const PlanState::DeletedColumnsMap& deleted_cols_map,
873  const RelAlgExecutionUnit* ra_exe_unit);
874 
875  std::shared_ptr<CompilationContext> optimizeAndCodegenCPU(
876  llvm::Function*,
877  llvm::Function*,
878  const std::unordered_set<llvm::Function*>&,
879  const CompilationOptions&);
880  std::shared_ptr<CompilationContext> optimizeAndCodegenGPU(
881  llvm::Function*,
882  llvm::Function*,
883  std::unordered_set<llvm::Function*>&,
884  const bool no_inline,
885  const CudaMgr_Namespace::CudaMgr* cuda_mgr,
886  const CompilationOptions&);
887  std::string generatePTX(const std::string&) const;
888  void initializeNVPTXBackend() const;
889 
890  int64_t deviceCycles(int milliseconds) const;
891 
893  llvm::Value* translated_value;
894  llvm::Value* original_value;
895  };
896 
898  const size_t col_width,
899  const CompilationOptions&,
900  const bool translate_null_val,
901  const int64_t translated_null_val,
903  std::stack<llvm::BasicBlock*>&,
904  const bool thread_mem_shared);
905 
906  llvm::Value* castToFP(llvm::Value*,
907  SQLTypeInfo const& from_ti,
908  SQLTypeInfo const& to_ti);
909  llvm::Value* castToIntPtrTyIn(llvm::Value* val, const size_t bit_width);
910 
911  std::tuple<RelAlgExecutionUnit, PlanState::DeletedColumnsMap> addDeletedColumn(
912  const RelAlgExecutionUnit& ra_exe_unit,
913  const CompilationOptions& co);
914 
915  bool isFragmentFullyDeleted(const int table_id,
916  const Fragmenter_Namespace::FragmentInfo& fragment);
917 
918  std::pair<bool, int64_t> skipFragment(
919  const InputDescriptor& table_desc,
920  const Fragmenter_Namespace::FragmentInfo& frag_info,
921  const std::list<std::shared_ptr<Analyzer::Expr>>& simple_quals,
922  const std::vector<uint64_t>& frag_offsets,
923  const size_t frag_idx);
924 
925  std::pair<bool, int64_t> skipFragmentInnerJoins(
926  const InputDescriptor& table_desc,
927  const RelAlgExecutionUnit& ra_exe_unit,
928  const Fragmenter_Namespace::FragmentInfo& fragment,
929  const std::vector<uint64_t>& frag_offsets,
930  const size_t frag_idx);
931 
933  const std::unordered_set<PhysicalInput>& phys_inputs);
935  const std::unordered_set<PhysicalInput>& phys_inputs);
936  TableGenerations computeTableGenerations(std::unordered_set<int> phys_table_ids);
937 
938  public:
939  void setupCaching(const std::unordered_set<PhysicalInput>& phys_inputs,
940  const std::unordered_set<int>& phys_table_ids);
941  void setColRangeCache(const AggregatedColRange& aggregated_col_range) {
942  agg_col_range_cache_ = aggregated_col_range;
943  }
944 
945  QuerySessionId& getCurrentQuerySession(mapd_shared_lock<mapd_shared_mutex>& read_lock);
946  size_t getRunningExecutorId(mapd_shared_lock<mapd_shared_mutex>& read_lock);
947  void setCurrentQuerySession(const QuerySessionId& query_session,
948  mapd_unique_lock<mapd_shared_mutex>& write_lock);
949  void setRunningExecutorId(const size_t id,
950  mapd_unique_lock<mapd_shared_mutex>& write_lock);
951  bool checkCurrentQuerySession(const std::string& candidate_query_session,
952  mapd_shared_lock<mapd_shared_mutex>& read_lock);
953  void invalidateRunningQuerySession(mapd_unique_lock<mapd_shared_mutex>& write_lock);
954  bool addToQuerySessionList(const QuerySessionId& query_session,
955  const std::string& query_str,
956  const std::string& submitted,
957  const size_t executor_id,
958  const QuerySessionStatus::QueryStatus query_status,
959  mapd_unique_lock<mapd_shared_mutex>& write_lock);
960  bool removeFromQuerySessionList(const QuerySessionId& query_session,
961  const std::string& submitted_time_str,
962  mapd_unique_lock<mapd_shared_mutex>& write_lock);
963  void setQuerySessionAsInterrupted(const QuerySessionId& query_session,
964  mapd_unique_lock<mapd_shared_mutex>& write_lock);
965  void resetQuerySessionInterruptFlag(const std::string& query_session,
966  mapd_unique_lock<mapd_shared_mutex>& write_lock);
967  bool checkIsQuerySessionInterrupted(const std::string& query_session,
968  mapd_shared_lock<mapd_shared_mutex>& read_lock);
970  bool checkIsQuerySessionEnrolled(const QuerySessionId& query_session,
971  mapd_shared_lock<mapd_shared_mutex>& read_lock);
973  const QuerySessionId& query_session,
974  const std::string& submitted_time_str,
975  const QuerySessionStatus::QueryStatus updated_query_status,
976  mapd_unique_lock<mapd_shared_mutex>& write_lock);
978  const QuerySessionId& query_session,
979  const std::string& submitted_time_str,
980  const size_t executor_id,
981  mapd_unique_lock<mapd_shared_mutex>& write_lock);
982  std::vector<QuerySessionStatus> getQuerySessionInfo(
983  const QuerySessionId& query_session,
984  mapd_shared_lock<mapd_shared_mutex>& read_lock);
985 
988  const QuerySessionId& query_session_id,
989  const std::string& query_str,
990  const std::string& query_submitted_time);
991  void checkPendingQueryStatus(const QuerySessionId& query_session);
992  void clearQuerySessionStatus(const QuerySessionId& query_session,
993  const std::string& submitted_time_str,
994  const bool acquire_spin_lock);
996  std::shared_ptr<const query_state::QueryState>& query_state,
997  const QuerySessionStatus::QueryStatus new_query_status);
998  void updateQuerySessionStatus(const QuerySessionId& query_session,
999  const std::string& submitted_time_str,
1000  const QuerySessionStatus::QueryStatus new_query_status);
1001  void enrollQuerySession(const QuerySessionId& query_session,
1002  const std::string& query_str,
1003  const std::string& submitted_time_str,
1004  const size_t executor_id,
1005  const QuerySessionStatus::QueryStatus query_session_status);
1006 
1007  // true when we have matched cardinality, and false otherwise
1008  using CachedCardinality = std::pair<bool, size_t>;
1009  void addToCardinalityCache(const std::string& cache_key, const size_t cache_value);
1010  CachedCardinality getCachedCardinality(const std::string& cache_key);
1011 
1015  JoinColumnSide target_side,
1016  bool extract_only_col_id);
1017 
1018  private:
1019  std::shared_ptr<CompilationContext> getCodeFromCache(const CodeCacheKey&,
1020  const CodeCache&);
1021 
1022  std::vector<int8_t> serializeLiterals(
1023  const std::unordered_map<int, CgenState::LiteralValues>& literals,
1024  const int device_id);
1025 
1026  static size_t align(const size_t off_in, const size_t alignment) {
1027  size_t off = off_in;
1028  if (off % alignment != 0) {
1029  off += (alignment - off % alignment);
1030  }
1031  return off;
1032  }
1033 
1034  std::unique_ptr<CgenState> cgen_state_;
1035 
1037  public:
1039  : cgen_state_(cgen_state), saved_fetch_cache(cgen_state_->fetch_cache_) {}
1041 
1042  private:
1044  std::unordered_map<int, std::vector<llvm::Value*>> saved_fetch_cache;
1045  };
1046 
1047  llvm::Value* spillDoubleElement(llvm::Value* elem_val, llvm::Type* elem_ty);
1048 
1049  std::unique_ptr<PlanState> plan_state_;
1050  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner_;
1051 
1052  static const int max_gpu_count{16};
1054 
1055  static std::mutex gpu_active_modules_mutex_;
1058  static std::atomic<bool> interrupted_;
1059 
1060  mutable std::mutex str_dict_mutex_;
1061 
1062  mutable std::unique_ptr<llvm::TargetMachine> nvptx_target_machine_;
1063 
1066 
1067  static const size_t baseline_threshold{
1068  1000000}; // if a perfect hash needs more entries, use baseline
1069  static const size_t code_cache_size{1000};
1070 
1071  const unsigned block_size_x_;
1072  const unsigned grid_size_x_;
1073  const size_t max_gpu_slab_size_;
1074  const std::string debug_dir_;
1075  const std::string debug_file_;
1076 
1081 
1084 
1085  // Singleton instance used for an execution unit which is a project with window
1086  // functions.
1087  std::unique_ptr<WindowProjectNodeContext> window_project_node_context_owned_;
1088  // The active window function.
1090 
1095  // a query session that currently is running
1097  // an executor's id that executes the running query
1099  // a pair of <QuerySessionId, interrupted_flag>
1101  // a pair of <QuerySessionId, query_session_status>
1103 
1104  static std::map<int, std::shared_ptr<Executor>> executors_;
1105  static std::atomic_flag execute_spin_lock_;
1106 
1107  // SQL queries take a shared lock, exclusive options (cache clear, memory clear) take a
1108  // write lock
1110 
1112  mapd_shared_lock<mapd_shared_mutex> shared_lock;
1113  mapd_unique_lock<mapd_shared_mutex> unique_lock;
1114  };
1116  ExecutorMutexHolder ret;
1118  // Only one unitary executor can run at a time
1119  ret.unique_lock = mapd_unique_lock<mapd_shared_mutex>(execute_mutex_);
1120  } else {
1121  ret.shared_lock = mapd_shared_lock<mapd_shared_mutex>(execute_mutex_);
1122  }
1123  return ret;
1124  }
1125 
1127 
1129  const QueryPlanHash INVALID_QUERY_PLAN_HASH{std::hash<std::string>{}(EMPTY_QUERY_PLAN)};
1131  static std::unordered_map<std::string, size_t> cardinality_cache_;
1132 
1133  public:
1134  static const int32_t ERR_DIV_BY_ZERO{1};
1135  static const int32_t ERR_OUT_OF_GPU_MEM{2};
1136  static const int32_t ERR_OUT_OF_SLOTS{3};
1137  static const int32_t ERR_UNSUPPORTED_SELF_JOIN{4};
1138  static const int32_t ERR_OUT_OF_RENDER_MEM{5};
1139  static const int32_t ERR_OUT_OF_CPU_MEM{6};
1140  static const int32_t ERR_OVERFLOW_OR_UNDERFLOW{7};
1141  static const int32_t ERR_OUT_OF_TIME{9};
1142  static const int32_t ERR_INTERRUPTED{10};
1143  static const int32_t ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED{11};
1144  static const int32_t ERR_TOO_MANY_LITERALS{12};
1145  static const int32_t ERR_STRING_CONST_IN_RESULTSET{13};
1147  static const int32_t ERR_SINGLE_VALUE_FOUND_MULTIPLE_VALUES{15};
1148  static const int32_t ERR_GEOS{16};
1149 
1150  static std::mutex compilation_mutex_;
1151  static std::mutex kernel_mutex_;
1152 
1154  friend class CodeGenerator;
1155  friend class ColumnFetcher;
1156  friend struct DiamondCodegen; // cgen_state_
1157  friend class ExecutionKernel;
1158  friend class HashJoin; // cgen_state_
1160  friend class GroupByAndAggregate;
1166  friend class ResultSet;
1167  friend class InValuesBitmap;
1168  friend class LeafAggregator;
1169  friend class PerfectJoinHashTable;
1170  friend class QueryRewriter;
1172  friend class RelAlgExecutor;
1173  friend class TableOptimizer;
1177  friend struct TargetExprCodegen;
1179 };
1180 
1181 inline std::string get_null_check_suffix(const SQLTypeInfo& lhs_ti,
1182  const SQLTypeInfo& rhs_ti) {
1183  if (lhs_ti.get_notnull() && rhs_ti.get_notnull()) {
1184  return "";
1185  }
1186  std::string null_check_suffix{"_nullable"};
1187  if (lhs_ti.get_notnull()) {
1188  CHECK(!rhs_ti.get_notnull());
1189  null_check_suffix += "_rhs";
1190  } else if (rhs_ti.get_notnull()) {
1191  CHECK(!lhs_ti.get_notnull());
1192  null_check_suffix += "_lhs";
1193  }
1194  return null_check_suffix;
1195 }
1196 
1197 inline bool is_unnest(const Analyzer::Expr* expr) {
1198  return dynamic_cast<const Analyzer::UOper*>(expr) &&
1199  static_cast<const Analyzer::UOper*>(expr)->get_optype() == kUNNEST;
1200 }
1201 
1202 inline bool is_constructed_point(const Analyzer::Expr* expr) {
1203  auto uoper = dynamic_cast<const Analyzer::UOper*>(expr);
1204  auto oper = (uoper && uoper->get_optype() == kCAST) ? uoper->get_operand() : expr;
1205  auto arr = dynamic_cast<const Analyzer::ArrayExpr*>(oper);
1206  return (arr && arr->isLocalAlloc() && arr->get_type_info().is_fixlen_array());
1207 }
1208 
1209 bool is_trivial_loop_join(const std::vector<InputTableInfo>& query_infos,
1210  const RelAlgExecutionUnit& ra_exe_unit);
1211 
1212 std::unordered_set<int> get_available_gpus(const Catalog_Namespace::Catalog& cat);
1213 
1214 size_t get_context_count(const ExecutorDeviceType device_type,
1215  const size_t cpu_count,
1216  const size_t gpu_count);
1217 
1218 extern "C" RUNTIME_EXPORT void register_buffer_with_executor_rsm(int64_t exec,
1219  int8_t* buffer);
1220 
1222 
1223 #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:4087
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:208
const std::string debug_dir_
Definition: Execute.h:1074
QuerySessionId & getCurrentQuerySession(mapd_shared_lock< mapd_shared_mutex > &read_lock)
Definition: Execute.cpp:3885
llvm::Value * translated_value
Definition: Execute.h:893
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:1601
bool is_agg(const Analyzer::Expr *expr)
static mapd_shared_mutex executor_session_mutex_
Definition: Execute.h:1094
AggregatedColRange computeColRangesCache(const std::unordered_set< PhysicalInput > &phys_inputs)
Definition: Execute.cpp:3796
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:669
void enableRuntimeQueryInterrupt(const double runtime_query_check_freq, const unsigned pending_query_check_freq) const
Definition: Execute.cpp:4218
SQLAgg
Definition: sqldefs.h:71
#define CHECK_EQ(x, y)
Definition: Logger.h:214
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:2098
void resetQuerySessionInterruptFlag(const std::string &query_session, mapd_unique_lock< mapd_shared_mutex > &write_lock)
Definition: Execute.cpp:4184
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 RegisteredQueryHint &query_hint)
Definition: Execute.cpp:3341
std::string JoinColumnsInfo
static QuerySessionMap queries_session_map_
Definition: Execute.h:1102
CudaMgr_Namespace::CudaMgr * cudaMgr() const
Definition: Execute.h:530
static mapd_shared_mutex execute_mutex_
Definition: Execute.h:1109
std::unique_ptr< llvm::TargetMachine > nvptx_target_machine_
Definition: Execute.h:1062
int64_t kernel_queue_time_ms_
Definition: Execute.h:1082
JoinType
Definition: sqldefs.h:108
size_t maxGpuSlabSize() const
Definition: Execute.cpp:3403
ExecutorMutexHolder acquireExecuteMutex()
Definition: Execute.h:1115
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:3103
Data_Namespace::DataMgr * data_mgr_
Definition: Execute.h:1079
int64_t compilation_queue_time_ms_
Definition: Execute.h:1083
const std::string & getQuerySubmittedTime()
Definition: Execute.h:127
friend class ResultSet
Definition: Execute.h:1166
std::map< const ColumnDescriptor *, std::set< int32_t >> ColumnToFragmentsMap
Definition: Execute.h:308
std::string cat(Ts &&...args)
void invalidateRunningQuerySession(mapd_unique_lock< mapd_shared_mutex > &write_lock)
Definition: Execute.cpp:3914
void checkPendingQueryStatus(const QuerySessionId &query_session)
Definition: Execute.cpp:3937
static const int32_t ERR_INTERRUPTED
Definition: Execute.h:1142
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:1161
FetchCacheAnchor(CgenState *cgen_state)
Definition: Execute.h:1038
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:842
const std::shared_ptr< RowSetMemoryOwner > getRowSetMemoryOwner() const
Definition: Execute.cpp:293
StringDictionaryProxy * getLiteralDictionary() const override
Definition: Execute.h:328
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:2257
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:1684
void read_rt_udf_cpu_module(const std::string &udf_ir)
Fragmenter_Namespace::RowDataProvider RowDataProvider
Definition: Execute.h:307
static const int max_gpu_count
Definition: Execute.h:1052
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:893
std::map< const QuerySessionId, std::map< std::string, QuerySessionStatus >> QuerySessionMap
Definition: Execute.h:151
#define const
size_t const getFragmentIndex() const
static const size_t code_cache_size
Definition: Execute.h:1069
void setQueryStatusAsRunning()
Definition: Execute.h:133
bool isArchPascalOrLater(const ExecutorDeviceType dt) const
Definition: Execute.h:537
std::ostream & operator<<(std::ostream &os, const SessionInfo &session_info)
Definition: SessionInfo.cpp:53
static std::atomic_flag execute_spin_lock_
Definition: Execute.h:1105
bool is_fp() const
Definition: sqltypes.h:502
std::pair< QuerySessionId, std::string > CurrentQueryStatus
Definition: Execute.h:81
bool is_constructed_point(const Analyzer::Expr *expr)
Definition: Execute.h:1202
static mapd_shared_mutex executors_cache_mutex_
Definition: Execute.h:1126
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:343
static const size_t baseline_threshold
Definition: Execute.h:1067
void registerActiveModule(void *module, const int device_id) const
JoinColumnSide
string name
Definition: setup.in.py:72
std::unordered_set< int > get_available_gpus(const Data_Namespace::DataMgr *data_mgr)
Definition: Execute.cpp:1039
std::tuple< RelAlgExecutionUnit, PlanState::DeletedColumnsMap > addDeletedColumn(const RelAlgExecutionUnit &ra_exe_unit, const CompilationOptions &co)
Definition: Execute.cpp:3485
TableGenerations computeTableGenerations(std::unordered_set< int > phys_table_ids)
Definition: Execute.cpp:3843
bool isArchPascalOrLater() const
Definition: CudaMgr.h:142
TableToFragmentIds fragments_with_deleted_rows
Definition: Execute.h:313
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()
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:667
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:201
bool checkCurrentQuerySession(const std::string &candidate_query_session, mapd_shared_lock< mapd_shared_mutex > &read_lock)
Definition: Execute.cpp:3906
void setRunningExecutorId(const size_t id, mapd_unique_lock< mapd_shared_mutex > &write_lock)
Definition: Execute.cpp:3897
const QuerySessionStatus::QueryStatus getQueryStatus()
Definition: Execute.h:128
static const int32_t ERR_GEOS
Definition: Execute.h:1148
const std::string query_str_
Definition: Execute.h:140
QuerySessionStatus(const QuerySessionId &query_session, const std::string &query_str, const std::string &submitted_time)
Definition: Execute.h:96
AggregatedColRange agg_col_range_cache_
Definition: Execute.h:1092
std::shared_ptr< ResultSet > ResultSetPtr
static void * gpu_active_modules_[max_gpu_count]
Definition: Execute.h:1057
std::unique_ptr< CgenState > cgen_state_
Definition: Execute.h:1034
static const int32_t ERR_TOO_MANY_LITERALS
Definition: Execute.h:1144
llvm::Value * original_value
Definition: Execute.h:894
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:4025
ParseIRError(const std::string message)
Definition: Execute.h:295
std::vector< Analyzer::Expr * > get_exprs_not_owned(const std::vector< std::shared_ptr< Analyzer::Expr >> &exprs)
Definition: Execute.h:251
static uint32_t gpu_active_modules_device_mask_
Definition: Execute.h:1056
TableUpdateMetadata executeUpdate(const RelAlgExecutionUnit &ra_exe_unit, const std::vector< InputTableInfo > &table_infos, const TableDescriptor *updated_table_desc, 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)
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:323
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:2837
int deviceCount(const ExecutorDeviceType) const
Definition: Execute.cpp:652
llvm::Value * castToIntPtrTyIn(llvm::Value *val, const size_t bit_width)
Definition: Execute.cpp:3439
size_t getNumBytesForFetchedRow(const std::set< int > &table_ids_to_fetch) const
Definition: Execute.cpp:313
static std::mutex kernel_mutex_
Definition: Execute.h:1151
unsigned numBlocksPerMP() const
Definition: Execute.cpp:3388
#define CHECK_GT(x, y)
Definition: Logger.h:218
Container for compilation results and assorted options for a single execution unit.
bool isCPUOnly() const
Definition: Execute.cpp:263
std::unique_ptr< WindowProjectNodeContext > window_project_node_context_owned_
Definition: Execute.h:1087
std::vector< QuerySessionStatus > getQuerySessionInfo(const QuerySessionId &query_session, mapd_shared_lock< mapd_shared_mutex > &read_lock)
Definition: Execute.cpp:4252
void addTransientStringLiterals(const RelAlgExecutionUnit &ra_exe_unit, const std::shared_ptr< RowSetMemoryOwner > &row_set_mem_owner)
Definition: Execute.cpp:1726
std::vector< FragmentsPerTable > FragmentsList
bool is_time() const
Definition: sqltypes.h:504
bool needFetchAllFragments(const InputColDescriptor &col_desc, const RelAlgExecutionUnit &ra_exe_unit, const FragmentsList &selected_fragments) const
Definition: Execute.cpp:2438
const QuerySessionId query_session_
Definition: Execute.h:138
std::shared_ptr< HashJoin > hash_table
Definition: Execute.h:858
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:4193
mapd_shared_mutex & getSessionLock()
Definition: Execute.cpp:3881
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:192
QuerySessionStatus(const QuerySessionId &query_session, const size_t executor_id, const std::string &query_str, const std::string &submitted_time)
Definition: Execute.h:104
std::function< void(const UpdateLogForFragment &, TableUpdateMetadata &)> Callback
Definition: Execute.h:343
Fragmenter_Namespace::TableInfo getTableInfo(const int table_id) const
Definition: Execute.cpp:301
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:461
QueryMustRunOnCpu(const std::string &err)
Definition: Execute.h:290
CodeCache gpu_code_cache_
Definition: Execute.h:1065
static const int32_t ERR_STRING_CONST_IN_RESULTSET
Definition: Execute.h:1145
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:167
std::vector< int64_t > getJoinHashTablePtrs(const ExecutorDeviceType device_type, const int device_id)
Definition: Execute.cpp:3286
void preloadFragOffsets(const std::vector< InputDescriptor > &input_descs, const std::vector< InputTableInfo > &query_infos)
Definition: Execute.cpp:3320
bool isFragmentFullyDeleted(const int table_id, const Fragmenter_Namespace::FragmentInfo &fragment)
Definition: Execute.cpp:3564
bool checkIsRunningQuerySessionInterrupted()
Definition: Execute.cpp:4204
bool checkIsQuerySessionEnrolled(const QuerySessionId &query_session, mapd_shared_lock< mapd_shared_mutex > &read_lock)
Definition: Execute.cpp:4209
void setQueryStatus(const QuerySessionStatus::QueryStatus &status)
Definition: Execute.h:129
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:2614
static const int32_t ERR_STREAMING_TOP_N_NOT_SUPPORTED_IN_RENDER_QUERY
Definition: Execute.h:1146
const ExecutorId executor_id_
Definition: Execute.h:1077
static const int32_t ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED
Definition: Execute.h:1143
const ResultSetPtr & get_temporary_table(const TemporaryTables *temporary_tables, const int table_id)
Definition: Execute.h:228
int8_t warpSize() const
Definition: Execute.cpp:3371
std::map< QuerySessionId, bool > InterruptFlagMap
Definition: Execute.h:82
const size_t max_gpu_slab_size_
Definition: Execute.h:1073
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:1012
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:1907
const ColumnDescriptor * getPhysicalColumnDescriptor(const Analyzer::ColumnVar *, int) const
Definition: Execute.cpp:274
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:1134
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:4050
llvm::Value * get_arg_by_name(llvm::Function *func, const std::string &name)
Definition: Execute.h:166
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:353
size_t get_context_count(const ExecutorDeviceType device_type, const size_t cpu_count, const size_t gpu_count)
Definition: Execute.cpp:1053
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:334
std::unordered_map< int, std::vector< llvm::Value * > > fetch_cache_
Definition: CgenState.h:341
decltype(FragmentInfoType::fragmentId) const getFragmentId() const
Definition: Execute.h:337
int64_t deviceCycles(int milliseconds) const
Definition: Execute.cpp:3407
std::string generatePTX(const std::string &) const
std::mutex str_dict_mutex_
Definition: Execute.h:1060
bool is_integer() const
Definition: sqltypes.h:500
const Catalog_Namespace::Catalog * catalog_
Definition: Execute.h:1078
friend class PendingExecutionClosure
Definition: Execute.h:1171
void setQuerySessionAsInterrupted(const QuerySessionId &query_session, mapd_unique_lock< mapd_shared_mutex > &write_lock)
Definition: Execute.cpp:4173
static const int32_t ERR_OUT_OF_RENDER_MEM
Definition: Execute.h:1138
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:905
std::shared_timed_mutex mapd_shared_mutex
const std::string debug_file_
Definition: Execute.h:1075
ResultSetPtr collectAllDeviceShardedTopResults(SharedKernelContext &shared_context, const RelAlgExecutionUnit &ra_exe_unit) const
Definition: Execute.cpp:2022
CachedCardinality getCachedCardinality(const std::string &cache_key)
Definition: Execute.cpp:4242
decltype(FragmentInfoType::physicalTableId) const getPhysicalTableId() const
Definition: Execute.h:334
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: Execute.h:1050
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:941
bool containsLeftDeepOuterJoin() const
Definition: Execute.h:419
void setCatalog(const Catalog_Namespace::Catalog *catalog)
Definition: Execute.cpp:289
StringDictionaryProxy * getStringDictionaryProxy(const int dict_id, const bool with_generation) const
Definition: Execute.h:404
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:1140
bool is_timeinterval() const
Definition: sqltypes.h:509
static std::unordered_map< std::string, size_t > cardinality_cache_
Definition: Execute.h:1131
const QueryPlanHash INVALID_QUERY_PLAN_HASH
Definition: Execute.h:1129
static InterruptFlagMap queries_interrupt_flag_
Definition: Execute.h:1100
FragmentInfoType const & getFragmentInfo() const
std::unique_ptr< PlanState > plan_state_
Definition: Execute.h:1049
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:1141
void initializeNVPTXBackend() const
mapd_unique_lock< mapd_shared_mutex > unique_lock
Definition: Execute.h:1113
std::map< int32_t, std::set< int32_t >> TableToFragmentIds
Definition: Execute.h:309
const std::string submitted_time_
Definition: Execute.h:141
const TableGeneration & getTableGeneration(const int table_id) const
Definition: Execute.cpp:305
llvm::Value * castToFP(llvm::Value *, SQLTypeInfo const &from_ti, SQLTypeInfo const &to_ti)
Definition: Execute.cpp:3412
size_t fragment_index_
Definition: Execute.h:349
std::pair< bool, size_t > CachedCardinality
Definition: Execute.h:1008
const ColumnDescriptor * getColumnDescriptor(const Analyzer::ColumnVar *) const
Definition: Execute.cpp:268
static const int32_t ERR_UNSUPPORTED_SELF_JOIN
Definition: Execute.h:1137
const unsigned block_size_x_
Definition: Execute.h:1071
const unsigned grid_size_x_
Definition: Execute.h:1072
specifies the content in-memory of a row in the column metadata table
bool is_boolean() const
Definition: sqltypes.h:505
std::vector< TargetValue > getTranslatedEntryAt(const size_t index) const override
static const int32_t ERR_SINGLE_VALUE_FOUND_MULTIPLE_VALUES
Definition: Execute.h:1147
static std::map< int, std::shared_ptr< Executor > > executors_
Definition: Execute.h:1104
static const int32_t ERR_OUT_OF_GPU_MEM
Definition: Execute.h:1135
const TemporaryTables * getTemporaryTables()
Definition: Execute.h:399
std::string get_null_check_suffix(const SQLTypeInfo &lhs_ti, const SQLTypeInfo &rhs_ti)
Definition: Execute.h:1181
static void addCodeToCache(const CodeCacheKey &, std::shared_ptr< CompilationContext >, llvm::Module *, CodeCache &)
const Catalog_Namespace::Catalog * getCatalog() const
Definition: Execute.cpp:285
#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:4113
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:146
ColumnToFragmentsMap columns_for_metadata_update
Definition: Execute.h:312
#define CHECK_LT(x, y)
Definition: Logger.h:216
ResultSetPtr resultsUnion(SharedKernelContext &shared_context, const RelAlgExecutionUnit &ra_exe_unit)
Definition: Execute.cpp:877
static QuerySessionId current_query_session_
Definition: Execute.h:1096
std::shared_ptr< ResultSet > rs_
Definition: Execute.h:350
std::vector< size_t > getFragmentCount(const FragmentsList &selected_fragments, const size_t scan_idx, const RelAlgExecutionUnit &ra_exe_unit)
Definition: Execute.cpp:2792
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:77
size_t ExecutorId
Definition: Execute.h:366
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:331
std::vector< int8_t > serializeLiterals(const std::unordered_map< int, CgenState::LiteralValues > &literals, const int device_id)
Definition: Execute.cpp:390
mapd_shared_mutex & getDataRecyclerLock()
Definition: Execute.cpp:3866
InputTableInfoCache input_table_info_cache_
Definition: Execute.h:1091
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:1064
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:3597
unsigned gridSize() const
Definition: Execute.cpp:3379
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:2389
size_t QueryPlanHash
StringDictionaryGenerations computeStringDictionaryGenerations(const std::unordered_set< PhysicalInput > &phys_inputs)
Definition: Execute.cpp:3822
Data_Namespace::DataMgr * getDataMgr() const
Definition: Execute.h:431
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:2457
void updateQuerySessionStatus(std::shared_ptr< const query_state::QueryState > &query_state, const QuerySessionStatus::QueryStatus new_query_status)
Definition: Execute.cpp:3987
void setExecutorId(const size_t executor_id)
Definition: Execute.h:132
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:2890
FragmentInfoType const & fragment_info_
Definition: Execute.h:348
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:3301
const std::string getQueryStr()
Definition: Execute.h:125
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:3763
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:2806
llvm::Value * codegenAggregateWindowState()
TableGenerations table_generations_
Definition: Execute.h:1093
void unregisterActiveModule(void *module, const int device_id) const
std::function< void(ResultSetPtr, const Fragmenter_Namespace::FragmentInfo &)> PerFragmentCallBack
Definition: Execute.h:555
void resetInterrupt()
mapd_shared_lock< mapd_shared_mutex > read_lock
const size_t getExecutorId()
Definition: Execute.h:126
size_t executor_id_
Definition: Execute.h:139
size_t getRunningExecutorId(mapd_shared_lock< mapd_shared_mutex > &read_lock)
Definition: Execute.cpp:3902
bool removeFromQuerySessionList(const QuerySessionId &query_session, const std::string &submitted_time_str, mapd_unique_lock< mapd_shared_mutex > &write_lock)
Definition: Execute.cpp:4138
std::string QuerySessionId
Definition: Execute.h:80
llvm::Value * addJoinLoopIterator(const std::vector< llvm::Value * > &prev_iters, const size_t level_idx)
Definition: IRCodegen.cpp:824
ResultSetPtr reduceMultiDeviceResultSets(std::vector< std::pair< ResultSetPtr, std::vector< size_t >>> &all_fragment_results, std::shared_ptr< RowSetMemoryOwner >, const QueryMemoryDescriptor &) const
Definition: Execute.cpp:952
llvm::Value * codegenWindowFunctionAggregate(const CompilationOptions &co)
void addToCardinalityCache(const std::string &cache_key, const size_t cache_value)
Definition: Execute.cpp:4233
constexpr char const * EMPTY_QUERY_PLAN
static std::atomic< bool > interrupted_
Definition: Execute.h:1058
#define CHECK(condition)
Definition: Logger.h:206
QueryPlanDagCache & getQueryPlanDagCache()
Definition: Execute.cpp:3870
static const int32_t ERR_OUT_OF_SLOTS
Definition: Execute.h:1136
void clearQuerySessionStatus(const QuerySessionId &query_session, const std::string &submitted_time_str, const bool acquire_spin_lock)
Definition: Execute.cpp:3963
static std::mutex compilation_mutex_
Definition: Execute.h:1150
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:2480
mapd_shared_lock< mapd_shared_mutex > shared_lock
Definition: Execute.h:1112
static size_t running_query_executor_id_
Definition: Execute.h:1098
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:1415
JoinColumnsInfo getJoinColumnsInfo(const Analyzer::Expr *join_expr, JoinColumnSide target_side, bool extract_only_col_id)
Definition: Execute.cpp:3874
std::unordered_map< int, const Analyzer::BinOper * > getInnerTabIdToJoinCond() const
Definition: Execute.cpp:2072
ExecutorDeviceType getDeviceTypeForTargets(const RelAlgExecutionUnit &ra_exe_unit, const ExecutorDeviceType requested_device_type)
Definition: Execute.cpp:1774
JoinLoop::HoistedFiltersCallback buildHoistLeftHandSideFiltersCb(const RelAlgExecutionUnit &ra_exe_unit, const size_t level_idx, const int inner_table_id, const CompilationOptions &co)
Definition: IRCodegen.cpp:502
uint32_t log2_bytes(const uint32_t bytes)
Definition: Execute.h:176
ExpressionRange getColRange(const PhysicalInput &) const
Definition: Execute.cpp:309
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:3920
mapd_unique_lock< mapd_shared_mutex > write_lock
void redeclareFilterFunction()
Definition: IRCodegen.cpp:725
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:113
UpdateLogForFragment(FragmentInfoType const &fragment_info, size_t const, const std::shared_ptr< ResultSet > &rs)
bool is_unnest(const Analyzer::Expr *expr)
Definition: Execute.h:1197
bool is_string() const
Definition: sqltypes.h:498
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:289
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:610
auto getResultSet() const
Definition: Execute.h:345
unsigned blockSize() const
Definition: Execute.cpp:3393
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:330
std::unordered_map< int, std::vector< llvm::Value * > > saved_fetch_cache
Definition: Execute.h:1044
static size_t align(const size_t off_in, const size_t alignment)
Definition: Execute.h:1026
std::unique_ptr< QueryMemoryDescriptor > QueryMemoryDescriptorOwned
Definition: Execute.h:79
size_t const getRowCount() const override
const QuerySessionId getQuerySession()
Definition: Execute.h:124
static const int32_t ERR_OUT_OF_CPU_MEM
Definition: Execute.h:1139
QuerySessionStatus::QueryStatus query_status_
Definition: Execute.h:148
bool is_decimal() const
Definition: sqltypes.h:501
int deviceCountForMemoryLevel(const Data_Namespace::MemoryLevel memory_level) const
Definition: Execute.cpp:660
void setCurrentQuerySession(const QuerySessionId &query_session, mapd_unique_lock< mapd_shared_mutex > &write_lock)
Definition: Execute.cpp:3890
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:318
bool is_rt_udf_module_present(bool cpu_only=false)
static size_t getArenaBlockSize()
Definition: Execute.cpp:217
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:1348
std::mutex gpu_exec_mutex_[max_gpu_count]
Definition: Execute.h:1053
HashType
Definition: HashTable.h:19
DEVICE void swap(ARGS &&...args)
Definition: gpu_enabled.h:114
static mapd_shared_mutex recycler_mutex_
Definition: Execute.h:1130
llvm::Value * codegenWindowFunction(const size_t target_index, const CompilationOptions &co)
SQLOps get_optype() const
Definition: Analyzer.h:370
static QueryPlanDagCache query_plan_dag_cache_
Definition: Execute.h:1128
WindowFunctionContext * active_window_function_
Definition: Execute.h:1089
static std::mutex gpu_active_modules_mutex_
Definition: Execute.h:1055
void setupCaching(const std::unordered_set< PhysicalInput > &phys_inputs, const std::unordered_set< int > &phys_table_ids)
Definition: Execute.cpp:3855
static void nukeCacheOfExecutors()
Definition: Execute.h:383
void clearMetaInfoCache()
Definition: Execute.cpp:384
const ColumnDescriptor * get_column_descriptor(const int col_id, const int table_id, const Catalog_Namespace::Catalog &cat)
Definition: Execute.h:191
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:1080
CompilationRetryNewScanLimit(const size_t new_scan_limit)
Definition: Execute.h:268
WatchdogException(const std::string &cause)
Definition: Execute.h:161
static const ExecutorId UNITARY_EXECUTOR_ID
Definition: Execute.h:367
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:2299
ResultSetPtr executeExplain(const QueryCompilationDescriptor &)
Definition: Execute.cpp:1722