Annotation of 42BSD/ingres/source/iutil/find.c, revision 1.1.1.1

1.1       root        1: # include      <ingres.h>
                      2: # include      <aux.h>
                      3: # include      <symbol.h>
                      4: # include      <access.h>
                      5: # include      <lock.h>
                      6: # include      <sccs.h>
                      7: 
                      8: SCCSID(@(#)find.c      7.1     2/5/81)
                      9: 
                     10: 
                     11: /*
                     12: **     Find - determine limits for scan of a relation
                     13: **
                     14: **     Find determines the values of an initial TID
                     15: **     and an ending TID for scanning a relation.
                     16: **     The possible calls to find are:
                     17: **
                     18: **     find(desc, NOKEY, lotid, hightid)
                     19: **             sets tids to scan entire relation
                     20: **
                     21: **     find(desc, EXACTKEY, lotid, hightid, key)
                     22: **             sets tids according to structure
                     23: **             of the relation. Key should have
                     24: **             been build using setkey.
                     25: **
                     26: **     find(desc, LRANGEKEY, lotid, hightid, keylow)
                     27: **             Finds lotid less then or equal to keylow
                     28: **             for isam relations. Otherwise scans whole relation.
                     29: **             This call should be followed by a call with HRANGEKEY.
                     30: **
                     31: **     find(desc, HRANGEKEY, lotid, hightid, keyhigh)
                     32: **             Finds hightid greater than or equal to
                     33: **             keyhigh for isam relations. Otherwise sets
                     34: **             hightid to maximum scan.
                     35: **
                     36: **     find(desc, FULLKEY, lotid, hightid, key)
                     37: **             Same as find with EXACTKEY and all keys
                     38: **             provided. This mode is used only by findbest
                     39: **             and replace.
                     40: **
                     41: **     returns:
                     42: **             <0 fatal error
                     43: **              0 success
                     44: **
                     45: **     Trace Flags:
                     46: **             22.0-8
                     47: */
                     48: 
                     49: 
                     50: find(d, mode, lotid, hightid, key)
                     51: register DESC  *d;
                     52: int            mode;
                     53: TID            *lotid;
                     54: TID            *hightid;
                     55: char           *key;
                     56: {
                     57:        register int    ret;
                     58:        bool            keyok;
                     59:        long            pageid;
                     60:        long            rhash();
                     61: 
                     62: #      ifdef xATR1
                     63:        if (tTf(22, 0))
                     64:        {
                     65:                printf("find: m%d,s%d,%.14s\n", mode, d->reldum.relspec, d->reldum.relid);
                     66:                if (mode != NOKEY)
                     67:                        printup(d, key);
                     68:        }
                     69: #      endif
                     70: 
                     71:        ret = 0;        /* assume successful return */
                     72:        keyok = FALSE;
                     73: 
                     74:        switch (mode)
                     75:        {
                     76: 
                     77:          case EXACTKEY:
                     78:                keyok = fullkey(d);
                     79:                break;
                     80: 
                     81:          case FULLKEY:
                     82:                keyok = TRUE;
                     83: 
                     84:          case NOKEY:
                     85:          case LRANGEKEY:
                     86:          case HRANGEKEY:
                     87:                break;
                     88: 
                     89:          default:
                     90:                syserr("FIND: bad mode %d", mode);
                     91:        }
                     92: 
                     93:        /* set lotid for beginning of scan */
                     94:        if (mode != HRANGEKEY)
                     95:        {
                     96:                pageid = 0;
                     97:                stuff_page(lotid, &pageid);
                     98:                lotid->line_id = -1;
                     99:        }
                    100: 
                    101:        /* set hitid for end of scan */
                    102:        if (mode != LRANGEKEY)
                    103:        {
                    104:                pageid = -1;
                    105:                stuff_page(hightid, &pageid);
                    106:                hightid->line_id = -1;
                    107:        }
                    108: 
                    109:        if (mode != NOKEY)
                    110:        {
                    111:                switch (abs(d->reldum.relspec))
                    112:                {
                    113:        
                    114:                  case M_HEAP:
                    115:                        break;
                    116:        
                    117:                  case M_ISAM:
                    118:                        if (mode != HRANGEKEY)
                    119:                        {
                    120:                                /* compute lo limit */
                    121:                                if (ret = ndxsearch(d, lotid, key, -1, keyok))
                    122:                                        break;  /* fatal error */
                    123:                        }
                    124:        
                    125:                        /* if the full key was provided and mode is exact, then done */
                    126:                        if (keyok)
                    127:                        {
                    128:                                bmove((char *) lotid, (char *) hightid, sizeof *lotid);
                    129:                                break;
                    130:                        }
                    131:        
                    132:                        if (mode != LRANGEKEY)
                    133:                                ret = ndxsearch(d, hightid, key, 1, keyok);
                    134:                        break;
                    135:        
                    136:                  case M_HASH:
                    137:                        if (!keyok)
                    138:                                break;          /* can't do anything */
                    139:                        pageid = rhash(d, key);
                    140:                        stuff_page(lotid, &pageid);
                    141:                        stuff_page(hightid, &pageid);
                    142:                        break;
                    143: 
                    144:                  default:
                    145:                        ret = acc_err(AMFIND_ERR);
                    146:                }
                    147:        }
                    148: 
                    149: #      ifdef xATR2
                    150:        if (tTf(22, 1))
                    151:        {
                    152:                printf("find: ret %d\tlow", ret);
                    153:                dumptid(lotid);
                    154:                printf("hi");
                    155:                dumptid(hightid);
                    156:        }
                    157: #      endif
                    158:        return (ret);
                    159: }
                    160: /*
                    161: ** This routine will check that enough of the tuple has been specified
                    162: ** to enable a key access.
                    163: */
                    164: 
                    165: fullkey(des)
                    166: DESC   *des;
                    167: {
                    168:        register DESC   *d;
                    169:        register int    i;
                    170: 
                    171:        d = des;
                    172:        for (i = 1; i <= d->reldum.relatts; i++)
                    173:                if (d->relxtra[i] && !d->relgiven[i])
                    174:                        return (FALSE);
                    175:        return (TRUE);
                    176: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.