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

Appearance settings

Commit 168d206

Browse filesBrowse files
committed
Provide statistics for hypothetical BRIN indexes
Trying to use hypothetical indexes with BRIN currently fails when trying to access a relation that does not exist when looking for the statistics. With the current API, it is not possible to easily pass a value for pages_per_range down to the hypothetical index, so this makes use of the default value of BRIN_DEFAULT_PAGES_PER_RANGE, which should be fine enough in most cases. Being able to refine or enforce the hypothetical costs in more optimistic ways would require more refactoring by filling in the statistics when building IndexOptInfo in plancat.c. This would involve ABI breakages around the costing routines, something not fit for stable branches. This is broken since 7e534ad, so backpatch down to v10. Author: Julien Rouhaud, Heikki Linnakangas Reviewed-by: Álvaro Herrera, Tom Lane, Michael Paquier Discussion: https://postgr.es/m/CAOBaU_ZH0LKEA8VFCocr6Lpte1ab0b6FpvgS0y4way+RPSXfYg@mail.gmail.com Backpatch-through: 10
1 parent 9ff5b69 commit 168d206
Copy full SHA for 168d206

File tree

Expand file treeCollapse file tree

1 file changed

+28
-9
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+28
-9
lines changed

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

Copy file name to clipboardExpand all lines: src/backend/utils/adt/selfuncs.c
+28-9Lines 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 obtained on the index in plancat.c.
6869+
* Obtain some data from the index itself, if possible. Otherwise invent
6870+
* some plausible internal statistics based on the relation 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.