OmniSciDB  8fa3bf436f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InputMetadata.cpp File Reference
#include "InputMetadata.h"
#include "Execute.h"
#include "../Fragmenter/Fragmenter.h"
#include <future>
+ Include dependency graph for InputMetadata.cpp:

Go to the source code of this file.

Namespaces

 

Functions

Fragmenter_Namespace::TableInfo anonymous_namespace{InputMetadata.cpp}::copy_table_info (const Fragmenter_Namespace::TableInfo &table_info)
 
Fragmenter_Namespace::TableInfo build_table_info (const std::vector< const TableDescriptor * > &shard_tables)
 
bool anonymous_namespace{InputMetadata.cpp}::uses_int_meta (const SQLTypeInfo &col_ti)
 
Fragmenter_Namespace::TableInfo anonymous_namespace{InputMetadata.cpp}::synthesize_table_info (const ResultSetPtr &rows)
 
void anonymous_namespace{InputMetadata.cpp}::collect_table_infos (std::vector< InputTableInfo > &table_infos, const std::vector< InputDescriptor > &input_descs, Executor *executor)
 
ChunkMetadataMap synthesize_metadata (const ResultSet *rows)
 
size_t get_frag_count_of_table (const int table_id, 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)
 

Function Documentation

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

Definition at line 39 of file InputMetadata.cpp.

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

Referenced by InputTableInfoCache::getTableInfo().

40  {
41  size_t total_number_of_tuples{0};
42  Fragmenter_Namespace::TableInfo table_info_all_shards;
43  for (const TableDescriptor* shard_table : shard_tables) {
44  CHECK(shard_table->fragmenter);
45  const auto& shard_metainfo = shard_table->fragmenter->getFragmentsForQuery();
46  total_number_of_tuples += shard_metainfo.getPhysicalNumTuples();
47  table_info_all_shards.fragments.reserve(table_info_all_shards.fragments.size() +
48  shard_metainfo.fragments.size());
49  table_info_all_shards.fragments.insert(table_info_all_shards.fragments.end(),
50  shard_metainfo.fragments.begin(),
51  shard_metainfo.fragments.end());
52  }
53  table_info_all_shards.setPhysicalNumTuples(total_number_of_tuples);
54  return table_info_all_shards;
55 }
std::vector< FragmentInfo > fragments
Definition: Fragmenter.h:160
#define CHECK(condition)
Definition: Logger.h:203
void setPhysicalNumTuples(const size_t physNumTuples)
Definition: Fragmenter.h:155

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t get_frag_count_of_table ( const int  table_id,
Executor executor 
)

Definition at line 241 of file InputMetadata.cpp.

References CHECK, and CHECK_GE.

Referenced by RelAlgExecutor::getOuterFragmentCount().

241  {
242  const auto temporary_tables = executor->getTemporaryTables();
243  CHECK(temporary_tables);
244  auto it = temporary_tables->find(table_id);
245  if (it != temporary_tables->end()) {
246  CHECK_GE(int(0), table_id);
247  return size_t(1);
248  } else {
249  const auto table_info = executor->getTableInfo(table_id);
250  return table_info.fragments.size();
251  }
252 }
#define CHECK_GE(x, y)
Definition: Logger.h:216
#define CHECK(condition)
Definition: Logger.h:203

+ 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 254 of file InputMetadata.cpp.

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

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

256  {
257  std::vector<InputTableInfo> table_infos;
258  collect_table_infos(table_infos, input_descs, executor);
259  return table_infos;
260 }
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 262 of file InputMetadata.cpp.

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

263  {
265  std::vector<InputTableInfo> table_infos;
266  collect_table_infos(table_infos, ra_exe_unit.input_descs, executor);
267  return table_infos;
268 }
std::vector< InputDescriptor > input_descs
#define INJECT_TIMER(DESC)
Definition: measure.h:93
std::vector< InputTableInfo > get_table_infos(const std::vector< InputDescriptor > &input_descs, Executor *executor)
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 135 of file InputMetadata.cpp.

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

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

135  {
136  auto timer = DEBUG_TIMER(__func__);
137  rows->moveToBegin();
138  std::vector<std::vector<std::unique_ptr<Encoder>>> dummy_encoders;
139  const size_t worker_count =
141  for (size_t worker_idx = 0; worker_idx < worker_count; ++worker_idx) {
142  dummy_encoders.emplace_back();
143  for (size_t i = 0; i < rows->colCount(); ++i) {
144  const auto& col_ti = rows->getColType(i);
145  dummy_encoders.back().emplace_back(Encoder::Create(nullptr, col_ti));
146  }
147  }
148  const auto do_work = [rows](const std::vector<TargetValue>& crt_row,
149  std::vector<std::unique_ptr<Encoder>>& dummy_encoders) {
150  for (size_t i = 0; i < rows->colCount(); ++i) {
151  const auto& col_ti = rows->getColType(i);
152  const auto& col_val = crt_row[i];
153  const auto scalar_col_val = boost::get<ScalarTargetValue>(&col_val);
154  CHECK(scalar_col_val);
155  if (uses_int_meta(col_ti)) {
156  const auto i64_p = boost::get<int64_t>(scalar_col_val);
157  CHECK(i64_p);
158  dummy_encoders[i]->updateStats(*i64_p, *i64_p == inline_int_null_val(col_ti));
159  } else if (col_ti.is_fp()) {
160  switch (col_ti.get_type()) {
161  case kFLOAT: {
162  const auto float_p = boost::get<float>(scalar_col_val);
163  CHECK(float_p);
164  dummy_encoders[i]->updateStats(*float_p,
165  *float_p == inline_fp_null_val(col_ti));
166  break;
167  }
168  case kDOUBLE: {
169  const auto double_p = boost::get<double>(scalar_col_val);
170  CHECK(double_p);
171  dummy_encoders[i]->updateStats(*double_p,
172  *double_p == inline_fp_null_val(col_ti));
173  break;
174  }
175  default:
176  CHECK(false);
177  }
178  } else {
179  throw std::runtime_error(col_ti.get_type_name() +
180  " is not supported in temporary table.");
181  }
182  }
183  };
185  const size_t worker_count = cpu_threads();
186  std::vector<std::future<void>> compute_stats_threads;
187  const auto entry_count = rows->entryCount();
188  for (size_t i = 0,
189  start_entry = 0,
190  stride = (entry_count + worker_count - 1) / worker_count;
191  i < worker_count && start_entry < entry_count;
192  ++i, start_entry += stride) {
193  const auto end_entry = std::min(start_entry + stride, entry_count);
194  compute_stats_threads.push_back(std::async(
195  std::launch::async,
196  [rows, &do_work, &dummy_encoders](
197  const size_t start, const size_t end, const size_t worker_idx) {
198  for (size_t i = start; i < end; ++i) {
199  const auto crt_row = rows->getRowAtNoTranslations(i);
200  if (!crt_row.empty()) {
201  do_work(crt_row, dummy_encoders[worker_idx]);
202  }
203  }
204  },
205  start_entry,
206  end_entry,
207  i));
208  }
209  for (auto& child : compute_stats_threads) {
210  child.wait();
211  }
212  for (auto& child : compute_stats_threads) {
213  child.get();
214  }
215  } else {
216  while (true) {
217  auto crt_row = rows->getNextRow(false, false);
218  if (crt_row.empty()) {
219  break;
220  }
221  do_work(crt_row, dummy_encoders[0]);
222  }
223  rows->moveToBegin();
224  }
225  ChunkMetadataMap metadata_map;
226  for (size_t worker_idx = 1; worker_idx < worker_count; ++worker_idx) {
227  CHECK_LT(worker_idx, dummy_encoders.size());
228  const auto& worker_encoders = dummy_encoders[worker_idx];
229  for (size_t i = 0; i < rows->colCount(); ++i) {
230  dummy_encoders[0][i]->reduceStats(*worker_encoders[i]);
231  }
232  }
233  for (size_t i = 0; i < rows->colCount(); ++i) {
234  const auto it_ok =
235  metadata_map.emplace(i, dummy_encoders[0][i]->getMetadata(rows->getColType(i)));
236  CHECK(it_ok.second);
237  }
238  return metadata_map;
239 }
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:1122
bool uses_int_meta(const SQLTypeInfo &col_ti)
#define CHECK_LT(x, y)
Definition: Logger.h:213
#define CHECK(condition)
Definition: Logger.h:203
#define DEBUG_TIMER(name)
Definition: Logger.h:319
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
int cpu_threads()
Definition: thread_count.h:24

+ Here is the call graph for this function:

+ Here is the caller graph for this function: