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

Commitf4cd710

Browse files
committed
Add support of bool, bpchar, name and uuid to btree_gin
Mostly for completeness, but I believe there are cases to use that inmulticolumn GIN indexes.Bump btree_gin module versionAuthor: Matheus OliveiraReviewed by: Tomas VondraDiscussion:https://www.postgresql.org/message-id/flat/CAJghg4LMJf6Z13fnZD-MBNiGxzd0cA2=F3TDjNkX3eQH58hktQ@mail.gmail.com
1 parent0a64b45 commitf4cd710

File tree

13 files changed

+690
-5
lines changed

13 files changed

+690
-5
lines changed

‎contrib/btree_gin/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ OBJS = btree_gin.o $(WIN32RES)
55

66
EXTENSION = btree_gin
77
DATA = btree_gin--1.0.sql btree_gin--1.0--1.1.sql btree_gin--1.1--1.2.sql\
8-
btree_gin--unpackaged--1.0.sql
8+
btree_gin--1.2--1.3.sqlbtree_gin--unpackaged--1.0.sql
99
PGFILEDESC = "btree_gin - B-tree equivalent GIN operator classes"
1010

1111
REGRESS = install_btree_gin int2 int4 int8 float4 float8 money oid\
1212
timestamp timestamptz time timetz date interval\
1313
macaddr macaddr8 inet cidr text varchar char bytea bit varbit\
14-
numeric enum
14+
numeric enum uuid name bool bpchar
1515

1616
ifdefUSE_PGXS
1717
PG_CONFIG = pg_config
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/* contrib/btree_gin/btree_gin--1.2--1.3.sql*/
2+
3+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
4+
\echo Use"ALTER EXTENSION btree_gin UPDATE TO '1.3'" to load this file. \quit
5+
6+
-- uuid datatype support new in 1.3.
7+
CREATEFUNCTIONgin_extract_value_uuid(uuid, internal)
8+
RETURNS internal
9+
AS'MODULE_PATHNAME'
10+
LANGUAGE C STRICT IMMUTABLE;
11+
12+
CREATEFUNCTIONgin_compare_prefix_uuid(uuid, uuid, int2, internal)
13+
RETURNS int4
14+
AS'MODULE_PATHNAME'
15+
LANGUAGE C STRICT IMMUTABLE;
16+
17+
CREATEFUNCTIONgin_extract_query_uuid(uuid, internal, int2, internal, internal)
18+
RETURNS internal
19+
AS'MODULE_PATHNAME'
20+
LANGUAGE C STRICT IMMUTABLE;
21+
22+
CREATEOPERATOR CLASSuuid_ops
23+
DEFAULT FOR TYPE uuid USING gin
24+
AS
25+
OPERATOR1<,
26+
OPERATOR2<=,
27+
OPERATOR3=,
28+
OPERATOR4>=,
29+
OPERATOR5>,
30+
FUNCTION1 uuid_cmp(uuid,uuid),
31+
FUNCTION2 gin_extract_value_uuid(uuid, internal),
32+
FUNCTION3 gin_extract_query_uuid(uuid, internal, int2, internal, internal),
33+
FUNCTION4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
34+
FUNCTION5 gin_compare_prefix_uuid(uuid,uuid,int2, internal),
35+
STORAGE uuid;
36+
37+
-- name datatype support new in 1.3.
38+
CREATEFUNCTIONgin_extract_value_name(name, internal)
39+
RETURNS internal
40+
AS'MODULE_PATHNAME'
41+
LANGUAGE C STRICT IMMUTABLE;
42+
43+
CREATEFUNCTIONgin_compare_prefix_name(name, name, int2, internal)
44+
RETURNS int4
45+
AS'MODULE_PATHNAME'
46+
LANGUAGE C STRICT IMMUTABLE;
47+
48+
CREATEFUNCTIONgin_extract_query_name(name, internal, int2, internal, internal)
49+
RETURNS internal
50+
AS'MODULE_PATHNAME'
51+
LANGUAGE C STRICT IMMUTABLE;
52+
53+
CREATEOPERATOR CLASSname_ops
54+
DEFAULT FOR TYPE name USING gin
55+
AS
56+
OPERATOR1<,
57+
OPERATOR2<=,
58+
OPERATOR3=,
59+
OPERATOR4>=,
60+
OPERATOR5>,
61+
FUNCTION1 btnamecmp(name,name),
62+
FUNCTION2 gin_extract_value_name(name, internal),
63+
FUNCTION3 gin_extract_query_name(name, internal, int2, internal, internal),
64+
FUNCTION4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
65+
FUNCTION5 gin_compare_prefix_name(name,name,int2, internal),
66+
STORAGE name;
67+
68+
-- bool datatype support new in 1.3.
69+
CREATEFUNCTIONgin_extract_value_bool(bool, internal)
70+
RETURNS internal
71+
AS'MODULE_PATHNAME'
72+
LANGUAGE C STRICT IMMUTABLE;
73+
74+
CREATEFUNCTIONgin_compare_prefix_bool(bool, bool, int2, internal)
75+
RETURNS int4
76+
AS'MODULE_PATHNAME'
77+
LANGUAGE C STRICT IMMUTABLE;
78+
79+
CREATEFUNCTIONgin_extract_query_bool(bool, internal, int2, internal, internal)
80+
RETURNS internal
81+
AS'MODULE_PATHNAME'
82+
LANGUAGE C STRICT IMMUTABLE;
83+
84+
CREATEOPERATOR CLASSbool_ops
85+
DEFAULT FOR TYPE bool USING gin
86+
AS
87+
OPERATOR1<,
88+
OPERATOR2<=,
89+
OPERATOR3=,
90+
OPERATOR4>=,
91+
OPERATOR5>,
92+
FUNCTION1 btboolcmp(bool,bool),
93+
FUNCTION2 gin_extract_value_bool(bool, internal),
94+
FUNCTION3 gin_extract_query_bool(bool, internal, int2, internal, internal),
95+
FUNCTION4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
96+
FUNCTION5 gin_compare_prefix_bool(bool,bool,int2, internal),
97+
STORAGE bool;
98+
99+
-- bpchar datatype support new in 1.3.
100+
CREATEFUNCTIONgin_extract_value_bpchar(bpchar, internal)
101+
RETURNS internal
102+
AS'MODULE_PATHNAME'
103+
LANGUAGE C STRICT IMMUTABLE;
104+
105+
CREATEFUNCTIONgin_compare_prefix_bpchar(bpchar, bpchar, int2, internal)
106+
RETURNS int4
107+
AS'MODULE_PATHNAME'
108+
LANGUAGE C STRICT IMMUTABLE;
109+
110+
CREATEFUNCTIONgin_extract_query_bpchar(bpchar, internal, int2, internal, internal)
111+
RETURNS internal
112+
AS'MODULE_PATHNAME'
113+
LANGUAGE C STRICT IMMUTABLE;
114+
115+
CREATEOPERATOR CLASSbpchar_ops
116+
DEFAULT FOR TYPE bpchar USING gin
117+
AS
118+
OPERATOR1<,
119+
OPERATOR2<=,
120+
OPERATOR3=,
121+
OPERATOR4>=,
122+
OPERATOR5>,
123+
FUNCTION1 bpcharcmp(bpchar, bpchar),
124+
FUNCTION2 gin_extract_value_bpchar(bpchar, internal),
125+
FUNCTION3 gin_extract_query_bpchar(bpchar, internal, int2, internal, internal),
126+
FUNCTION4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
127+
FUNCTION5 gin_compare_prefix_bpchar(bpchar,bpchar,int2, internal),
128+
STORAGE bpchar;

‎contrib/btree_gin/btree_gin.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include"utils/numeric.h"
1515
#include"utils/timestamp.h"
1616
#include"utils/varbit.h"
17+
#include"utils/uuid.h"
1718

1819
PG_MODULE_MAGIC;
1920

@@ -350,6 +351,8 @@ leftmostvalue_text(void)
350351

351352
GIN_SUPPORT(text, true,leftmostvalue_text,bttextcmp)
352353

354+
GIN_SUPPORT(bpchar, true,leftmostvalue_text,bpcharcmp)
355+
353356
staticDatum
354357
leftmostvalue_char(void)
355358
{
@@ -437,7 +440,6 @@ GIN_SUPPORT(numeric, true, leftmostvalue_numeric, gin_numeric_cmp)
437440
* routines it needs it, so we can't use DirectFunctionCall2.
438441
*/
439442

440-
441443
#defineENUM_IS_LEFTMOST(x) ((x) == InvalidOid)
442444

443445
PG_FUNCTION_INFO_V1(gin_enum_cmp);
@@ -477,3 +479,30 @@ leftmostvalue_enum(void)
477479
}
478480

479481
GIN_SUPPORT(anyenum, false,leftmostvalue_enum,gin_enum_cmp)
482+
483+
staticDatum
484+
leftmostvalue_uuid(void)
485+
{
486+
/* palloc0 will create the UUID with all zeroes: "00000000-0000-0000-0000-000000000000" */
487+
pg_uuid_t*retval= (pg_uuid_t*)palloc0(sizeof(pg_uuid_t));
488+
returnUUIDPGetDatum(retval);
489+
}
490+
491+
GIN_SUPPORT(uuid, false,leftmostvalue_uuid,uuid_cmp)
492+
493+
staticDatum
494+
leftmostvalue_name(void)
495+
{
496+
NameData*result= (NameData*)palloc0(NAMEDATALEN);
497+
returnNameGetDatum(result);
498+
}
499+
500+
GIN_SUPPORT(name, false,leftmostvalue_name,btnamecmp)
501+
502+
staticDatum
503+
leftmostvalue_bool(void)
504+
{
505+
returnBoolGetDatum(false);
506+
}
507+
508+
GIN_SUPPORT(bool, false,leftmostvalue_bool,btboolcmp)

‎contrib/btree_gin/btree_gin.control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# btree_gin extension
22
comment = 'support for indexing common datatypes in GIN'
3-
default_version = '1.2'
3+
default_version = '1.3'
44
module_pathname = '$libdir/btree_gin'
55
relocatable = true

‎contrib/btree_gin/expected/bool.out

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
set enable_seqscan=off;
2+
CREATE TABLE test_bool (
3+
i boolean
4+
);
5+
INSERT INTO test_bool VALUES (false),(true),(null);
6+
CREATE INDEX idx_bool ON test_bool USING gin (i);
7+
SELECT * FROM test_bool WHERE i<true ORDER BY i;
8+
i
9+
---
10+
f
11+
(1 row)
12+
13+
SELECT * FROM test_bool WHERE i<=true ORDER BY i;
14+
i
15+
---
16+
f
17+
t
18+
(2 rows)
19+
20+
SELECT * FROM test_bool WHERE i=true ORDER BY i;
21+
i
22+
---
23+
t
24+
(1 row)
25+
26+
SELECT * FROM test_bool WHERE i>=true ORDER BY i;
27+
i
28+
---
29+
t
30+
(1 row)
31+
32+
SELECT * FROM test_bool WHERE i>true ORDER BY i;
33+
i
34+
---
35+
(0 rows)
36+
37+
SELECT * FROM test_bool WHERE i<false ORDER BY i;
38+
i
39+
---
40+
(0 rows)
41+
42+
SELECT * FROM test_bool WHERE i<=false ORDER BY i;
43+
i
44+
---
45+
f
46+
(1 row)
47+
48+
SELECT * FROM test_bool WHERE i=false ORDER BY i;
49+
i
50+
---
51+
f
52+
(1 row)
53+
54+
SELECT * FROM test_bool WHERE i>=false ORDER BY i;
55+
i
56+
---
57+
f
58+
t
59+
(2 rows)
60+
61+
SELECT * FROM test_bool WHERE i>false ORDER BY i;
62+
i
63+
---
64+
t
65+
(1 row)
66+
67+
EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i<true ORDER BY i;
68+
QUERY PLAN
69+
-------------------------------------------
70+
Sort
71+
Sort Key: i
72+
-> Bitmap Heap Scan on test_bool
73+
Recheck Cond: (i < true)
74+
-> Bitmap Index Scan on idx_bool
75+
Index Cond: (i < true)
76+
(6 rows)
77+
78+
EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i<=true ORDER BY i;
79+
QUERY PLAN
80+
-------------------------------------------
81+
Sort
82+
Sort Key: i
83+
-> Bitmap Heap Scan on test_bool
84+
Recheck Cond: (i <= true)
85+
-> Bitmap Index Scan on idx_bool
86+
Index Cond: (i <= true)
87+
(6 rows)
88+
89+
EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i=true ORDER BY i;
90+
QUERY PLAN
91+
-----------------------------
92+
Sort
93+
Sort Key: i
94+
-> Seq Scan on test_bool
95+
Filter: i
96+
(4 rows)
97+
98+
EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i>=true ORDER BY i;
99+
QUERY PLAN
100+
-------------------------------------------
101+
Sort
102+
Sort Key: i
103+
-> Bitmap Heap Scan on test_bool
104+
Recheck Cond: (i >= true)
105+
-> Bitmap Index Scan on idx_bool
106+
Index Cond: (i >= true)
107+
(6 rows)
108+
109+
EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i>true ORDER BY i;
110+
QUERY PLAN
111+
-------------------------------------------
112+
Sort
113+
Sort Key: i
114+
-> Bitmap Heap Scan on test_bool
115+
Recheck Cond: (i > true)
116+
-> Bitmap Index Scan on idx_bool
117+
Index Cond: (i > true)
118+
(6 rows)
119+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp