OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
InputMetadata.h File Reference
+ Include dependency graph for InputMetadata.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  InputTableInfo
 
class  InputTableInfoCache
 

Namespaces

 Catalog_Namespace
 

Typedefs

using TemporaryTables = std::unordered_map< int, const ResultSetPtr & >
 

Functions

ChunkMetadataMap synthesize_metadata (const ResultSet *rows)
 
size_t get_frag_count_of_table (const shared::TableKey &table_key, Executor *executor)
 
std::vector< InputTableInfoget_table_infos (const std::vector< InputDescriptor > &input_descs, Executor *executor)
 
std::vector< InputTableInfoget_table_infos (const RelAlgExecutionUnit &ra_exe_unit, Executor *executor)
 
Fragmenter_Namespace::TableInfo build_table_info (const std::vector< const TableDescriptor * > &shard_tables)
 

Typedef Documentation

using TemporaryTables = std::unordered_map<int, const ResultSetPtr&>

Definition at line 31 of file InputMetadata.h.

Function Documentation

Fragmenter_Namespace::TableInfo build_table_info ( const std::vector< const TableDescriptor * > &  shard_tables)

Definition at line 44 of file InputMetadata.cpp.

References CHECK, Fragmenter_Namespace::TableInfo::fragments, and Fragmenter_Namespace::TableInfo::setPhysicalNumTuples().

Referenced by InputTableInfoCache::getTableInfo().

45  {
46  size_t total_number_of_tuples{0};
47  Fragmenter_Namespace::TableInfo table_info_all_shards;
48  for (const TableDescriptor* shard_table : shard_tables) {
49  CHECK(shard_table->fragmenter);
50  const auto& shard_metainfo = shard_table->fragmenter->getFragmentsForQuery();
51  total_number_of_tuples += shard_metainfo.getPhysicalNumTuples();
52  table_info_all_shards.fragments.reserve(table_info_all_shards.fragments.size() +
53  shard_metainfo.fragments.size());
54  table_info_all_shards.fragments.insert(table_info_all_shards.fragments.end(),
55  shard_metainfo.fragments.begin(),
56  shard_metainfo.fragments.end());
57  }
58  table_info_all_shards.setPhysicalNumTuples(total_number_of_tuples);
59  return table_info_all_shards;
60 }
std::vector< FragmentInfo > fragments
Definition: Fragmenter.h:171
#define CHECK(condition)
Definition: Logger.h:291
void setPhysicalNumTuples(const size_t physNumTuples)
Definition: Fragmenter.h:166

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t get_frag_count_of_table ( const shared::TableKey table_key,
Executor executor 
)

Definition at line 456 of file InputMetadata.cpp.

References CHECK, CHECK_GE, and shared::TableKey::table_id.

Referenced by RelAlgExecutor::getOuterFragmentCount().

456  {
457  const auto temporary_tables = executor->getTemporaryTables();
458  CHECK(temporary_tables);
459  auto it = temporary_tables->find(table_key.table_id);
460  if (it != temporary_tables->end()) {
461  CHECK_GE(int(0), table_key.table_id);
462  return size_t(1);
463  } else {
464  const auto table_info = executor->getTableInfo(table_key);
465  return table_info.fragments.size();
466  }
467 }
#define CHECK_GE(x, y)
Definition: Logger.h:306
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

std::vector<InputTableInfo> get_table_infos ( const std::vector< InputDescriptor > &  input_descs,
Executor executor 
)

Definition at line 469 of file InputMetadata.cpp.

References anonymous_namespace{InputMetadata.cpp}::collect_table_infos().

Referenced by RelAlgExecutor::computeWindow(), RelAlgExecutor::createAggregateWorkUnit(), RelAlgExecutor::createCompoundWorkUnit(), RelAlgExecutor::createFilterWorkUnit(), RelAlgExecutor::createProjectWorkUnit(), RelAlgExecutor::createTableFunctionWorkUnit(), RelAlgExecutor::createUnionWorkUnit(), RelAlgExecutor::executeDelete(), RelAlgExecutor::executeTableFunction(), RelAlgExecutor::executeUpdate(), RelAlgExecutor::executeWorkUnit(), TableOptimizer::getDeletedColumnStats(), RelAlgExecutor::getFilteredCountAll(), RelAlgExecutor::getFilterSelectivity(), RelAlgExecutor::getNDVEstimation(), RelAlgExecutor::handleOutOfMemoryRetry(), TableOptimizer::recomputeColumnMetadata(), and RelAlgExecutor::selectFiltersToBePushedDown().

471  {
472  std::vector<InputTableInfo> table_infos;
473  collect_table_infos(table_infos, input_descs, executor);
474  return table_infos;
475 }
void collect_table_infos(std::vector< InputTableInfo > &table_infos, const std::vector< InputDescriptor > &input_descs, Executor *executor)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector<InputTableInfo> get_table_infos ( const RelAlgExecutionUnit ra_exe_unit,
Executor executor 
)

Definition at line 477 of file InputMetadata.cpp.

References anonymous_namespace{InputMetadata.cpp}::collect_table_infos(), and RelAlgExecutionUnit::input_descs.

478  {
479  std::vector<InputTableInfo> table_infos;
480  collect_table_infos(table_infos, ra_exe_unit.input_descs, executor);
481  return table_infos;
482 }
std::vector< InputDescriptor > input_descs
void collect_table_infos(std::vector< InputTableInfo > &table_infos, const std::vector< InputDescriptor > &input_descs, Executor *executor)

+ Here is the call graph for this function:

ChunkMetadataMap synthesize_metadata ( const ResultSet rows)

Definition at line 332 of file InputMetadata.cpp.

References threading_serial::async(), CHECK, CHECK_LT, cpu_threads(), Encoder::Create(), DEBUG_TIMER, inline_fp_null_val(), inline_int_null_val(), kDOUBLE, kFLOAT, synthesize_metadata_table_function(), TableFunction, result_set::use_parallel_algorithms(), and anonymous_namespace{InputMetadata.cpp}::uses_int_meta().

Referenced by Fragmenter_Namespace::FragmentInfo::getChunkMetadataMap().

332  {
333  auto timer = DEBUG_TIMER(__func__);
334  ChunkMetadataMap metadata_map;
335 
336  if (rows->definitelyHasNoRows()) {
337  // resultset has no valid storage, so we fill dummy metadata and return early
338  std::vector<std::unique_ptr<Encoder>> decoders;
339  for (size_t i = 0; i < rows->colCount(); ++i) {
340  decoders.emplace_back(Encoder::Create(nullptr, rows->getColType(i)));
341  const auto it_ok =
342  metadata_map.emplace(i, decoders.back()->getMetadata(rows->getColType(i)));
343  CHECK(it_ok.second);
344  }
345  return metadata_map;
346  }
347 
348  std::vector<std::vector<std::unique_ptr<Encoder>>> dummy_encoders;
349  const size_t worker_count =
351  for (size_t worker_idx = 0; worker_idx < worker_count; ++worker_idx) {
352  dummy_encoders.emplace_back();
353  for (size_t i = 0; i < rows->colCount(); ++i) {
354  const auto& col_ti = rows->getColType(i);
355  dummy_encoders.back().emplace_back(Encoder::Create(nullptr, col_ti));
356  }
357  }
358 
359  if (rows->getQueryMemDesc().getQueryDescriptionType() ==
362  }
363  rows->moveToBegin();
364  const auto do_work = [rows](const std::vector<TargetValue>& crt_row,
365  std::vector<std::unique_ptr<Encoder>>& dummy_encoders) {
366  for (size_t i = 0; i < rows->colCount(); ++i) {
367  const auto& col_ti = rows->getColType(i);
368  const auto& col_val = crt_row[i];
369  const auto scalar_col_val = boost::get<ScalarTargetValue>(&col_val);
370  CHECK(scalar_col_val);
371  if (uses_int_meta(col_ti)) {
372  const auto i64_p = boost::get<int64_t>(scalar_col_val);
373  CHECK(i64_p);
374  dummy_encoders[i]->updateStats(*i64_p, *i64_p == inline_int_null_val(col_ti));
375  } else if (col_ti.is_fp()) {
376  switch (col_ti.get_type()) {
377  case kFLOAT: {
378  const auto float_p = boost::get<float>(scalar_col_val);
379  CHECK(float_p);
380  dummy_encoders[i]->updateStats(*float_p,
381  *float_p == inline_fp_null_val(col_ti));
382  break;
383  }
384  case kDOUBLE: {
385  const auto double_p = boost::get<double>(scalar_col_val);
386  CHECK(double_p);
387  dummy_encoders[i]->updateStats(*double_p,
388  *double_p == inline_fp_null_val(col_ti));
389  break;
390  }
391  default:
392  CHECK(false);
393  }
394  } else {
395  throw std::runtime_error(col_ti.get_type_name() +
396  " is not supported in temporary table.");
397  }
398  }
399  };
401  const size_t worker_count = cpu_threads();
402  std::vector<std::future<void>> compute_stats_threads;
403  const auto entry_count = rows->entryCount();
404  for (size_t i = 0,
405  start_entry = 0,
406  stride = (entry_count + worker_count - 1) / worker_count;
407  i < worker_count && start_entry < entry_count;
408  ++i, start_entry += stride) {
409  const auto end_entry = std::min(start_entry + stride, entry_count);
410  compute_stats_threads.push_back(std::async(
412  [rows, &do_work, &dummy_encoders](
413  const size_t start, const size_t end, const size_t worker_idx) {
414  for (size_t i = start; i < end; ++i) {
415  const auto crt_row = rows->getRowAtNoTranslations(i);
416  if (!crt_row.empty()) {
417  do_work(crt_row, dummy_encoders[worker_idx]);
418  }
419  }
420  },
421  start_entry,
422  end_entry,
423  i));
424  }
425  for (auto& child : compute_stats_threads) {
426  child.wait();
427  }
428  for (auto& child : compute_stats_threads) {
429  child.get();
430  }
431  } else {
432  while (true) {
433  auto crt_row = rows->getNextRow(false, false);
434  if (crt_row.empty()) {
435  break;
436  }
437  do_work(crt_row, dummy_encoders[0]);
438  }
439  }
440  rows->moveToBegin();
441  for (size_t worker_idx = 1; worker_idx < worker_count; ++worker_idx) {
442  CHECK_LT(worker_idx, dummy_encoders.size());
443  const auto& worker_encoders = dummy_encoders[worker_idx];
444  for (size_t i = 0; i < rows->colCount(); ++i) {
445  dummy_encoders[0][i]->reduceStats(*worker_encoders[i]);
446  }
447  }
448  for (size_t i = 0; i < rows->colCount(); ++i) {
449  const auto it_ok =
450  metadata_map.emplace(i, dummy_encoders[0][i]->getMetadata(rows->getColType(i)));
451  CHECK(it_ok.second);
452  }
453  return metadata_map;
454 }
ChunkMetadataMap synthesize_metadata_table_function(const ResultSet *rows)
static Encoder * Create(Data_Namespace::AbstractBuffer *buffer, const SQLTypeInfo sqlType)
Definition: Encoder.cpp:26
double inline_fp_null_val(const SQL_TYPE_INFO &ti)
std::map< int, std::shared_ptr< ChunkMetadata >> ChunkMetadataMap
bool use_parallel_algorithms(const ResultSet &rows)
Definition: ResultSet.cpp:1577
future< Result > async(Fn &&fn, Args &&...args)
bool uses_int_meta(const SQLTypeInfo &col_ti)
#define CHECK_LT(x, y)
Definition: Logger.h:303
#define CHECK(condition)
Definition: Logger.h:291
#define DEBUG_TIMER(name)
Definition: Logger.h:411
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
int cpu_threads()
Definition: thread_count.h:25

+ Here is the call graph for this function:

+ Here is the caller graph for this function: