diff options
| author | Tom Lane | 2001-05-07 00:43:27 +0000 |
|---|---|---|
| committer | Tom Lane | 2001-05-07 00:43:27 +0000 |
| commit | f905d65ee35b3f84b6d4433a5198af0e2e7bd090 (patch) | |
| tree | 68f5955bb1a7ecaa531cf6b3752f563943dbe079 /src/backend/access | |
| parent | 9583aea9d09f6b3839ede8e57f990262b24e6979 (diff) | |
Rewrite of planner statistics-gathering code. ANALYZE is now available as
a separate statement (though it can still be invoked as part of VACUUM, too).
pg_statistic redesigned to be more flexible about what statistics are
stored. ANALYZE now collects a list of several of the most common values,
not just one, plus a histogram (not just the min and max values). Random
sampling is used to make the process reasonably fast even on very large
tables. The number of values and histogram bins collected is now
user-settable via an ALTER TABLE command.
There is more still to do; the new stats are not being used everywhere
they could be in the planner. But the remaining changes for this project
should be localized, and the behavior is already better than before.
A not-very-related change is that sorting now makes use of btree comparison
routines if it can find one, rather than invoking '<' twice.
Diffstat (limited to 'src/backend/access')
| -rw-r--r-- | src/backend/access/common/tupdesc.c | 18 | ||||
| -rw-r--r-- | src/backend/access/gist/gist.c | 16 | ||||
| -rw-r--r-- | src/backend/access/hash/hash.c | 12 | ||||
| -rw-r--r-- | src/backend/access/heap/tuptoaster.c | 39 | ||||
| -rw-r--r-- | src/backend/access/nbtree/nbtree.c | 12 | ||||
| -rw-r--r-- | src/backend/access/rtree/rtree.c | 12 |
6 files changed, 73 insertions, 36 deletions
diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c index 769f754b669..86d704e8d08 100644 --- a/src/backend/access/common/tupdesc.c +++ b/src/backend/access/common/tupdesc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.73 2001/03/22 06:16:06 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.74 2001/05/07 00:43:15 tgl Exp $ * * NOTES * some of the executor utility code such as "ExecTypeFromTL" should be @@ -237,16 +237,16 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2) Form_pg_attribute attr2 = tupdesc2->attrs[i]; /* - * We do not need to check every single field here, and in fact - * some fields such as attdispersion probably shouldn't be - * compared. We can also disregard attnum (it was used to place - * the row in the attrs array) and everything derived from the - * column datatype. + * We do not need to check every single field here: we can disregard + * attrelid, attnum (it was used to place the row in the attrs array) + * and everything derived from the column datatype. */ if (strcmp(NameStr(attr1->attname), NameStr(attr2->attname)) != 0) return false; if (attr1->atttypid != attr2->atttypid) return false; + if (attr1->attstattarget != attr2->attstattarget) + return false; if (attr1->atttypmod != attr2->atttypmod) return false; if (attr1->attstorage != attr2->attstorage) @@ -365,12 +365,12 @@ TupleDescInitEntry(TupleDesc desc, else MemSet(NameStr(att->attname), 0, NAMEDATALEN); - att->attdispersion = 0; /* dummy value */ + att->attstattarget = 0; att->attcacheoff = -1; att->atttypmod = typmod; att->attnum = attributeNumber; - att->attnelems = attdim; + att->attndims = attdim; att->attisset = attisset; att->attnotnull = false; @@ -506,7 +506,7 @@ TupleDescMakeSelfReference(TupleDesc desc, att->attbyval = true; att->attalign = 'i'; att->attstorage = 'p'; - att->attnelems = 0; + att->attndims = 0; } /* ---------------------------------------------------------------- diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c index 1c5577b88a0..06010896821 100644 --- a/src/backend/access/gist/gist.c +++ b/src/backend/access/gist/gist.c @@ -6,7 +6,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.72 2001/03/22 03:59:12 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.73 2001/05/07 00:43:15 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -84,8 +84,8 @@ static void gist_dumptree(Relation r, int level, BlockNumber blk, OffsetNumber c #endif /* -** routine to build an index. Basically calls insert over and over -*/ + * routine to build an index. Basically calls insert over and over + */ Datum gistbuild(PG_FUNCTION_ARGS) { @@ -105,7 +105,7 @@ gistbuild(PG_FUNCTION_ARGS) itupdesc; Datum attdata[INDEX_MAX_KEYS]; char nulls[INDEX_MAX_KEYS]; - int nhtups, + double nhtups, nitups; Node *pred = indexInfo->ii_Predicate; @@ -172,7 +172,7 @@ gistbuild(PG_FUNCTION_ARGS) #endif /* OMIT_PARTIAL_INDEX */ /* build the index */ - nhtups = nitups = 0; + nhtups = nitups = 0.0; compvec = (bool *) palloc(sizeof(bool) * indexInfo->ii_NumIndexAttrs); @@ -183,7 +183,7 @@ gistbuild(PG_FUNCTION_ARGS) { MemoryContextReset(econtext->ecxt_per_tuple_memory); - nhtups++; + nhtups += 1.0; #ifndef OMIT_PARTIAL_INDEX @@ -196,7 +196,7 @@ gistbuild(PG_FUNCTION_ARGS) slot->val = htup; if (ExecQual((List *) oldPred, econtext, false)) { - nitups++; + nitups += 1.0; continue; } } @@ -213,7 +213,7 @@ gistbuild(PG_FUNCTION_ARGS) } #endif /* OMIT_PARTIAL_INDEX */ - nitups++; + nitups += 1.0; /* * For the current heap tuple, extract all the attributes we use diff --git a/src/backend/access/hash/hash.c b/src/backend/access/hash/hash.c index aa76ba232a0..9617fcc33a6 100644 --- a/src/backend/access/hash/hash.c +++ b/src/backend/access/hash/hash.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.50 2001/03/22 03:59:12 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.51 2001/05/07 00:43:15 tgl Exp $ * * NOTES * This file contains only the public interface routines. @@ -57,7 +57,7 @@ hashbuild(PG_FUNCTION_ARGS) itupdesc; Datum attdata[INDEX_MAX_KEYS]; char nulls[INDEX_MAX_KEYS]; - int nhtups, + double nhtups, nitups; HashItem hitem; Node *pred = indexInfo->ii_Predicate; @@ -109,7 +109,7 @@ hashbuild(PG_FUNCTION_ARGS) #endif /* OMIT_PARTIAL_INDEX */ /* build the index */ - nhtups = nitups = 0; + nhtups = nitups = 0.0; /* start a heap scan */ hscan = heap_beginscan(heap, 0, SnapshotNow, 0, (ScanKey) NULL); @@ -118,7 +118,7 @@ hashbuild(PG_FUNCTION_ARGS) { MemoryContextReset(econtext->ecxt_per_tuple_memory); - nhtups++; + nhtups += 1.0; #ifndef OMIT_PARTIAL_INDEX @@ -131,7 +131,7 @@ hashbuild(PG_FUNCTION_ARGS) slot->val = htup; if (ExecQual((List *) oldPred, econtext, false)) { - nitups++; + nitups += 1.0; continue; } } @@ -148,7 +148,7 @@ hashbuild(PG_FUNCTION_ARGS) } #endif /* OMIT_PARTIAL_INDEX */ - nitups++; + nitups += 1.0; /* * For the current heap tuple, extract all the attributes we use diff --git a/src/backend/access/heap/tuptoaster.c b/src/backend/access/heap/tuptoaster.c index fb509ab66de..2a9df577b10 100644 --- a/src/backend/access/heap/tuptoaster.c +++ b/src/backend/access/heap/tuptoaster.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/heap/tuptoaster.c,v 1.21 2001/03/25 00:45:20 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/heap/tuptoaster.c,v 1.22 2001/05/07 00:43:15 tgl Exp $ * * * INTERFACE ROUTINES @@ -167,6 +167,43 @@ heap_tuple_untoast_attr(varattrib *attr) /* ---------- + * toast_raw_datum_size - + * + * Return the raw (detoasted) size of a varlena datum + * ---------- + */ +Size +toast_raw_datum_size(Datum value) +{ + varattrib *attr = (varattrib *) DatumGetPointer(value); + Size result; + + if (VARATT_IS_COMPRESSED(attr)) + { + /* + * va_rawsize shows the original data size, whether the datum + * is external or not. + */ + result = attr->va_content.va_compressed.va_rawsize + VARHDRSZ; + } + else if (VARATT_IS_EXTERNAL(attr)) + { + /* + * an uncompressed external attribute has rawsize including the + * header (not too consistent!) + */ + result = attr->va_content.va_external.va_rawsize; + } + else + { + /* plain untoasted datum */ + result = VARSIZE(attr); + } + return result; +} + + +/* ---------- * toast_delete - * * Cascaded delete toast-entries on DELETE diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c index 97d99da4fde..f456e0c9306 100644 --- a/src/backend/access/nbtree/nbtree.c +++ b/src/backend/access/nbtree/nbtree.c @@ -12,7 +12,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.79 2001/03/22 03:59:15 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.80 2001/05/07 00:43:16 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -69,7 +69,7 @@ btbuild(PG_FUNCTION_ARGS) itupdesc; Datum attdata[INDEX_MAX_KEYS]; char nulls[INDEX_MAX_KEYS]; - int nhtups, + double nhtups, nitups; Node *pred = indexInfo->ii_Predicate; @@ -156,7 +156,7 @@ btbuild(PG_FUNCTION_ARGS) #endif /* OMIT_PARTIAL_INDEX */ /* build the index */ - nhtups = nitups = 0; + nhtups = nitups = 0.0; if (usefast) { @@ -196,7 +196,7 @@ btbuild(PG_FUNCTION_ARGS) MemoryContextReset(econtext->ecxt_per_tuple_memory); - nhtups++; + nhtups += 1.0; #ifndef OMIT_PARTIAL_INDEX @@ -209,7 +209,7 @@ btbuild(PG_FUNCTION_ARGS) slot->val = htup; if (ExecQual((List *) oldPred, econtext, false)) { - nitups++; + nitups += 1.0; continue; } } @@ -226,7 +226,7 @@ btbuild(PG_FUNCTION_ARGS) } #endif /* OMIT_PARTIAL_INDEX */ - nitups++; + nitups += 1.0; /* * For the current heap tuple, extract all the attributes we use diff --git a/src/backend/access/rtree/rtree.c b/src/backend/access/rtree/rtree.c index 3752a59e99a..a8c6a13ea3c 100644 --- a/src/backend/access/rtree/rtree.c +++ b/src/backend/access/rtree/rtree.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.61 2001/03/22 03:59:16 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.62 2001/05/07 00:43:16 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -100,7 +100,7 @@ rtbuild(PG_FUNCTION_ARGS) itupdesc; Datum attdata[INDEX_MAX_KEYS]; char nulls[INDEX_MAX_KEYS]; - int nhtups, + double nhtups, nitups; Node *pred = indexInfo->ii_Predicate; @@ -163,7 +163,7 @@ rtbuild(PG_FUNCTION_ARGS) #endif /* OMIT_PARTIAL_INDEX */ /* count the tuples as we insert them */ - nhtups = nitups = 0; + nhtups = nitups = 0.0; /* start a heap scan */ hscan = heap_beginscan(heap, 0, SnapshotNow, 0, (ScanKey) NULL); @@ -172,7 +172,7 @@ rtbuild(PG_FUNCTION_ARGS) { MemoryContextReset(econtext->ecxt_per_tuple_memory); - nhtups++; + nhtups += 1.0; #ifndef OMIT_PARTIAL_INDEX @@ -185,7 +185,7 @@ rtbuild(PG_FUNCTION_ARGS) slot->val = htup; if (ExecQual((List *) oldPred, econtext, false)) { - nitups++; + nitups += 1.0; continue; } } @@ -202,7 +202,7 @@ rtbuild(PG_FUNCTION_ARGS) } #endif /* OMIT_PARTIAL_INDEX */ - nitups++; + nitups += 1.0; /* * For the current heap tuple, extract all the attributes we use |
