Пример #1
0
  /**
   * Get the best plan for the SQL statement given, assuming the given costModel.
   *
   * @return The best plan found for the SQL statement.
   * @throws PlanningErrorException on failure.
   */
  public CompiledPlan plan() throws PlanningErrorException {
    // reset any error message
    m_recentErrorMsg = null;

    // what's going to happen next:
    //  If a parameterized statement exists, try to make a plan with it
    //  On success return the plan.
    //  On failure, try the plan again without parameterization

    if (m_paramzInfo != null) {
      try {
        // compile the plan with new parameters
        CompiledPlan plan =
            compileFromXML(m_paramzInfo.parameterizedXmlSQL, m_paramzInfo.paramLiteralValues);
        if (plan != null) {
          if (m_isUpsert) {
            replacePlanForUpsert(plan);
          }
          if (plan.extractParamValues(m_paramzInfo)) {
            return plan;
          }
        } else {
          if (m_debuggingStaticModeToRetryOnError) {
            plan =
                compileFromXML(m_paramzInfo.parameterizedXmlSQL, m_paramzInfo.paramLiteralValues);
          }
        }
        // fall through to try replan without parameterization.
      } catch (Exception e) {
        // ignore any errors planning with parameters
        // fall through to re-planning without them
        m_hasExceptionWhenParameterized = true;

        // note, expect real planning errors ignored here to be thrown again below
        m_recentErrorMsg = null;
        m_partitioning.resetAnalysisState();
      }
    }

    // if parameterization isn't requested or if it failed, plan here
    CompiledPlan plan = compileFromXML(m_xmlSQL, null);
    if (plan == null) {
      if (m_debuggingStaticModeToRetryOnError) {
        plan = compileFromXML(m_xmlSQL, null);
      }
      throw new PlanningErrorException(m_recentErrorMsg);
    }

    if (m_isUpsert) {
      replacePlanForUpsert(plan);
    }

    return plan;
  }