mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
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.
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user