Exemplo n.º 1
0
int ObPhysicalPlan::create_and_assign_tree(
    const ObPhyOperator *other,
    bool main_query,
    bool is_query,
    ObPhyOperator *&out_op)
{
    int ret = OB_SUCCESS;
    ObPhyOperator *op = NULL;
    if (!other)
    {
        ret = OB_ERR_UNEXPECTED;
        TBSYS_LOG(WARN, "Operator to be assigned cna not be NULL, ret=%d", ret);
    }
    else if ((op = ObPhyOperator::alloc(other->get_type())) == NULL)
    {
        ret = OB_ALLOCATE_MEMORY_FAILED;
        TBSYS_LOG(WARN, "Create operator fail:type[%d]", other->get_type());
    }
    else if ((ret = operators_store_.push_back(op)) != OB_SUCCESS)
    {
        // should free op here
        ObPhyOperator::free(op);
        TBSYS_LOG(WARN, "Fail to push operator to operators_store:ret[%d]", ret);
    }
    else if (is_query && (ret = this->add_phy_query(op, NULL, main_query)) != OB_SUCCESS)
    {
        TBSYS_LOG(WARN, "Add operator to physical plan failed, ret=%d", ret);
    }
    else
    {
        op->set_phy_plan(this);
        op->set_id(other->get_id());
        out_op = op;

        if ((ret = op->assign(other)) != OB_SUCCESS)
        {
            TBSYS_LOG(WARN, "Assign operator of physical plan failed, ret=%d", ret);
        }
        TBSYS_LOG(DEBUG, "assign operator, type=%s main_query=%c", ob_phy_operator_type_str(other->get_type()),
                  main_query?'Y':'N');
    }
    for (int32_t i = 0; ret == OB_SUCCESS && i < other->get_child_num(); i++)
    {
        ObPhyOperator *child = NULL;
        if (!other->get_child(i))
        {
            ret = OB_ERR_GEN_PLAN;
            TBSYS_LOG(WARN, "Wrong physical plan, ret=%d", ret);
        }
        else if ((ret = create_and_assign_tree(other->get_child(i), false, false, child)) != OB_SUCCESS)
        {
            TBSYS_LOG(WARN, "Fail to create_and_assign tree:ret[%d]", ret);
        }
        else if (OB_SUCCESS != (ret = op->set_child(i, *child)))
        {
            TBSYS_LOG(WARN, "Fail to set child:ret[%d]", ret);
        }
    }
    return ret;
}
Exemplo n.º 2
0
int ObPhysicalPlan::serialize_tree(char *buf, int64_t buf_len, int64_t &pos, const ObPhyOperator &root) const
{
    int ret = OB_SUCCESS;

    if (OB_SUCCESS == ret)
    {
        if (OB_SUCCESS != (ret = encode_vi32(buf, buf_len, pos, root.get_type())))
        {
            TBSYS_LOG(WARN, "fail to encode op type:ret[%d]", ret);
        }
        else if (OB_SUCCESS != (ret = root.serialize(buf, buf_len, pos)))
        {
            TBSYS_LOG(WARN, "fail to serialize root:ret[%d] type=%d op=%s", ret, root.get_type(), to_cstring(root));
        }
        else
        {
            TBSYS_LOG(DEBUG, "serialize operator succ, type=%d", root.get_type());
        }
    }

    for (int64_t i=0; OB_SUCCESS == ret && i<root.get_child_num(); i++)
    {
        if (NULL != root.get_child(static_cast<int32_t>(i)) )
        {
            if (OB_SUCCESS != (ret = serialize_tree(buf, buf_len, pos, *(root.get_child(static_cast<int32_t>(i))))))
            {
                TBSYS_LOG(WARN, "fail to serialize tree:ret[%d]", ret);
            }
        }
        else
        {
            ret = OB_ERR_UNEXPECTED;
            TBSYS_LOG(WARN, "this operator should has child:type[%d]", root.get_type());
        }
    }
    return ret;
}
Exemplo n.º 3
0
int ObWhenFilter::open()
{
  int ret = OB_SUCCESS;
  ObRowDesc tmp_row_desc;
  //ObRow tmp_row;
  tmp_row.clear();
  tmp_row.set_row_desc(tmp_row_desc);
  if (OB_UNLIKELY(ObMultiChildrenPhyOperator::get_child_num() <= 0))
  {
    ret = OB_NOT_INIT;
    TBSYS_LOG(ERROR, "ObWhenFilter has no child operator, ret=%d", ret);
  }
  else
  {
    for (int32_t i = 1; ret == OB_SUCCESS && i < ObMultiChildrenPhyOperator::get_child_num(); i++)
    {
      const ObRow *child_row = NULL;
      ObPhyOperator *op = NULL;
      if ((op = get_child(i)) == NULL)
      {
        ret = OB_ERR_GEN_PLAN;
        TBSYS_LOG(WARN, "Can not get %dth child of ObWhenFilter ret=%d", i, ret);
        break;
      }
      else if ((ret = op->open()) != OB_SUCCESS)
      {
        if (!IS_SQL_ERR(ret))
        {
          TBSYS_LOG(WARN, "Open the %dth child of ObWhenFilter failed, ret=%d", i, ret);
        }
        break;
      }
      else if ((ret = op->get_next_row(child_row)) != OB_SUCCESS)
      {
        TBSYS_LOG(WARN, "Get nex row of %dth child failed ret=%d", i, ret);
        break;
      }
      switch (op->get_type())
      {
        case PHY_ROW_COUNT:
        {
          uint64_t table_id = OB_INVALID_ID;
          uint64_t column_id = OB_INVALID_ID;
          const ObObj *cell = NULL;
          if ((ret = child_row->raw_get_cell(0, cell, table_id, column_id)) != OB_SUCCESS)
          {
            TBSYS_LOG(WARN, "Wrong index of ObRowCount, idx=%d ret=%d", 0, ret);
          }
          else if ((ret = tmp_row_desc.add_column_desc(table_id, column_id)) != OB_SUCCESS)
          {
            TBSYS_LOG(WARN, "Add column to ObRowDesc failed, ret=%d", ret);
          }
          else if ((ret = tmp_row.set_cell(table_id, column_id, *cell)) != OB_SUCCESS)
          {
            TBSYS_LOG(WARN, "Add cell to ObRow failed, ret=%d", ret);
          }
          break;
        }
        default:
        {
          ret = OB_ERR_ILLEGAL_TYPE;
          TBSYS_LOG(WARN, "Unknown child type of ObWhenFilter, index=%d, ret=%d", i, ret);
        }
      }
    }
    const ObObj *result = NULL;
    for (int32_t i = 0; ret == OB_SUCCESS && i < filters_.count(); ++i)
    {
      ObSqlExpression &expr = filters_.at(i);
      if (OB_SUCCESS != (ret = expr.calc(tmp_row, result)))
      {
        TBSYS_LOG(WARN, "Failed to calc expression, err=%d", ret);
      }
      else if (!result->is_true())
      {
        ret = OB_ERR_WHEN_UNSATISFIED;
        char buf[OB_MAX_RESULT_MESSAGE_LENGTH];
        int64_t pos = 0;
        databuff_printf(buf, OB_MAX_RESULT_MESSAGE_LENGTH, 
                        pos, "Number %ld When filter failed, ret=%d", when_number_, ret);
        for (int32_t i = 1; i < ObMultiChildrenPhyOperator::get_child_num(); i++)
        {
          const common::ObObj *cell;
          uint64_t table_id = OB_INVALID_ID;
          uint64_t column_id = OB_INVALID_ID;
          if (tmp_row.raw_get_cell(i - 1, cell, table_id, column_id) != OB_SUCCESS)
            break;
          switch (get_child(i)->get_type())
          {
            case PHY_ROW_COUNT:
            {
              int64_t row_count = -1;
              if (cell->get_int(row_count) != OB_SUCCESS)
                break;
              databuff_printf(buf, OB_MAX_RESULT_MESSAGE_LENGTH, 
                              pos, ", func %d: ROW_COUNT()=%ld", i, row_count);
              break;
            }
            default:
            {
              break;
            }
          }
        }
        buf[OB_MAX_RESULT_MESSAGE_LENGTH == pos ? pos - 1 : pos] = '\0';
        TBSYS_LOG(USER_ERROR, "%s", buf);
      }
    } // end for
    // close when functions when out of use wheather successed or failed
    for (int32_t i = 1; ret == OB_SUCCESS && i < ObMultiChildrenPhyOperator::get_child_num(); i++)
    {
      if ((ret = get_child(i)->close()) != OB_SUCCESS)
      {
        TBSYS_LOG(WARN, "Close the %dth child of ObWhenFilter failed, ret=%d", i, ret);
      }
    }
    if (ret == OB_SUCCESS)
    {
      if ((ret =  get_child(0)->open()) == OB_SUCCESS)
      {
        could_do_next_ = true;
      }
      else
      {
        if (!IS_SQL_ERR(ret))
        {
          TBSYS_LOG(WARN, "Open the first child of ObWhenFilter failed, ret=%d", ret);
        }
      }
    }
  }
  return ret;
}