mirror of
https://github.com/postgres/postgres.git
synced 2025-10-28 11:55:03 +03:00
Support index-only scans using the visibility map to avoid heap fetches.
When a btree index contains all columns required by the query, and the visibility map shows that all tuples on a target heap page are visible-to-all, we don't need to fetch that heap page. This patch depends on the previous patches that made the visibility map reliable. There's a fair amount left to do here, notably trying to figure out a less chintzy way of estimating the cost of an index-only scan, but the core functionality seems ready to commit. Robert Haas and Ibrar Ahmed, with some previous work by Heikki Linnakangas.
This commit is contained in:
@@ -144,6 +144,9 @@ extern void index_rescan(IndexScanDesc scan,
|
||||
extern void index_endscan(IndexScanDesc scan);
|
||||
extern void index_markpos(IndexScanDesc scan);
|
||||
extern void index_restrpos(IndexScanDesc scan);
|
||||
extern ItemPointer index_getnext_tid(IndexScanDesc scan,
|
||||
ScanDirection direction);
|
||||
extern HeapTuple index_fetch_heap(IndexScanDesc scan);
|
||||
extern HeapTuple index_getnext(IndexScanDesc scan, ScanDirection direction);
|
||||
extern int64 index_getbitmap(IndexScanDesc scan, TIDBitmap *bitmap);
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "access/genam.h"
|
||||
#include "access/heapam.h"
|
||||
#include "access/itup.h"
|
||||
|
||||
|
||||
typedef struct HeapScanDescData
|
||||
@@ -66,6 +67,7 @@ typedef struct IndexScanDescData
|
||||
int numberOfOrderBys; /* number of ordering operators */
|
||||
ScanKey keyData; /* array of index qualifier descriptors */
|
||||
ScanKey orderByData; /* array of ordering op descriptors */
|
||||
bool xs_want_itup; /* caller requests index tuples */
|
||||
|
||||
/* signaling to index AM about killing index tuples */
|
||||
bool kill_prior_tuple; /* last-returned tuple is dead */
|
||||
@@ -76,6 +78,9 @@ typedef struct IndexScanDescData
|
||||
/* index access method's private state */
|
||||
void *opaque; /* access-method-specific info */
|
||||
|
||||
/* in an index-only scan, this is valid after a successful amgettuple */
|
||||
IndexTuple xs_itup; /* index tuple returned by AM, or NULL */
|
||||
|
||||
/* xs_ctup/xs_cbuf/xs_recheck are valid after a successful index_getnext */
|
||||
HeapTupleData xs_ctup; /* current heap tuple, if any */
|
||||
Buffer xs_cbuf; /* current heap buffer in scan, if any */
|
||||
|
||||
Reference in New Issue
Block a user