Annotation of 42BSD/ingres/source/dbu/udestroy.c, revision 1.1.1.1

1.1       root        1: # include      <ingres.h>
                      2: # include      <aux.h>
                      3: # include      <catalog.h>
                      4: # include      <sccs.h>
                      5: 
                      6: SCCSID(@(#)udestroy.c  7.1     2/5/81)
                      7: 
                      8: 
                      9: /*
                     10: **  USERDESTROY -- auxiliary cleanup for destroy of a user relation
                     11: **
                     12: **     userdestroy is called during the destroy of a non system
                     13: **     relation. If the relation is indexed or is itself an index
                     14: **     then the appropriate action is taken. If it is indexed,
                     15: **     then all secondary indices on the relation are also destroyed.
                     16: **     If it is a secondary index, then the entry in the indexes relation
                     17: **     is removed and the "relindxd" bit on the primary relation is
                     18: **     cleared if this was the last index on the relation.
                     19: **
                     20: **     If the relation was a view or had integrity constraints or
                     21: **     protection constraints on it, then those definitions are
                     22: **     removed from the appropriate system catalogues.
                     23: **
                     24: **     Parameters:
                     25: **             reltup -- the relation relation tuple.
                     26: **
                     27: **     Returns:
                     28: **             none
                     29: **
                     30: **     Side Effects:
                     31: **             zero or more system catalogues will be updated.
                     32: **
                     33: **     Called By:
                     34: **             destroy
                     35: */
                     36: 
                     37: userdestroy(reltup)
                     38: struct relation        *reltup;
                     39: {
                     40:        register int                    i;
                     41:        register struct relation        *rel;
                     42:        struct tup_id                   tid, limtid;
                     43:        char                            newrelname[MAXNAME + 3];
                     44:        extern DESC                     Reldes, Attdes, Inddes;
                     45:        extern DESC                     Treedes, Intdes, Prodes;
                     46:        struct relation                 relt, relk;
                     47:        struct index                    indk, indt;
                     48: 
                     49:        rel = reltup;
                     50: 
                     51:        /* handle special case of destroying a secondary index */
                     52:        if (rel->relindxd < 0)
                     53:        {
                     54:                opencatalog("indexes", 2);
                     55:                setkey(&Inddes, &indk, rel->relid, IRELIDI);
                     56:                setkey(&Inddes, &indk, rel->relowner, IOWNERP);
                     57:                if ((i = getequal(&Inddes, &indk, &indt, &tid)) != 0)
                     58:                        syserr("destroy: geteq(ind,%.12s) %d", rel->relid, i);
                     59: 
                     60:                /* remove entry in INDEX catalog */
                     61:                bmove(indt.irelidp, newrelname, MAXNAME);
                     62:                bmove(indt.iownerp, &newrelname[MAXNAME], 2);
                     63:                if ((i = delete(&Inddes, &tid)) != 0)
                     64:                        syserr("DESTROY: delete(ind/%.12s) %d", rel->relid, i);
                     65:                clearkeys(&Inddes);
                     66:                setkey(&Inddes, &indk, newrelname, IRELIDP);
                     67:                setkey(&Inddes, &indk, &newrelname[MAXNAME], IOWNERP);
                     68: 
                     69:                /* reset relindxd field in relation catalog if no other indexes exist on this primary */
                     70:                if (getequal(&Inddes, &indk, &indt, &tid) != 0)
                     71:                {
                     72:                        clearkeys(&Reldes);
                     73:                        setkey(&Reldes, &relk, newrelname, RELID);
                     74:                        setkey(&Reldes, &relk, &newrelname[MAXNAME], RELOWNER);
                     75:                        if (i = getequal(&Reldes, &relk, &relt, &tid))
                     76:                                syserr("destroy: getequal(rel, %s) %d", newrelname, i);
                     77:                        relt.relindxd = 0;
                     78:                        if ((i = replace(&Reldes, &tid, &relt, 0)) != 0)
                     79:                                syserr("destroy: replace(rel) %d", i);
                     80:                }
                     81:        }
                     82: 
                     83:        /* check special case of destroying primary relation */
                     84:        if (rel->relindxd > 0)
                     85:        {
                     86:                opencatalog("indexes", 2);
                     87:                setkey(&Inddes, &indk, rel->relid, IRELIDP);
                     88:                setkey(&Inddes, &indk, rel->relowner, IOWNERP);
                     89:                if (i = find(&Inddes, EXACTKEY, &tid, &limtid, &indk))
                     90:                        syserr("destroy: find(ind,%.12s) %d", rel->relid, i);
                     91:                while ((i = get(&Inddes, &tid, &limtid, &indt, TRUE)) == 0)
                     92:                {
                     93:                        if (kcompare(&Inddes, &indk, &indt) != 0)
                     94:                                continue;
                     95:                        if ((i = delete(&Inddes, &tid)) != 0)
                     96:                                syserr("DESTROY: delete(ind/%.12s) %d", rel->relid, i);
                     97:                        clearkeys(&Reldes);
                     98:                        purgetup(&Reldes, indt.irelidi, RELID, indt.iownerp, RELOWNER, 0);
                     99:                        if (i = flush_rel(&Reldes, FALSE))      /* flush for recovery & concurrency reasons */
                    100:                                syserr("destroy:flush irel %d", i);
                    101:                        purgetup(&Attdes, indt.irelidi, ATTRELID, indt.iownerp, ATTOWNER, 0);
                    102:                        ingresname(indt.irelidi, indt.iownerp, newrelname);
                    103:                        if (unlink(newrelname))
                    104:                                syserr("destroy: unlink(%s)", newrelname);
                    105:                }
                    106:                if (i < 0)
                    107:                {
                    108:                        syserr("destroy: get(ind) %d", i);
                    109:                }
                    110:        }
                    111: 
                    112:        /* if any integrity constraints exist, remove them */
                    113:        if (rel->relstat & S_INTEG)
                    114:        {
                    115:                opencatalog("integrities", 2);
                    116:                purgetup(&Intdes, rel->relid, INTRELID, rel->relowner, INTRELOWNER);
                    117:        }
                    118: 
                    119:        /* if any protection clauses exist, remove them */
                    120:        if (rel->relstat & S_PROTUPS)
                    121:        {
                    122:                opencatalog("protect", 2);
                    123:                purgetup(&Prodes, rel->relid, PRORELID, rel->relowner, PRORELOWN);
                    124:        }
                    125: 
                    126:        /* remove any trees associated with the relation */
                    127:        if (rel->relstat & (S_PROTUPS | S_VIEW | S_INTEG))
                    128:        {
                    129:                opencatalog("tree", 2);
                    130:                purgetup(&Treedes, rel->relid, TREERELID, rel->relowner, TREEOWNER);
                    131:        }
                    132: }

unix.superglobalmegacorp.com

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