Esempio n. 1
0
   INT32 _qgmOptiNLJoin::makeCondition()
   {
      PD_TRACE_ENTRY( SDB__QGMOPTINLJOIN_MAKECONDITION ) ;
      INT32 rc = SDB_OK ;
      qgmFilterUnit *condUnit = NULL ;

      if ( !needMakeCondition() )
      {
         goto done ; ;
      }

      rc = _makeCondVar( _condition ) ;
      if ( SDB_OK != rc )
      {
         goto error ;
      }

      rc = _createJoinUnit() ;
      if ( SDB_OK != rc )
      {
         goto error ;
      }

      if ( _hints.empty() )
      {
         // create a condtion oprUnit
         condUnit = SDB_OSS_NEW qgmFilterUnit( QGM_OPTI_TYPE_FILTER ) ;
         if ( !condUnit )
         {
            rc = SDB_OOM ;
            goto error ;
         }
         condUnit->setCondition( _condition ) ;
         _condition = NULL ;
         condUnit->setDispatchAlias( inner()->getAlias( TRUE ) ) ;
         _oprUnits.push_back( condUnit ) ;
         condUnit = NULL ;
      }
      else
      {
         _varList.clear() ;
      }

      _hasMakeVar = TRUE ;

   done:
      PD_TRACE_EXITRC( SDB__QGMOPTINLJOIN_MAKECONDITION, rc ) ;
      return rc ;
   error:
      if ( condUnit )
      {
         SDB_OSS_DEL condUnit ;
      }
      goto done ;
   }
Esempio n. 2
0
INT32 _qgmOptiNLJoin::_makeCondVar( qgmConditionNode * cond )
{
    PD_TRACE_ENTRY( SDB__QGMOPTINLJOIN__MAKECONDVAR ) ;
    INT32 rc = SDB_OK ;
    BOOLEAN existed = FALSE ;
    varItem item ;

    if ( cond->type == SQL_GRAMMAR::OR )
    {
        PD_LOG_MSG( PDERROR, "Join condition not suport or" ) ;
        rc = SDB_SYS ;
        goto error ;
    }
    else if ( cond->type == SQL_GRAMMAR::NOT )
    {
        PD_LOG_MSG( PDERROR, "Join condition not suport not" ) ;
        rc = SDB_SYS ;
        goto error ;
    }
    else if ( cond->type == SQL_GRAMMAR::AND )
    {
        rc = _makeCondVar( cond->left ) ;
        if ( SDB_OK != rc )
        {
            goto error ;
        }

        rc = _makeCondVar( cond->right ) ;
        if ( SDB_OK != rc )
        {
            goto error ;
        }
    }
    else
    {
        if ( cond->left->value.relegation() == outer()->getAlias( TRUE ) )
        {
            _qgmConditionNode *tmp = cond->left ;
            cond->left = cond->right ;
            cond->right = tmp ;
            if ( SQL_GRAMMAR::LT == cond->type )
            {
                cond->type = SQL_GRAMMAR::GT ;
            }
            else if ( SQL_GRAMMAR::GT == cond->type )
            {
                cond->type = SQL_GRAMMAR::LT ;
            }
            else if ( SQL_GRAMMAR::GTE == cond->type )
            {
                cond->type = SQL_GRAMMAR::LTE ;
            }
            else if ( SQL_GRAMMAR::LTE == cond->type )
            {
                cond->type = SQL_GRAMMAR::GTE ;
            }
            else
            {
            }
        }
#ifdef _DEBUG
        if ( cond->right->type != SQL_GRAMMAR::DBATTR ||
                cond->right->value.relegation() != outer()->getAlias( TRUE ) )
        {
            PD_LOG_MSG( PDERROR, "Join condition[%s] invalid",
                        qgmConditionNodeHelper(cond).toJson().c_str() ) ;
            rc = SDB_INVALIDARG ;
            goto error ;
        }
#endif //_DEBUG

        item._fieldName = cond->right->value ;
        item._varName = cond->right->value ;
        item._varName.relegation() = _uniqueNameR ;
        rc = _param->addVar( item._varName, cond->right->var, &existed ) ;
        if ( SDB_OK != rc )
        {
            PD_LOG( PDERROR, "Add var[%s, %s] failed, rc: %d",
                    item._fieldName.toString().c_str(),
                    item._varName.toString().c_str(), rc ) ;
            goto error ;
        }
        if ( !existed )
        {
            _varList.push_back( item ) ;
        }

        if ( _hints.empty() )
        {
            cond->right->type = SQL_GRAMMAR::SQLMAX + 1 ;
        }
    }

done:
    PD_TRACE_EXITRC( SDB__QGMOPTINLJOIN__MAKECONDVAR, rc ) ;
    return rc ;
error:
    goto done ;
}