Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit168d206

Browse files
committed
Provide statistics for hypothetical BRIN indexes
Trying to use hypothetical indexes with BRIN currently fails when tryingto access a relation that does not exist when looking for thestatistics. With the current API, it is not possible to easily passa value for pages_per_range down to the hypothetical index, so thismakes use of the default value of BRIN_DEFAULT_PAGES_PER_RANGE, whichshould be fine enough in most cases.Being able to refine or enforce the hypothetical costs in moreoptimistic ways would require more refactoring by filling in thestatistics when building IndexOptInfo in plancat.c. This would involveABI breakages around the costing routines, something not fit for stablebranches.This is broken since7e534ad, so backpatch down to v10.Author: Julien Rouhaud, Heikki LinnakangasReviewed-by: Álvaro Herrera, Tom Lane, Michael PaquierDiscussion:https://postgr.es/m/CAOBaU_ZH0LKEA8VFCocr6Lpte1ab0b6FpvgS0y4way+RPSXfYg@mail.gmail.comBackpatch-through: 10
1 parent9ff5b69 commit168d206

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

‎src/backend/utils/adt/selfuncs.c

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
#include<math.h>
103103

104104
#include"access/brin.h"
105+
#include"access/brin_page.h"
105106
#include"access/gin.h"
106107
#include"access/table.h"
107108
#include"access/tableam.h"
@@ -6865,12 +6866,34 @@ brincostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
68656866
&spc_seq_page_cost);
68666867

68676868
/*
6868-
* Obtain some data from the index itself. A lock should have already
6869-
*been obtainedon theindex in plancat.c.
6869+
* Obtain some data from the index itself, if possible. Otherwise invent
6870+
*some plausible internal statistics basedon therelation page count.
68706871
*/
6871-
indexRel=index_open(index->indexoid,NoLock);
6872-
brinGetStats(indexRel,&statsData);
6873-
index_close(indexRel,NoLock);
6872+
if (!index->hypothetical)
6873+
{
6874+
/*
6875+
* A lock should have already been obtained on the index in plancat.c.
6876+
*/
6877+
indexRel=index_open(index->indexoid,NoLock);
6878+
brinGetStats(indexRel,&statsData);
6879+
index_close(indexRel,NoLock);
6880+
6881+
/* work out the actual number of ranges in the index */
6882+
indexRanges=Max(ceil((double)baserel->pages /
6883+
statsData.pagesPerRange),1.0);
6884+
}
6885+
else
6886+
{
6887+
/*
6888+
* Assume default number of pages per range, and estimate the number
6889+
* of ranges based on that.
6890+
*/
6891+
indexRanges=Max(ceil((double)baserel->pages /
6892+
BRIN_DEFAULT_PAGES_PER_RANGE),1.0);
6893+
6894+
statsData.pagesPerRange=BRIN_DEFAULT_PAGES_PER_RANGE;
6895+
statsData.revmapNumPages= (indexRanges /REVMAP_PAGE_MAXITEMS)+1;
6896+
}
68746897

68756898
/*
68766899
* Compute index correlation
@@ -6970,10 +6993,6 @@ brincostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
69706993
baserel->relid,
69716994
JOIN_INNER,NULL);
69726995

6973-
/* work out the actual number of ranges in the index */
6974-
indexRanges=Max(ceil((double)baserel->pages /statsData.pagesPerRange),
6975-
1.0);
6976-
69776996
/*
69786997
* Now calculate the minimum possible ranges we could match with if all of
69796998
* the rows were in the perfect order in the table's heap.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp