We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see ourdocumentation.
There was an error while loading.Please reload this page.
1 parent81939cf commit971007cCopy full SHA for 971007c
Makefile
@@ -55,7 +55,7 @@ CRUSH_TESTS = init_extended circle_extended
55
PGS_SQL = pgs_types.sql pgs_point.sql pgs_euler.sql pgs_circle.sql\
56
pgs_line.sql pgs_ellipse.sql pgs_polygon.sql pgs_path.sql\
57
pgs_box.sql pgs_contains_ops.sql pgs_contains_ops_compat.sql\
58
- pgs_gist.sql gnomo.sql pgs_brin.sql pgs_circle_sel.sql
+ pgs_gist.sql gnomo.sql pgs_brin.sql pgs_circle_sel.sql pgs_hash.sql
59
60
ifneq ($(USE_HEALPIX),0)
61
TESTS += healpix moc moc1 moc100 mocautocast
@@ -199,7 +199,7 @@ ifeq ($(has_index_options),y)
199
pg_sphere--1.3.1--1.3.2.sql: pgs_moc_options.sql.in
200
endif
201
202
-pg_sphere--1.3.1--1.3.2.sql: pgs_circle_sel.sql.in
+pg_sphere--1.3.1--1.3.2.sql: pgs_circle_sel.sql.in pgs_hash.sql.in
203
cat upgrade_scripts/$@.in$^>$@
204
205
# end of local stuff
expected/index.out
@@ -195,3 +195,39 @@ EXPLAIN (COSTS OFF) SELECT count(*) FROM spheretmp1b WHERE p = spoint '(3.09 , 1
195
4
196
(1 row)
197
198
+-- test hash opclass
+CREATE TABLE spheretmp1c AS TABLE spheretmp1;
+SELECT p FROM spheretmp1c WHERE p <@ scircle '<(1,1),0.2>' ORDER BY p::text;
+ p
+---------------
+ (0.67 , 0.97)
206
207
+ (1.07 , 1.09)
208
209
210
211
+ (1.24 , 0.95)
212
213
214
215
+(12 rows)
216
+
217
+WITH points AS (SELECT DISTINCT p FROM spheretmp1c WHERE p <@ scircle '<(1,1),0.2>')
218
+ SELECT p FROM points ORDER BY p::text;
219
220
221
222
223
224
+(3 rows)
225
226
+CREATE INDEX spheretmp1c_hash_idx ON spheretmp1c USING hash(p);
227
+EXPLAIN (COSTS OFF) SELECT * FROM spheretmp1c WHERE p = '(0.67 , 0.97)';
228
+ QUERY PLAN
229
+------------------------------------------------------
230
+ Index Scan using spheretmp1c_hash_idx on spheretmp1c
231
+ Index Cond: (p = '(0.67 , 0.97)'::spoint)
232
+(2 rows)
233
pgs_hash.sql.in
@@ -0,0 +1,19 @@
1
+CREATE FUNCTION spoint_hash32 (spoint)
2
+ RETURNS int
3
+ IMMUTABLE STRICT
+ PARALLEL SAFE
5
+ LANGUAGE C
6
+ AS 'MODULE_PATHNAME', 'spherepoint_hash32';
7
8
+UPDATE pg_operator
9
+ SET oprcanhash = true
10
+ WHERE oprname = '=' AND
11
+ oprleft = 'spoint'::regtype AND oprright = 'spoint'::regtype;
12
13
+/* PG17: ALTER OPERATOR = (spoint, spoint) SET (HASHES); */
14
15
+CREATE OPERATOR CLASS spoint_hash_ops
16
+ DEFAULT FOR TYPE spoint USING hash
17
+ AS
18
+ OPERATOR 1 = (spoint, spoint),
19
+ FUNCTION 1 spoint_hash32(spoint);
sql/index.sql
@@ -76,3 +76,14 @@ EXPLAIN (COSTS OFF) SELECT count(*) FROM spheretmp1b WHERE p <@ scircle '<(1,1),
76
SELECTcount(*)FROM spheretmp1bWHERE p<@ scircle'<(1,1),0.3>';
77
EXPLAIN (COSTS OFF)SELECTcount(*)FROM spheretmp1bWHERE p= spoint'(3.09 , 1.25)';
78
SELECTcount(*)FROM spheretmp1bWHERE p= spoint'(3.09 , 1.25)';
79
80
81
82
+CREATETABLEspheretmp1cAS TABLE spheretmp1;
83
84
+SELECT pFROM spheretmp1cWHERE p<@ scircle'<(1,1),0.2>'ORDER BY p::text;
85
+WITH pointsAS (SELECT DISTINCT pFROM spheretmp1cWHERE p<@ scircle'<(1,1),0.2>')
86
+SELECT pFROM pointsORDER BY p::text;
87
88
+CREATEINDEXspheretmp1c_hash_idxON spheretmp1c USING hash(p);
89
+EXPLAIN (COSTS OFF)SELECT*FROM spheretmp1cWHERE p='(0.67 , 0.97)';
src/point.c
@@ -16,6 +16,7 @@ PG_FUNCTION_INFO_V1(spherepoint_y);
PG_FUNCTION_INFO_V1(spherepoint_z);
PG_FUNCTION_INFO_V1(spherepoint_xyz);
PG_FUNCTION_INFO_V1(spherepoint_equal);
+PG_FUNCTION_INFO_V1(spherepoint_hash32);
20
21
staticOidpoint_id=InvalidOid;
22
@@ -309,3 +310,23 @@ spherepoint_equal(PG_FUNCTION_ARGS)
309
310
311
PG_RETURN_BOOL(spoint_eq(p1,p2));
312
}
313
314
+Datum
315
+spherepoint_hash32(PG_FUNCTION_ARGS)
316
+{
317
+SPoint*p1= (SPoint*)PG_GETARG_POINTER(0);
318
319
+unionspoint_int32 {
320
+SPointp;
321
+struct {
322
+int32f1,f2,f3,f4;
323
+};
324
+}u;
325
326
+int32res;
327
328
+u.p=*p1;
329
+res=u.f1 ^u.f2 ^u.f3 ^u.f4;
330
331
+PG_RETURN_INT32(res);
332
+}
src/point.h
@@ -102,4 +102,9 @@ Datumspherepoint_xyz(PG_FUNCTION_ARGS);
102
*/
103
Datumspherepoint_equal(PG_FUNCTION_ARGS);
104
105
+/*
106
+ * Compute a 32-bit hash value of a point.
107
+ */
108
+Datumspherepoint_hash32(PG_FUNCTION_ARGS);
109
110
#endif