1: # include <ingres.h> 2: # include <btree.h> 3: # include <sccs.h> 4: 5: SCCSID(@(#)btreerange.c 8.1 12/31/84) 6: 7: /* 8: ** Btreerange finds the smallest and largest tids corresponding to 9: ** the lids found between two given lids. 10: */ 11: 12: btreerange(d, low_lid, high_lid, lotid, hitid) 13: 14: DESC *d; 15: long low_lid[], high_lid[]; 16: register TID *lotid, *hitid; 17: { 18: register int i; 19: long l, h, tid, temp; 20: struct locator block; 21: long page, t, last, hbtid, last_lid(); 22: int done, first; 23: long start, next; 24: 25: /* find tid corresponding to high lid */ 26: page = RT; 27: for (i = 0; i < d->reldum.reldim; ++i) 28: { 29: if ((t = get_tid(page, high_lid[i], &block)) < 0) 30: syserr("get_tid error in btreerange, lid = %ld\n", high_lid[i]); 31: page = t; 32: } 33: hbtid = page; 34: /* find starting point of scan */ 35: page = RT; 36: for (i = 0; i < d->reldum.reldim - 1; ++i) 37: { 38: last = last_lid(page) - 1; 39: if (low_lid[i] > last) 40: low_lid[i] = last; 41: if ((t = get_tid(page, low_lid[i], &block)) < 0) 42: syserr("get_tid error in btreerange, lid = %ld\n", low_lid[i]); 43: page = t; 44: } 45: first = 1; 46: last = last_lid(page) - 1; 47: if (low_lid[d->reldum.reldim - 1] > last) 48: low_lid[d->reldum.reldim - 1] = last; 49: start = low_lid[d->reldum.reldim - 1]; 50: do 51: { 52: get_node(page, &block.page); 53: next = block.page.nexttree; 54: if ((tid = get_tid(page, start, &block)) < 0) 55: syserr("get_tid error in btreerange, lid = %ld\n", low_lid[d->reldum.reldim - 1]); 56: /* set high and low to intial value */ 57: if (first) 58: { 59: first = 0; 60: pluck_page(&tid, &l); 61: pluck_page(&tid, &h); 62: } 63: page = block.pageno; 64: done = 0; 65: while (done == 0) 66: { 67: for (i = 0; i < block.page.nelmts && done == 0; ++i) 68: { 69: tid = block.page.node.leafnode.tid_pos[block.page.node.leafnode.tid_loc[i]]; 70: pluck_page(&tid, &temp); 71: if (temp > h) 72: h = temp; 73: else if (temp < l) 74: l = temp; 75: if (tid == hbtid) 76: done = 1; 77: } 78: page = block.page.node.leafnode.nextleaf; 79: if (page == NULL) 80: done = 1; 81: else 82: get_node(page, &block.page); 83: } 84: start = 1; 85: } while (page = next && !done); 86: stuff_page(lotid, &l); 87: stuff_page(hitid, &h); 88: lotid->line_id = hitid->line_id = -1; 89: }