Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0cc9932

Browse files
committed
Rename the "point is strictly above/below point" comparison operators.
Historically these were called >^ and <^, but that is inconsistent with the similar box, polygon, and circle operators, which are named |>> and <<| respectively. Worse, the >^ and <^ names are used for *not* strict above/below tests for the box type. Hence, invent new operators following the more common naming. The old operators remain available for now, and are still accepted by the relevant index opclasses too. But there's a deprecation notice, so maybe we can get rid of them someday. Emre Hasegeli, reviewed by Pavel Borisov Discussion: https://postgr.es/m/24348.1587444160@sss.pgh.pa.us
1 parent d36228a commit 0cc9932

17 files changed

+159
-132
lines changed

doc/src/sgml/func.sgml

+14-32
Original file line numberDiff line numberDiff line change
@@ -10609,7 +10609,7 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
1060910609
</para>
1061010610
<para>
1061110611
Is first object strictly below second?
10612-
Available for <type>box</type>, <type>polygon</type>,
10612+
Available for <type>point</type>, <type>box</type>, <type>polygon</type>,
1061310613
<type>circle</type>.
1061410614
</para>
1061510615
<para>
@@ -10625,7 +10625,7 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
1062510625
</para>
1062610626
<para>
1062710627
Is first object strictly above second?
10628-
Available for <type>box</type>, <type>polygon</type>,
10628+
Available for <type>point</type>, <type>box</type>, <type>polygon</type>,
1062910629
<type>circle</type>.
1063010630
</para>
1063110631
<para>
@@ -10680,21 +10680,6 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
1068010680
</para></entry>
1068110681
</row>
1068210682

10683-
<row>
10684-
<entry role="func_table_entry"><para role="func_signature">
10685-
<type>point</type> <literal>&lt;^</literal> <type>point</type>
10686-
<returnvalue>boolean</returnvalue>
10687-
</para>
10688-
<para>
10689-
Is first object strictly below second?
10690-
(This operator is misnamed; it should be <literal>&lt;&lt;|</literal>.)
10691-
</para>
10692-
<para>
10693-
<literal>point '(1,0)' &lt;^ point '(1,1)'</literal>
10694-
<returnvalue>t</returnvalue>
10695-
</para></entry>
10696-
</row>
10697-
1069810683
<row>
1069910684
<entry role="func_table_entry"><para role="func_signature">
1070010685
<type>box</type> <literal>&gt;^</literal> <type>box</type>
@@ -10709,21 +10694,6 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
1070910694
</para></entry>
1071010695
</row>
1071110696

10712-
<row>
10713-
<entry role="func_table_entry"><para role="func_signature">
10714-
<type>point</type> <literal>&gt;^</literal> <type>point</type>
10715-
<returnvalue>boolean</returnvalue>
10716-
</para>
10717-
<para>
10718-
Is first object strictly above second?
10719-
(This operator is misnamed; it should be <literal>|&gt;&gt;</literal>.)
10720-
</para>
10721-
<para>
10722-
<literal>point '(1,1)' &gt;^ point '(1,0)'</literal>
10723-
<returnvalue>t</returnvalue>
10724-
</para></entry>
10725-
</row>
10726-
1072710697
<row>
1072810698
<entry role="func_table_entry"><para role="func_signature">
1072910699
<replaceable>geometric_type</replaceable> <literal>?#</literal> <replaceable>geometric_type</replaceable>
@@ -10877,6 +10847,18 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
1087710847
</para>
1087810848
</caution>
1087910849

10850+
<note>
10851+
<para>
10852+
Before <productname>PostgreSQL</productname> 14, the point
10853+
is strictly below/above comparison operators <type>point</type>
10854+
<literal>&lt;&lt;|</literal> <type>point</type> and <type>point</type>
10855+
<literal>|&gt;&gt;</literal> <type>point</type> were respectively
10856+
called <literal>&lt;^</literal> and <literal>&gt;^</literal>. These
10857+
names are still available, but are deprecated and will eventually be
10858+
removed.
10859+
</para>
10860+
</note>
10861+
1088010862
<table id="functions-geometry-func-table">
1088110863
<title>Geometric Functions</title>
1088210864
<tgroup cols="1">

doc/src/sgml/gist.sgml

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@
118118

119119
<row>
120120
<entry valign="middle" morerows="7"><literal>point_ops</literal></entry>
121-
<entry><literal>&gt;^ (point,point)</literal></entry>
121+
<entry><literal>|&gt;&gt; (point,point)</literal></entry>
122122
<entry valign="middle" morerows="7"><literal>&lt;-&gt; (point,point)</literal></entry>
123123
</row>
124124
<row><entry><literal>&lt;&lt; (point,point)</literal></entry></row>
125125
<row><entry><literal>&gt;&gt; (point,point)</literal></entry></row>
126-
<row><entry><literal>&lt;^ (point,point)</literal></entry></row>
126+
<row><entry><literal>&lt;&lt;| (point,point)</literal></entry></row>
127127
<row><entry><literal>~= (point,point)</literal></entry></row>
128128
<row><entry><literal>&lt;@ (point,box)</literal></entry></row>
129129
<row><entry><literal>&lt;@ (point,polygon)</literal></entry></row>

doc/src/sgml/spgist.sgml

+7-7
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<row>
7777
<entry valign="middle" morerows="11"><literal>box_ops</literal></entry>
7878
<entry><literal>&lt;&lt; (box,box)</literal></entry>
79-
<entry valign="middle" morerows="11"><literal>&lt;-&gt; (box,point)</literal></entry>
79+
<entry valign="middle" morerows="11"><literal>&lt;-&gt; (box,point)</literal></entry>
8080
</row>
8181
<row><entry><literal>&amp;&lt; (box,box)</literal></entry></row>
8282
<row><entry><literal>&amp;&gt; (box,box)</literal></entry></row>
@@ -92,12 +92,12 @@
9292

9393
<row>
9494
<entry valign="middle" morerows="5"><literal>kd_point_ops</literal></entry>
95-
<entry><literal>&gt;^ (point,point)</literal></entry>
95+
<entry><literal>|&gt;&gt; (point,point)</literal></entry>
9696
<entry valign="middle" morerows="5"><literal>&lt;-&gt; (point,point)</literal></entry>
9797
</row>
9898
<row><entry><literal>&lt;&lt; (point,point)</literal></entry></row>
9999
<row><entry><literal>&gt;&gt; (point,point)</literal></entry></row>
100-
<row><entry><literal>&lt;^ (point,point)</literal></entry></row>
100+
<row><entry><literal>&lt;&lt;| (point,point)</literal></entry></row>
101101
<row><entry><literal>~= (point,point)</literal></entry></row>
102102
<row><entry><literal>&lt;@ (point,box)</literal></entry></row>
103103

@@ -132,16 +132,16 @@
132132
<row><entry><literal>&lt;&lt;| (polygon,polygon)</literal></entry></row>
133133
<row><entry><literal>&amp;&lt;| (polygon,polygon)</literal></entry></row>
134134
<row><entry><literal>|&gt;&gt; (polygon,polygon)</literal></entry></row>
135-
<row><entry><literal>|&amp;&gt; (polygon,polygon)</literal></entry></row>
135+
<row><entry><literal>|&amp;&gt; (polygon,polygon)</literal></entry></row>
136136

137137
<row>
138138
<entry valign="middle" morerows="5"><literal>quad_point_ops</literal></entry>
139-
<entry><literal>&gt;^ (point,point)</literal></entry>
139+
<entry><literal>|&gt;&gt; (point,point)</literal></entry>
140140
<entry valign="middle" morerows="5"><literal>&lt;-&gt; (point,point)</literal></entry>
141141
</row>
142142
<row><entry><literal>&lt;&lt; (point,point)</literal></entry></row>
143143
<row><entry><literal>&gt;&gt; (point,point)</literal></entry></row>
144-
<row><entry><literal>&lt;^ (point,point)</literal></entry></row>
144+
<row><entry><literal>&lt;&lt;| (point,point)</literal></entry></row>
145145
<row><entry><literal>~= (point,point)</literal></entry></row>
146146
<row><entry><literal>&lt;@ (point,box)</literal></entry></row>
147147

@@ -159,7 +159,7 @@
159159
<row><entry><literal>&amp;&lt; (anyrange,anyrange)</literal></entry></row>
160160
<row><entry><literal>&amp;&gt; (anyrange,anyrange)</literal></entry></row>
161161
<row><entry><literal>-|- (anyrange,anyrange)</literal></entry></row>
162-
162+
163163
<row>
164164
<entry valign="middle" morerows="9"><literal>text_ops</literal></entry>
165165
<entry><literal>= (text,text)</literal></entry>

src/backend/access/gist/gistproc.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -1341,8 +1341,18 @@ gist_point_consistent(PG_FUNCTION_ARGS)
13411341
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
13421342
bool *recheck = (bool *) PG_GETARG_POINTER(4);
13431343
bool result;
1344-
StrategyNumber strategyGroup = strategy / GeoStrategyNumberOffset;
1344+
StrategyNumber strategyGroup;
1345+
1346+
/*
1347+
* We have to remap these strategy numbers to get this klugy
1348+
* classification logic to work.
1349+
*/
1350+
if (strategy == RTOldBelowStrategyNumber)
1351+
strategy = RTBelowStrategyNumber;
1352+
else if (strategy == RTOldAboveStrategyNumber)
1353+
strategy = RTAboveStrategyNumber;
13451354

1355+
strategyGroup = strategy / GeoStrategyNumberOffset;
13461356
switch (strategyGroup)
13471357
{
13481358
case PointStrategyNumberGroup:

src/backend/access/spgist/spgkdtreeproc.c

+2
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,12 @@ spg_kd_inner_consistent(PG_FUNCTION_ARGS)
209209
}
210210
break;
211211
case RTBelowStrategyNumber:
212+
case RTOldBelowStrategyNumber:
212213
if ((in->level % 2) == 0 && FPlt(query->y, coord))
213214
which &= (1 << 1);
214215
break;
215216
case RTAboveStrategyNumber:
217+
case RTOldAboveStrategyNumber:
216218
if ((in->level % 2) == 0 && FPgt(query->y, coord))
217219
which &= (1 << 2);
218220
break;

src/backend/access/spgist/spgquadtreeproc.c

+4
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,12 @@ spg_quad_inner_consistent(PG_FUNCTION_ARGS)
316316
which &= (1 << getQuadrant(centroid, query));
317317
break;
318318
case RTBelowStrategyNumber:
319+
case RTOldBelowStrategyNumber:
319320
if (SPTEST(point_above, centroid, query))
320321
which &= (1 << 2) | (1 << 3);
321322
break;
322323
case RTAboveStrategyNumber:
324+
case RTOldAboveStrategyNumber:
323325
if (SPTEST(point_below, centroid, query))
324326
which &= (1 << 1) | (1 << 4);
325327
break;
@@ -434,9 +436,11 @@ spg_quad_leaf_consistent(PG_FUNCTION_ARGS)
434436
res = SPTEST(point_eq, datum, query);
435437
break;
436438
case RTBelowStrategyNumber:
439+
case RTOldBelowStrategyNumber:
437440
res = SPTEST(point_below, datum, query);
438441
break;
439442
case RTAboveStrategyNumber:
443+
case RTOldAboveStrategyNumber:
440444
res = SPTEST(point_above, datum, query);
441445
break;
442446
case RTContainedByStrategyNumber:

src/include/access/stratnum.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ typedef uint16 StrategyNumber;
7676
#define RTSuperStrategyNumber 26 /* for inet << */
7777
#define RTSuperEqualStrategyNumber 27 /* for inet >>= */
7878
#define RTPrefixStrategyNumber 28 /* for text ^@ */
79+
#define RTOldBelowStrategyNumber 29 /* for old spelling of <<| */
80+
#define RTOldAboveStrategyNumber 30 /* for old spelling of |>> */
7981

80-
#define RTMaxStrategyNumber 28
82+
#define RTMaxStrategyNumber 30
8183

8284

8385
#endif /* STRATNUM_H */

src/include/catalog/catversion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 202011191
56+
#define CATALOG_VERSION_NO 202011231
5757

5858
#endif

src/include/catalog/pg_amop.dat

+24-6
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,10 @@
11111111

11121112
# gist point_ops
11131113
{ amopfamily => 'gist/point_ops', amoplefttype => 'point',
1114-
amoprighttype => 'point', amopstrategy => '11', amopopr => '>^(point,point)',
1114+
amoprighttype => 'point', amopstrategy => '11', amopopr => '|>>(point,point)',
1115+
amopmethod => 'gist' },
1116+
{ amopfamily => 'gist/point_ops', amoplefttype => 'point',
1117+
amoprighttype => 'point', amopstrategy => '30', amopopr => '>^(point,point)',
11151118
amopmethod => 'gist' },
11161119
{ amopfamily => 'gist/point_ops', amoplefttype => 'point',
11171120
amoprighttype => 'point', amopstrategy => '1', amopopr => '<<(point,point)',
@@ -1120,7 +1123,10 @@
11201123
amoprighttype => 'point', amopstrategy => '5', amopopr => '>>(point,point)',
11211124
amopmethod => 'gist' },
11221125
{ amopfamily => 'gist/point_ops', amoplefttype => 'point',
1123-
amoprighttype => 'point', amopstrategy => '10', amopopr => '<^(point,point)',
1126+
amoprighttype => 'point', amopstrategy => '10', amopopr => '<<|(point,point)',
1127+
amopmethod => 'gist' },
1128+
{ amopfamily => 'gist/point_ops', amoplefttype => 'point',
1129+
amoprighttype => 'point', amopstrategy => '29', amopopr => '<^(point,point)',
11241130
amopmethod => 'gist' },
11251131
{ amopfamily => 'gist/point_ops', amoplefttype => 'point',
11261132
amoprighttype => 'point', amopstrategy => '6', amopopr => '~=(point,point)',
@@ -1370,7 +1376,10 @@
13701376

13711377
# SP-GiST quad_point_ops
13721378
{ amopfamily => 'spgist/quad_point_ops', amoplefttype => 'point',
1373-
amoprighttype => 'point', amopstrategy => '11', amopopr => '>^(point,point)',
1379+
amoprighttype => 'point', amopstrategy => '11', amopopr => '|>>(point,point)',
1380+
amopmethod => 'spgist' },
1381+
{ amopfamily => 'spgist/quad_point_ops', amoplefttype => 'point',
1382+
amoprighttype => 'point', amopstrategy => '30', amopopr => '>^(point,point)',
13741383
amopmethod => 'spgist' },
13751384
{ amopfamily => 'spgist/quad_point_ops', amoplefttype => 'point',
13761385
amoprighttype => 'point', amopstrategy => '1', amopopr => '<<(point,point)',
@@ -1379,7 +1388,10 @@
13791388
amoprighttype => 'point', amopstrategy => '5', amopopr => '>>(point,point)',
13801389
amopmethod => 'spgist' },
13811390
{ amopfamily => 'spgist/quad_point_ops', amoplefttype => 'point',
1382-
amoprighttype => 'point', amopstrategy => '10', amopopr => '<^(point,point)',
1391+
amoprighttype => 'point', amopstrategy => '10', amopopr => '<<|(point,point)',
1392+
amopmethod => 'spgist' },
1393+
{ amopfamily => 'spgist/quad_point_ops', amoplefttype => 'point',
1394+
amoprighttype => 'point', amopstrategy => '29', amopopr => '<^(point,point)',
13831395
amopmethod => 'spgist' },
13841396
{ amopfamily => 'spgist/quad_point_ops', amoplefttype => 'point',
13851397
amoprighttype => 'point', amopstrategy => '6', amopopr => '~=(point,point)',
@@ -1394,7 +1406,10 @@
13941406

13951407
# SP-GiST kd_point_ops
13961408
{ amopfamily => 'spgist/kd_point_ops', amoplefttype => 'point',
1397-
amoprighttype => 'point', amopstrategy => '11', amopopr => '>^(point,point)',
1409+
amoprighttype => 'point', amopstrategy => '11', amopopr => '|>>(point,point)',
1410+
amopmethod => 'spgist' },
1411+
{ amopfamily => 'spgist/kd_point_ops', amoplefttype => 'point',
1412+
amoprighttype => 'point', amopstrategy => '30', amopopr => '>^(point,point)',
13981413
amopmethod => 'spgist' },
13991414
{ amopfamily => 'spgist/kd_point_ops', amoplefttype => 'point',
14001415
amoprighttype => 'point', amopstrategy => '1', amopopr => '<<(point,point)',
@@ -1403,7 +1418,10 @@
14031418
amoprighttype => 'point', amopstrategy => '5', amopopr => '>>(point,point)',
14041419
amopmethod => 'spgist' },
14051420
{ amopfamily => 'spgist/kd_point_ops', amoplefttype => 'point',
1406-
amoprighttype => 'point', amopstrategy => '10', amopopr => '<^(point,point)',
1421+
amoprighttype => 'point', amopstrategy => '10', amopopr => '<<|(point,point)',
1422+
amopmethod => 'spgist' },
1423+
{ amopfamily => 'spgist/kd_point_ops', amoplefttype => 'point',
1424+
amoprighttype => 'point', amopstrategy => '29', amopopr => '<^(point,point)',
14071425
amopmethod => 'spgist' },
14081426
{ amopfamily => 'spgist/kd_point_ops', amoplefttype => 'point',
14091427
amoprighttype => 'point', amopstrategy => '6', amopopr => '~=(point,point)',

src/include/catalog/pg_operator.dat

+11-2
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@
395395
oprname => '<=', oprleft => 'box', oprright => 'box', oprresult => 'bool',
396396
oprcom => '>=(box,box)', oprnegate => '>(box,box)', oprcode => 'box_le',
397397
oprrest => 'areasel', oprjoin => 'areajoinsel' },
398-
{ oid => '506', descr => 'is above',
398+
{ oid => '506', descr => 'deprecated, use |>> instead',
399399
oprname => '>^', oprleft => 'point', oprright => 'point', oprresult => 'bool',
400400
oprcode => 'point_above', oprrest => 'positionsel',
401401
oprjoin => 'positionjoinsel' },
@@ -407,7 +407,7 @@
407407
oprname => '>>', oprleft => 'point', oprright => 'point', oprresult => 'bool',
408408
oprcode => 'point_right', oprrest => 'positionsel',
409409
oprjoin => 'positionjoinsel' },
410-
{ oid => '509', descr => 'is below',
410+
{ oid => '509', descr => 'deprecated, use <<| instead',
411411
oprname => '<^', oprleft => 'point', oprright => 'point', oprresult => 'bool',
412412
oprcode => 'point_below', oprrest => 'positionsel',
413413
oprjoin => 'positionjoinsel' },
@@ -1878,6 +1878,15 @@
18781878
oprname => '#', oprleft => 'line', oprright => 'line', oprresult => 'point',
18791879
oprcom => '#(line,line)', oprcode => 'line_interpt' },
18801880

1881+
{ oid => '4161', descr => 'is above',
1882+
oprname => '|>>', oprleft => 'point', oprright => 'point',
1883+
oprresult => 'bool', oprcode => 'point_above', oprrest => 'positionsel',
1884+
oprjoin => 'positionjoinsel' },
1885+
{ oid => '4162', descr => 'is below',
1886+
oprname => '<<|', oprleft => 'point', oprright => 'point',
1887+
oprresult => 'bool', oprcode => 'point_below', oprrest => 'positionsel',
1888+
oprjoin => 'positionjoinsel' },
1889+
18811890
# MACADDR type
18821891
{ oid => '1220', descr => 'equal',
18831892
oprname => '=', oprcanmerge => 't', oprcanhash => 't', oprleft => 'macaddr',

src/test/regress/expected/create_index.out

+8-8
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ SELECT count(*) FROM point_tbl p WHERE p.f1 >> '(0.0, 0.0)';
160160
4
161161
(1 row)
162162

163-
SELECT count(*) FROM point_tbl p WHERE p.f1 <^ '(0.0, 0.0)';
163+
SELECT count(*) FROM point_tbl p WHERE p.f1 <<| '(0.0, 0.0)';
164164
count
165165
-------
166166
1
167167
(1 row)
168168

169-
SELECT count(*) FROM point_tbl p WHERE p.f1 >^ '(0.0, 0.0)';
169+
SELECT count(*) FROM point_tbl p WHERE p.f1 |>> '(0.0, 0.0)';
170170
count
171171
-------
172172
5
@@ -470,30 +470,30 @@ SELECT count(*) FROM point_tbl p WHERE p.f1 >> '(0.0, 0.0)';
470470
(1 row)
471471

472472
EXPLAIN (COSTS OFF)
473-
SELECT count(*) FROM point_tbl p WHERE p.f1 <^ '(0.0, 0.0)';
473+
SELECT count(*) FROM point_tbl p WHERE p.f1 <<| '(0.0, 0.0)';
474474
QUERY PLAN
475475
------------------------------------------------------
476476
Aggregate
477477
-> Index Only Scan using gpointind on point_tbl p
478-
Index Cond: (f1 <^ '(0,0)'::point)
478+
Index Cond: (f1 <<| '(0,0)'::point)
479479
(3 rows)
480480

481-
SELECT count(*) FROM point_tbl p WHERE p.f1 <^ '(0.0, 0.0)';
481+
SELECT count(*) FROM point_tbl p WHERE p.f1 <<| '(0.0, 0.0)';
482482
count
483483
-------
484484
1
485485
(1 row)
486486

487487
EXPLAIN (COSTS OFF)
488-
SELECT count(*) FROM point_tbl p WHERE p.f1 >^ '(0.0, 0.0)';
488+
SELECT count(*) FROM point_tbl p WHERE p.f1 |>> '(0.0, 0.0)';
489489
QUERY PLAN
490490
------------------------------------------------------
491491
Aggregate
492492
-> Index Only Scan using gpointind on point_tbl p
493-
Index Cond: (f1 >^ '(0,0)'::point)
493+
Index Cond: (f1 |>> '(0,0)'::point)
494494
(3 rows)
495495

496-
SELECT count(*) FROM point_tbl p WHERE p.f1 >^ '(0.0, 0.0)';
496+
SELECT count(*) FROM point_tbl p WHERE p.f1 |>> '(0.0, 0.0)';
497497
count
498498
-------
499499
5

0 commit comments

Comments
 (0)