*** ./src/backend/catalog/index.c.orig Tue May 25 12:16:15 1999 --- ./src/backend/catalog/index.c Tue May 25 19:44:59 1999 *************** *** 1323,1338 **** */ relpages = RelationGetNumberOfBlocks(whichRel); - /* - * We shouldn't have to do this, but we do... Modify the reldesc in - * place with the new values so that the cache contains the latest - * copy. - */ - - whichRel->rd_rel->relhasindex = hasindex; - whichRel->rd_rel->relpages = relpages; - whichRel->rd_rel->reltuples = reltuples; - for (i = 0; i < Natts_pg_class; i++) { nulls[i] = heap_attisnull(tuple, i + 1) ? 'n' : ' '; --- 1323,1328 ---- *************** *** 1344,1351 **** * If reltuples wasn't supplied take an educated guess. */ if (reltuples == 0) ! reltuples = relpages * NTUPLES_PER_PAGE(whichRel->rd_rel->relnatts); if (IsBootstrapProcessingMode()) { --- 1334,1366 ---- * If reltuples wasn't supplied take an educated guess. */ if (reltuples == 0) ! if (relpages == 0) ! { ! /* ! * Empty relation, leave bogus default in place, see comment in heap.c ! */ ! reltuples = 1000; /* bogus estimates */ ! relpages = 10; ! } ! else if (whichRel->rd_rel->relkind == RELKIND_INDEX && relpages == 2) ! /* ! * Empty index ?, leave bogus default in place ! */ ! reltuples = 1000; /* bogus estimates */ ! else ! reltuples = relpages * NTUPLES_PER_PAGE(whichRel->rd_rel->relnatts); + /* + * We shouldn't have to do this, but we do... Modify the reldesc in + * place with the new values so that the cache contains the latest + * copy. + */ + + whichRel->rd_rel->relhasindex = hasindex; + whichRel->rd_rel->relpages = relpages; + whichRel->rd_rel->reltuples = reltuples; + + if (IsBootstrapProcessingMode()) { *************** *** 1522,1527 **** --- 1537,1543 ---- { reltuples++; + #ifndef OMIT_PARTIAL_INDEX /* * If oldPred != NULL, this is an EXTEND INDEX command, so skip * this tuple if it was already in the existing partial index *************** *** 1528,1534 **** */ if (oldPred != NULL) { - #ifndef OMIT_PARTIAL_INDEX /* SetSlotContents(slot, heapTuple); */ slot->val = heapTuple; if (ExecQual((List *) oldPred, econtext) == true) --- 1544,1549 ---- *************** *** 1536,1542 **** indtuples++; continue; } - #endif /* OMIT_PARTIAL_INDEX */ } /* --- 1551,1556 ---- *************** *** 1545,1557 **** */ if (predicate != NULL) { - #ifndef OMIT_PARTIAL_INDEX /* SetSlotContents(slot, heapTuple); */ slot->val = heapTuple; if (ExecQual((List *) predicate, econtext) == false) continue; - #endif /* OMIT_PARTIAL_INDEX */ } indtuples++; --- 1559,1570 ---- */ if (predicate != NULL) { /* SetSlotContents(slot, heapTuple); */ slot->val = heapTuple; if (ExecQual((List *) predicate, econtext) == false) continue; } + #endif /* OMIT_PARTIAL_INDEX */ indtuples++; *************** *** 1584,1595 **** heap_endscan(scan); if (predicate != NULL || oldPred != NULL) { - #ifndef OMIT_PARTIAL_INDEX ExecDestroyTupleTable(tupleTable, false); - #endif /* OMIT_PARTIAL_INDEX */ } pfree(nullv); pfree(datum); --- 1597,1608 ---- heap_endscan(scan); + #ifndef OMIT_PARTIAL_INDEX if (predicate != NULL || oldPred != NULL) { ExecDestroyTupleTable(tupleTable, false); } + #endif /* OMIT_PARTIAL_INDEX */ pfree(nullv); pfree(datum); *** ./src/backend/catalog/heap.c.orig Tue May 25 12:16:15 1999 --- ./src/backend/catalog/heap.c Tue May 25 19:01:56 1999 *************** *** 676,686 **** * enough to discourage the optimizer from using nested-loop plans. * With this hack, nested-loop plans will be preferred only after * the table has been proven to be small by VACUUM or CREATE INDEX. ! * (NOTE: if user does CREATE TABLE, then CREATE INDEX, then loads ! * the table, he still loses until he vacuums, because CREATE INDEX ! * will set reltuples to zero. Can't win 'em all. Maintaining the ! * stats on-the-fly would solve the problem, but the overhead of that ! * would likely cost more than it'd save.) * ---------------- */ new_rel_reltup->relpages = 10; /* bogus estimates */ --- 676,685 ---- * enough to discourage the optimizer from using nested-loop plans. * With this hack, nested-loop plans will be preferred only after * the table has been proven to be small by VACUUM or CREATE INDEX. ! * (NOTE: CREATE INDEX also sets these bogus estimates if the ! * relation has 0 rows and pages. See index.c.) ! * Maintaining the stats on-the-fly would solve the problem, ! * but the overhead of that would likely cost more than it'd save. * ---------------- */ new_rel_reltup->relpages = 10; /* bogus estimates */