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

Commit4cbe473

Browse files
committed
Add point_ops opclass for GiST.
1 parente99767b commit4cbe473

File tree

16 files changed

+511
-20
lines changed

16 files changed

+511
-20
lines changed

‎src/backend/access/gist/gistproc.c

Lines changed: 171 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Portions Copyright (c) 1994, Regents of the University of California
1111
*
1212
* IDENTIFICATION
13-
*$PostgreSQL: pgsql/src/backend/access/gist/gistproc.c,v 1.19 2010/01/02 16:57:34 momjian Exp $
13+
*$PostgreSQL: pgsql/src/backend/access/gist/gistproc.c,v 1.20 2010/01/14 16:31:09 teodor Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -165,7 +165,8 @@ gist_box_compress(PG_FUNCTION_ARGS)
165165
}
166166

167167
/*
168-
* GiST DeCompress method for boxes (also used for polygons and circles)
168+
* GiST DeCompress method for boxes (also used for points, polygons
169+
* and circles)
169170
*
170171
* do not do anything --- we just use the stored box as is.
171172
*/
@@ -176,7 +177,7 @@ gist_box_decompress(PG_FUNCTION_ARGS)
176177
}
177178

178179
/*
179-
* The GiST Penalty method for boxes
180+
* The GiST Penalty method for boxes (also used for points)
180181
*
181182
* As in the R-tree paper, we use change in area as our penalty metric
182183
*/
@@ -341,6 +342,8 @@ fallbackSplit(GistEntryVector *entryvec, GIST_SPLITVEC *v)
341342
*
342343
* New linear algorithm, see 'New Linear Node Splitting Algorithm for R-tree',
343344
* C.H.Ang and T.C.Tan
345+
*
346+
* This is used for both boxes and points.
344347
*/
345348
Datum
346349
gist_box_picksplit(PG_FUNCTION_ARGS)
@@ -533,6 +536,8 @@ gist_box_picksplit(PG_FUNCTION_ARGS)
533536

534537
/*
535538
* Equality method
539+
*
540+
* This is used for both boxes and points.
536541
*/
537542
Datum
538543
gist_box_same(PG_FUNCTION_ARGS)
@@ -872,3 +877,166 @@ gist_circle_consistent(PG_FUNCTION_ARGS)
872877

873878
PG_RETURN_BOOL(result);
874879
}
880+
881+
/**************************************************
882+
* Point ops
883+
**************************************************/
884+
885+
Datum
886+
gist_point_compress(PG_FUNCTION_ARGS)
887+
{
888+
GISTENTRY*entry= (GISTENTRY*)PG_GETARG_POINTER(0);
889+
890+
if (entry->leafkey)/* Point, actually */
891+
{
892+
BOX*box=palloc(sizeof(BOX));
893+
Point*point=DatumGetPointP(entry->key);
894+
GISTENTRY*retval=palloc(sizeof(GISTENTRY));
895+
896+
box->high=box->low=*point;
897+
898+
gistentryinit(*retval,BoxPGetDatum(box),
899+
entry->rel,entry->page,entry->offset, FALSE);
900+
901+
PG_RETURN_POINTER(retval);
902+
}
903+
904+
PG_RETURN_POINTER(entry);
905+
}
906+
907+
staticbool
908+
gist_point_consistent_internal(StrategyNumberstrategy,
909+
boolisLeaf,BOX*key,Point*query)
910+
{
911+
boolresult= false;
912+
913+
switch (strategy)
914+
{
915+
caseRTLeftStrategyNumber:
916+
result=FPlt(key->low.x,query->x);
917+
break;
918+
caseRTRightStrategyNumber:
919+
result=FPgt(key->high.x,query->x);
920+
break;
921+
caseRTAboveStrategyNumber:
922+
result=FPgt(key->high.y,query->y);
923+
break;
924+
caseRTBelowStrategyNumber:
925+
result=FPlt(key->low.y,query->y);
926+
break;
927+
caseRTSameStrategyNumber:
928+
if (isLeaf)
929+
{
930+
result=FPeq(key->low.x,query->x)
931+
&&FPeq(key->low.y,query->y);
932+
}
933+
else
934+
{
935+
result= (query->x <=key->high.x&&query->x >=key->low.x&&
936+
query->y <=key->high.y&&query->y >=key->low.y);
937+
}
938+
break;
939+
default:
940+
elog(ERROR,"unknown strategy number: %d",strategy);
941+
}
942+
943+
returnresult;
944+
}
945+
946+
#defineGeoStrategyNumberOffset20
947+
#definePointStrategyNumberGroup0
948+
#defineBoxStrategyNumberGroup1
949+
#definePolygonStrategyNumberGroup2
950+
#defineCircleStrategyNumberGroup3
951+
952+
Datum
953+
gist_point_consistent(PG_FUNCTION_ARGS)
954+
{
955+
GISTENTRY*entry= (GISTENTRY*)PG_GETARG_POINTER(0);
956+
StrategyNumberstrategy= (StrategyNumber)PG_GETARG_UINT16(2);
957+
boolresult;
958+
bool*recheck= (bool*)PG_GETARG_POINTER(4);
959+
StrategyNumberstrategyGroup=strategy /GeoStrategyNumberOffset;
960+
961+
switch (strategyGroup)
962+
{
963+
casePointStrategyNumberGroup:
964+
result=gist_point_consistent_internal(strategy %GeoStrategyNumberOffset,
965+
GIST_LEAF(entry),
966+
DatumGetBoxP(entry->key),
967+
PG_GETARG_POINT_P(1));
968+
*recheck= false;
969+
break;
970+
caseBoxStrategyNumberGroup:
971+
result=DatumGetBool(DirectFunctionCall5(
972+
gist_box_consistent,
973+
PointerGetDatum(entry),
974+
PG_GETARG_DATUM(1),
975+
Int16GetDatum(RTOverlapStrategyNumber),
976+
0,PointerGetDatum(recheck)));
977+
break;
978+
casePolygonStrategyNumberGroup:
979+
{
980+
POLYGON*query=PG_GETARG_POLYGON_P(1);
981+
982+
result=DatumGetBool(DirectFunctionCall5(
983+
gist_poly_consistent,
984+
PointerGetDatum(entry),
985+
PolygonPGetDatum(query),
986+
Int16GetDatum(RTOverlapStrategyNumber),
987+
0,PointerGetDatum(recheck)));
988+
989+
if (GIST_LEAF(entry)&&result)
990+
{
991+
/*
992+
* We are on leaf page and quick check shows overlapping
993+
* of polygon's bounding box and point
994+
*/
995+
BOX*box=DatumGetBoxP(entry->key);
996+
997+
Assert(box->high.x==box->low.x
998+
&&box->high.y==box->low.y);
999+
result=DatumGetBool(DirectFunctionCall2(
1000+
poly_contain_pt,
1001+
PolygonPGetDatum(query),
1002+
PointPGetDatum(&box->high)));
1003+
*recheck= false;
1004+
}
1005+
}
1006+
break;
1007+
caseCircleStrategyNumberGroup:
1008+
{
1009+
CIRCLE*query=PG_GETARG_CIRCLE_P(1);
1010+
1011+
result=DatumGetBool(DirectFunctionCall5(
1012+
gist_circle_consistent,
1013+
PointerGetDatum(entry),
1014+
CirclePGetDatum(query),
1015+
Int16GetDatum(RTOverlapStrategyNumber),
1016+
0,PointerGetDatum(recheck)));
1017+
1018+
if (GIST_LEAF(entry)&&result)
1019+
{
1020+
/*
1021+
* We are on leaf page and quick check shows overlapping
1022+
* of polygon's bounding box and point
1023+
*/
1024+
BOX*box=DatumGetBoxP(entry->key);
1025+
1026+
Assert(box->high.x==box->low.x
1027+
&&box->high.y==box->low.y);
1028+
result=DatumGetBool(DirectFunctionCall2(
1029+
circle_contain_pt,
1030+
CirclePGetDatum(query),
1031+
PointPGetDatum(&box->high)));
1032+
*recheck= false;
1033+
}
1034+
}
1035+
break;
1036+
default:
1037+
result= false;/* silence compiler warning */
1038+
elog(ERROR,"unknown strategy number: %d",strategy);
1039+
}
1040+
1041+
PG_RETURN_BOOL(result);
1042+
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/geo_ops.c,v 1.106 2010/01/02 16:57:54 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/geo_ops.c,v 1.107 2010/01/14 16:31:09 teodor Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -3202,6 +3202,16 @@ on_pb(PG_FUNCTION_ARGS)
32023202
pt->y <=box->high.y&&pt->y >=box->low.y);
32033203
}
32043204

3205+
Datum
3206+
box_contain_pt(PG_FUNCTION_ARGS)
3207+
{
3208+
BOX*box=PG_GETARG_BOX_P(0);
3209+
Point*pt=PG_GETARG_POINT_P(1);
3210+
3211+
PG_RETURN_BOOL(pt->x <=box->high.x&&pt->x >=box->low.x&&
3212+
pt->y <=box->high.y&&pt->y >=box->low.y);
3213+
}
3214+
32053215
/* on_ppath -
32063216
*Whether a point lies within (on) a polyline.
32073217
*If open, we have to (groan) check each segment.

‎src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.571 2010/01/12 02:42:52 momjian Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.572 2010/01/14 16:31:09 teodor Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201001111
56+
#defineCATALOG_VERSION_NO201001141
5757

5858
#endif

‎src/include/catalog/pg_amop.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
3030
* Portions Copyright (c) 1994, Regents of the University of California
3131
*
32-
* $PostgreSQL: pgsql/src/include/catalog/pg_amop.h,v 1.92 2010/01/05 01:06:56 tgl Exp $
32+
* $PostgreSQL: pgsql/src/include/catalog/pg_amop.h,v 1.93 2010/01/14 16:31:09 teodor Exp $
3333
*
3434
* NOTES
3535
* the genbki.pl script reads this file and generates .bki
@@ -582,6 +582,22 @@ DATA(insert (2593 603 603 12 2572783 ));
582582
DATA(insert (2593603603132863783 ));
583583
DATA(insert (2593603603142862783 ));
584584

585+
/*
586+
* gist point_ops
587+
*/
588+
DATA(insert (102960060011506783 ));
589+
DATA(insert (10296006001507783 ));
590+
DATA(insert (10296006005508783 ));
591+
DATA(insert (102960060010509783 ));
592+
DATA(insert (10296006006510783 ));
593+
DATA(insert (102960360027433783 ));
594+
DATA(insert (102960060328511783 ));
595+
DATA(insert (102960460047757783 ));
596+
DATA(insert (102960060448756783 ));
597+
DATA(insert (102971860067759783 ));
598+
DATA(insert (102960071868758783 ));
599+
600+
585601
/*
586602
*gist poly_ops (supports polygons)
587603
*/

‎src/include/catalog/pg_amproc.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
2323
* Portions Copyright (c) 1994, Regents of the University of California
2424
*
25-
* $PostgreSQL: pgsql/src/include/catalog/pg_amproc.h,v 1.77 2010/01/05 01:06:56 tgl Exp $
25+
* $PostgreSQL: pgsql/src/include/catalog/pg_amproc.h,v 1.78 2010/01/14 16:31:09 teodor Exp $
2626
*
2727
* NOTES
2828
* the genbki.pl script reads this file and generates .bki
@@ -197,6 +197,13 @@ DATA(insert (3702 3615 3615 4 3696 ));
197197
DATA(insert (37023615361553700 ));
198198
DATA(insert (37023615361563697 ));
199199
DATA(insert (37023615361573699 ));
200+
DATA(insert (102960060012179 ));
201+
DATA(insert (102960060022583 ));
202+
DATA(insert (102960060031030 ));
203+
DATA(insert (102960060042580 ));
204+
DATA(insert (102960060052581 ));
205+
DATA(insert (102960060062582 ));
206+
DATA(insert (102960060072584 ));
200207

201208

202209
/* gin */

‎src/include/catalog/pg_opclass.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
2929
* Portions Copyright (c) 1994, Regents of the University of California
3030
*
31-
* $PostgreSQL: pgsql/src/include/catalog/pg_opclass.h,v 1.87 2010/01/05 01:06:56 tgl Exp $
31+
* $PostgreSQL: pgsql/src/include/catalog/pg_opclass.h,v 1.88 2010/01/14 16:31:09 teodor Exp $
3232
*
3333
* NOTES
3434
* the genbki.pl script reads this file and generates .bki
@@ -170,6 +170,7 @@ DATA(insert (403reltime_opsPGNSP PGUID 2233 703 t 0 ));
170170
DATA(insert (403tinterval_opsPGNSPPGUID2234704t0 ));
171171
DATA(insert (405aclitem_opsPGNSPPGUID22351033t0 ));
172172
DATA(insert (783box_opsPGNSPPGUID2593603t0 ));
173+
DATA(insert (783point_opsPGNSPPGUID1029600t603 ));
173174
DATA(insert (783poly_opsPGNSPPGUID2594604t603 ));
174175
DATA(insert (783circle_opsPGNSPPGUID2595718t603 ));
175176
DATA(insert (2742_int4_opsPGNSPPGUID27451007t23 ));

‎src/include/catalog/pg_operator.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/catalog/pg_operator.h,v 1.169 2010/01/05 01:06:56 tgl Exp $
11+
* $PostgreSQL: pgsql/src/include/catalog/pg_operator.h,v 1.170 2010/01/14 16:31:09 teodor Exp $
1212
*
1313
* NOTES
1414
* the genbki.pl script reads this file and generates .bki
@@ -171,7 +171,8 @@ DATA(insert OID = 507 ( "<<" PGNSP PGUID b f f 600 60016 0 0 point_left p
171171
DATA(insertOID=508 (">>"PGNSPPGUIDbff6006001600point_rightpositionselpositionjoinsel ));
172172
DATA(insertOID=509 ("<^"PGNSPPGUIDbff6006001600point_belowpositionselpositionjoinsel ));
173173
DATA(insertOID=510 ("~="PGNSPPGUIDbff60060016510713point_eqeqseleqjoinsel ));
174-
DATA(insertOID=511 ("<@"PGNSPPGUIDbff6006031600on_pb-- ));
174+
DATA(insertOID=511 ("<@"PGNSPPGUIDbff600603164330on_pbcontselcontjoinsel ));
175+
DATA(insertOID=433 ("@>"PGNSPPGUIDbff603600165110box_contain_ptcontselcontjoinsel ));
175176
DATA(insertOID=512 ("<@"PGNSPPGUIDbff600602167550on_ppath-- ));
176177
DATA(insertOID=513 ("@@"PGNSPPGUIDlff060360000box_center-- ));
177178
DATA(insertOID=514 ("*"PGNSPPGUIDbff2323235140int4mul-- ));
@@ -359,10 +360,10 @@ DATA(insert OID = 737 ( "-" PGNSP PGUID b f f602 600602 0 0 path_sub_
359360
DATA(insertOID=738 ("*"PGNSPPGUIDbff60260060200path_mul_pt-- ));
360361
DATA(insertOID=739 ("/"PGNSPPGUIDbff60260060200path_div_pt-- ));
361362
DATA(insertOID=755 ("@>"PGNSPPGUIDbff602600165120path_contain_pt-- ));
362-
DATA(insertOID=756 ("<@"PGNSPPGUIDbff600604167570pt_contained_poly-- ));
363-
DATA(insertOID=757 ("@>"PGNSPPGUIDbff604600167560poly_contain_pt-- ));
364-
DATA(insertOID=758 ("<@"PGNSPPGUIDbff600718167590pt_contained_circle-- ));
365-
DATA(insertOID=759 ("@>"PGNSPPGUIDbff718600167580circle_contain_pt-- ));
363+
DATA(insertOID=756 ("<@"PGNSPPGUIDbff600604167570pt_contained_polycontselcontjoinsel ));
364+
DATA(insertOID=757 ("@>"PGNSPPGUIDbff604600167560poly_contain_ptcontselcontjoinsel ));
365+
DATA(insertOID=758 ("<@"PGNSPPGUIDbff600718167590pt_contained_circlecontselcontjoinsel ));
366+
DATA(insertOID=759 ("@>"PGNSPPGUIDbff718600167580circle_contain_ptcontselcontjoinsel ));
366367

367368
DATA(insertOID=773 ("@"PGNSPPGUIDlff0232300int4abs-- ));
368369

‎src/include/catalog/pg_opfamily.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/catalog/pg_opfamily.h,v 1.13 2010/01/05 01:06:56 tgl Exp $
11+
* $PostgreSQL: pgsql/src/include/catalog/pg_opfamily.h,v 1.14 2010/01/14 16:31:09 teodor Exp $
1212
*
1313
* NOTES
1414
* the genbki.pl script reads this file and generates .bki
@@ -127,6 +127,7 @@ DATA(insert OID = 2235 (405aclitem_opsPGNSP PGUID ));
127127
DATA(insertOID=2593 (783box_opsPGNSPPGUID ));
128128
DATA(insertOID=2594 (783poly_opsPGNSPPGUID ));
129129
DATA(insertOID=2595 (783circle_opsPGNSPPGUID ));
130+
DATA(insertOID=1029 (783point_opsPGNSPPGUID ));
130131
DATA(insertOID=2745 (2742array_opsPGNSPPGUID ));
131132
DATA(insertOID=2968 (403uuid_opsPGNSPPGUID ));
132133
DATA(insertOID=2969 (405uuid_opsPGNSPPGUID ));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp