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

Commit3a20b0e

Browse files
committed
Add index-only scan support to inet GiST opclass.
Andreas Karlsson
1 parent16bbb96 commit3a20b0e

File tree

7 files changed

+57
-1
lines changed

7 files changed

+57
-1
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,33 @@ inet_gist_decompress(PG_FUNCTION_ARGS)
587587
PG_RETURN_POINTER(entry);
588588
}
589589

590+
/*
591+
* The GiST fetch function
592+
*
593+
* Reconstruct the original inet datum from a GistInetKey.
594+
*/
595+
Datum
596+
inet_gist_fetch(PG_FUNCTION_ARGS)
597+
{
598+
GISTENTRY*entry= (GISTENTRY*)PG_GETARG_POINTER(0);
599+
GistInetKey*key=DatumGetInetKeyP(entry->key);
600+
GISTENTRY*retval;
601+
inet*dst;
602+
603+
dst= (inet*)palloc0(sizeof(inet));
604+
605+
ip_family(dst)=gk_ip_family(key);
606+
ip_bits(dst)=gk_ip_minbits(key);
607+
memcpy(ip_addr(dst),gk_ip_addr(key),ip_addrsize(dst));
608+
SET_INET_VARSIZE(dst);
609+
610+
retval=palloc(sizeof(GISTENTRY));
611+
gistentryinit(*retval,InetPGetDatum(dst),entry->rel,entry->page,
612+
entry->offset, FALSE);
613+
614+
PG_RETURN_POINTER(retval);
615+
}
616+
590617
/*
591618
* The GiST page split penalty function
592619
*

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201503261
56+
#defineCATALOG_VERSION_NO201503281
5757

5858
#endif

‎src/include/catalog/pg_amproc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ DATA(insert (3550 869869 4 3556 ));
411411
DATA(insert (355086986953557 ));
412412
DATA(insert (355086986963558 ));
413413
DATA(insert (355086986973559 ));
414+
DATA(insert (355086986993573 ));
414415

415416
/* sp-gist */
416417
DATA(insert (34743831383113469 ));

‎src/include/catalog/pg_proc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,8 @@ DATA(insert OID = 3555 ( inet_gist_compressPGNSP PGUID 12 1 0 0 0 f f f f t f
22402240
DESCR("GiST support");
22412241
DATA(insert OID = 3556 ( inet_gist_decompressPGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ inet_gist_decompress _null_ _null_ _null_ ));
22422242
DESCR("GiST support");
2243+
DATA(insert OID = 3573 ( inet_gist_fetchPGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ inet_gist_fetch _null_ _null_ _null_ ));
2244+
DESCR("GiST support");
22432245
DATA(insert OID = 3557 ( inet_gist_penaltyPGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ inet_gist_penalty _null_ _null_ _null_ ));
22442246
DESCR("GiST support");
22452247
DATA(insert OID = 3558 ( inet_gist_picksplitPGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ inet_gist_picksplit _null_ _null_ _null_ ));

‎src/include/utils/inet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ extern intbitncommon(const unsigned char *l, const unsigned char *r, int n);
123123
/*
124124
* GiST support functions in network_gist.c
125125
*/
126+
externDatuminet_gist_fetch(PG_FUNCTION_ARGS);
126127
externDatuminet_gist_consistent(PG_FUNCTION_ARGS);
127128
externDatuminet_gist_union(PG_FUNCTION_ARGS);
128129
externDatuminet_gist_compress(PG_FUNCTION_ARGS);

‎src/test/regress/expected/inet.out

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,25 @@ SELECT * FROM inet_tbl WHERE i <> '192.168.1.0/24'::cidr ORDER BY i;
390390
10:23::8000/113 | 10:23::ffff
391391
(16 rows)
392392

393+
-- test index-only scans
394+
EXPLAIN (COSTS OFF)
395+
SELECT i FROM inet_tbl WHERE i << '192.168.1.0/24'::cidr ORDER BY i;
396+
QUERY PLAN
397+
---------------------------------------------------
398+
Sort
399+
Sort Key: i
400+
-> Index Only Scan using inet_idx2 on inet_tbl
401+
Index Cond: (i << '192.168.1.0/24'::inet)
402+
(4 rows)
403+
404+
SELECT i FROM inet_tbl WHERE i << '192.168.1.0/24'::cidr ORDER BY i;
405+
i
406+
------------------
407+
192.168.1.0/25
408+
192.168.1.255/25
409+
192.168.1.226
410+
(3 rows)
411+
393412
SET enable_seqscan TO on;
394413
DROP INDEX inet_idx2;
395414
-- simple tests of inet boolean and arithmetic operators

‎src/test/regress/sql/inet.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ SELECT * FROM inet_tbl WHERE i = '192.168.1.0/24'::cidr ORDER BY i;
8484
SELECT*FROM inet_tblWHERE i>='192.168.1.0/24'::cidrORDER BY i;
8585
SELECT*FROM inet_tblWHERE i>'192.168.1.0/24'::cidrORDER BY i;
8686
SELECT*FROM inet_tblWHERE i<>'192.168.1.0/24'::cidrORDER BY i;
87+
88+
-- test index-only scans
89+
EXPLAIN (COSTS OFF)
90+
SELECT iFROM inet_tblWHERE i<<'192.168.1.0/24'::cidrORDER BY i;
91+
SELECT iFROM inet_tblWHERE i<<'192.168.1.0/24'::cidrORDER BY i;
92+
8793
SET enable_seqscan TOon;
8894
DROPINDEX inet_idx2;
8995

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp