mirror of
https://github.com/postgres/postgres.git
synced 2025-06-30 21:42:05 +03:00
Add support for index-only scans in GiST.
This adds a new GiST opclass method, 'fetch', which is used to reconstruct the original Datum from the value stored in the index. Also, the 'canreturn' index AM interface function gains a new 'attno' argument. That makes it possible to use index-only scans on a multi-column index where some of the opclasses support index-only scans but some do not. This patch adds support in the box and point opclasses. Other opclasses can added later as follow-on patches (btree_gist would be particularly interesting). Anastasia Lubennikova, with additional fixes and modifications by me.
This commit is contained in:
@ -151,6 +151,16 @@ gist_box_decompress(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_POINTER(PG_GETARG_POINTER(0));
|
||||
}
|
||||
|
||||
/*
|
||||
* GiST Fetch method for boxes
|
||||
* do not do anything --- we just return the stored box as is.
|
||||
*/
|
||||
Datum
|
||||
gist_box_fetch(PG_FUNCTION_ARGS)
|
||||
{
|
||||
PG_RETURN_POINTER(PG_GETARG_POINTER(0));
|
||||
}
|
||||
|
||||
/*
|
||||
* The GiST Penalty method for boxes (also used for points)
|
||||
*
|
||||
@ -1186,6 +1196,33 @@ gist_point_compress(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_POINTER(entry);
|
||||
}
|
||||
|
||||
/*
|
||||
* GiST Fetch method for point
|
||||
*
|
||||
* Get point coordinates from its bounding box coordinates and form new
|
||||
* gistentry.
|
||||
*/
|
||||
Datum
|
||||
gist_point_fetch(PG_FUNCTION_ARGS)
|
||||
{
|
||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
||||
BOX *in = DatumGetBoxP(entry->key);
|
||||
Point *r;
|
||||
GISTENTRY *retval;
|
||||
|
||||
retval = palloc(sizeof(GISTENTRY));
|
||||
|
||||
r = (Point *) palloc(sizeof(Point));
|
||||
r->x = in->high.x;
|
||||
r->y = in->high.y;
|
||||
gistentryinit(*retval, PointerGetDatum(r),
|
||||
entry->rel, entry->page,
|
||||
entry->offset, FALSE);
|
||||
|
||||
PG_RETURN_POINTER(retval);
|
||||
}
|
||||
|
||||
|
||||
#define point_point_distance(p1,p2) \
|
||||
DatumGetFloat8(DirectFunctionCall2(point_distance, \
|
||||
PointPGetDatum(p1), PointPGetDatum(p2)))
|
||||
|
Reference in New Issue
Block a user