Exemple #1
0
GroupExpression *Memo::InsertExpression(std::shared_ptr<GroupExpression> gexpr,
                                        GroupID target_group, bool enforced) {
  // If leaf, then just return
  if (gexpr->Op().GetType() == OpType::Leaf) {
    const LeafOperator *leaf = gexpr->Op().As<LeafOperator>();
    PELOTON_ASSERT(target_group == UNDEFINED_GROUP ||
           target_group == leaf->origin_group);
    gexpr->SetGroupID(leaf->origin_group);
    return nullptr;
  }

  // Lookup in hash table
  auto it = group_expressions_.find(gexpr.get());

  if (it != group_expressions_.end()) {
    gexpr->SetGroupID((*it)->GetGroupID());
    return *it;
  } else {
    group_expressions_.insert(gexpr.get());
    // New expression, so try to insert into an existing group or
    // create a new group if none specified
    GroupID group_id;
    if (target_group == UNDEFINED_GROUP) {
      group_id = AddNewGroup(gexpr);
    } else {
      group_id = target_group;
    }
    Group *group = GetGroupByID(group_id);
    group->AddExpression(gexpr, enforced);
    return gexpr.get();
  }
}
Exemple #2
0
bool Memo::InsertExpression(std::shared_ptr<GroupExpression> gexpr,
                            GroupID target_group)
{
  // If leaf, then just return
  if (gexpr->Op().type() == OpType::Leaf) {
    const LeafOperator *leaf = gexpr->Op().as<LeafOperator>();
    assert(target_group == UNDEFINED_GROUP ||
           target_group == leaf->origin_group);
    gexpr->SetGroupID(leaf->origin_group);
    return false;
  }

  // Lookup in hash table
  auto it = group_expressions.find(gexpr.get());

  bool new_expression;
  if (it != group_expressions.end()) {
    new_expression = false;
    assert(target_group == UNDEFINED_GROUP ||
           target_group == (*it)->GetGroupID());
    gexpr->SetGroupID((*it)->GetGroupID());
  } else {
    new_expression = true;
    group_expressions.insert(gexpr.get());
    // New expression, so try to insert into an existing group or
    // create a new group if none specified
    GroupID group_id;
    if (target_group == UNDEFINED_GROUP) {
      group_id = AddNewGroup();
    } else {
      group_id = target_group;
    }
    Group *group = GetGroupByID(group_id);
    group->AddExpression(gexpr);
  }

  return new_expression;
}