OmniSciDB  5ade3759e0
Execute.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef QUERYENGINE_EXECUTE_H
18 #define QUERYENGINE_EXECUTE_H
19 
20 #include "AggregatedColRange.h"
21 #include "BufferCompaction.h"
22 #include "CartesianProduct.h"
23 #include "CgenState.h"
24 #include "CodeCache.h"
25 #include "DateTimeUtils.h"
27 #include "GroupByAndAggregate.h"
28 #include "JoinHashTable.h"
30 #include "NvidiaKernel.h"
31 #include "PlanState.h"
32 #include "RelAlgExecutionUnit.h"
33 #include "RelAlgTranslator.h"
35 #include "TableGenerations.h"
36 #include "TargetMetaInfo.h"
37 #include "WindowContext.h"
38 
39 #include "../Chunk/Chunk.h"
40 #include "../Fragmenter/InsertOrderFragmenter.h"
41 #include "../Planner/Planner.h"
42 #include "../Shared/MapDParameters.h"
43 #include "../Shared/measure.h"
44 #include "../Shared/thread_count.h"
45 #include "../StringDictionary/LruCache.hpp"
46 #include "../StringDictionary/StringDictionary.h"
47 #include "../StringDictionary/StringDictionaryProxy.h"
48 
49 #include <llvm/IR/Function.h>
50 #include <llvm/IR/Value.h>
51 #include <llvm/Linker/Linker.h>
52 #include <llvm/Transforms/Utils/ValueMapper.h>
53 #include <rapidjson/document.h>
54 
55 #include <unistd.h>
56 #include <algorithm>
57 #include <condition_variable>
58 #include <cstddef>
59 #include <cstdlib>
60 #include <deque>
61 #include <functional>
62 #include <limits>
63 #include <map>
64 #include <mutex>
65 #include <stack>
66 #include <unordered_map>
67 #include <unordered_set>
68 
69 extern bool g_enable_watchdog;
70 extern bool g_enable_dynamic_watchdog;
71 extern unsigned g_dynamic_watchdog_time_limit;
72 extern unsigned g_trivial_loop_join_threshold;
73 extern bool g_from_table_reordering;
74 extern bool g_enable_filter_push_down;
75 extern bool g_allow_cpu_retry;
76 extern bool g_null_div_by_zero;
77 extern bool g_bigint_count;
79 extern float g_filter_push_down_low_frac;
80 extern float g_filter_push_down_high_frac;
82 extern bool g_enable_columnar_output;
83 extern bool g_enable_overlaps_hashjoin;
85 extern bool g_strip_join_covered_quals;
86 extern size_t g_constrained_by_in_threshold;
87 extern size_t g_big_group_threshold;
88 extern bool g_enable_window_functions;
89 extern size_t g_max_memory_allocation_size;
91 
93 using QueryCompilationDescriptorOwned = std::unique_ptr<QueryCompilationDescriptor>;
95 using QueryMemoryDescriptorOwned = std::unique_ptr<QueryMemoryDescriptor>;
96 
97 extern void read_udf_gpu_module(const std::string& udf_ir_filename);
98 extern void read_udf_cpu_module(const std::string& udf_ir_filename);
99 extern bool is_udf_module_present(bool cpu_only = false);
100 extern void read_rt_udf_gpu_module(const std::string& udf_ir);
101 extern void read_rt_udf_cpu_module(const std::string& udf_ir);
102 extern bool is_rt_udf_module_present(bool cpu_only = false);
103 
104 class ColumnFetcher;
105 class ExecutionResult;
106 
107 class WatchdogException : public std::runtime_error {
108  public:
109  WatchdogException(const std::string& cause) : std::runtime_error(cause) {}
110 };
111 
112 class Executor;
113 
114 inline llvm::Value* get_arg_by_name(llvm::Function* func, const std::string& name) {
115  for (auto& arg : func->args()) {
116  if (arg.getName() == name) {
117  return &arg;
118  }
119  }
120  CHECK(false);
121  return nullptr;
122 }
123 
124 inline uint32_t log2_bytes(const uint32_t bytes) {
125  switch (bytes) {
126  case 1:
127  return 0;
128  case 2:
129  return 1;
130  case 4:
131  return 2;
132  case 8:
133  return 3;
134  default:
135  abort();
136  }
137 }
138 
140  const int col_id,
141  const int table_id,
142  const Catalog_Namespace::Catalog& cat) {
143  CHECK_GT(table_id, 0);
144  const auto col_desc = cat.getMetadataForColumn(table_id, col_id);
145  CHECK(col_desc);
146  return col_desc;
147 }
148 
149 inline const Analyzer::Expr* extract_cast_arg(const Analyzer::Expr* expr) {
150  const auto cast_expr = dynamic_cast<const Analyzer::UOper*>(expr);
151  if (!cast_expr || cast_expr->get_optype() != kCAST) {
152  return expr;
153  }
154  return cast_expr->get_operand();
155 }
156 
157 inline std::string numeric_type_name(const SQLTypeInfo& ti) {
158  CHECK(ti.is_integer() || ti.is_decimal() || ti.is_boolean() || ti.is_time() ||
159  ti.is_fp() || (ti.is_string() && ti.get_compression() == kENCODING_DICT) ||
160  ti.is_timeinterval());
161  if (ti.is_integer() || ti.is_decimal() || ti.is_boolean() || ti.is_time() ||
162  ti.is_string() || ti.is_timeinterval()) {
163  return "int" + std::to_string(ti.get_logical_size() * 8) + "_t";
164  }
165  return ti.get_type() == kDOUBLE ? "double" : "float";
166 }
167 
169  const int col_id,
170  const int table_id,
171  const Catalog_Namespace::Catalog& cat) {
172  CHECK(table_id);
173  return table_id > 0 ? get_column_descriptor(col_id, table_id, cat) : nullptr;
174 }
175 
176 inline const ResultSetPtr& get_temporary_table(const TemporaryTables* temporary_tables,
177  const int table_id) {
178  CHECK_LT(table_id, 0);
179  const auto it = temporary_tables->find(table_id);
180  CHECK(it != temporary_tables->end());
181  return it->second;
182 }
183 
184 inline const SQLTypeInfo get_column_type(const int col_id,
185  const int table_id,
186  const ColumnDescriptor* cd,
187  const TemporaryTables* temporary_tables) {
188  CHECK(cd || temporary_tables);
189  if (cd) {
190  CHECK_EQ(col_id, cd->columnId);
191  CHECK_EQ(table_id, cd->tableId);
192  return cd->columnType;
193  }
194  const auto& temp = get_temporary_table(temporary_tables, table_id);
195  return temp->getColType(col_id);
196 }
197 
198 template <typename PtrTy>
200  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
201  const PtrTy& result,
202  const int number) {
203  std::vector<SQLTypeInfo> col_types;
204  for (size_t i = 0; i < result->colCount(); ++i) {
205  col_types.push_back(get_logical_type_info(result->getColType(i)));
206  }
207  return new ColumnarResults(row_set_mem_owner, *result, number, col_types);
208 }
209 
210 // TODO(alex): Adjust interfaces downstream and make this not needed.
211 inline std::vector<Analyzer::Expr*> get_exprs_not_owned(
212  const std::vector<std::shared_ptr<Analyzer::Expr>>& exprs) {
213  std::vector<Analyzer::Expr*> exprs_not_owned;
214  for (const auto expr : exprs) {
215  exprs_not_owned.push_back(expr.get());
216  }
217  return exprs_not_owned;
218 }
219 
221  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
222  const ResultSetPtr& result,
223  const int frag_id) {
225  CHECK_EQ(0, frag_id);
226  return rows_to_columnar_results(row_set_mem_owner, result, result->colCount());
227 }
228 
229 class CompilationRetryNoLazyFetch : public std::runtime_error {
230  public:
232  : std::runtime_error("Retry query compilation with no GPU lazy fetch.") {}
233 };
234 
235 class CompilationRetryNewScanLimit : public std::runtime_error {
236  public:
237  CompilationRetryNewScanLimit(const size_t new_scan_limit)
238  : std::runtime_error("Retry query compilation with new scan limit.")
239  , new_scan_limit_(new_scan_limit) {}
240 
242 };
243 
244 class TooManyLiterals : public std::runtime_error {
245  public:
246  TooManyLiterals() : std::runtime_error("Too many literals in the query") {}
247 };
248 
249 class CompilationRetryNoCompaction : public std::runtime_error {
250  public:
252  : std::runtime_error("Retry query compilation with no compaction.") {}
253 };
254 
255 class QueryMustRunOnCpu : public std::runtime_error {
256  public:
257  QueryMustRunOnCpu() : std::runtime_error("Query must run in cpu mode.") {}
258 };
259 
260 class SringConstInResultSet : public std::runtime_error {
261  public:
263  : std::runtime_error(
264  "NONE ENCODED String types are not supported as input result set.") {}
265 };
266 
267 class ExtensionFunction;
268 
269 namespace std {
270 template <>
271 struct hash<std::vector<int>> {
272  size_t operator()(const std::vector<int>& vec) const {
273  return vec.size() ^ boost::hash_range(vec.begin(), vec.end());
274  }
275 };
276 
277 template <>
278 struct hash<std::pair<int, int>> {
279  size_t operator()(const std::pair<int, int>& p) const {
280  return boost::hash<std::pair<int, int>>()(p);
281  }
282 };
283 
284 } // namespace std
285 
287 
289  public:
291 
292  UpdateLogForFragment(FragmentInfoType const& fragment_info,
293  size_t const,
294  const std::shared_ptr<ResultSet>& rs);
295 
296  std::vector<TargetValue> getEntryAt(const size_t index) const override;
297  std::vector<TargetValue> getTranslatedEntryAt(const size_t index) const override;
298 
299  size_t count() const override;
301  return rs_->getRowSetMemOwner()->getLiteralStringDictProxy();
302  }
303  size_t const getEntryCount() const;
304  size_t const getFragmentIndex() const;
305  FragmentInfoType const& getFragmentInfo() const;
306  decltype(FragmentInfoType::physicalTableId) const getPhysicalTableId() const {
307  return fragment_info_.physicalTableId;
308  }
309  decltype(FragmentInfoType::fragmentId) const getFragmentId() const {
310  return fragment_info_.fragmentId;
311  }
312 
313  SQLTypeInfo getColumnType(const size_t col_idx) const;
314 
315  using Callback = std::function<void(const UpdateLogForFragment&)>;
316 
317  private:
320  std::shared_ptr<ResultSet> rs_;
321 };
322 
323 using PerFragmentCB =
324  std::function<void(ResultSetPtr, const Fragmenter_Namespace::FragmentInfo&)>;
325 
327 
328 class Executor {
329  static_assert(sizeof(float) == 4 && sizeof(double) == 8,
330  "Host hardware not supported, unexpected size of float / double.");
331  static_assert(sizeof(time_t) == 8,
332  "Host hardware not supported, 64-bit time support is required.");
333 
334  public:
335  Executor(const int db_id,
336  const size_t block_size_x,
337  const size_t grid_size_x,
338  const std::string& debug_dir,
339  const std::string& debug_file,
340  ::QueryRenderer::QueryRenderManager* render_manager);
341 
342  static std::shared_ptr<Executor> getExecutor(
343  const int db_id,
344  const std::string& debug_dir = "",
345  const std::string& debug_file = "",
346  const MapDParameters mapd_parameters = MapDParameters(),
347  ::QueryRenderer::QueryRenderManager* render_manager = nullptr);
348 
349  static void nukeCacheOfExecutors() {
350  std::lock_guard<std::mutex> flush_lock(
351  execute_mutex_); // don't want native code to vanish while executing
352  mapd_unique_lock<mapd_shared_mutex> lock(executors_cache_mutex_);
353  (decltype(executors_){}).swap(executors_);
354  }
355 
356  static void clearMemory(const Data_Namespace::MemoryLevel memory_level);
357 
358  typedef std::tuple<std::string, const Analyzer::Expr*, int64_t, const size_t> AggInfo;
359 
360  std::shared_ptr<ResultSet> execute(const Planner::RootPlan* root_plan,
362  const bool hoist_literals,
363  const ExecutorDeviceType device_type,
364  const ExecutorOptLevel,
365  const bool allow_multifrag,
366  const bool allow_loop_joins,
367  RenderInfo* render_query_data = nullptr);
368 
369  std::shared_ptr<ResultSet> renderPointsNonInSitu(
370  const std::string& queryStr,
371  const ExecutionResult& results,
373  const int render_widget_id,
374  const ::QueryRenderer::JSONLocation* data_loc,
375  RenderInfo* render_query_data);
376 
377  std::shared_ptr<ResultSet> renderPointsInSitu(RenderInfo* render_query_data);
378 
379  std::shared_ptr<ResultSet> renderPolygonsNonInSitu(
380  const std::string& queryStr,
381  const ExecutionResult& results,
383  const int render_widget_id,
384  const ::QueryRenderer::JSONLocation* data_loc,
385  RenderInfo* render_query_data,
386  const std::string& poly_table_name);
387 
388  std::shared_ptr<ResultSet> renderLinesNonInSitu(
389  const std::string& queryStr,
390  const ExecutionResult& results,
392  const int render_widget_id,
393  const ::QueryRenderer::JSONLocation* data_loc,
394  RenderInfo* render_query_data);
395 
396 #if HAVE_CUDA
397  enum class InSituGeoRenderType { kPOLYGONS, kLINES };
398 
399  std::shared_ptr<ResultSet> renderGeoInSitu(
400  const InSituGeoRenderType in_situ_geo_render_type,
401  const std::string& queryStr,
402  const ExecutionResult& results,
404  const int render_widget_id,
405  const ::QueryRenderer::JSONLocation* data_loc,
406  RenderInfo* render_query_data,
407  const std::string& line_table_name);
408 #endif
409 
410  std::vector<int32_t> getStringIds(
411  const std::string& col_name,
412  const std::vector<std::string>& col_vals,
413  const ::QueryRenderer::QueryDataLayout* query_data_layout,
414  const ResultSet* results,
415  const std::shared_ptr<RowSetMemoryOwner>& row_set_mem_owner,
416  const bool warn = false) const;
417 
418  std::vector<std::string> getStringsFromIds(
419  const std::string& col_name,
420  const std::vector<int32_t>& ids,
421  const ::QueryRenderer::QueryDataLayout* query_data_layout,
422  const ResultSet* results,
423  const std::shared_ptr<RowSetMemoryOwner>& row_set_mem_owner) const;
424 
425  StringDictionaryProxy* getStringDictionaryProxy(
426  const int dictId,
427  const std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
428  const bool with_generation) const;
429 
430  bool isCPUOnly() const;
431 
432  bool isArchMaxwell(const ExecutorDeviceType dt) const;
433 
435  return cgen_state_->contains_left_deep_outer_join_;
436  }
437 
438  const ColumnDescriptor* getColumnDescriptor(const Analyzer::ColumnVar*) const;
439 
440  const ColumnDescriptor* getPhysicalColumnDescriptor(const Analyzer::ColumnVar*,
441  int) const;
442 
443  const Catalog_Namespace::Catalog* getCatalog() const;
444 
445  const std::shared_ptr<RowSetMemoryOwner> getRowSetMemoryOwner() const;
446 
447  const TemporaryTables* getTemporaryTables() const;
448 
449  Fragmenter_Namespace::TableInfo getTableInfo(const int table_id) const;
450 
451  const TableGeneration& getTableGeneration(const int table_id) const;
452 
453  ExpressionRange getColRange(const PhysicalInput&) const;
454 
455  size_t getNumBytesForFetchedRow() const;
456 
457  std::vector<ColumnLazyFetchInfo> getColLazyFetchInfo(
458  const std::vector<Analyzer::Expr*>& target_exprs) const;
459 
460  void registerActiveModule(void* module, const int device_id) const;
461  void unregisterActiveModule(void* module, const int device_id) const;
462  void interrupt();
463  void resetInterrupt();
464 
465  static const size_t high_scan_limit{32000000};
466 
467  private:
468  void clearMetaInfoCache();
469 
470  int deviceCount(const ExecutorDeviceType) const;
471  int deviceCountForMemoryLevel(const Data_Namespace::MemoryLevel memory_level) const;
472 
473  // Generate code for a window function target.
474  llvm::Value* codegenWindowFunction(const size_t target_index,
475  const CompilationOptions& co);
476 
477  // Generate code for an aggregate window function target.
478  llvm::Value* codegenWindowFunctionAggregate(const CompilationOptions& co);
479 
480  // The aggregate state requires a state reset when starting a new partition. Generate
481  // the new partition check and return the continuation basic block.
482  llvm::BasicBlock* codegenWindowResetStateControlFlow();
483 
484  // Generate code for initializing the state of a window aggregate.
485  void codegenWindowFunctionStateInit(llvm::Value* aggregate_state);
486 
487  // Generates the required calls for an aggregate window function and returns the final
488  // result.
489  llvm::Value* codegenWindowFunctionAggregateCalls(llvm::Value* aggregate_state,
490  const CompilationOptions& co);
491 
492  // The AVG window function requires some post-processing: the sum is divided by count
493  // and the result is stored back for the current row.
494  void codegenWindowAvgEpilogue(llvm::Value* crt_val,
495  llvm::Value* window_func_null_val,
496  llvm::Value* multiplicity_lv);
497 
498  // Generates code which loads the current aggregate value for the window context.
499  llvm::Value* codegenAggregateWindowState();
500 
501  llvm::Value* aggregateWindowStatePtr();
502 
504  std::vector<std::pair<void*, void*>> native_functions;
505  std::unordered_map<int, CgenState::LiteralValues> literal_values;
507  std::string llvm_ir;
508  };
509 
511  if (dt == ExecutorDeviceType::GPU) {
512  const auto cuda_mgr = catalog_->getDataMgr().getCudaMgr();
513  LOG_IF(FATAL, cuda_mgr == nullptr)
514  << "No CudaMgr instantiated, unable to check device architecture";
515  return cuda_mgr->isArchPascalOrLater();
516  }
517  return false;
518  }
519 
520  struct FetchResult {
521  std::vector<std::vector<const int8_t*>> col_buffers;
522  std::vector<std::vector<int64_t>> num_rows;
523  std::vector<std::vector<uint64_t>> frag_offsets;
524  };
525 
526  bool needFetchAllFragments(const InputColDescriptor& col_desc,
527  const RelAlgExecutionUnit& ra_exe_unit,
528  const FragmentsList& selected_fragments) const;
529 
531  private:
532  Executor* executor_;
534  const std::vector<InputTableInfo>& query_infos_;
536  mutable std::vector<uint64_t> all_frag_row_offsets_;
537  mutable std::mutex all_frag_row_offsets_mutex_;
538  const std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner_;
540  std::vector<std::pair<ResultSetPtr, std::vector<size_t>>> all_fragment_results_;
541  std::atomic_flag dynamic_watchdog_set_ = ATOMIC_FLAG_INIT;
542  static std::mutex reduce_mutex_;
543 
544  void runImpl(const ExecutorDeviceType chosen_device_type,
545  int chosen_device_id,
546  const ExecutionOptions& eo,
547  const ColumnFetcher& column_fetcher,
548  const QueryCompilationDescriptor& query_comp_desc,
549  const QueryMemoryDescriptor& query_mem_desc,
550  const FragmentsList& frag_list,
551  const ExecutorDispatchMode kernel_dispatch_mode,
552  const int64_t rowid_lookup_key);
553 
554  public:
555  ExecutionDispatch(Executor* executor,
556  const RelAlgExecutionUnit& ra_exe_unit,
557  const std::vector<InputTableInfo>& query_infos,
558  const Catalog_Namespace::Catalog& cat,
559  const std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
560  RenderInfo* render_info);
561 
562  ExecutionDispatch(const ExecutionDispatch&) = delete;
563 
564  ExecutionDispatch& operator=(const ExecutionDispatch&) = delete;
565 
567 
568  ExecutionDispatch& operator=(ExecutionDispatch&&) = delete;
569 
570  std::tuple<QueryCompilationDescriptorOwned, QueryMemoryDescriptorOwned> compile(
571  const size_t max_groups_buffer_entry_guess,
572  const int8_t crt_min_byte_width,
573  const CompilationOptions& co,
574  const ExecutionOptions& eo,
575  const ColumnFetcher& column_fetcher,
576  const bool has_cardinality_estimation);
577 
578  void run(const ExecutorDeviceType chosen_device_type,
579  int chosen_device_id,
580  const ExecutionOptions& eo,
581  const ColumnFetcher& column_fetcher,
582  const QueryCompilationDescriptor& query_comp_desc,
583  const QueryMemoryDescriptor& query_mem_desc,
584  const FragmentsList& frag_ids,
585  const ExecutorDispatchMode kernel_dispatch_mode,
586  const int64_t rowid_lookup_key);
587 
588  const RelAlgExecutionUnit& getExecutionUnit() const;
589 
590  const std::vector<uint64_t>& getFragOffsets() const;
591 
592  std::vector<std::pair<ResultSetPtr, std::vector<size_t>>>& getFragmentResults();
593 
595  };
596 
597  ResultSetPtr executeWorkUnit(size_t& max_groups_buffer_entry_guess,
598  const bool is_agg,
599  const std::vector<InputTableInfo>&,
600  const RelAlgExecutionUnit&,
601  const CompilationOptions&,
602  const ExecutionOptions& options,
604  std::shared_ptr<RowSetMemoryOwner>,
605  RenderInfo* render_info,
606  const bool has_cardinality_estimation,
607  ColumnCacheMap& column_cache);
608 
609  void executeUpdate(const RelAlgExecutionUnit& ra_exe_unit,
610  const InputTableInfo& table_info,
611  const CompilationOptions& co,
612  const ExecutionOptions& eo,
613  const Catalog_Namespace::Catalog& cat,
614  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
616 
622  void executeWorkUnitPerFragment(const RelAlgExecutionUnit& ra_exe_unit,
623  const InputTableInfo& table_info,
624  const CompilationOptions& co,
625  const ExecutionOptions& eo,
626  const Catalog_Namespace::Catalog& cat,
627  PerFragmentCB& cb);
628 
629  ResultSetPtr executeExplain(const QueryCompilationDescriptor&);
630 
631  // TODO(alex): remove
632  ExecutorDeviceType getDeviceTypeForTargets(
633  const RelAlgExecutionUnit& ra_exe_unit,
634  const ExecutorDeviceType requested_device_type);
635 
636  ResultSetPtr collectAllDeviceResults(
637  ExecutionDispatch& execution_dispatch,
638  const std::vector<Analyzer::Expr*>& target_exprs,
639  const QueryMemoryDescriptor& query_mem_desc,
640  const ExecutorDeviceType device_type,
641  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner);
642 
643  ResultSetPtr collectAllDeviceShardedTopResults(
644  ExecutionDispatch& execution_dispatch) const;
645 
646  std::unordered_map<int, const Analyzer::BinOper*> getInnerTabIdToJoinCond() const;
647 
648  void dispatchFragments(
649  const std::function<void(const ExecutorDeviceType chosen_device_type,
650  int chosen_device_id,
651  const QueryCompilationDescriptor& query_comp_desc,
652  const QueryMemoryDescriptor& query_mem_desc,
653  const FragmentsList& frag_list,
654  const ExecutorDispatchMode kernel_dispatch_mode,
655  const int64_t rowid_lookup_key)> dispatch,
656  const ExecutionDispatch& execution_dispatch,
657  const std::vector<InputTableInfo>& table_infos,
658  const ExecutionOptions& eo,
659  const bool is_agg,
660  const bool allow_single_frag_table_opt,
661  const size_t context_count,
662  const QueryCompilationDescriptor& query_comp_desc,
663  const QueryMemoryDescriptor& query_mem_desc,
664  QueryFragmentDescriptor& fragment_descriptor,
665  std::unordered_set<int>& available_gpus,
666  int& available_cpus);
667 
668  std::vector<size_t> getTableFragmentIndices(
669  const RelAlgExecutionUnit& ra_exe_unit,
670  const ExecutorDeviceType device_type,
671  const size_t table_idx,
672  const size_t outer_frag_idx,
673  std::map<int, const TableFragments*>& selected_tables_fragments,
674  const std::unordered_map<int, const Analyzer::BinOper*>&
675  inner_table_id_to_join_condition);
676 
677  bool skipFragmentPair(const Fragmenter_Namespace::FragmentInfo& outer_fragment_info,
678  const Fragmenter_Namespace::FragmentInfo& inner_fragment_info,
679  const int inner_table_id,
680  const std::unordered_map<int, const Analyzer::BinOper*>&
681  inner_table_id_to_join_condition,
682  const RelAlgExecutionUnit& ra_exe_unit,
683  const ExecutorDeviceType device_type);
684 
685  FetchResult fetchChunks(const ColumnFetcher&,
686  const RelAlgExecutionUnit& ra_exe_unit,
687  const int device_id,
689  const std::map<int, const TableFragments*>&,
690  const FragmentsList& selected_fragments,
692  std::list<ChunkIter>&,
693  std::list<std::shared_ptr<Chunk_NS::Chunk>>&);
694 
695  std::pair<std::vector<std::vector<int64_t>>, std::vector<std::vector<uint64_t>>>
696  getRowCountAndOffsetForAllFrags(
697  const RelAlgExecutionUnit& ra_exe_unit,
698  const CartesianProduct<std::vector<std::vector<size_t>>>& frag_ids_crossjoin,
699  const std::vector<InputDescriptor>& input_descs,
700  const std::map<int, const TableFragments*>& all_tables_fragments);
701 
702  void buildSelectedFragsMapping(
703  std::vector<std::vector<size_t>>& selected_fragments_crossjoin,
704  std::vector<size_t>& local_col_to_frag_pos,
705  const std::list<std::shared_ptr<const InputColDescriptor>>& col_global_ids,
706  const FragmentsList& selected_fragments,
707  const RelAlgExecutionUnit& ra_exe_unit);
708 
709  std::vector<size_t> getFragmentCount(const FragmentsList& selected_fragments,
710  const size_t scan_idx,
711  const RelAlgExecutionUnit& ra_exe_unit);
712 
713  int32_t executePlanWithGroupBy(const RelAlgExecutionUnit& ra_exe_unit,
714  const CompilationResult&,
715  const bool hoist_literals,
716  ResultSetPtr& results,
717  const ExecutorDeviceType device_type,
718  std::vector<std::vector<const int8_t*>>& col_buffers,
719  const std::vector<size_t> outer_tab_frag_ids,
721  const std::vector<std::vector<int64_t>>& num_rows,
722  const std::vector<std::vector<uint64_t>>& frag_offsets,
724  const int device_id,
725  const int64_t limit,
726  const uint32_t start_rowid,
727  const uint32_t num_tables,
728  RenderInfo* render_info);
729  int32_t executePlanWithoutGroupBy(
730  const RelAlgExecutionUnit& ra_exe_unit,
731  const CompilationResult&,
732  const bool hoist_literals,
733  ResultSetPtr& results,
734  const std::vector<Analyzer::Expr*>& target_exprs,
735  const ExecutorDeviceType device_type,
736  std::vector<std::vector<const int8_t*>>& col_buffers,
737  QueryExecutionContext* query_exe_context,
738  const std::vector<std::vector<int64_t>>& num_rows,
739  const std::vector<std::vector<uint64_t>>& frag_offsets,
740  Data_Namespace::DataMgr* data_mgr,
741  const int device_id,
742  const uint32_t start_rowid,
743  const uint32_t num_tables,
744  RenderInfo* render_info);
745 
746  public: // Temporary, ask saman about this
747  static std::pair<int64_t, int32_t> reduceResults(const SQLAgg agg,
748  const SQLTypeInfo& ti,
749  const int64_t agg_init_val,
750  const int8_t out_byte_width,
751  const int64_t* out_vec,
752  const size_t out_vec_sz,
753  const bool is_group_by,
754  const bool float_argument_input);
755 
756  static void addCodeToCache(const CodeCacheKey&,
757  std::vector<std::tuple<void*, ExecutionEngineWrapper>>,
758  llvm::Module*,
759  CodeCache&);
760 
761  private:
762  static ResultSetPtr resultsUnion(ExecutionDispatch& execution_dispatch);
763  std::vector<int64_t> getJoinHashTablePtrs(const ExecutorDeviceType device_type,
764  const int device_id);
765  ResultSetPtr reduceMultiDeviceResults(
766  const RelAlgExecutionUnit&,
767  std::vector<std::pair<ResultSetPtr, std::vector<size_t>>>& all_fragment_results,
768  std::shared_ptr<RowSetMemoryOwner>,
769  const QueryMemoryDescriptor&) const;
770  ResultSetPtr reduceMultiDeviceResultSets(
771  std::vector<std::pair<ResultSetPtr, std::vector<size_t>>>& all_fragment_results,
772  std::shared_ptr<RowSetMemoryOwner>,
773  const QueryMemoryDescriptor&) const;
774  ResultSetPtr reduceSpeculativeTopN(
775  const RelAlgExecutionUnit&,
776  std::vector<std::pair<ResultSetPtr, std::vector<size_t>>>& all_fragment_results,
777  std::shared_ptr<RowSetMemoryOwner>,
778  const QueryMemoryDescriptor&) const;
779  void executeSimpleInsert(const Planner::RootPlan* root_plan);
780 
781  ResultSetPtr executeWorkUnitImpl(size_t& max_groups_buffer_entry_guess,
782  const bool is_agg,
783  const bool allow_single_frag_table_opt,
784  const std::vector<InputTableInfo>&,
785  const RelAlgExecutionUnit&,
786  const CompilationOptions&,
787  const ExecutionOptions& options,
789  std::shared_ptr<RowSetMemoryOwner>,
790  RenderInfo* render_info,
791  const bool has_cardinality_estimation,
792  ColumnCacheMap& column_cache);
793 
794  std::vector<llvm::Value*> inlineHoistedLiterals();
795 
796  std::tuple<Executor::CompilationResult, std::unique_ptr<QueryMemoryDescriptor>>
797  compileWorkUnit(const std::vector<InputTableInfo>& query_infos,
798  const RelAlgExecutionUnit& ra_exe_unit,
799  const CompilationOptions& co,
800  const ExecutionOptions& eo,
801  const CudaMgr_Namespace::CudaMgr* cuda_mgr,
802  const bool allow_lazy_fetch,
803  std::shared_ptr<RowSetMemoryOwner>,
804  const size_t max_groups_buffer_entry_count,
805  const int8_t crt_min_byte_width,
806  const bool has_cardinality_estimation,
807  ColumnCacheMap& column_cache,
808  RenderInfo* render_info = nullptr);
809  // Generate code to skip the deleted rows in the outermost table.
810  llvm::BasicBlock* codegenSkipDeletedOuterTableRow(
811  const RelAlgExecutionUnit& ra_exe_unit,
812  const CompilationOptions& co);
813  std::vector<JoinLoop> buildJoinLoops(RelAlgExecutionUnit& ra_exe_unit,
814  const CompilationOptions& co,
815  const ExecutionOptions& eo,
816  const std::vector<InputTableInfo>& query_infos,
817  ColumnCacheMap& column_cache);
818  // Create a callback which generates code which returns true iff the row on the given
819  // level is deleted.
820  std::function<llvm::Value*(const std::vector<llvm::Value*>&, llvm::Value*)>
821  buildIsDeletedCb(const RelAlgExecutionUnit& ra_exe_unit,
822  const size_t level_idx,
823  const CompilationOptions& co);
824  // Builds a join hash table for the provided conditions on the current level.
825  // Returns null iff on failure and provides the reasons in `fail_reasons`.
826  std::shared_ptr<JoinHashTableInterface> buildCurrentLevelHashTable(
827  const JoinCondition& current_level_join_conditions,
828  RelAlgExecutionUnit& ra_exe_unit,
829  const CompilationOptions& co,
830  const std::vector<InputTableInfo>& query_infos,
831  ColumnCacheMap& column_cache,
832  std::vector<std::string>& fail_reasons);
833  llvm::Value* addJoinLoopIterator(const std::vector<llvm::Value*>& prev_iters,
834  const size_t level_idx);
835  void codegenJoinLoops(const std::vector<JoinLoop>& join_loops,
836  const RelAlgExecutionUnit& ra_exe_unit,
837  GroupByAndAggregate& group_by_and_aggregate,
838  llvm::Function* query_func,
839  llvm::BasicBlock* entry_bb,
840  const QueryMemoryDescriptor& query_mem_desc,
841  const CompilationOptions& co,
842  const ExecutionOptions& eo);
843  bool compileBody(const RelAlgExecutionUnit& ra_exe_unit,
844  GroupByAndAggregate& group_by_and_aggregate,
845  const QueryMemoryDescriptor& query_mem_desc,
846  const CompilationOptions& co);
847 
848  void createErrorCheckControlFlow(llvm::Function* query_func,
849  bool run_with_dynamic_watchdog,
850  ExecutorDeviceType device_type);
851 
852  void preloadFragOffsets(const std::vector<InputDescriptor>& input_descs,
853  const std::vector<InputTableInfo>& query_infos);
854 
856  std::shared_ptr<JoinHashTableInterface> hash_table;
857  std::string fail_reason;
858  };
859 
860  JoinHashTableOrError buildHashTableForQualifier(
861  const std::shared_ptr<Analyzer::BinOper>& qual_bin_oper,
862  const std::vector<InputTableInfo>& query_infos,
863  const MemoryLevel memory_level,
864  const JoinHashTableInterface::HashType preferred_hash_type,
865  ColumnCacheMap& column_cache);
866  void nukeOldState(const bool allow_lazy_fetch,
867  const std::vector<InputTableInfo>& query_infos,
868  const RelAlgExecutionUnit& ra_exe_unit);
869 
870  std::vector<std::pair<void*, void*>> optimizeAndCodegenCPU(
871  llvm::Function*,
872  llvm::Function*,
873  const std::unordered_set<llvm::Function*>&,
874  const CompilationOptions&);
875  std::vector<std::pair<void*, void*>> optimizeAndCodegenGPU(
876  llvm::Function*,
877  llvm::Function*,
878  std::unordered_set<llvm::Function*>&,
879  const bool no_inline,
880  const CudaMgr_Namespace::CudaMgr* cuda_mgr,
881  const CompilationOptions&);
882  std::string generatePTX(const std::string&) const;
883  void initializeNVPTXBackend() const;
884 
885  int8_t warpSize() const;
886  unsigned gridSize() const;
887  unsigned blockSize() const;
888 
889  int64_t deviceCycles(int milliseconds) const;
890 
892  llvm::Value* translated_value;
893  llvm::Value* original_value;
894  };
895 
896  GroupColLLVMValue groupByColumnCodegen(Analyzer::Expr* group_by_col,
897  const size_t col_width,
898  const CompilationOptions&,
899  const bool translate_null_val,
900  const int64_t translated_null_val,
902  std::stack<llvm::BasicBlock*>&,
903  const bool thread_mem_shared);
904 
905  llvm::Value* castToFP(llvm::Value* val);
906  llvm::Value* castToIntPtrTyIn(llvm::Value* val, const size_t bit_width);
907 
908  RelAlgExecutionUnit addDeletedColumn(const RelAlgExecutionUnit& ra_exe_unit);
909 
910  std::pair<bool, int64_t> skipFragment(
911  const InputDescriptor& table_desc,
912  const Fragmenter_Namespace::FragmentInfo& frag_info,
913  const std::list<std::shared_ptr<Analyzer::Expr>>& simple_quals,
914  const std::vector<uint64_t>& frag_offsets,
915  const size_t frag_idx);
916 
917  std::pair<bool, int64_t> skipFragmentInnerJoins(
918  const InputDescriptor& table_desc,
919  const RelAlgExecutionUnit& ra_exe_unit,
920  const Fragmenter_Namespace::FragmentInfo& fragment,
921  const std::vector<uint64_t>& frag_offsets,
922  const size_t frag_idx);
923 
924  std::vector<std::pair<void*, void*>> getCodeFromCache(const CodeCacheKey&,
925  const CodeCache&);
926 
927  void addCodeToCache(const CodeCacheKey&,
928  const std::vector<std::tuple<void*, GpuCompilationContext*>>&,
929  llvm::Module*,
930  CodeCache&);
931 
932  std::vector<int8_t> serializeLiterals(
933  const std::unordered_map<int, CgenState::LiteralValues>& literals,
934  const int device_id);
935 
936  static size_t align(const size_t off_in, const size_t alignment) {
937  size_t off = off_in;
938  if (off % alignment != 0) {
939  off += (alignment - off % alignment);
940  }
941  return off;
942  }
943 
944  std::unique_ptr<CgenState> cgen_state_;
945 
947  public:
949  : cgen_state_(cgen_state), saved_fetch_cache(cgen_state_->fetch_cache_) {}
950  ~FetchCacheAnchor() { cgen_state_->fetch_cache_.swap(saved_fetch_cache); }
951 
952  private:
954  std::unordered_map<int, std::vector<llvm::Value*>> saved_fetch_cache;
955  };
956 
957  llvm::Value* spillDoubleElement(llvm::Value* elem_val, llvm::Type* elem_ty);
958 
959  std::unique_ptr<PlanState> plan_state_;
960  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner_;
961 
962  static const int max_gpu_count{16};
963  std::mutex gpu_exec_mutex_[max_gpu_count];
964 
965  mutable std::mutex gpu_active_modules_mutex_;
967  mutable void* gpu_active_modules_[max_gpu_count];
969 
970  mutable std::shared_ptr<StringDictionaryProxy> lit_str_dict_proxy_;
971  mutable std::mutex str_dict_mutex_;
972 
973  mutable std::unique_ptr<llvm::TargetMachine> nvptx_target_machine_;
974 
977 
978  ::QueryRenderer::QueryRenderManager* render_manager_;
979 
980  static const size_t baseline_threshold{
981  1000000}; // if a perfect hash needs more entries, use baseline
982  static const size_t code_cache_size{10000};
983 
984  const unsigned block_size_x_;
985  const unsigned grid_size_x_;
986  const std::string debug_dir_;
987  const std::string debug_file_;
988 
989  const int db_id_;
992 
997 
998  static std::map<std::pair<int, ::QueryRenderer::QueryRenderManager*>,
999  std::shared_ptr<Executor>>
1001  static std::mutex execute_mutex_;
1003 
1004  static const int32_t ERR_DIV_BY_ZERO{1};
1005  static const int32_t ERR_OUT_OF_GPU_MEM{2};
1006  static const int32_t ERR_OUT_OF_SLOTS{3};
1007  static const int32_t ERR_UNSUPPORTED_SELF_JOIN{4};
1008  static const int32_t ERR_OUT_OF_RENDER_MEM{5};
1009  static const int32_t ERR_OUT_OF_CPU_MEM{6};
1010  static const int32_t ERR_OVERFLOW_OR_UNDERFLOW{7};
1011  static const int32_t ERR_SPECULATIVE_TOP_OOM{8};
1012  static const int32_t ERR_OUT_OF_TIME{9};
1013  static const int32_t ERR_INTERRUPTED{10};
1014  static const int32_t ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED{11};
1015  static const int32_t ERR_TOO_MANY_LITERALS{12};
1016  static const int32_t ERR_STRING_CONST_IN_RESULTSET{13};
1017  static const int32_t ERR_STREAMING_TOP_N_NOT_SUPPORTED_IN_RENDER_QUERY{14};
1019  friend class CodeGenerator;
1020  friend class ColumnFetcher;
1022  friend class GroupByAndAggregate;
1028  friend class ResultSet;
1029  friend class InValuesBitmap;
1030  friend class JoinHashTable;
1031  friend class LeafAggregator;
1032  friend class QueryRewriter;
1033  friend class PendingExecutionClosure;
1034  friend class RelAlgExecutor;
1035  friend class TableOptimizer;
1037  friend struct TargetExprCodegen;
1038 
1039  template <typename META_TYPE_CLASS>
1041 };
1042 
1043 inline std::string get_null_check_suffix(const SQLTypeInfo& lhs_ti,
1044  const SQLTypeInfo& rhs_ti) {
1045  if (lhs_ti.get_notnull() && rhs_ti.get_notnull()) {
1046  return "";
1047  }
1048  std::string null_check_suffix{"_nullable"};
1049  if (lhs_ti.get_notnull()) {
1050  CHECK(!rhs_ti.get_notnull());
1051  null_check_suffix += "_rhs";
1052  } else if (rhs_ti.get_notnull()) {
1053  CHECK(!lhs_ti.get_notnull());
1054  null_check_suffix += "_lhs";
1055  }
1056  return null_check_suffix;
1057 }
1058 
1059 inline bool is_unnest(const Analyzer::Expr* expr) {
1060  return dynamic_cast<const Analyzer::UOper*>(expr) &&
1061  static_cast<const Analyzer::UOper*>(expr)->get_optype() == kUNNEST;
1062 }
1063 
1064 bool is_trivial_loop_join(const std::vector<InputTableInfo>& query_infos,
1065  const RelAlgExecutionUnit& ra_exe_unit);
1066 
1067 std::unordered_set<int> get_available_gpus(const Catalog_Namespace::Catalog& cat);
1068 
1069 size_t get_context_count(const ExecutorDeviceType device_type,
1070  const size_t cpu_count,
1071  const size_t gpu_count);
1072 
1073 extern "C" void register_buffer_with_executor_rsm(int64_t exec, int8_t* buffer);
1074 
1076 
1077 #endif // QUERYENGINE_EXECUTE_H
std::vector< std::vector< int64_t > > num_rows
Definition: Execute.h:522
void read_rt_udf_gpu_module(const std::string &udf_ir)
const std::string debug_dir_
Definition: Execute.h:986
llvm::Value * translated_value
Definition: Execute.h:892
SQLAgg
Definition: sqldefs.h:71
float g_filter_push_down_high_frac
Definition: Execute.cpp:82
#define CHECK_EQ(x, y)
Definition: Logger.h:195
std::vector< uint64_t > all_frag_row_offsets_
Definition: Execute.h:536
std::unique_ptr< llvm::TargetMachine > nvptx_target_machine_
Definition: Execute.h:973
bool is_time() const
Definition: sqltypes.h:456
const int8_t const int64_t * num_rows
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:81
bool is_fp() const
Definition: sqltypes.h:454
bool g_strip_join_covered_quals
Definition: Execute.cpp:88
std::shared_ptr< StringDictionaryProxy > lit_str_dict_proxy_
Definition: Execute.h:970
std::vector< std::vector< uint64_t > > frag_offsets
Definition: Execute.h:523
FetchCacheAnchor(CgenState *cgen_state)
Definition: Execute.h:948
StringDictionaryProxy * getLiteralDictionary() const override
Definition: Execute.h:300
ExecutorDeviceType
std::shared_ptr< ResultSet > renderLinesNonInSitu(const std::string &queryStr, const ExecutionResult &results, const Catalog_Namespace::SessionInfo &session, const int render_widget_id, const ::QueryRenderer::JSONLocation *data_loc, RenderInfo *render_query_data)
void read_rt_udf_cpu_module(const std::string &udf_ir)
Fragmenter_Namespace::RowDataProvider RowDataProvider
Definition: Execute.h:286
decltype(FragmentInfoType::physicalTableId) const getPhysicalTableId() const
Definition: Execute.h:306
bool g_null_div_by_zero
Definition: Execute.cpp:73
std::unordered_map< int, CgenState::LiteralValues > literal_values
Definition: Execute.h:505
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:330
static mapd_shared_mutex executors_cache_mutex_
Definition: Execute.h:1002
bool is_udf_module_present(bool cpu_only=false)
bool containsLeftDeepOuterJoin() const
Definition: Execute.h:434
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:323
static std::mutex reduce_mutex_
Definition: Execute.h:542
const SQLTypeInfo get_column_type(const int col_id, const int table_id, const ColumnDescriptor *cd, const TemporaryTables *temporary_tables)
Definition: Execute.h:184
std::shared_ptr< ResultSet > renderPolygonsNonInSitu(const std::string &queryStr, const ExecutionResult &results, const Catalog_Namespace::SessionInfo &session, const int render_widget_id, const ::QueryRenderer::JSONLocation *data_loc, RenderInfo *render_query_data, const std::string &poly_table_name)
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...
SQLTypeInfo get_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:840
void read_udf_gpu_module(const std::string &udf_ir_filename)
Definition: sqldefs.h:49
std::vector< std::string > CodeCacheKey
Definition: CodeCache.h:61
bool g_inner_join_fragment_skipping
Definition: Execute.cpp:76
const Analyzer::Expr * extract_cast_arg(const Analyzer::Expr *expr)
Definition: Execute.h:149
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
const ColumnarResults * rows_to_columnar_results(std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner, const PtrTy &result, const int number)
Definition: Execute.h:199
bool g_enable_filter_push_down
Definition: Execute.cpp:80
const Analyzer::Expr * remove_cast_to_int(const Analyzer::Expr *expr)
Definition: ColumnIR.cpp:527
AggregatedColRange agg_col_range_cache_
Definition: Execute.h:994
size_t operator()(const std::pair< int, int > &p) const
Definition: Execute.h:279
std::shared_ptr< ResultSet > ResultSetPtr
std::unique_ptr< CgenState > cgen_state_
Definition: Execute.h:944
llvm::Value * original_value
Definition: Execute.h:893
std::vector< std::vector< const int8_t * > > col_buffers
Definition: Execute.h:521
std::vector< Analyzer::Expr * > get_exprs_not_owned(const std::vector< std::shared_ptr< Analyzer::Expr >> &exprs)
Definition: Execute.h:211
uint32_t gpu_active_modules_device_mask_
Definition: Execute.h:966
bool isArchPascalOrLater(const ExecutorDeviceType dt) const
Definition: Execute.h:510
size_t g_constrained_by_in_threshold
Definition: Execute.cpp:89
#define CHECK_GT(x, y)
Definition: Logger.h:199
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:331
std::vector< FragmentsPerTable > FragmentsList
std::string to_string(char const *&&v)
std::function< void(const UpdateLogForFragment &)> Callback
Definition: Execute.h:315
#define LOG_IF(severity, condition)
Definition: Logger.h:273
bool g_enable_watchdog
Definition: Execute.cpp:69
ResultSet(const std::vector< TargetInfo > &targets, const ExecutorDeviceType device_type, const QueryMemoryDescriptor &query_mem_desc, const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner, const Executor *executor)
Definition: ResultSet.cpp:91
ExecutorOptLevel
ExecutorDispatchMode
CodeCache gpu_code_cache_
Definition: Execute.h:976
std::mutex all_frag_row_offsets_mutex_
Definition: Execute.h:537
::QueryRenderer::QueryRenderManager * render_manager_
Definition: Execute.h:978
std::unordered_map< int, const ResultSetPtr & > TemporaryTables
Definition: InputMetadata.h:31
bool g_enable_dynamic_watchdog
Definition: Execute.cpp:70
const ResultSetPtr & get_temporary_table(const TemporaryTables *temporary_tables, const int table_id)
Definition: Execute.h:176
bool is_timeinterval() const
Definition: sqltypes.h:461
decltype(FragmentInfoType::fragmentId) const getFragmentId() const
Definition: Execute.h:309
bool is_integer() const
Definition: sqltypes.h:452
llvm::Value * get_arg_by_name(llvm::Function *func, const std::string &name)
Definition: Execute.h:114
std::unordered_set< int > get_available_gpus(const Catalog_Namespace::Catalog &cat)
Definition: Execute.cpp:934
bool g_enable_overlaps_hashjoin
Definition: Execute.cpp:85
const ColumnDescriptor * get_column_descriptor_maybe(const int col_id, const int table_id, const Catalog_Namespace::Catalog &cat)
Definition: Execute.h:168
const Catalog_Namespace::Catalog & cat_
Definition: Execute.h:535
std::mutex str_dict_mutex_
Definition: Execute.h:971
const Catalog_Namespace::Catalog * catalog_
Definition: Execute.h:990
#define INJECT_TIMER(DESC)
Definition: measure.h:91
std::shared_timed_mutex mapd_shared_mutex
bool is_decimal() const
Definition: sqltypes.h:453
const std::string debug_file_
Definition: Execute.h:987
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: Execute.h:960
Used by Fragmenter classes to store info about each fragment - the fragment id and number of tuples(r...
Definition: Fragmenter.h:79
const std::vector< InputTableInfo > & query_infos_
Definition: Execute.h:534
std::unique_ptr< PlanState > plan_state_
Definition: Execute.h:959
const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: Execute.h:538
size_t fragment_index_
Definition: Execute.h:319
const unsigned block_size_x_
Definition: Execute.h:984
const unsigned grid_size_x_
Definition: Execute.h:985
double g_bump_allocator_step_reduction
Definition: Execute.cpp:97
specifies the content in-memory of a row in the column metadata table
bool g_from_table_reordering
Definition: Execute.cpp:75
size_t operator()(const std::vector< int > &vec) const
Definition: Execute.h:272
size_t g_overlaps_max_table_size_bytes
Definition: Execute.cpp:87
std::string get_null_check_suffix(const SQLTypeInfo &lhs_ti, const SQLTypeInfo &rhs_ti)
Definition: Execute.h:1043
float g_filter_push_down_low_frac
Definition: Execute.cpp:81
bool g_allow_cpu_retry
Definition: Execute.cpp:72
bool is_boolean() const
Definition: sqltypes.h:457
std::shared_ptr< JoinHashTableInterface > hash_table
Definition: Execute.h:856
#define CHECK_LT(x, y)
Definition: Logger.h:197
std::shared_ptr< ResultSet > rs_
Definition: Execute.h:320
std::unique_ptr< QueryCompilationDescriptor > QueryCompilationDescriptorOwned
Definition: Execute.h:93
bool g_bigint_count
size_t get_context_count(const ExecutorDeviceType device_type, const size_t cpu_count, const size_t gpu_count)
Definition: Execute.cpp:946
const ColumnarResults * columnarize_result(std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner, const ResultSetPtr &result, const int frag_id)
Definition: Execute.h:220
StringDictionaryGenerations string_dictionary_generations_
Definition: Execute.h:995
InputTableInfoCache input_table_info_cache_
Definition: Execute.h:993
std::vector< std::pair< void *, void * > > native_functions
Definition: Execute.h:504
CodeCache cpu_code_cache_
Definition: Execute.h:975
size_t g_filter_push_down_passing_row_ubound
Definition: Execute.cpp:83
const int64_t const uint32_t const uint32_t const uint32_t const bool const bool const int32_t frag_idx
size_t g_big_group_threshold
Definition: Execute.cpp:90
FragmentInfoType const & fragment_info_
Definition: Execute.h:318
int get_logical_size() const
Definition: sqltypes.h:334
unsigned g_trivial_loop_join_threshold
Definition: Execute.cpp:74
TableGenerations table_generations_
Definition: Execute.h:996
std::tuple< std::string, const Analyzer::Expr *, int64_t, const size_t > AggInfo
Definition: Execute.h:358
std::function< void(ResultSetPtr, const Fragmenter_Namespace::FragmentInfo &)> PerFragmentCB
Definition: Execute.h:324
unsigned g_dynamic_watchdog_time_limit
Definition: Execute.cpp:71
Executor(const int db_id, const size_t block_size_x, const size_t grid_size_x, const std::string &debug_dir, const std::string &debug_file, ::QueryRenderer::QueryRenderManager *render_manager)
Definition: Execute.cpp:101
#define CHECK(condition)
Definition: Logger.h:187
const int8_t * literals
bool g_enable_columnar_output
Definition: Execute.cpp:84
bool is_trivial_loop_join(const std::vector< InputTableInfo > &query_infos, const RelAlgExecutionUnit &ra_exe_unit)
Definition: Execute.cpp:1054
std::unordered_map< int, std::unordered_map< int, std::shared_ptr< const ColumnarResults > > > ColumnCacheMap
std::vector< std::pair< ResultSetPtr, std::vector< size_t > > > all_fragment_results_
Definition: Execute.h:540
uint32_t log2_bytes(const uint32_t bytes)
Definition: Execute.h:124
std::string numeric_type_name(const SQLTypeInfo &ti)
Definition: Execute.h:157
SQLTypeInfo columnType
static bool run
bool is_unnest(const Analyzer::Expr *expr)
Definition: Execute.h:1059
Execution unit for relational algebra. It&#39;s a low-level description of any relational algebra operati...
std::unordered_map< int, std::vector< llvm::Value * > > saved_fetch_cache
Definition: Execute.h:954
CgenState * cgen_state_
Definition: Execute.h:953
__attribute__((noinline)) int32_t pos_start_impl(int32_t *error_code)
static size_t align(const size_t off_in, const size_t alignment)
Definition: Execute.h:936
RenderInfo * render_info_
Definition: Execute.h:539
static std::map< std::pair< int, ::QueryRenderer::QueryRenderManager * >, std::shared_ptr< Executor > > executors_
Definition: Execute.h:1000
std::unique_ptr< QueryMemoryDescriptor > QueryMemoryDescriptorOwned
Definition: Execute.h:95
static std::mutex execute_mutex_
Definition: Execute.h:1001
size_t g_max_memory_allocation_size
Definition: Execute.cpp:92
TSessionId session
Descriptor for the fragments required for a query.
bool is_rt_udf_module_present(bool cpu_only=false)
bool is_string() const
Definition: sqltypes.h:450
void register_buffer_with_executor_rsm(int64_t exec, int8_t *buffer)
bool interrupted_
Definition: Execute.h:968
const int db_id_
Definition: Execute.h:989
const RelAlgExecutionUnit & ra_exe_unit_
Definition: Execute.h:533
std::mutex gpu_active_modules_mutex_
Definition: Execute.h:965
SQLOps get_optype() const
Definition: Analyzer.h:363
static void nukeCacheOfExecutors()
Definition: Execute.h:349
const ColumnDescriptor * get_column_descriptor(const int col_id, const int table_id, const Catalog_Namespace::Catalog &cat)
Definition: Execute.h:139
const TemporaryTables * temporary_tables_
Definition: Execute.h:991
CompilationRetryNewScanLimit(const size_t new_scan_limit)
Definition: Execute.h:237
bool g_enable_window_functions
Definition: Execute.cpp:91
WatchdogException(const std::string &cause)
Definition: Execute.h:109
int deviceCount(const Catalog_Namespace::Catalog *catalog, const ExecutorDeviceType device_type)