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

Commit62074a3

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 parentd40efd2 commit62074a3

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

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

Lines changed: 25 additions & 8 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/htup_details.h"
107108
#include"access/relscan.h"
@@ -8148,11 +8149,31 @@ brincostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
81488149
&spc_seq_page_cost);
81498150

81508151
/*
8151-
* Obtain some data from the index itself.
8152+
* Obtain some data from the index itself, if possible. Otherwise invent
8153+
* some plausible internal statistics based on the relation page count.
81528154
*/
8153-
indexRel=index_open(index->indexoid,AccessShareLock);
8154-
brinGetStats(indexRel,&statsData);
8155-
index_close(indexRel,AccessShareLock);
8155+
if (!index->hypothetical)
8156+
{
8157+
indexRel=index_open(index->indexoid,AccessShareLock);
8158+
brinGetStats(indexRel,&statsData);
8159+
index_close(indexRel,AccessShareLock);
8160+
8161+
/* work out the actual number of ranges in the index */
8162+
indexRanges=Max(ceil((double)baserel->pages /
8163+
statsData.pagesPerRange),1.0);
8164+
}
8165+
else
8166+
{
8167+
/*
8168+
* Assume default number of pages per range, and estimate the number
8169+
* of ranges based on that.
8170+
*/
8171+
indexRanges=Max(ceil((double)baserel->pages /
8172+
BRIN_DEFAULT_PAGES_PER_RANGE),1.0);
8173+
8174+
statsData.pagesPerRange=BRIN_DEFAULT_PAGES_PER_RANGE;
8175+
statsData.revmapNumPages= (indexRanges /REVMAP_PAGE_MAXITEMS)+1;
8176+
}
81568177

81578178
/*
81588179
* Compute index correlation
@@ -8253,10 +8274,6 @@ brincostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
82538274
baserel->relid,
82548275
JOIN_INNER,NULL);
82558276

8256-
/* work out the actual number of ranges in the index */
8257-
indexRanges=Max(ceil((double)baserel->pages /statsData.pagesPerRange),
8258-
1.0);
8259-
82608277
/*
82618278
* Now calculate the minimum possible ranges we could match with if all of
82628279
* the rows were in the perfect order in the table's heap.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp