Migrate rtree_gist functionality into the core system, and add some

basic regression tests for GiST to the standard regression tests.
I took the opportunity to add an rtree-equivalent gist opclass for
circles; the contrib version only covered boxes and polygons, but
indexing circles is very handy for distance searches.
This commit is contained in:
Tom Lane 2005-07-01 19:19:05 +00:00
parent 875efad481
commit e7e1694295
16 changed files with 1406 additions and 24 deletions

View File

@ -4,7 +4,7 @@
# Makefile for access/gist
#
# IDENTIFICATION
# $PostgreSQL: pgsql/src/backend/access/gist/Makefile,v 1.14 2005/06/20 10:29:36 teodor Exp $
# $PostgreSQL: pgsql/src/backend/access/gist/Makefile,v 1.15 2005/07/01 19:19:02 tgl Exp $
#
#-------------------------------------------------------------------------
@ -12,7 +12,8 @@ subdir = src/backend/access/gist
top_builddir = ../../../..
include $(top_builddir)/src/Makefile.global
OBJS = gist.o gistutil.o gistxlog.o gistvacuum.o gistget.o gistscan.o
OBJS = gist.o gistutil.o gistxlog.o gistvacuum.o gistget.o gistscan.o \
gistproc.o
all: SUBSYS.o

View File

@ -0,0 +1,708 @@
/*-------------------------------------------------------------------------
*
* gistproc.c
* Support procedures for GiSTs over 2-D objects (boxes, polygons, circles).
*
* This gives R-tree behavior, with Guttman's poly-time split algorithm.
*
*
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/gist/gistproc.c,v 1.1 2005/07/01 19:19:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "access/gist.h"
#include "access/itup.h"
#include "access/rtree.h"
#include "utils/geo_decls.h"
typedef struct
{
BOX *key;
int pos;
} KBsort;
static int compare_KB(const void *a, const void *b);
static bool gist_box_leaf_consistent(BOX *key, BOX *query,
StrategyNumber strategy);
static double size_box(Datum dbox);
static bool rtree_internal_consistent(BOX *key, BOX *query,
StrategyNumber strategy);
/**************************************************
* Box ops
**************************************************/
/*
* The GiST Consistent method for boxes
*
* Should return false if for all data items x below entry,
* the predicate x op query must be FALSE, where op is the oper
* corresponding to strategy in the pg_amop table.
*/
Datum
gist_box_consistent(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
BOX *query = PG_GETARG_BOX_P(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
if (DatumGetBoxP(entry->key) == NULL || query == NULL)
PG_RETURN_BOOL(FALSE);
/*
* if entry is not leaf, use rtree_internal_consistent, else use
* gist_box_leaf_consistent
*/
if (GIST_LEAF(entry))
PG_RETURN_BOOL(gist_box_leaf_consistent(DatumGetBoxP(entry->key),
query,
strategy));
else
PG_RETURN_BOOL(rtree_internal_consistent(DatumGetBoxP(entry->key),
query,
strategy));
}
/*
* The GiST Union method for boxes
*
* returns the minimal bounding box that encloses all the entries in entryvec
*/
Datum
gist_box_union(PG_FUNCTION_ARGS)
{
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
int *sizep = (int *) PG_GETARG_POINTER(1);
int numranges,
i;
BOX *cur,
*pageunion;
numranges = entryvec->n;
pageunion = (BOX *) palloc(sizeof(BOX));
cur = DatumGetBoxP(entryvec->vector[0].key);
memcpy((void *) pageunion, (void *) cur, sizeof(BOX));
for (i = 1; i < numranges; i++)
{
cur = DatumGetBoxP(entryvec->vector[i].key);
if (pageunion->high.x < cur->high.x)
pageunion->high.x = cur->high.x;
if (pageunion->low.x > cur->low.x)
pageunion->low.x = cur->low.x;
if (pageunion->high.y < cur->high.y)
pageunion->high.y = cur->high.y;
if (pageunion->low.y > cur->low.y)
pageunion->low.y = cur->low.y;
}
*sizep = sizeof(BOX);
PG_RETURN_POINTER(pageunion);
}
/*
* GiST Compress methods for boxes
*
* do not do anything.
*/
Datum
gist_box_compress(PG_FUNCTION_ARGS)
{
PG_RETURN_POINTER(PG_GETARG_POINTER(0));
}
/*
* GiST DeCompress method for boxes (also used for polygons and circles)
*
* do not do anything --- we just use the stored box as is.
*/
Datum
gist_box_decompress(PG_FUNCTION_ARGS)
{
PG_RETURN_POINTER(PG_GETARG_POINTER(0));
}
/*
* The GiST Penalty method for boxes
*
* As in the R-tree paper, we use change in area as our penalty metric
*/
Datum
gist_box_penalty(PG_FUNCTION_ARGS)
{
GISTENTRY *origentry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *newentry = (GISTENTRY *) PG_GETARG_POINTER(1);
float *result = (float *) PG_GETARG_POINTER(2);
Datum ud;
ud = DirectFunctionCall2(rt_box_union, origentry->key, newentry->key);
*result = (float) (size_box(ud) - size_box(origentry->key));
PG_RETURN_POINTER(result);
}
/*
* qsort comparator for box areas
*/
static int
compare_KB(const void *a, const void *b)
{
BOX *abox = ((const KBsort *) a)->key;
BOX *bbox = ((const KBsort *) b)->key;
double sa = (abox->high.x - abox->low.x) * (abox->high.y - abox->low.y);
double sb = (bbox->high.x - bbox->low.x) * (bbox->high.y - bbox->low.y);
if (sa == sb)
return 0;
return (sa > sb) ? 1 : -1;
}
/*
* The GiST PickSplit method
*
* New linear algorithm, see 'New Linear Node Splitting Algorithm for R-tree',
* C.H.Ang and T.C.Tan
*/
Datum
gist_box_picksplit(PG_FUNCTION_ARGS)
{
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
OffsetNumber i;
OffsetNumber *listL,
*listR,
*listB,
*listT;
BOX *unionL,
*unionR,
*unionB,
*unionT;
int posL,
posR,
posB,
posT;
BOX pageunion;
BOX *cur;
char direction = ' ';
bool allisequal = true;
OffsetNumber maxoff;
int nbytes;
posL = posR = posB = posT = 0;
maxoff = entryvec->n - 1;
cur = DatumGetBoxP(entryvec->vector[FirstOffsetNumber].key);
memcpy((void *) &pageunion, (void *) cur, sizeof(BOX));
/* find MBR */
for (i = OffsetNumberNext(FirstOffsetNumber); i <= maxoff; i = OffsetNumberNext(i))
{
cur = DatumGetBoxP(entryvec->vector[i].key);
if (allisequal == true && (
pageunion.high.x != cur->high.x ||
pageunion.high.y != cur->high.y ||
pageunion.low.x != cur->low.x ||
pageunion.low.y != cur->low.y
))
allisequal = false;
if (pageunion.high.x < cur->high.x)
pageunion.high.x = cur->high.x;
if (pageunion.low.x > cur->low.x)
pageunion.low.x = cur->low.x;
if (pageunion.high.y < cur->high.y)
pageunion.high.y = cur->high.y;
if (pageunion.low.y > cur->low.y)
pageunion.low.y = cur->low.y;
}
nbytes = (maxoff + 2) * sizeof(OffsetNumber);
listL = (OffsetNumber *) palloc(nbytes);
listR = (OffsetNumber *) palloc(nbytes);
unionL = (BOX *) palloc(sizeof(BOX));
unionR = (BOX *) palloc(sizeof(BOX));
if (allisequal)
{
cur = DatumGetBoxP(entryvec->vector[OffsetNumberNext(FirstOffsetNumber)].key);
if (memcmp((void *) cur, (void *) &pageunion, sizeof(BOX)) == 0)
{
v->spl_left = listL;
v->spl_right = listR;
v->spl_nleft = v->spl_nright = 0;
memcpy((void *) unionL, (void *) &pageunion, sizeof(BOX));
memcpy((void *) unionR, (void *) &pageunion, sizeof(BOX));
for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
{
if (i <= (maxoff - FirstOffsetNumber + 1) / 2)
{
v->spl_left[v->spl_nleft] = i;
v->spl_nleft++;
}
else
{
v->spl_right[v->spl_nright] = i;
v->spl_nright++;
}
}
v->spl_ldatum = BoxPGetDatum(unionL);
v->spl_rdatum = BoxPGetDatum(unionR);
PG_RETURN_POINTER(v);
}
}
listB = (OffsetNumber *) palloc(nbytes);
listT = (OffsetNumber *) palloc(nbytes);
unionB = (BOX *) palloc(sizeof(BOX));
unionT = (BOX *) palloc(sizeof(BOX));
#define ADDLIST( list, unionD, pos, num ) do { \
if ( pos ) { \
if ( (unionD)->high.x < cur->high.x ) (unionD)->high.x = cur->high.x; \
if ( (unionD)->low.x > cur->low.x ) (unionD)->low.x = cur->low.x; \
if ( (unionD)->high.y < cur->high.y ) (unionD)->high.y = cur->high.y; \
if ( (unionD)->low.y > cur->low.y ) (unionD)->low.y = cur->low.y; \
} else { \
memcpy( (void*)(unionD), (void*) cur, sizeof( BOX ) ); \
} \
(list)[pos] = num; \
(pos)++; \
} while(0)
for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
{
cur = DatumGetBoxP(entryvec->vector[i].key);
if (cur->low.x - pageunion.low.x < pageunion.high.x - cur->high.x)
ADDLIST(listL, unionL, posL, i);
else
ADDLIST(listR, unionR, posR, i);
if (cur->low.y - pageunion.low.y < pageunion.high.y - cur->high.y)
ADDLIST(listB, unionB, posB, i);
else
ADDLIST(listT, unionT, posT, i);
}
/* bad disposition, sort by ascending and resplit */
if ((posR == 0 || posL == 0) && (posT == 0 || posB == 0))
{
KBsort *arr = (KBsort *) palloc(sizeof(KBsort) * maxoff);
posL = posR = posB = posT = 0;
for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
{
arr[i - 1].key = DatumGetBoxP(entryvec->vector[i].key);
arr[i - 1].pos = i;
}
qsort(arr, maxoff, sizeof(KBsort), compare_KB);
for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
{
cur = arr[i - 1].key;
if (cur->low.x - pageunion.low.x < pageunion.high.x - cur->high.x)
ADDLIST(listL, unionL, posL, arr[i - 1].pos);
else if (cur->low.x - pageunion.low.x == pageunion.high.x - cur->high.x)
{
if (posL > posR)
ADDLIST(listR, unionR, posR, arr[i - 1].pos);
else
ADDLIST(listL, unionL, posL, arr[i - 1].pos);
}
else
ADDLIST(listR, unionR, posR, arr[i - 1].pos);
if (cur->low.y - pageunion.low.y < pageunion.high.y - cur->high.y)
ADDLIST(listB, unionB, posB, arr[i - 1].pos);
else if (cur->low.y - pageunion.low.y == pageunion.high.y - cur->high.y)
{
if (posB > posT)
ADDLIST(listT, unionT, posT, arr[i - 1].pos);
else
ADDLIST(listB, unionB, posB, arr[i - 1].pos);
}
else
ADDLIST(listT, unionT, posT, arr[i - 1].pos);
}
}
/* which split more optimal? */
if (Max(posL, posR) < Max(posB, posT))
direction = 'x';
else if (Max(posL, posR) > Max(posB, posT))
direction = 'y';
else
{
Datum interLR = DirectFunctionCall2(rt_box_inter,
BoxPGetDatum(unionL),
BoxPGetDatum(unionR));
Datum interBT = DirectFunctionCall2(rt_box_inter,
BoxPGetDatum(unionB),
BoxPGetDatum(unionT));
double sizeLR,
sizeBT;
sizeLR = size_box(interLR);
sizeBT = size_box(interBT);
if (sizeLR < sizeBT)
direction = 'x';
else
direction = 'y';
}
if (direction == 'x')
{
v->spl_left = listL;
v->spl_right = listR;
v->spl_nleft = posL;
v->spl_nright = posR;
v->spl_ldatum = BoxPGetDatum(unionL);
v->spl_rdatum = BoxPGetDatum(unionR);
}
else
{
v->spl_left = listB;
v->spl_right = listT;
v->spl_nleft = posB;
v->spl_nright = posT;
v->spl_ldatum = BoxPGetDatum(unionB);
v->spl_rdatum = BoxPGetDatum(unionT);
}
PG_RETURN_POINTER(v);
}
/*
* Equality method
*/
Datum
gist_box_same(PG_FUNCTION_ARGS)
{
BOX *b1 = PG_GETARG_BOX_P(0);
BOX *b2 = PG_GETARG_BOX_P(1);
bool *result = (bool *) PG_GETARG_POINTER(2);
if (b1 && b2)
*result = DatumGetBool(DirectFunctionCall2(box_same,
PointerGetDatum(b1),
PointerGetDatum(b2)));
else
*result = (b1 == NULL && b2 == NULL) ? TRUE : FALSE;
PG_RETURN_POINTER(result);
}
/*
* Leaf-level consistency for boxes: just apply the query operator
*/
static bool
gist_box_leaf_consistent(BOX *key, BOX *query, StrategyNumber strategy)
{
bool retval;
switch (strategy)
{
case RTLeftStrategyNumber:
retval = DatumGetBool(DirectFunctionCall2(box_left,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
case RTOverLeftStrategyNumber:
retval = DatumGetBool(DirectFunctionCall2(box_overleft,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
case RTOverlapStrategyNumber:
retval = DatumGetBool(DirectFunctionCall2(box_overlap,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
case RTOverRightStrategyNumber:
retval = DatumGetBool(DirectFunctionCall2(box_overright,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
case RTRightStrategyNumber:
retval = DatumGetBool(DirectFunctionCall2(box_right,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
case RTSameStrategyNumber:
retval = DatumGetBool(DirectFunctionCall2(box_same,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
case RTContainsStrategyNumber:
retval = DatumGetBool(DirectFunctionCall2(box_contain,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
case RTContainedByStrategyNumber:
retval = DatumGetBool(DirectFunctionCall2(box_contained,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
case RTOverBelowStrategyNumber:
retval = DatumGetBool(DirectFunctionCall2(box_overbelow,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
case RTBelowStrategyNumber:
retval = DatumGetBool(DirectFunctionCall2(box_below,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
case RTAboveStrategyNumber:
retval = DatumGetBool(DirectFunctionCall2(box_above,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
case RTOverAboveStrategyNumber:
retval = DatumGetBool(DirectFunctionCall2(box_overabove,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
default:
retval = FALSE;
}
return retval;
}
static double
size_box(Datum dbox)
{
BOX *box = DatumGetBoxP(dbox);
if (box == NULL || box->high.x <= box->low.x || box->high.y <= box->low.y)
return 0.0;
return (box->high.x - box->low.x) * (box->high.y - box->low.y);
}
/*****************************************
* Common rtree functions (for boxes, polygons, and circles)
*****************************************/
/*
* Internal-page consistency for all these types
*
* We can use the same function since all types use bounding boxes as the
* internal-page representation.
*
* This implements the same logic as the rtree internal-page strategy map.
*/
static bool
rtree_internal_consistent(BOX *key, BOX *query, StrategyNumber strategy)
{
bool retval;
switch (strategy)
{
case RTLeftStrategyNumber:
retval = !DatumGetBool(DirectFunctionCall2(box_overright,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
case RTOverLeftStrategyNumber:
retval = !DatumGetBool(DirectFunctionCall2(box_right,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
case RTOverlapStrategyNumber:
retval = DatumGetBool(DirectFunctionCall2(box_overlap,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
case RTOverRightStrategyNumber:
retval = !DatumGetBool(DirectFunctionCall2(box_left,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
case RTRightStrategyNumber:
retval = !DatumGetBool(DirectFunctionCall2(box_overleft,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
case RTSameStrategyNumber:
case RTContainsStrategyNumber:
retval = DatumGetBool(DirectFunctionCall2(box_contain,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
case RTContainedByStrategyNumber:
retval = DatumGetBool(DirectFunctionCall2(box_overlap,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
case RTOverBelowStrategyNumber:
retval = !DatumGetBool(DirectFunctionCall2(box_above,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
case RTBelowStrategyNumber:
retval = !DatumGetBool(DirectFunctionCall2(box_overabove,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
case RTAboveStrategyNumber:
retval = !DatumGetBool(DirectFunctionCall2(box_overbelow,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
case RTOverAboveStrategyNumber:
retval = !DatumGetBool(DirectFunctionCall2(box_below,
PointerGetDatum(key),
PointerGetDatum(query)));
break;
default:
retval = FALSE;
}
return retval;
}
/**************************************************
* Polygon ops
**************************************************/
/*
* GiST compress for polygons: represent a polygon by its bounding box
*/
Datum
gist_poly_compress(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *retval;
if (entry->leafkey)
{
retval = palloc(sizeof(GISTENTRY));
if (DatumGetPointer(entry->key) != NULL)
{
POLYGON *in = DatumGetPolygonP(entry->key);
BOX *r;
r = (BOX *) palloc(sizeof(BOX));
memcpy((void *) r, (void *) &(in->boundbox), sizeof(BOX));
gistentryinit(*retval, PointerGetDatum(r),
entry->rel, entry->page,
entry->offset, sizeof(BOX), FALSE);
}
else
{
gistentryinit(*retval, (Datum) 0,
entry->rel, entry->page,
entry->offset, 0, FALSE);
}
}
else
retval = entry;
PG_RETURN_POINTER(retval);
}
/*
* The GiST Consistent method for polygons
*/
Datum
gist_poly_consistent(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
POLYGON *query = PG_GETARG_POLYGON_P(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
bool result;
if (DatumGetBoxP(entry->key) == NULL || query == NULL)
PG_RETURN_BOOL(FALSE);
/*
* Since the operators are marked lossy anyway, we can just use
* rtree_internal_consistent even at leaf nodes. (This works
* in part because the index entries are bounding boxes not polygons.)
*/
result = rtree_internal_consistent(DatumGetBoxP(entry->key),
&(query->boundbox), strategy);
/* Avoid memory leak if supplied poly is toasted */
PG_FREE_IF_COPY(query, 1);
PG_RETURN_BOOL(result);
}
/**************************************************
* Circle ops
**************************************************/
/*
* GiST compress for circles: represent a circle by its bounding box
*/
Datum
gist_circle_compress(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *retval;
if (entry->leafkey)
{
retval = palloc(sizeof(GISTENTRY));
if (DatumGetCircleP(entry->key) != NULL)
{
CIRCLE *in = DatumGetCircleP(entry->key);
BOX *r;
r = (BOX *) palloc(sizeof(BOX));
r->high.x = in->center.x + in->radius;
r->low.x = in->center.x - in->radius;
r->high.y = in->center.y + in->radius;
r->low.y = in->center.y - in->radius;
gistentryinit(*retval, PointerGetDatum(r),
entry->rel, entry->page,
entry->offset, sizeof(BOX), FALSE);
}
else
{
gistentryinit(*retval, (Datum) 0,
entry->rel, entry->page,
entry->offset, 0, FALSE);
}
}
else
retval = entry;
PG_RETURN_POINTER(retval);
}
/*
* The GiST Consistent method for circles
*/
Datum
gist_circle_consistent(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
CIRCLE *query = PG_GETARG_CIRCLE_P(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
BOX bbox;
bool result;
if (DatumGetBoxP(entry->key) == NULL || query == NULL)
PG_RETURN_BOOL(FALSE);
/*
* Since the operators are marked lossy anyway, we can just use
* rtree_internal_consistent even at leaf nodes. (This works
* in part because the index entries are bounding boxes not circles.)
*/
bbox.high.x = query->center.x + query->radius;
bbox.low.x = query->center.x - query->radius;
bbox.high.y = query->center.y + query->radius;
bbox.low.y = query->center.y - query->radius;
result = rtree_internal_consistent(DatumGetBoxP(entry->key),
&bbox, strategy);
PG_RETURN_BOOL(result);
}

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/geo_ops.c,v 1.89 2005/06/24 20:53:31 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/geo_ops.c,v 1.90 2005/07/01 19:19:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -4605,8 +4605,7 @@ circle_contain(PG_FUNCTION_ARGS)
}
/* circle_positionop -
* is circle1 entirely {above,below} circle2?
/* circle_below - is circle1 strictly below circle2?
*/
Datum
circle_below(PG_FUNCTION_ARGS)
@ -4614,18 +4613,46 @@ circle_below(PG_FUNCTION_ARGS)
CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
PG_RETURN_BOOL(FPle(circle1->center.y + circle1->radius,
circle2->center.y - circle2->radius));
PG_RETURN_BOOL(FPlt((circle1->center.y + circle1->radius),
(circle2->center.y - circle2->radius)));
}
/* circle_above - is circle1 strictly above circle2?
*/
Datum
circle_above(PG_FUNCTION_ARGS)
{
CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
PG_RETURN_BOOL(FPge(circle1->center.y - circle1->radius,
circle2->center.y + circle2->radius));
PG_RETURN_BOOL(FPgt((circle1->center.y - circle1->radius),
(circle2->center.y + circle2->radius)));
}
/* circle_overbelow - is the upper edge of circle1 at or below
* the upper edge of circle2?
*/
Datum
circle_overbelow(PG_FUNCTION_ARGS)
{
CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
PG_RETURN_BOOL(FPle((circle1->center.y + circle1->radius),
(circle2->center.y + circle2->radius)));
}
/* circle_overabove - is the lower edge of circle1 at or above
* the lower edge of circle2?
*/
Datum
circle_overabove(PG_FUNCTION_ARGS)
{
CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
PG_RETURN_BOOL(FPge((circle1->center.y - circle1->radius),
(circle2->center.y - circle2->radius)));
}

View File

@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.283 2005/06/28 05:09:04 tgl Exp $
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.284 2005/07/01 19:19:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -53,6 +53,6 @@
*/
/* yyyymmddN */
#define CATALOG_VERSION_NO 200506272
#define CATALOG_VERSION_NO 200507011
#endif

View File

@ -23,7 +23,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/catalog/pg_amop.h,v 1.64 2005/06/24 20:53:31 tgl Exp $
* $PostgreSQL: pgsql/src/include/catalog/pg_amop.h,v 1.65 2005/07/01 19:19:03 tgl Exp $
*
* NOTES
* the genbki.sh script reads this file and generates .bki
@ -619,4 +619,55 @@ DATA(insert ( 2232 0 1 f 2334 ));
/* aclitem_ops */
DATA(insert ( 2235 0 1 f 974 ));
/*
* gist box_ops
*/
DATA(insert ( 2593 0 1 f 493 ));
DATA(insert ( 2593 0 2 f 494 ));
DATA(insert ( 2593 0 3 f 500 ));
DATA(insert ( 2593 0 4 f 495 ));
DATA(insert ( 2593 0 5 f 496 ));
DATA(insert ( 2593 0 6 f 499 ));
DATA(insert ( 2593 0 7 f 498 ));
DATA(insert ( 2593 0 8 f 497 ));
DATA(insert ( 2593 0 9 f 2571 ));
DATA(insert ( 2593 0 10 f 2570 ));
DATA(insert ( 2593 0 11 f 2573 ));
DATA(insert ( 2593 0 12 f 2572 ));
/*
* gist poly_ops (supports polygons)
*/
DATA(insert ( 2594 0 1 t 485 ));
DATA(insert ( 2594 0 2 t 486 ));
DATA(insert ( 2594 0 3 t 492 ));
DATA(insert ( 2594 0 4 t 487 ));
DATA(insert ( 2594 0 5 t 488 ));
DATA(insert ( 2594 0 6 t 491 ));
DATA(insert ( 2594 0 7 t 490 ));
DATA(insert ( 2594 0 8 t 489 ));
DATA(insert ( 2594 0 9 t 2575 ));
DATA(insert ( 2594 0 10 t 2574 ));
DATA(insert ( 2594 0 11 t 2577 ));
DATA(insert ( 2594 0 12 t 2576 ));
/*
* gist circle_ops
*/
DATA(insert ( 2595 0 1 t 1506 ));
DATA(insert ( 2595 0 2 t 1507 ));
DATA(insert ( 2595 0 3 t 1513 ));
DATA(insert ( 2595 0 4 t 1508 ));
DATA(insert ( 2595 0 5 t 1509 ));
DATA(insert ( 2595 0 6 t 1512 ));
DATA(insert ( 2595 0 7 t 1511 ));
DATA(insert ( 2595 0 8 t 1510 ));
DATA(insert ( 2595 0 9 t 2589 ));
DATA(insert ( 2595 0 10 t 1515 ));
DATA(insert ( 2595 0 11 t 1514 ));
DATA(insert ( 2595 0 12 t 2590 ));
#endif /* PG_AMOP_H */

View File

@ -19,7 +19,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/catalog/pg_amproc.h,v 1.53 2005/04/14 01:38:20 tgl Exp $
* $PostgreSQL: pgsql/src/include/catalog/pg_amproc.h,v 1.54 2005/07/01 19:19:03 tgl Exp $
*
* NOTES
* the genbki.sh script reads this file and generates .bki
@ -170,4 +170,28 @@ DATA(insert ( 2231 0 1 456 ));
DATA(insert ( 2232 0 1 455 ));
DATA(insert ( 2235 0 1 329 ));
/* gist */
DATA(insert ( 2593 0 1 2578 ));
DATA(insert ( 2593 0 2 2583 ));
DATA(insert ( 2593 0 3 2579 ));
DATA(insert ( 2593 0 4 2580 ));
DATA(insert ( 2593 0 5 2581 ));
DATA(insert ( 2593 0 6 2582 ));
DATA(insert ( 2593 0 7 2584 ));
DATA(insert ( 2594 0 1 2585 ));
DATA(insert ( 2594 0 2 2583 ));
DATA(insert ( 2594 0 3 2586 ));
DATA(insert ( 2594 0 4 2580 ));
DATA(insert ( 2594 0 5 2581 ));
DATA(insert ( 2594 0 6 2582 ));
DATA(insert ( 2594 0 7 2584 ));
DATA(insert ( 2595 0 1 2591 ));
DATA(insert ( 2595 0 2 2583 ));
DATA(insert ( 2595 0 3 2592 ));
DATA(insert ( 2595 0 4 2580 ));
DATA(insert ( 2595 0 5 2581 ));
DATA(insert ( 2595 0 6 2582 ));
DATA(insert ( 2595 0 7 2584 ));
#endif /* PG_AMPROC_H */

View File

@ -27,7 +27,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/catalog/pg_opclass.h,v 1.65 2005/06/28 05:09:07 tgl Exp $
* $PostgreSQL: pgsql/src/include/catalog/pg_opclass.h,v 1.66 2005/07/01 19:19:03 tgl Exp $
*
* NOTES
* the genbki.sh script reads this file and generates .bki
@ -175,5 +175,8 @@ DATA(insert OID = 2232 ( 405 name_pattern_ops PGNSP PGUID 19 f 0 ));
DATA(insert OID = 2233 ( 403 reltime_ops PGNSP PGUID 703 t 0 ));
DATA(insert OID = 2234 ( 403 tinterval_ops PGNSP PGUID 704 t 0 ));
DATA(insert OID = 2235 ( 405 aclitem_ops PGNSP PGUID 1033 t 0 ));
DATA(insert OID = 2593 ( 783 box_ops PGNSP PGUID 603 t 0 ));
DATA(insert OID = 2594 ( 783 poly_ops PGNSP PGUID 604 t 603 ));
DATA(insert OID = 2595 ( 783 circle_ops PGNSP PGUID 718 t 603 ));
#endif /* PG_OPCLASS_H */

View File

@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/catalog/pg_operator.h,v 1.135 2005/06/28 05:09:07 tgl Exp $
* $PostgreSQL: pgsql/src/include/catalog/pg_operator.h,v 1.136 2005/07/01 19:19:03 tgl Exp $
*
* NOTES
* the genbki.sh script reads this file and generates .bki
@ -568,8 +568,8 @@ DATA(insert OID = 1510 ( "@" PGNSP PGUID b f 718 718 16 1511 0 0 0 0 0
DATA(insert OID = 1511 ( "~" PGNSP PGUID b f 718 718 16 1510 0 0 0 0 0 circle_contain contsel contjoinsel ));
DATA(insert OID = 1512 ( "~=" PGNSP PGUID b f 718 718 16 1512 0 0 0 0 0 circle_same eqsel eqjoinsel ));
DATA(insert OID = 1513 ( "&&" PGNSP PGUID b f 718 718 16 1513 0 0 0 0 0 circle_overlap areasel areajoinsel ));
DATA(insert OID = 1514 ( ">^" PGNSP PGUID b f 718 718 16 0 0 0 0 0 0 circle_above positionsel positionjoinsel ));
DATA(insert OID = 1515 ( "<^" PGNSP PGUID b f 718 718 16 0 0 0 0 0 0 circle_below positionsel positionjoinsel ));
DATA(insert OID = 1514 ( "|>>" PGNSP PGUID b f 718 718 16 0 0 0 0 0 0 circle_above positionsel positionjoinsel ));
DATA(insert OID = 1515 ( "<<|" PGNSP PGUID b f 718 718 16 0 0 0 0 0 0 circle_below positionsel positionjoinsel ));
DATA(insert OID = 1516 ( "+" PGNSP PGUID b f 718 600 718 0 0 0 0 0 0 circle_add_pt - - ));
DATA(insert OID = 1517 ( "-" PGNSP PGUID b f 718 600 718 0 0 0 0 0 0 circle_sub_pt - - ));
@ -874,6 +874,8 @@ DATA(insert OID = 2574 ( "<<|" PGNSP PGUID b f 604 604 16 0 0 0 0 0 0
DATA(insert OID = 2575 ( "&<|" PGNSP PGUID b f 604 604 16 0 0 0 0 0 0 poly_overbelow positionsel positionjoinsel ));
DATA(insert OID = 2576 ( "|&>" PGNSP PGUID b f 604 604 16 0 0 0 0 0 0 poly_overabove positionsel positionjoinsel ));
DATA(insert OID = 2577 ( "|>>" PGNSP PGUID b f 604 604 16 0 0 0 0 0 0 poly_above positionsel positionjoinsel ));
DATA(insert OID = 2589 ( "&<|" PGNSP PGUID b f 718 718 16 0 0 0 0 0 0 circle_overbelow positionsel positionjoinsel ));
DATA(insert OID = 2590 ( "|&>" PGNSP PGUID b f 718 718 16 0 0 0 0 0 0 circle_overabove positionsel positionjoinsel ));
/*

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.372 2005/06/28 05:09:09 tgl Exp $
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.373 2005/07/01 19:19:03 tgl Exp $
*
* NOTES
* The script catalog/genbki.sh reads this file and generates .bki
@ -3675,6 +3675,34 @@ DATA(insert OID = 2568 ( poly_overabove PGNSP PGUID 12 f f t f i 2 16 "604 60
DESCR("overlaps or is above");
DATA(insert OID = 2569 ( poly_above PGNSP PGUID 12 f f t f i 2 16 "604 604" _null_ _null_ _null_ poly_above - _null_ ));
DESCR("is above");
DATA(insert OID = 2587 ( circle_overbelow PGNSP PGUID 12 f f t f i 2 16 "718 718" _null_ _null_ _null_ circle_overbelow - _null_ ));
DESCR("overlaps or is below");
DATA(insert OID = 2588 ( circle_overabove PGNSP PGUID 12 f f t f i 2 16 "718 718" _null_ _null_ _null_ circle_overabove - _null_ ));
DESCR("overlaps or is above");
/* support functions for GiST r-tree emulation */
DATA(insert OID = 2578 ( gist_box_consistent PGNSP PGUID 12 f f t f i 3 16 "2281 603 23" _null_ _null_ _null_ gist_box_consistent - _null_ ));
DESCR("GiST support");
DATA(insert OID = 2579 ( gist_box_compress PGNSP PGUID 12 f f t f i 1 2281 "2281" _null_ _null_ _null_ gist_box_compress - _null_ ));
DESCR("GiST support");
DATA(insert OID = 2580 ( gist_box_decompress PGNSP PGUID 12 f f t f i 1 2281 "2281" _null_ _null_ _null_ gist_box_decompress - _null_ ));
DESCR("GiST support");
DATA(insert OID = 2581 ( gist_box_penalty PGNSP PGUID 12 f f t f i 3 2281 "2281 2281 2281" _null_ _null_ _null_ gist_box_penalty - _null_ ));
DESCR("GiST support");
DATA(insert OID = 2582 ( gist_box_picksplit PGNSP PGUID 12 f f t f i 2 2281 "2281 2281" _null_ _null_ _null_ gist_box_picksplit - _null_ ));
DESCR("GiST support");
DATA(insert OID = 2583 ( gist_box_union PGNSP PGUID 12 f f t f i 2 603 "2281 2281" _null_ _null_ _null_ gist_box_union - _null_ ));
DESCR("GiST support");
DATA(insert OID = 2584 ( gist_box_same PGNSP PGUID 12 f f t f i 3 2281 "603 603 2281" _null_ _null_ _null_ gist_box_same - _null_ ));
DESCR("GiST support");
DATA(insert OID = 2585 ( gist_poly_consistent PGNSP PGUID 12 f f t f i 3 16 "2281 604 23" _null_ _null_ _null_ gist_poly_consistent - _null_ ));
DESCR("GiST support");
DATA(insert OID = 2586 ( gist_poly_compress PGNSP PGUID 12 f f t f i 1 2281 "2281" _null_ _null_ _null_ gist_poly_compress - _null_ ));
DESCR("GiST support");
DATA(insert OID = 2591 ( gist_circle_consistent PGNSP PGUID 12 f f t f i 3 16 "2281 718 23" _null_ _null_ _null_ gist_circle_consistent - _null_ ));
DESCR("GiST support");
DATA(insert OID = 2592 ( gist_circle_compress PGNSP PGUID 12 f f t f i 1 2281 "2281" _null_ _null_ _null_ gist_circle_compress - _null_ ));
DESCR("GiST support");
/*

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/utils/geo_decls.h,v 1.47 2005/06/24 20:53:33 tgl Exp $
* $PostgreSQL: pgsql/src/include/utils/geo_decls.h,v 1.48 2005/07/01 19:19:04 tgl Exp $
*
* NOTE
* These routines do *not* use the float types from adt/.
@ -379,6 +379,8 @@ extern Datum circle_contained(PG_FUNCTION_ARGS);
extern Datum circle_contain(PG_FUNCTION_ARGS);
extern Datum circle_below(PG_FUNCTION_ARGS);
extern Datum circle_above(PG_FUNCTION_ARGS);
extern Datum circle_overbelow(PG_FUNCTION_ARGS);
extern Datum circle_overabove(PG_FUNCTION_ARGS);
extern Datum circle_eq(PG_FUNCTION_ARGS);
extern Datum circle_ne(PG_FUNCTION_ARGS);
extern Datum circle_lt(PG_FUNCTION_ARGS);
@ -404,7 +406,7 @@ extern Datum poly_circle(PG_FUNCTION_ARGS);
extern Datum circle_poly(PG_FUNCTION_ARGS);
extern Datum circle_area(PG_FUNCTION_ARGS);
/* support routines for the rtree access method (rtproc.c) */
/* support routines for the rtree access method (access/rtree/rtproc.c) */
extern Datum rt_box_union(PG_FUNCTION_ARGS);
extern Datum rt_box_inter(PG_FUNCTION_ARGS);
extern Datum rt_box_size(PG_FUNCTION_ARGS);
@ -412,6 +414,19 @@ extern Datum rt_poly_size(PG_FUNCTION_ARGS);
extern Datum rt_poly_union(PG_FUNCTION_ARGS);
extern Datum rt_poly_inter(PG_FUNCTION_ARGS);
/* support routines for the GiST access method (access/gist/gistproc.c) */
extern Datum gist_box_compress(PG_FUNCTION_ARGS);
extern Datum gist_box_decompress(PG_FUNCTION_ARGS);
extern Datum gist_box_union(PG_FUNCTION_ARGS);
extern Datum gist_box_picksplit(PG_FUNCTION_ARGS);
extern Datum gist_box_consistent(PG_FUNCTION_ARGS);
extern Datum gist_box_penalty(PG_FUNCTION_ARGS);
extern Datum gist_box_same(PG_FUNCTION_ARGS);
extern Datum gist_poly_compress(PG_FUNCTION_ARGS);
extern Datum gist_poly_consistent(PG_FUNCTION_ARGS);
extern Datum gist_circle_compress(PG_FUNCTION_ARGS);
extern Datum gist_circle_consistent(PG_FUNCTION_ARGS);
/* geo_selfuncs.c */
extern Datum areasel(PG_FUNCTION_ARGS);
extern Datum areajoinsel(PG_FUNCTION_ARGS);

File diff suppressed because it is too large Load Diff

View File

@ -54,7 +54,28 @@ CREATE INDEX onek2_stu1_prtl ON onek2 USING btree(stringu1 name_ops)
-- benchmark).
--
CREATE INDEX rect2ind ON fast_emp4000 USING rtree (home_base);
-- there's no easy way to check that this command actually is using
SET enable_seqscan = ON;
SET enable_indexscan = OFF;
SET enable_bitmapscan = OFF;
SELECT * FROM fast_emp4000
WHERE home_base @ '(200,200),(2000,1000)'::box
ORDER BY home_base USING <<;
home_base
-----------------------
(337,455),(240,359)
(1444,403),(1346,344)
(2 rows)
SELECT count(*) FROM fast_emp4000 WHERE home_base && '(1000,1000,0,0)'::box;
count
-------
2
(1 row)
SET enable_seqscan = OFF;
SET enable_indexscan = ON;
SET enable_bitmapscan = ON;
-- there's no easy way to check that these commands actually use
-- the index, unfortunately. (EXPLAIN would work, but its output
-- changes too often for me to want to put an EXPLAIN in the test...)
SELECT * FROM fast_emp4000
@ -66,6 +87,125 @@ SELECT * FROM fast_emp4000
(1444,403),(1346,344)
(2 rows)
SELECT count(*) FROM fast_emp4000 WHERE home_base && '(1000,1000,0,0)'::box;
count
-------
2
(1 row)
DROP INDEX rect2ind;
--
-- GiST (rtree-equivalent opclasses only)
--
CREATE INDEX grect2ind ON fast_emp4000 USING gist (home_base);
CREATE INDEX gpolygonind ON polygon_tbl USING gist (f1);
CREATE INDEX gcircleind ON circle_tbl USING gist (f1);
CREATE TEMP TABLE gpolygon_tbl AS
SELECT polygon(home_base) AS f1 FROM slow_emp4000;
CREATE TEMP TABLE gcircle_tbl AS
SELECT circle(home_base) AS f1 FROM slow_emp4000;
CREATE INDEX ggpolygonind ON gpolygon_tbl USING gist (f1);
CREATE INDEX ggcircleind ON gcircle_tbl USING gist (f1);
SET enable_seqscan = ON;
SET enable_indexscan = OFF;
SET enable_bitmapscan = OFF;
SELECT * FROM fast_emp4000
WHERE home_base @ '(200,200),(2000,1000)'::box
ORDER BY home_base USING <<;
home_base
-----------------------
(337,455),(240,359)
(1444,403),(1346,344)
(2 rows)
SELECT count(*) FROM fast_emp4000 WHERE home_base && '(1000,1000,0,0)'::box;
count
-------
2
(1 row)
SELECT * FROM polygon_tbl WHERE f1 ~ '((1,1),(2,2),(2,1))'::polygon
ORDER BY f1 USING <<;
f1
---------------------
((2,0),(2,4),(0,0))
(1 row)
SELECT * FROM circle_tbl WHERE f1 && circle(point(1,-2), 1)
ORDER BY f1 USING <<;
f1
---------------
<(1,3),5>
<(1,2),100>
<(1,2),3>
<(100,1),115>
(4 rows)
SELECT count(*) FROM gpolygon_tbl WHERE f1 && '(1000,1000,0,0)'::polygon;
count
-------
2
(1 row)
SELECT count(*) FROM gcircle_tbl WHERE f1 && '<(500,500),500>'::circle;
count
-------
2
(1 row)
SET enable_seqscan = OFF;
SET enable_indexscan = ON;
SET enable_bitmapscan = ON;
-- there's no easy way to check that these commands actually use
-- the index, unfortunately. (EXPLAIN would work, but its output
-- changes too often for me to want to put an EXPLAIN in the test...)
SELECT * FROM fast_emp4000
WHERE home_base @ '(200,200),(2000,1000)'::box
ORDER BY home_base USING <<;
home_base
-----------------------
(337,455),(240,359)
(1444,403),(1346,344)
(2 rows)
SELECT count(*) FROM fast_emp4000 WHERE home_base && '(1000,1000,0,0)'::box;
count
-------
2
(1 row)
SELECT * FROM polygon_tbl WHERE f1 ~ '((1,1),(2,2),(2,1))'::polygon
ORDER BY f1 USING <<;
f1
---------------------
((2,0),(2,4),(0,0))
(1 row)
SELECT * FROM circle_tbl WHERE f1 && circle(point(1,-2), 1)
ORDER BY f1 USING <<;
f1
---------------
<(1,3),5>
<(1,2),100>
<(1,2),3>
<(100,1),115>
(4 rows)
SELECT count(*) FROM gpolygon_tbl WHERE f1 && '(1000,1000,0,0)'::polygon;
count
-------
2
(1 row)
SELECT count(*) FROM gcircle_tbl WHERE f1 && '<(500,500),500>'::circle;
count
-------
2
(1 row)
RESET enable_seqscan;
RESET enable_indexscan;
RESET enable_bitmapscan;
--
-- HASH
--

View File

@ -765,9 +765,12 @@ WHERE p1.amopclaid = p3.oid AND p3.opcamid = p2.oid AND
-- Detect missing pg_amop entries: should have as many strategy operators
-- as AM expects for each opclass for the AM. When nondefault subtypes are
-- present, enforce condition separately for each subtype.
-- We have to exclude GiST, unfortunately, since it hasn't got any fixed
-- requirements about strategy operators.
SELECT p1.oid, p1.amname, p2.oid, p2.opcname, p3.amopsubtype
FROM pg_am AS p1, pg_opclass AS p2, pg_amop AS p3
WHERE p2.opcamid = p1.oid AND p3.amopclaid = p2.oid AND
p1.amname != 'gist' AND
p1.amstrategies != (SELECT count(*) FROM pg_amop AS p4
WHERE p4.amopclaid = p2.oid AND
p4.amopsubtype = p3.amopsubtype);
@ -819,7 +822,19 @@ ORDER BY 1, 2, 3;
403 | 5 | ~>~
405 | 1 | =
405 | 1 | ~=~
(24 rows)
783 | 1 | <<
783 | 2 | &<
783 | 3 | &&
783 | 4 | &>
783 | 5 | >>
783 | 6 | ~=
783 | 7 | ~
783 | 8 | @
783 | 9 | &<|
783 | 10 | <<|
783 | 11 | |>>
783 | 12 | |&>
(36 rows)
-- Check that all operators linked to by opclass entries have selectivity
-- estimators. This is not absolutely required, but it seems a reasonable

View File

@ -14,6 +14,7 @@ SELECT relname, relhasindex
bt_i4_heap | t
bt_name_heap | t
bt_txt_heap | t
circle_tbl | t
fast_emp4000 | t
func_index_heap | t
hash_f8_heap | t
@ -59,11 +60,12 @@ SELECT relname, relhasindex
pg_tablespace | t
pg_trigger | t
pg_type | t
polygon_tbl | t
road | t
shighway | t
tenk1 | t
tenk2 | t
(53 rows)
(55 rows)
--
-- another sanity check: every system catalog that has OIDs should have

View File

@ -77,13 +77,98 @@ CREATE INDEX onek2_stu1_prtl ON onek2 USING btree(stringu1 name_ops)
--
CREATE INDEX rect2ind ON fast_emp4000 USING rtree (home_base);
-- there's no easy way to check that this command actually is using
SET enable_seqscan = ON;
SET enable_indexscan = OFF;
SET enable_bitmapscan = OFF;
SELECT * FROM fast_emp4000
WHERE home_base @ '(200,200),(2000,1000)'::box
ORDER BY home_base USING <<;
SELECT count(*) FROM fast_emp4000 WHERE home_base && '(1000,1000,0,0)'::box;
SET enable_seqscan = OFF;
SET enable_indexscan = ON;
SET enable_bitmapscan = ON;
-- there's no easy way to check that these commands actually use
-- the index, unfortunately. (EXPLAIN would work, but its output
-- changes too often for me to want to put an EXPLAIN in the test...)
SELECT * FROM fast_emp4000
WHERE home_base @ '(200,200),(2000,1000)'::box
ORDER BY home_base USING <<;
SELECT count(*) FROM fast_emp4000 WHERE home_base && '(1000,1000,0,0)'::box;
DROP INDEX rect2ind;
--
-- GiST (rtree-equivalent opclasses only)
--
CREATE INDEX grect2ind ON fast_emp4000 USING gist (home_base);
CREATE INDEX gpolygonind ON polygon_tbl USING gist (f1);
CREATE INDEX gcircleind ON circle_tbl USING gist (f1);
CREATE TEMP TABLE gpolygon_tbl AS
SELECT polygon(home_base) AS f1 FROM slow_emp4000;
CREATE TEMP TABLE gcircle_tbl AS
SELECT circle(home_base) AS f1 FROM slow_emp4000;
CREATE INDEX ggpolygonind ON gpolygon_tbl USING gist (f1);
CREATE INDEX ggcircleind ON gcircle_tbl USING gist (f1);
SET enable_seqscan = ON;
SET enable_indexscan = OFF;
SET enable_bitmapscan = OFF;
SELECT * FROM fast_emp4000
WHERE home_base @ '(200,200),(2000,1000)'::box
ORDER BY home_base USING <<;
SELECT count(*) FROM fast_emp4000 WHERE home_base && '(1000,1000,0,0)'::box;
SELECT * FROM polygon_tbl WHERE f1 ~ '((1,1),(2,2),(2,1))'::polygon
ORDER BY f1 USING <<;
SELECT * FROM circle_tbl WHERE f1 && circle(point(1,-2), 1)
ORDER BY f1 USING <<;
SELECT count(*) FROM gpolygon_tbl WHERE f1 && '(1000,1000,0,0)'::polygon;
SELECT count(*) FROM gcircle_tbl WHERE f1 && '<(500,500),500>'::circle;
SET enable_seqscan = OFF;
SET enable_indexscan = ON;
SET enable_bitmapscan = ON;
-- there's no easy way to check that these commands actually use
-- the index, unfortunately. (EXPLAIN would work, but its output
-- changes too often for me to want to put an EXPLAIN in the test...)
SELECT * FROM fast_emp4000
WHERE home_base @ '(200,200),(2000,1000)'::box
ORDER BY home_base USING <<;
SELECT count(*) FROM fast_emp4000 WHERE home_base && '(1000,1000,0,0)'::box;
SELECT * FROM polygon_tbl WHERE f1 ~ '((1,1),(2,2),(2,1))'::polygon
ORDER BY f1 USING <<;
SELECT * FROM circle_tbl WHERE f1 && circle(point(1,-2), 1)
ORDER BY f1 USING <<;
SELECT count(*) FROM gpolygon_tbl WHERE f1 && '(1000,1000,0,0)'::polygon;
SELECT count(*) FROM gcircle_tbl WHERE f1 && '<(500,500),500>'::circle;
RESET enable_seqscan;
RESET enable_indexscan;
RESET enable_bitmapscan;
--
-- HASH
--

View File

@ -631,10 +631,13 @@ WHERE p1.amopclaid = p3.oid AND p3.opcamid = p2.oid AND
-- Detect missing pg_amop entries: should have as many strategy operators
-- as AM expects for each opclass for the AM. When nondefault subtypes are
-- present, enforce condition separately for each subtype.
-- We have to exclude GiST, unfortunately, since it hasn't got any fixed
-- requirements about strategy operators.
SELECT p1.oid, p1.amname, p2.oid, p2.opcname, p3.amopsubtype
FROM pg_am AS p1, pg_opclass AS p2, pg_amop AS p3
WHERE p2.opcamid = p1.oid AND p3.amopclaid = p2.oid AND
p1.amname != 'gist' AND
p1.amstrategies != (SELECT count(*) FROM pg_amop AS p4
WHERE p4.amopclaid = p2.oid AND
p4.amopsubtype = p3.amopsubtype);