コード例 #1
0
 /**
  * @brief Constructor for merging sorted runs to generate a sorted relation.
  *
  * @param input_relation The relation to merge sorted blocks.
  * @param output_relation The output relation.
  * @param output_destination_index The index of the InsertDestination in the
  *        QueryContext to store the sorted blocks in.
  * @param run_relation The temporary relation used to store intermediate runs
  *                     of blocks.
  * @param run_block_destination_index The index of the InsertDestination in
  *        the QueryContext to store the intermediate blocks in the merging
  *        process.
  * @param sort_config_index The index of the Sort configuration in
  *        QueryContext.
  * @param merge_factor Merge factor of this operator.
  * @param top_k Only return the first \c top_k results. Return all results if
  *              \c top_k is 0.
  * @param input_relation_is_stored Boolean to indicate is input relation is
  *                                 stored or streamed.
  **/
 SortMergeRunOperator(const CatalogRelation &input_relation,
                      const CatalogRelation &output_relation,
                      const QueryContext::insert_destination_id output_destination_index,
                      const CatalogRelation &run_relation,
                      const QueryContext::insert_destination_id run_block_destination_index,
                      const QueryContext::sort_config_id sort_config_index,
                      const std::size_t merge_factor,
                      const std::size_t top_k,
                      const bool input_relation_is_stored)
     : input_relation_(input_relation),
       output_relation_(output_relation),
       output_destination_index_(output_destination_index),
       sort_config_index_(sort_config_index),
       merge_factor_(merge_factor),
       top_k_(top_k),
       merge_tree_(merge_factor_),
       input_relation_block_ids_(input_relation_is_stored
                                     ? input_relation.getBlocksSnapshot()
                                     : std::vector<block_id>()),
       num_input_workorders_generated_(0),
       run_relation_(run_relation),
       run_block_destination_index_(run_block_destination_index),
       input_relation_is_stored_(input_relation_is_stored),
       input_stream_done_(input_relation_is_stored),
       started_(false) {
   DCHECK_GT(merge_factor_, 1u);
 }
コード例 #2
0
 /**
  * @brief Constructor for aggregating with arbitrary expressions in projection
  *        list.
  *
  * @param input_relation The relation to perform aggregation over.
  * @param input_relation_is_stored If input_relation is a stored relation and
  *        is fully available to the operator before it can start generating
  *        workorders.
  * @param aggr_state_index The index of the AggregationState in QueryContext.
  **/
 AggregationOperator(const CatalogRelation &input_relation,
                     bool input_relation_is_stored,
                     const QueryContext::aggregation_state_id aggr_state_index)
     : input_relation_is_stored_(input_relation_is_stored),
       input_relation_block_ids_(input_relation_is_stored ? input_relation.getBlocksSnapshot()
                                                          : std::vector<block_id>()),
       aggr_state_index_(aggr_state_index),
       num_workorders_generated_(0),
       started_(false) {}
コード例 #3
0
ファイル: PrintToScreen.cpp プロジェクト: zuowang/quickstep
std::size_t PrintToScreen::GetNumTuplesInRelation(
    const CatalogRelation &relation, StorageManager *storage_manager) {
  const std::vector<block_id> &blocks = relation.getBlocksSnapshot();
  std::size_t total_num_tuples = 0;
  for (block_id block : blocks) {
    total_num_tuples +=
        storage_manager->getBlock(block, relation)->getNumTuples();
  }
  return total_num_tuples;
}
コード例 #4
0
 /**
  * @brief Constructor for sorting tuples in blocks based on the sort
  * configuration and writing to output destination.
  *
  * @param input_relation The relation to generate sorted runs of.
  * @param output_relation The output relation.
  * @param output_destination_index The index of the InsertDestination in the
  *        QueryContext to store the sorted blocks of runs.
  * @param sort_config Sort configuration specifying ORDER BY, ordering and
  *                    null ordering. The operator makes a copy of the
  *                    configuration.
  * @param input_relation_is_stored Does the input relation contain the blocks
  *                                 to sort. If \c false, the blocks are
  *                                 streamed.
  **/
 SortRunGenerationOperator(const CatalogRelation &input_relation,
                           const CatalogRelation &output_relation,
                           const QueryContext::insert_destination_id output_destination_index,
                           const QueryContext::sort_config_id sort_config_index,
                           bool input_relation_is_stored)
     : input_relation_(input_relation),
       output_relation_(output_relation),
       output_destination_index_(output_destination_index),
       sort_config_index_(sort_config_index),
       input_relation_block_ids_(input_relation_is_stored ? input_relation.getBlocksSnapshot()
                                                          : std::vector<block_id>()),
       num_workorders_generated_(0),
       started_(false),
       input_relation_is_stored_(input_relation_is_stored) {}
コード例 #5
0
 /**
  * @brief Constructor.
  *
  * @param input_relation The relation to build hash table on.
  * @param input_relation_is_stored If input_relation is a stored relation and
  *        is fully available to the operator before it can start generating
  *        workorders.
  * @param join_key_attributes The IDs of equijoin attributes in
  *        input_relation.
  * @param any_join_key_attributes_nullable If any attribute is nullable.
  * @param hash_table_index The index of the JoinHashTable in QueryContext.
  *        The HashTable's key Type(s) should be the Type(s) of the
  *        join_key_attributes in input_relation.
  **/
 BuildHashOperator(const CatalogRelation &input_relation,
                   const bool input_relation_is_stored,
                   const std::vector<attribute_id> &join_key_attributes,
                   const bool any_join_key_attributes_nullable,
                   const QueryContext::join_hash_table_id hash_table_index)
   : input_relation_(input_relation),
     input_relation_is_stored_(input_relation_is_stored),
     join_key_attributes_(join_key_attributes),
     any_join_key_attributes_nullable_(any_join_key_attributes_nullable),
     hash_table_index_(hash_table_index),
     input_relation_block_ids_(input_relation_is_stored ? input_relation.getBlocksSnapshot()
                                                        : std::vector<block_id>()),
     num_workorders_generated_(0),
     started_(false) {}
コード例 #6
0
 /**
  * @brief Constructor for selection with arbitrary expressions in projection
  *        list.
  *
  * @param input_relation The relation to perform selection over.
  * @param output_relation The output relation.
  * @param output_destination_index The index of the InsertDestination in the
  *        QueryContext to insert the selection results.
  * @param predicate_index The index of selection predicate in QueryContext.
  *        All tuples matching pred will be selected (or kInvalidPredicateId to
  *        select all tuples).
  * @param selection_index The group index of Scalars in QueryContext, which
  *        will be evaluated to project input tuples.
  * @param input_relation_is_stored If input_relation is a stored relation and
  *        is fully available to the operator before it can start generating
  *        workorders.
  **/
 SelectOperator(const CatalogRelation &input_relation,
                const CatalogRelation &output_relation,
                const QueryContext::insert_destination_id output_destination_index,
                const QueryContext::predicate_id predicate_index,
                const QueryContext::scalar_group_id selection_index,
                bool input_relation_is_stored)
     : input_relation_(input_relation),
       output_relation_(output_relation),
       output_destination_index_(output_destination_index),
       predicate_index_(predicate_index),
       selection_index_(selection_index),
       simple_selection_(nullptr),
       input_relation_block_ids_(input_relation_is_stored ? input_relation.getBlocksSnapshot()
                                                          : std::vector<block_id>()),
       num_workorders_generated_(0),
       simple_projection_(false),
       input_relation_is_stored_(input_relation_is_stored),
       started_(false) {}
コード例 #7
0
 /**
  * @brief Constructor for SampleOperator with the sampling percentage and type of sampling.
  *
  * @param query_id The ID of the query to which this operator belongs.
  * @param input_relation The relation to perform sampling over.
  * @param output_relation The output relation.
  * @param output_destination_index The index of the InsertDestination in the
  *        QueryContext to insert the sampling results.
  * @param input_relation_is_stored If input_relation is a stored relation and
  *        is fully available to the operator before it can start generating
  *        workorders.
  * @param is_block_sample Flag indicating whether the sample type is block or tuple.
  * @param percentage The percentage of data to be sampled.
  **/
 SampleOperator(
     const std::size_t query_id,
     const CatalogRelation &input_relation,
     const CatalogRelationSchema &output_relation,
     const QueryContext::insert_destination_id output_destination_index,
     const bool input_relation_is_stored,
     const bool is_block_sample,
     const int percentage)
     : RelationalOperator(query_id),
       input_relation_(input_relation),
       output_relation_(output_relation),
       output_destination_index_(output_destination_index),
       input_relation_is_stored_(input_relation_is_stored),
       is_block_sample_(is_block_sample),
       percentage_(percentage),
       input_relation_block_ids_(input_relation_is_stored
                                     ? input_relation.getBlocksSnapshot()
                                     : std::vector<block_id>()),
       num_workorders_generated_(0),
       started_(false) {}
コード例 #8
0
void DropTableWorkOrder::execute(QueryContext *query_context,
                                 CatalogDatabase *database,
                                 StorageManager *storage_manager) {
  DCHECK(database != nullptr);
  DCHECK(storage_manager != nullptr);

  CatalogRelation *relation = database->getRelationByIdMutable(rel_id_);
  DCHECK(relation != nullptr);

  std::vector<block_id> relation_blocks(relation->getBlocksSnapshot());

  for (const block_id relation_block_id : relation_blocks) {
    storage_manager->deleteBlockOrBlobFile(relation_block_id);
  }

  if (only_drop_blocks_) {
    relation->clearBlocks();
  } else {
    database->dropRelationById(rel_id_);
  }
}
コード例 #9
0
ファイル: PrintToScreen.cpp プロジェクト: zuowang/quickstep
void PrintToScreen::PrintRelation(const CatalogRelation &relation,
                                  StorageManager *storage_manager,
                                  FILE *out) {
  if (!FLAGS_printing_enabled) {
    return;
  }

  vector<int> column_widths;
  column_widths.reserve(relation.size());

  for (CatalogRelation::const_iterator attr_it = relation.begin();
       attr_it != relation.end();
       ++attr_it) {
    // Printed column needs to be wide enough to print:
    //   1. The attribute name (in the printed "header").
    //   2. Any value of the attribute's Type.
    //   3. If the attribute's Type is nullable, the 4-character string "NULL".
    // We pick the largest of these 3 widths as the column width.
    int column_width = static_cast<int>(attr_it->getDisplayName().length());
    column_width = column_width < attr_it->getType().getPrintWidth()
                   ? attr_it->getType().getPrintWidth()
                   : column_width;
    column_width = attr_it->getType().isNullable() && (column_width < 4)
                   ? 4
                   : column_width;
    column_widths.push_back(column_width);
  }

  printHBar(column_widths, out);

  fputc('|', out);
  vector<int>::const_iterator width_it = column_widths.begin();
  CatalogRelation::const_iterator attr_it = relation.begin();
  for (; width_it != column_widths.end(); ++width_it, ++attr_it) {
    fprintf(out,
            "%-*s|",
            *width_it,
            attr_it->getDisplayName().c_str());
  }
  fputc('\n', out);

  printHBar(column_widths, out);

  std::vector<block_id> blocks = relation.getBlocksSnapshot();
  for (const block_id current_block_id : blocks) {
    BlockReference block = storage_manager->getBlock(current_block_id, relation);
    const TupleStorageSubBlock &tuple_store = block->getTupleStorageSubBlock();

    if (tuple_store.isPacked()) {
      for (tuple_id tid = 0; tid <= tuple_store.getMaxTupleID(); ++tid) {
        printTuple(tuple_store, tid, column_widths, out);
      }
    } else {
      std::unique_ptr<TupleIdSequence> existence_map(tuple_store.getExistenceMap());
      for (tuple_id tid : *existence_map) {
        printTuple(tuple_store, tid, column_widths, out);
      }
    }
  }

  printHBar(column_widths, out);
}