diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2010-10-17 20:52:32 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2010-10-17 20:52:32 -0400 |
commit | 48c7d9f6ff99714495b7d6d2ebc44fbbe992cc8f (patch) | |
tree | 73082c19da244fedf1bfc81d5c5eb2a1f3eddd9e /src/backend/access/gin/ginbtree.c | |
parent | cd0e8253216907982fe369b91f6d788d699b6c47 (diff) | |
download | postgresql-48c7d9f6ff99714495b7d6d2ebc44fbbe992cc8f.tar.gz postgresql-48c7d9f6ff99714495b7d6d2ebc44fbbe992cc8f.zip |
Improve GIN indexscan cost estimation.
The better estimate requires more statistics than we previously stored:
in particular, counts of "entry" versus "data" pages within the index,
as well as knowledge of the number of distinct key values. We collect
this information during initial index build and update it during VACUUM,
storing the info in new fields on the index metapage. No initdb is
required because these fields will read as zeroes in a pre-existing
index, and the new gincostestimate code is coded to behave (reasonably)
sanely if they are zeroes.
Teodor Sigaev, reviewed by Jan Urbanski, Tom Lane, and Itagaki Takahiro.
Diffstat (limited to 'src/backend/access/gin/ginbtree.c')
-rw-r--r-- | src/backend/access/gin/ginbtree.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/backend/access/gin/ginbtree.c b/src/backend/access/gin/ginbtree.c index 82d7dd18a80..812e241f449 100644 --- a/src/backend/access/gin/ginbtree.c +++ b/src/backend/access/gin/ginbtree.c @@ -268,10 +268,13 @@ findParents(GinBtree btree, GinBtreeStack *stack, /* * Insert value (stored in GinBtree) to tree described by stack * + * During an index build, buildStats is non-null and the counters + * it contains should be incremented as needed. + * * NB: the passed-in stack is freed, as though by freeGinBtreeStack. */ void -ginInsertValue(GinBtree btree, GinBtreeStack *stack) +ginInsertValue(GinBtree btree, GinBtreeStack *stack, GinStatsData *buildStats) { GinBtreeStack *parent = stack; BlockNumber rootBlkno = InvalidBuffer; @@ -330,6 +333,15 @@ ginInsertValue(GinBtree btree, GinBtreeStack *stack) ((ginxlogSplit *) (rdata->data))->rootBlkno = rootBlkno; + /* During index build, count the newly-split page */ + if (buildStats) + { + if (btree->isData) + buildStats->nDataPages++; + else + buildStats->nEntryPages++; + } + parent = stack->parent; if (parent == NULL) @@ -381,6 +393,15 @@ ginInsertValue(GinBtree btree, GinBtreeStack *stack) freeGinBtreeStack(stack); + /* During index build, count the newly-added root page */ + if (buildStats) + { + if (btree->isData) + buildStats->nDataPages++; + else + buildStats->nEntryPages++; + } + return; } else |