Пример #1
0
/*{
** Name: opn_bfkhget	- get keyinfo structure given histogram and eqcls
**
** Description:
**	Get the opb_bfkeyinfo struct that corresponds to the given
**	eqclass and its associated type and length as found among the histos 
**      in relations histogram list.  Note, that for any particular relation
**      there will be a set of equivalences classes associated with that
**      relation.  For each equivalence class there will be exactly one
**      or no histograms associated with that equivalence class.
**      Thus, given the equivalence class
**      and the list of histograms, the histogram associated with the
**      equivalence class can be determined.  For every histogram there is
**      an original joinop attribute associated with it.  The type and length
**      associated with the joinop attribute will be used to obtain the keylist
**      from the boolean factor with the same type and length.  
**        
** Inputs:
**      subquery                        ptr to subquery being analyzed
**      bp                              ptr to boolean factor which has the
**                                      keylists
**      eqc                             equivalence class from which a key
**                                      element is required - there may be
**                                      several keylists in bp associated
**                                      with this equivalence class
**      hp                              list of histograms associated with
**                                      relation
**
** Outputs:
**      hpp                             get histogram associated with 
**                                      equivalence class if this ptr is not
**                                      NULL
**	Returns:
**	    OPB_BFKEYINFO ptr of key associated with (equivalence class and
**          histogram pair).  There will only one histogram in this list with
**	    this equivalence class - get that histogram and use the type and 
**          length associated with the histogram and the input equivalence
**          class to obtain the key from the boolean factor.
**	Exceptions:
**	    none
**
** Side Effects:
**	    none
**
** History:
**	22-may-86 (seputis)
**          initial creation
**	25-apr-94 (rganski)
**	    b59982 - added histdt parameter to call to opb_bfkget(). See
**	    comment in opb_bfkget() for more details.
{@history_line@}
[@history_line@]...
*/
OPB_BFKEYINFO *
opn_bfkhget(
	OPS_SUBQUERY	   *subquery,
	OPB_BOOLFACT       *bp,
	OPE_IEQCLS         eqc,
	OPH_HISTOGRAM      *hp,
	bool               mustfind,
	OPH_HISTOGRAM      **hpp)
{
    OPH_HISTOGRAM       *thp;	    /* histogram associated with equivalence
                                    ** class eqc */
    OPZ_ATTS            *attrp;     /* ptr to joinop attribute associated with
                                    ** histogram thp
                                    */
    OPB_BFKEYINFO       *bfkeyp;    /* ptr to struct with proper equivalence
                                    ** class, type and length characteristics
                                    */
    OPH_HISTOGRAM       **thpp;     /* used in case NULL is returned */
    if (!(thpp = opn_eqtamp(subquery, &hp, eqc, mustfind)) )
	return (NULL);
    thp = *thpp;
    attrp = subquery->ops_attrs.opz_base->opz_attnums[thp->oph_attribute]; /* 
                                ** get attribute pointer associated with
                                ** histogram */
    if ((bfkeyp = opb_bfkget(subquery, bp, eqc, &attrp->opz_dataval,
			     &attrp->opz_histogram.oph_dataval, mustfind))
	== NULL)
	return (NULL);
    if (hpp)			/* return this info if requested */
	*hpp = thp;
    return (bfkeyp);
}
Пример #2
0
/*{
** Name: opb_mbf	- find matching boolean factors for keylist
**
** Description:
**	See if there are the right matching boolean factors for
**	the given attributes so that they can be used to key the
**	relation.
**
** Inputs:
**      subquery                        ptr to subquery being analyzed
**      storage                         storage structure associated with
**                                      keylist
**      mbf                             matching boolean factor list
**                                      - contains keylist on which the
**                                      relation is ordered, but the matching
**                                      boolean factors have not been found
**
** Outputs:
**      mbf                             ptr to structure which will contain
**                                      the matching boolean factors for the
**                                      attributes in the dmfkeylist
**	Returns:
**	    TRUE if a limiting boolean factor has been found
**	Exceptions:
**	    none
**
** Side Effects:
**	    none
**
** History:
**	4-may-86 (seputis)
**
**	25-apr-94 (rganski)
**	    b59982 - added histdt parameter to call to opb_bfkget(). See
**	    comment in opb_bfkget() for more details.
**	26-oct-00 (inkdo01)
**	    Dropped use of OPB_SSINGLEALL since its sole purpose appeared
**	    to be to prevent IN-lists on lower order columns of multi-att,
**	    non-hash key structures. Just didn't make sense.
**	22-nov-01 (inkdo01)
**	    Check for "tid is null" and don't return key structure (these 
**	    may be outer join tricks and are useless for key access).
{@history_line@}...
*/
bool
opb_mbf(
	OPS_SUBQUERY       *subquery,
	OPO_STORAGE	   storage,
	OPB_MBF            *mbf)
{
    i4                  count;	/* count of number of active elements in the
                                ** the keylist
                                */

    mbf->opb_maorder = NULL;
    if ( (count = mbf->opb_count) <= 0)
        return(FALSE);		/* keylist does not exist so this relation
                                ** does not have a useful ordering for this
                                ** query
                                */
    if (storage == DB_HEAP_STORE)
        return(FALSE);		/* heap is not useful for limiting predicates*/
    
    {
	bool		rangeOk;
	i4                    keyi;	/* offset in opb_keyorder array of
                                        ** of attribute being analyzed
                                        */
	OPZ_AT                 *abase;  /* base of joinop attributes array */
        OPB_BFT                *bfbase; /* base of boolean factor array */
	OPE_ET                 *ebase;  /* base of equivalence class array */

	abase = subquery->ops_attrs.opz_base; 
        bfbase = subquery->ops_bfs.opb_base;
        ebase = subquery->ops_eclass.ope_base;
	rangeOk = (storage != DB_HASH_STORE);
	for (keyi = 0; keyi < count; keyi++)
	{
	    OPB_ATBFLST		*keydesc;/* ptr to key attribute being 
                                        ** analyzed */
	    OPZ_ATTS		*ap;	/* ptr to joinop attribute associated
                                        ** with key element
                                        */
	    OPE_IEQCLS		eqcls;	/* equivalence class of joinop
                                        ** attribute */
	    bool		usable;	/* class of best limiting boolean 
                                        ** factor found so far */

	    usable = FALSE;		/* Assume no limiting predicates */
	    keydesc = &mbf->opb_kbase->opb_keyorder[keyi];
	    ap = abase->opz_attnums[keydesc->opb_attno];
	    if ( (eqcls = ap->opz_equcls) >= 0) 
	    {	/* if equivalence class exists then check if a list of limiting
		** predicates is associated with the equivalence class
		*/
		OPB_IBF            bfi; /* boolean factor number which contains
                                        ** OPB_BFGLOBAL information */

		bfi = ebase->ope_eqclist[eqcls]->ope_nbf; /* get boolean factor
                                        ** which contains summary of information
                                        ** for this equivalence class */
                if (bfi != OPB_NOBF)	/* check if any boolean factors
                                        ** exist for this equivalence class */
		{
		    OPB_BOOLFACT    *bfp;/* ptr to boolean factor which
                                        ** contains the OPB_BFGLOBAL info
                                        ** for this equivalence class 
                                        */
		    OPB_BFKEYINFO   *bfinfop; /* ptr to bfkeyinfo for this
					** joinop attribute (type,length)
					*/
		    bfp = bfbase->opb_boolfact[bfi];

		    /* Check for "tid is null" - a predicate that's useless
		    ** for keying. */
		    if (count == 1 && 
			ebase->ope_eqclist[eqcls]->ope_eqctype == OPE_TID &&
			bfp->opb_qnode &&
			bfp->opb_qnode->pst_sym.pst_value.pst_s_op.pst_opno ==
			    subquery->ops_global->ops_cb->ops_server->opg_isnull)
		    {
			mbf->opb_bfcount = 0;
			return(FALSE);	/* show no key from TID */
		    }

		    bfinfop = opb_bfkget( subquery, bfp, eqcls, 
			&ap->opz_dataval, &ap->opz_histogram.oph_dataval, TRUE);
					/* get the keyinfo ptr
                                        ** for the type and length
                                        ** of the attribute, which
                                        ** contains the OPB_BFGLOBAL
                                        ** information for the
                                        ** attribute
                                        */
		    usable = opb_bestbf( bfi, bfinfop, rangeOk, keydesc);
		}
	    }
	    if (!usable)
	    {   /* boolean factor for attribute not found so stop with
		** what we have so far (if anything).
		*/
		if (storage == DB_HASH_STORE)
		{
		    mbf->opb_bfcount = 0;	/* boolean facts for
                                                ** all key attributes must exist
						** for hash key to be built
                                                */
		    return(FALSE);              /* key cannot be built */
		}
		mbf->opb_bfcount = keyi;        /* save the number of attributes
                                                ** which have useful keys */
		return( keyi > 0 );		/* partial key can be built */
	    }

	}
    }
    mbf->opb_bfcount = mbf->opb_count; /* all attributes have matching boolean
                                    ** factors */
    return( TRUE );		    /* boolean factors were found for key */
}