[PATCH] btree_gin, add support for uuid, bool, name, bpchar and anyrange types
Hi all.
Here is a patch to add support for more types on btree_gin.
I was missing UUID type, so I added it. Since I was there, I checked all
other built-in types with B-tree but not GIN support, and the remaining
list was: uuid, bool, name, bpchar and anyrange (at least ones that seem to
make sense to me). So I added support for all of them.
If you have any other type I missed and you wish to have support to, please
let me know and I can add it.
Thanks a lot.
Regards,
--
Matheus de Oliveira
Attachments:
btree_gin-new-types.v1.patchtext/x-patch; charset=US-ASCII; name=btree_gin-new-types.v1.patchDownload
diff --git a/contrib/btree_gin/Makefile b/contrib/btree_gin/Makefile
index 690e1d7..d36f5ad 100644
*** a/contrib/btree_gin/Makefile
--- b/contrib/btree_gin/Makefile
***************
*** 5,17 **** OBJS = btree_gin.o $(WIN32RES)
EXTENSION = btree_gin
DATA = btree_gin--1.0.sql btree_gin--1.0--1.1.sql btree_gin--1.1--1.2.sql \
! btree_gin--unpackaged--1.0.sql
PGFILEDESC = "btree_gin - B-tree equivalent GIN operator classes"
REGRESS = install_btree_gin int2 int4 int8 float4 float8 money oid \
timestamp timestamptz time timetz date interval \
macaddr macaddr8 inet cidr text varchar char bytea bit varbit \
! numeric enum
ifdef USE_PGXS
PG_CONFIG = pg_config
--- 5,17 ----
EXTENSION = btree_gin
DATA = btree_gin--1.0.sql btree_gin--1.0--1.1.sql btree_gin--1.1--1.2.sql \
! btree_gin--1.2--1.3.sql btree_gin--unpackaged--1.0.sql
PGFILEDESC = "btree_gin - B-tree equivalent GIN operator classes"
REGRESS = install_btree_gin int2 int4 int8 float4 float8 money oid \
timestamp timestamptz time timetz date interval \
macaddr macaddr8 inet cidr text varchar char bytea bit varbit \
! numeric enum uuid name bool anyrange bpchar
ifdef USE_PGXS
PG_CONFIG = pg_config
diff --git a/contrib/btree_gin/btindex dd81d27..8965247 100644
*** a/contrib/btree_gin/btree_gin--1.0--1.1.sql
--- b/contrib/btree_gin/btree_gin--1.0--1.1.sql
***************
*** 3,9 ****
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION btree_gin UPDATE TO '1.1'" to load this file. \quit
! -- macaddr8 datatype support new in 10.0.
CREATE FUNCTION gin_extract_value_macaddr8(macaddr8, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
--- 3,9 ----
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION btree_gin UPDATE TO '1.1'" to load this file. \quit
! -- macaddr8 datatype support new in 1.0.
CREATE FUNCTION gin_extract_value_macaddr8(macaddr8, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
diff --git a/contrib/btree_gin/btree_gin--1.1--1index 2a16837..bb3e1ba 100644
*** a/contrib/btree_gin/btree_gin--1.1--1.2.sql
--- b/contrib/btree_gin/btree_gin--1.1--1.2.sql
***************
*** 1,7 ****
/* contrib/btree_gin/btree_gin--1.1--1.2.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
! \echo Use "ALTER EXTENSION btree_gin UPDATE TO '1.1'" to load this file. \quit
--
--
--- 1,7 ----
/* contrib/btree_gin/btree_gin--1.1--1.2.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
! \echo Use "ALTER EXTENSION btree_gin UPDATE TO '1.2'" to load this file. \quit
--
--
diff --git a/contrib/btree_gin/btree_gin--1.2--1new file mode 100644
index 0000000..f7523a3
*** /dev/null
--- b/contrib/btree_gin/btree_gin--1.2--1.3.sql
***************
*** 0 ****
--- 1,164 ----
+ /* contrib/btree_gin/btree_gin--1.2--1.3.sql */
+
+ -- complain if script is sourced in psql, rather than via CREATE EXTENSION
+ \echo Use "ALTER EXTENSION btree_gin UPDATE TO '1.3'" to load this file. \quit
+
+ -- uuid datatype support new in 1.3.
+ CREATE FUNCTION gin_extract_value_uuid(uuid, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_compare_prefix_uuid(uuid, uuid, int2, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_extract_query_uuid(uuid, internal, int2, internal, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE OPERATOR CLASS uuid_ops
+ DEFAULT FOR TYPE uuid USING gin
+ AS
+ OPERATOR 1 <,
+ OPERATOR 2 <=,
+ OPERATOR 3 =,
+ OPERATOR 4 >=,
+ OPERATOR 5 >,
+ FUNCTION 1 uuid_cmp(uuid,uuid),
+ FUNCTION 2 gin_extract_value_uuid(uuid, internal),
+ FUNCTION 3 gin_extract_query_uuid(uuid, internal, int2, internal, internal),
+ FUNCTION 4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
+ FUNCTION 5 gin_compare_prefix_uuid(uuid,uuid,int2, internal),
+ STORAGE uuid;
+
+ -- name datatype support new in 1.3.
+ CREATE FUNCTION gin_extract_value_name(name, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_compare_prefix_name(name, name, int2, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_extract_query_name(name, internal, int2, internal, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE OPERATOR CLASS name_ops
+ DEFAULT FOR TYPE name USING gin
+ AS
+ OPERATOR 1 <,
+ OPERATOR 2 <=,
+ OPERATOR 3 =,
+ OPERATOR 4 >=,
+ OPERATOR 5 >,
+ FUNCTION 1 btnamecmp(name,name),
+ FUNCTION 2 gin_extract_value_name(name, internal),
+ FUNCTION 3 gin_extract_query_name(name, internal, int2, internal, internal),
+ FUNCTION 4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
+ FUNCTION 5 gin_compare_prefix_name(name,name,int2, internal),
+ STORAGE name;
+
+ -- bool datatype support new in 1.3.
+ CREATE FUNCTION gin_extract_value_bool(bool, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_compare_prefix_bool(bool, bool, int2, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_extract_query_bool(bool, internal, int2, internal, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE OPERATOR CLASS bool_ops
+ DEFAULT FOR TYPE bool USING gin
+ AS
+ OPERATOR 1 <,
+ OPERATOR 2 <=,
+ OPERATOR 3 =,
+ OPERATOR 4 >=,
+ OPERATOR 5 >,
+ FUNCTION 1 btboolcmp(bool,bool),
+ FUNCTION 2 gin_extract_value_bool(bool, internal),
+ FUNCTION 3 gin_extract_query_bool(bool, internal, int2, internal, internal),
+ FUNCTION 4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
+ FUNCTION 5 gin_compare_prefix_bool(bool,bool,int2, internal),
+ STORAGE bool;
+
+ -- anyrange datatype support new in 1.3.
+ CREATE FUNCTION gin_anyrange_cmp(anyrange, anyrange)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_extract_value_anyrange(anyrange, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_compare_prefix_anyrange(anyrange, anyrange, int2, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_extract_query_anyrange(anyrange, internal, int2, internal, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE OPERATOR CLASS anyrange_ops
+ DEFAULT FOR TYPE anyrange USING gin
+ AS
+ OPERATOR 1 <,
+ OPERATOR 2 <=,
+ OPERATOR 3 =,
+ OPERATOR 4 >=,
+ OPERATOR 5 >,
+ FUNCTION 1 gin_anyrange_cmp(anyrange,anyrange),
+ FUNCTION 2 gin_extract_value_anyrange(anyrange, internal),
+ FUNCTION 3 gin_extract_query_anyrange(anyrange, internal, int2, internal, internal),
+ FUNCTION 4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
+ FUNCTION 5 gin_compare_prefix_anyrange(anyrange,anyrange,int2, internal),
+ STORAGE anyrange;
+
+ -- bpchar datatype support new in 1.3.
+ CREATE FUNCTION gin_extract_value_bpchar(bpchar, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_compare_prefix_bpchar(bpchar, bpchar, int2, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_extract_query_bpchar(bpchar, internal, int2, internal, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE OPERATOR CLASS bpchar_ops
+ DEFAULT FOR TYPE bpchar USING gin
+ AS
+ OPERATOR 1 <,
+ OPERATOR 2 <=,
+ OPERATOR 3 =,
+ OPERATOR 4 >=,
+ OPERATOR 5 >,
+ FUNCTION 1 bpcharcmp(bpchar, bpchar),
+ FUNCTION 2 gin_extract_value_bpchar(bpchar, internal),
+ FUNCTION 3 gin_extract_query_bpchar(bpchar, internal, int2, internal, internal),
+ FUNCTION 4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
+ FUNCTION 5 gin_compare_prefix_bpchar(bpchar,bpchar,int2, internal),
+ STORAGE bpchar;
diff --git a/contrib/btree_gin/btree_gin.c b/conindex 2473f79..e1206a6 100644
*** a/contrib/btree_gin/btree_gin.c
--- b/contrib/btree_gin/btree_gin.c
***************
*** 14,19 ****
--- 14,21 ----
#include "utils/numeric.h"
#include "utils/timestamp.h"
#include "utils/varbit.h"
+ #include "utils/uuid.h"
+ #include "utils/rangetypes.h"
PG_MODULE_MAGIC;
***************
*** 350,355 **** leftmostvalue_text(void)
--- 352,359 ----
GIN_SUPPORT(text, true, leftmostvalue_text, bttextcmp)
+ GIN_SUPPORT(bpchar, true, leftmostvalue_text, bpcharcmp)
+
static Datum
leftmostvalue_char(void)
{
***************
*** 477,479 **** leftmostvalue_enum(void)
--- 481,559 ----
}
GIN_SUPPORT(anyenum, false, leftmostvalue_enum, gin_enum_cmp)
+
+ static Datum
+ leftmostvalue_uuid(void)
+ {
+ /* palloc0 will create the UUID with all zeroes: "00000000-0000-0000-0000-000000000000" */
+ pg_uuid_t *retval = (pg_uuid_t *) palloc0(sizeof(pg_uuid_t));
+ return UUIDPGetDatum(retval);
+ }
+
+ GIN_SUPPORT(uuid, false, leftmostvalue_uuid, uuid_cmp)
+
+ static Datum
+ leftmostvalue_name(void)
+ {
+ NameData* result = (NameData *) palloc0(NAMEDATALEN);
+ return NameGetDatum(result);
+ }
+
+ GIN_SUPPORT(name, false, leftmostvalue_name, btnamecmp)
+
+ static Datum
+ leftmostvalue_bool(void)
+ {
+ return BoolGetDatum(false);
+ }
+
+ GIN_SUPPORT(bool, false, leftmostvalue_bool, btboolcmp)
+
+ /*
+ * Use a similar trick to that used for numeric for anyrange, since we don't
+ * know the concrete type. We could try to build a fake empty range, but that
+ * seems weaker and more complex than simple using the NULL ref trick.
+ *
+ * Note that we use CallerFInfoFunctionCall2 here so that range_cmp
+ * gets a valid fn_extra to work with. Unlike most other type comparison
+ * routines it needs it, so we can't use DirectFunctionCall2.
+ */
+ #define ANYRANGE_IS_LEFTMOST(x) ((x) == NULL)
+
+ PG_FUNCTION_INFO_V1(gin_anyrange_cmp);
+
+ Datum
+ gin_anyrange_cmp(PG_FUNCTION_ARGS)
+ {
+ RangeType *a = (RangeType *) PG_GETARG_POINTER(0);
+ RangeType *b = (RangeType *) PG_GETARG_POINTER(1);
+ int res = 0;
+
+ if (ANYRANGE_IS_LEFTMOST(a))
+ {
+ res = (ANYRANGE_IS_LEFTMOST(b)) ? 0 : -1;
+ }
+ else if (ANYRANGE_IS_LEFTMOST(b))
+ {
+ res = 1;
+ }
+ else
+ {
+ res = DatumGetInt32(CallerFInfoFunctionCall2(
+ range_cmp,
+ fcinfo->flinfo,
+ PG_GET_COLLATION(),
+ RangeTypePGetDatum(a),
+ RangeTypePGetDatum(b)));
+ }
+
+ PG_RETURN_INT32(res);
+ }
+
+ static Datum
+ leftmostvalue_anyrange(void)
+ {
+ return PointerGetDatum(NULL);
+ }
+
+ GIN_SUPPORT(anyrange, false, leftmostvalue_anyrange, gin_anyrange_cmp)
diff --git a/contrib/btree_gin/btreeindex 3acc5af..d576da7 100644
*** a/contrib/btree_gin/btree_gin.control
--- b/contrib/btree_gin/btree_gin.control
***************
*** 1,5 ****
# btree_gin extension
comment = 'support for indexing common datatypes in GIN'
! default_version = '1.2'
module_pathname = '$libdir/btree_gin'
relocatable = true
--- 1,5 ----
# btree_gin extension
comment = 'support for indexing common datatypes in GIN'
! default_version = '1.3'
module_pathname = '$libdir/btree_gin'
relocatable = true
diff --git a/contrib/btree_gin/expected/annew file mode 100644
index 0000000..93b24f4
*** /dev/null
--- b/contrib/btree_gin/expected/anyrange.out
***************
*** 0 ****
--- 1,113 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_tsrange (
+ i tsrange
+ );
+ INSERT INTO test_tsrange VALUES
+ ( 'empty' ),
+ ( '(,)' ),
+ ( '[2018-02-02 03:55:08,2018-04-02 03:55:08)' ),
+ ( '[2018-02-02 04:55:08,2018-04-02 04:55:08)' ),
+ ( '[2018-02-02 05:55:08,2018-04-02 05:55:08)' ),
+ ( '[2018-02-02 08:55:08,2018-04-02 08:55:08)' ),
+ ( '[2018-02-02 09:55:08,2018-04-02 09:55:08)' ),
+ ( '[2018-02-02 10:55:08,2018-04-02 10:55:08)' ),
+ ( '[infinity,infinity]' )
+ ;
+ CREATE INDEX idx_tsrange ON test_tsrange USING gin (i);
+ SELECT * FROM test_tsrange WHERE i<'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ i
+ ---------------------------------------------------------
+ empty
+ (,)
+ ["Fri Feb 02 03:55:08 2018","Mon Apr 02 03:55:08 2018")
+ ["Fri Feb 02 04:55:08 2018","Mon Apr 02 04:55:08 2018")
+ ["Fri Feb 02 05:55:08 2018","Mon Apr 02 05:55:08 2018")
+ (5 rows)
+
+ SELECT * FROM test_tsrange WHERE i<='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ i
+ ---------------------------------------------------------
+ empty
+ (,)
+ ["Fri Feb 02 03:55:08 2018","Mon Apr 02 03:55:08 2018")
+ ["Fri Feb 02 04:55:08 2018","Mon Apr 02 04:55:08 2018")
+ ["Fri Feb 02 05:55:08 2018","Mon Apr 02 05:55:08 2018")
+ ["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")
+ (6 rows)
+
+ SELECT * FROM test_tsrange WHERE i='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ i
+ ---------------------------------------------------------
+ ["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")
+ (1 row)
+
+ SELECT * FROM test_tsrange WHERE i>='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ i
+ ---------------------------------------------------------
+ ["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")
+ ["Fri Feb 02 09:55:08 2018","Mon Apr 02 09:55:08 2018")
+ ["Fri Feb 02 10:55:08 2018","Mon Apr 02 10:55:08 2018")
+ [infinity,infinity]
+ (4 rows)
+
+ SELECT * FROM test_tsrange WHERE i>'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ i
+ ---------------------------------------------------------
+ ["Fri Feb 02 09:55:08 2018","Mon Apr 02 09:55:08 2018")
+ ["Fri Feb 02 10:55:08 2018","Mon Apr 02 10:55:08 2018")
+ [infinity,infinity]
+ (3 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i<'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ QUERY PLAN
+ ----------------------------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_tsrange
+ Recheck Cond: (i < '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ -> Bitmap Index Scan on idx_tsrange
+ Index Cond: (i < '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i<='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ QUERY PLAN
+ -----------------------------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_tsrange
+ Recheck Cond: (i <= '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ -> Bitmap Index Scan on idx_tsrange
+ Index Cond: (i <= '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ QUERY PLAN
+ ----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on test_tsrange
+ Recheck Cond: (i = '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ -> Bitmap Index Scan on idx_tsrange
+ Index Cond: (i = '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ (4 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i>='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ QUERY PLAN
+ -----------------------------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_tsrange
+ Recheck Cond: (i >= '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ -> Bitmap Index Scan on idx_tsrange
+ Index Cond: (i >= '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i>'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ QUERY PLAN
+ ----------------------------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_tsrange
+ Recheck Cond: (i > '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ -> Bitmap Index Scan on idx_tsrange
+ Index Cond: (i > '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ (6 rows)
+
diff --git a/contrib/btree_gin/expected/bool.onew file mode 100644
index 0000000..efb3e1e
*** /dev/null
--- b/contrib/btree_gin/expected/bool.out
***************
*** 0 ****
--- 1,119 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_bool (
+ i boolean
+ );
+ INSERT INTO test_bool VALUES (false),(true),(null);
+ CREATE INDEX idx_bool ON test_bool USING gin (i);
+ SELECT * FROM test_bool WHERE i<true ORDER BY i;
+ i
+ ---
+ f
+ (1 row)
+
+ SELECT * FROM test_bool WHERE i<=true ORDER BY i;
+ i
+ ---
+ f
+ t
+ (2 rows)
+
+ SELECT * FROM test_bool WHERE i=true ORDER BY i;
+ i
+ ---
+ t
+ (1 row)
+
+ SELECT * FROM test_bool WHERE i>=true ORDER BY i;
+ i
+ ---
+ t
+ (1 row)
+
+ SELECT * FROM test_bool WHERE i>true ORDER BY i;
+ i
+ ---
+ (0 rows)
+
+ SELECT * FROM test_bool WHERE i<false ORDER BY i;
+ i
+ ---
+ (0 rows)
+
+ SELECT * FROM test_bool WHERE i<=false ORDER BY i;
+ i
+ ---
+ f
+ (1 row)
+
+ SELECT * FROM test_bool WHERE i=false ORDER BY i;
+ i
+ ---
+ f
+ (1 row)
+
+ SELECT * FROM test_bool WHERE i>=false ORDER BY i;
+ i
+ ---
+ f
+ t
+ (2 rows)
+
+ SELECT * FROM test_bool WHERE i>false ORDER BY i;
+ i
+ ---
+ t
+ (1 row)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i<true ORDER BY i;
+ QUERY PLAN
+ -------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bool
+ Recheck Cond: (i < true)
+ -> Bitmap Index Scan on idx_bool
+ Index Cond: (i < true)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i<=true ORDER BY i;
+ QUERY PLAN
+ -------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bool
+ Recheck Cond: (i <= true)
+ -> Bitmap Index Scan on idx_bool
+ Index Cond: (i <= true)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i=true ORDER BY i;
+ QUERY PLAN
+ -----------------------------
+ Sort
+ Sort Key: i
+ -> Seq Scan on test_bool
+ Filter: i
+ (4 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i>=true ORDER BY i;
+ QUERY PLAN
+ -------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bool
+ Recheck Cond: (i >= true)
+ -> Bitmap Index Scan on idx_bool
+ Index Cond: (i >= true)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i>true ORDER BY i;
+ QUERY PLAN
+ -------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bool
+ Recheck Cond: (i > true)
+ -> Bitmap Index Scan on idx_bool
+ Index Cond: (i > true)
+ (6 rows)
+
diff --git a/contrib/btree_gin/expected/bpnew file mode 100644
index 0000000..2eb8855
*** /dev/null
--- b/contrib/btree_gin/expected/bpchar.out
***************
*** 0 ****
--- 1,109 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_bpchar (
+ i char(10)
+ );
+ INSERT INTO test_bpchar VALUES ('a'),('ab'),('abc'),('abc '),('abb'),('axy'),('xyz'),('xyz ');
+ CREATE INDEX idx_bpchar ON test_bpchar USING gin (i);
+ SELECT * FROM test_bpchar WHERE i<'abc' ORDER BY i;
+ i
+ ------------
+ a
+ ab
+ abb
+ (3 rows)
+
+ SELECT * FROM test_bpchar WHERE i<='abc' ORDER BY i;
+ i
+ ------------
+ a
+ ab
+ abb
+ abc
+ abc
+ (5 rows)
+
+ SELECT * FROM test_bpchar WHERE i='abc' ORDER BY i;
+ i
+ ------------
+ abc
+ abc
+ (2 rows)
+
+ SELECT * FROM test_bpchar WHERE i='abc ' ORDER BY i;
+ i
+ ------------
+ abc
+ abc
+ (2 rows)
+
+ SELECT * FROM test_bpchar WHERE i>='abc' ORDER BY i;
+ i
+ ------------
+ abc
+ abc
+ axy
+ xyz
+ xyz
+ (5 rows)
+
+ SELECT * FROM test_bpchar WHERE i>'abc' ORDER BY i;
+ i
+ ------------
+ axy
+ xyz
+ xyz
+ (3 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i<'abc' ORDER BY i;
+ QUERY PLAN
+ -----------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bpchar
+ Recheck Cond: (i < 'abc'::bpchar)
+ -> Bitmap Index Scan on idx_bpchar
+ Index Cond: (i < 'abc'::bpchar)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i<='abc' ORDER BY i;
+ QUERY PLAN
+ ------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bpchar
+ Recheck Cond: (i <= 'abc'::bpchar)
+ -> Bitmap Index Scan on idx_bpchar
+ Index Cond: (i <= 'abc'::bpchar)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i='abc' ORDER BY i;
+ QUERY PLAN
+ -----------------------------------------
+ Bitmap Heap Scan on test_bpchar
+ Recheck Cond: (i = 'abc'::bpchar)
+ -> Bitmap Index Scan on idx_bpchar
+ Index Cond: (i = 'abc'::bpchar)
+ (4 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i>='abc' ORDER BY i;
+ QUERY PLAN
+ ------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bpchar
+ Recheck Cond: (i >= 'abc'::bpchar)
+ -> Bitmap Index Scan on idx_bpchar
+ Index Cond: (i >= 'abc'::bpchar)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i>'abc' ORDER BY i;
+ QUERY PLAN
+ -----------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bpchar
+ Recheck Cond: (i > 'abc'::bpchar)
+ -> Bitmap Index Scan on idx_bpchar
+ Index Cond: (i > 'abc'::bpchar)
+ (6 rows)
+
diff --git a/contrib/btree_gin/expected/namenew file mode 100644
index 0000000..174de65
*** /dev/null
--- b/contrib/btree_gin/expected/name.out
***************
*** 0 ****
--- 1,97 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_name (
+ i name
+ );
+ INSERT INTO test_name VALUES ('a'),('ab'),('abc'),('abb'),('axy'),('xyz');
+ CREATE INDEX idx_name ON test_name USING gin (i);
+ SELECT * FROM test_name WHERE i<'abc' ORDER BY i;
+ i
+ -----
+ a
+ ab
+ abb
+ (3 rows)
+
+ SELECT * FROM test_name WHERE i<='abc' ORDER BY i;
+ i
+ -----
+ a
+ ab
+ abb
+ abc
+ (4 rows)
+
+ SELECT * FROM test_name WHERE i='abc' ORDER BY i;
+ i
+ -----
+ abc
+ (1 row)
+
+ SELECT * FROM test_name WHERE i>='abc' ORDER BY i;
+ i
+ -----
+ abc
+ axy
+ xyz
+ (3 rows)
+
+ SELECT * FROM test_name WHERE i>'abc' ORDER BY i;
+ i
+ -----
+ axy
+ xyz
+ (2 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i<'abc' ORDER BY i;
+ QUERY PLAN
+ ---------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_name
+ Recheck Cond: (i < 'abc'::name)
+ -> Bitmap Index Scan on idx_name
+ Index Cond: (i < 'abc'::name)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i<='abc' ORDER BY i;
+ QUERY PLAN
+ ----------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_name
+ Recheck Cond: (i <= 'abc'::name)
+ -> Bitmap Index Scan on idx_name
+ Index Cond: (i <= 'abc'::name)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i='abc' ORDER BY i;
+ QUERY PLAN
+ ---------------------------------------
+ Bitmap Heap Scan on test_name
+ Recheck Cond: (i = 'abc'::name)
+ -> Bitmap Index Scan on idx_name
+ Index Cond: (i = 'abc'::name)
+ (4 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i>='abc' ORDER BY i;
+ QUERY PLAN
+ ----------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_name
+ Recheck Cond: (i >= 'abc'::name)
+ -> Bitmap Index Scan on idx_name
+ Index Cond: (i >= 'abc'::name)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i>'abc' ORDER BY i;
+ QUERY PLAN
+ ---------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_name
+ Recheck Cond: (i > 'abc'::name)
+ -> Bitmap Index Scan on idx_name
+ Index Cond: (i > 'abc'::name)
+ (6 rows)
+
diff --git a/contrib/btree_gin/expected/uunew file mode 100644
index 0000000..60fd8d6
*** /dev/null
--- b/contrib/btree_gin/expected/uuid.out
***************
*** 0 ****
--- 1,104 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_uuid (
+ i uuid
+ );
+ INSERT INTO test_uuid VALUES
+ ( '00000000-0000-0000-0000-000000000000' ),
+ ( '299bc99f-2f79-4e3e-bfea-2cbfd62a7c27' ),
+ ( '6264af33-0d43-4337-bf4e-43509b8a4be8' ),
+ ( 'ce41c936-6acb-4feb-8c91-852a673e5a5c' ),
+ ( 'd2ce731f-f2a8-4a2b-be37-8f0ba637427f' ),
+ ( 'ffffffff-ffff-ffff-ffff-ffffffffffff' )
+ ;
+ CREATE INDEX idx_uuid ON test_uuid USING gin (i);
+ SELECT * FROM test_uuid WHERE i<'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ i
+ --------------------------------------
+ 00000000-0000-0000-0000-000000000000
+ 299bc99f-2f79-4e3e-bfea-2cbfd62a7c27
+ 6264af33-0d43-4337-bf4e-43509b8a4be8
+ (3 rows)
+
+ SELECT * FROM test_uuid WHERE i<='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ i
+ --------------------------------------
+ 00000000-0000-0000-0000-000000000000
+ 299bc99f-2f79-4e3e-bfea-2cbfd62a7c27
+ 6264af33-0d43-4337-bf4e-43509b8a4be8
+ ce41c936-6acb-4feb-8c91-852a673e5a5c
+ (4 rows)
+
+ SELECT * FROM test_uuid WHERE i='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ i
+ --------------------------------------
+ ce41c936-6acb-4feb-8c91-852a673e5a5c
+ (1 row)
+
+ SELECT * FROM test_uuid WHERE i>='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ i
+ --------------------------------------
+ ce41c936-6acb-4feb-8c91-852a673e5a5c
+ d2ce731f-f2a8-4a2b-be37-8f0ba637427f
+ ffffffff-ffff-ffff-ffff-ffffffffffff
+ (3 rows)
+
+ SELECT * FROM test_uuid WHERE i>'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ i
+ --------------------------------------
+ d2ce731f-f2a8-4a2b-be37-8f0ba637427f
+ ffffffff-ffff-ffff-ffff-ffffffffffff
+ (2 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i<'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ QUERY PLAN
+ ------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_uuid
+ Recheck Cond: (i < 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ -> Bitmap Index Scan on idx_uuid
+ Index Cond: (i < 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i<='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ QUERY PLAN
+ -------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_uuid
+ Recheck Cond: (i <= 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ -> Bitmap Index Scan on idx_uuid
+ Index Cond: (i <= 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ QUERY PLAN
+ ------------------------------------------------------------------------
+ Bitmap Heap Scan on test_uuid
+ Recheck Cond: (i = 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ -> Bitmap Index Scan on idx_uuid
+ Index Cond: (i = 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ (4 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i>='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ QUERY PLAN
+ -------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_uuid
+ Recheck Cond: (i >= 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ -> Bitmap Index Scan on idx_uuid
+ Index Cond: (i >= 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i>'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ QUERY PLAN
+ ------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_uuid
+ Recheck Cond: (i > 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ -> Bitmap Index Scan on idx_uuid
+ Index Cond: (i > 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ (6 rows)
+
diff --git a/contrib/btree_gin/sql/anyrangnew file mode 100644
index 0000000..97157ad
*** /dev/null
--- b/contrib/btree_gin/sql/anyrange.sql
***************
*** 0 ****
--- 1,31 ----
+ set enable_seqscan=off;
+
+ CREATE TABLE test_tsrange (
+ i tsrange
+ );
+
+ INSERT INTO test_tsrange VALUES
+ ( 'empty' ),
+ ( '(,)' ),
+ ( '[2018-02-02 03:55:08,2018-04-02 03:55:08)' ),
+ ( '[2018-02-02 04:55:08,2018-04-02 04:55:08)' ),
+ ( '[2018-02-02 05:55:08,2018-04-02 05:55:08)' ),
+ ( '[2018-02-02 08:55:08,2018-04-02 08:55:08)' ),
+ ( '[2018-02-02 09:55:08,2018-04-02 09:55:08)' ),
+ ( '[2018-02-02 10:55:08,2018-04-02 10:55:08)' ),
+ ( '[infinity,infinity]' )
+ ;
+
+ CREATE INDEX idx_tsrange ON test_tsrange USING gin (i);
+
+ SELECT * FROM test_tsrange WHERE i<'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ SELECT * FROM test_tsrange WHERE i<='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ SELECT * FROM test_tsrange WHERE i='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ SELECT * FROM test_tsrange WHERE i>='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ SELECT * FROM test_tsrange WHERE i>'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i<'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i<='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i>='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i>'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
diff --git a/contrib/btree_gin/sql/bool.snew file mode 100644
index 0000000..dad2ff3
*** /dev/null
--- b/contrib/btree_gin/sql/bool.sql
***************
*** 0 ****
--- 1,27 ----
+ set enable_seqscan=off;
+
+ CREATE TABLE test_bool (
+ i boolean
+ );
+
+ INSERT INTO test_bool VALUES (false),(true),(null);
+
+ CREATE INDEX idx_bool ON test_bool USING gin (i);
+
+ SELECT * FROM test_bool WHERE i<true ORDER BY i;
+ SELECT * FROM test_bool WHERE i<=true ORDER BY i;
+ SELECT * FROM test_bool WHERE i=true ORDER BY i;
+ SELECT * FROM test_bool WHERE i>=true ORDER BY i;
+ SELECT * FROM test_bool WHERE i>true ORDER BY i;
+
+ SELECT * FROM test_bool WHERE i<false ORDER BY i;
+ SELECT * FROM test_bool WHERE i<=false ORDER BY i;
+ SELECT * FROM test_bool WHERE i=false ORDER BY i;
+ SELECT * FROM test_bool WHERE i>=false ORDER BY i;
+ SELECT * FROM test_bool WHERE i>false ORDER BY i;
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i<true ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i<=true ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i=true ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i>=true ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i>true ORDER BY i;
diff --git a/contrib/btree_gin/sql/bpnew file mode 100644
index 0000000..4c951e3
*** /dev/null
--- b/contrib/btree_gin/sql/bpchar.sql
***************
*** 0 ****
--- 1,22 ----
+ set enable_seqscan=off;
+
+ CREATE TABLE test_bpchar (
+ i char(10)
+ );
+
+ INSERT INTO test_bpchar VALUES ('a'),('ab'),('abc'),('abc '),('abb'),('axy'),('xyz'),('xyz ');
+
+ CREATE INDEX idx_bpchar ON test_bpchar USING gin (i);
+
+ SELECT * FROM test_bpchar WHERE i<'abc' ORDER BY i;
+ SELECT * FROM test_bpchar WHERE i<='abc' ORDER BY i;
+ SELECT * FROM test_bpchar WHERE i='abc' ORDER BY i;
+ SELECT * FROM test_bpchar WHERE i='abc ' ORDER BY i;
+ SELECT * FROM test_bpchar WHERE i>='abc' ORDER BY i;
+ SELECT * FROM test_bpchar WHERE i>'abc' ORDER BY i;
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i<'abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i<='abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i='abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i>='abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i>'abc' ORDER BY i;
diff --git a/contrib/btree_gin/sql/namenew file mode 100644
index 0000000..c11580c
*** /dev/null
--- b/contrib/btree_gin/sql/name.sql
***************
*** 0 ****
--- 1,21 ----
+ set enable_seqscan=off;
+
+ CREATE TABLE test_name (
+ i name
+ );
+
+ INSERT INTO test_name VALUES ('a'),('ab'),('abc'),('abb'),('axy'),('xyz');
+
+ CREATE INDEX idx_name ON test_name USING gin (i);
+
+ SELECT * FROM test_name WHERE i<'abc' ORDER BY i;
+ SELECT * FROM test_name WHERE i<='abc' ORDER BY i;
+ SELECT * FROM test_name WHERE i='abc' ORDER BY i;
+ SELECT * FROM test_name WHERE i>='abc' ORDER BY i;
+ SELECT * FROM test_name WHERE i>'abc' ORDER BY i;
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i<'abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i<='abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i='abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i>='abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i>'abc' ORDER BY i;
diff --git a/contrib/btree_gin/sql/uunew file mode 100644
index 0000000..3c141bd
*** /dev/null
--- b/contrib/btree_gin/sql/uuid.sql
***************
*** 0 ****
--- 1,28 ----
+ set enable_seqscan=off;
+
+ CREATE TABLE test_uuid (
+ i uuid
+ );
+
+ INSERT INTO test_uuid VALUES
+ ( '00000000-0000-0000-0000-000000000000' ),
+ ( '299bc99f-2f79-4e3e-bfea-2cbfd62a7c27' ),
+ ( '6264af33-0d43-4337-bf4e-43509b8a4be8' ),
+ ( 'ce41c936-6acb-4feb-8c91-852a673e5a5c' ),
+ ( 'd2ce731f-f2a8-4a2b-be37-8f0ba637427f' ),
+ ( 'ffffffff-ffff-ffff-ffff-ffffffffffff' )
+ ;
+
+ CREATE INDEX idx_uuid ON test_uuid USING gin (i);
+
+ SELECT * FROM test_uuid WHERE i<'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ SELECT * FROM test_uuid WHERE i<='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ SELECT * FROM test_uuid WHERE i='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ SELECT * FROM test_uuid WHERE i>='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ SELECT * FROM test_uuid WHERE i>'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i<'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i<='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i>='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i>'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
diff --git a/doc/src/sgml/btree-gin.sindex e491fa7..a951f86 100644
*** a/doc/src/sgml/btree-gin.sgml
--- b/doc/src/sgml/btree-gin.sgml
***************
*** 17,23 ****
<type>oid</type>, <type>money</type>, <type>"char"</type>,
<type>varchar</type>, <type>text</type>, <type>bytea</type>, <type>bit</type>,
<type>varbit</type>, <type>macaddr</type>, <type>macaddr8</type>, <type>inet</type>,
! <type>cidr</type>, and all <type>enum</type> types.
</para>
<para>
--- 17,24 ----
<type>oid</type>, <type>money</type>, <type>"char"</type>,
<type>varchar</type>, <type>text</type>, <type>bytea</type>, <type>bit</type>,
<type>varbit</type>, <type>macaddr</type>, <type>macaddr8</type>, <type>inet</type>,
! <type>cidr</type>, <type>uuid</type>, <type>name</type>, <type>bool</type>,
! <type>bpchar</type>, and all <type>enum</type> and <type>range</type> types.
</para>
<para>
Hi,
On 02/20/2018 03:34 PM, Matheus de Oliveira wrote:
Hi all.
Here is a patch to add support for more types on btree_gin.
I was missing UUID type, so I added it. Since I was there, I checked
all other built-in types with B-tree but not GIN support, and the
remaining list was: uuid, bool, name, bpchar and anyrange (at least
ones that seem to make sense to me). So I added support for all of
them.If you have any other type I missed and you wish to have support to,
please let me know and I can add it.
I've looked at this patch today - it's a fairly straightforward addition
to btree_gin, and it seems in pretty good shape in general. It passes
all the various tests (even under valgrind), and the code seems OK too.
A couple of minor comments:
1) I personally am not that sure GIN indexes on ranges are very useful,
considering those columns are usually queried for containment (i.e. is
this value contained in the range) rather than equality. And we already
have gist/spgist opclasses for ranges, which seems way more useful. We
seem to already have hash opclasses for ranges, but I'm not sure that's
a proof of usefulness.
So I'd cut this, although it's a tiny amount of code.
2) The patch tweaks a couple of .sql files from previous versions. It
modifies a comment in the 1.0--1.1 upgrade script from
-- macaddr8 datatype support new in 10.0.
to
-- macaddr8 datatype support new in 1.0.
which is obviously incorrect, because not only is that in upgrade script
to 1.1. (so it should be "new in 1.1) but the original comment probably
refers to PostgreSQL 10, not the btree_gin version.
It also tweaks \echo in 1.1--1.2 upgrade script to mention 1.2 instead
of 1.1. This change seems correct, but it seems more like a bugfix that
part of this patch.
3) The documentation refers to <type>range</type>, which is bogus as
there is no such type. It should say <type>anyrange</type> instead.
4) The opclass is called "anyrange_ops", which is somewhat inconsistent
with the opclasses for btree, hash, gist and spgist. All those index
types use "range_ops" so I suggest using the same name.
5) I've tweaked a comment in btree_gin.c a bit, the original wording
seemed a bit unclear to me. And I've moved part of the comment to the
following function (it wasn't really about the left-most value).
Attached is a patch that does all of this, but it may be incomplete (I
haven't really checked if it breaks tests, for example).
regards
--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachments:
btree_gin-fixes.patchtext/x-patch; name=btree_gin-fixes.patchDownload
diff --git a/contrib/btree_gin/btree_gin--1.0--1.1.sql b/contrib/btree_gin/btree_gin--1.0--1.1.sql
index 8965247..dd81d27 100644
--- a/contrib/btree_gin/btree_gin--1.0--1.1.sql
+++ b/contrib/btree_gin/btree_gin--1.0--1.1.sql
@@ -3,7 +3,7 @@
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION btree_gin UPDATE TO '1.1'" to load this file. \quit
--- macaddr8 datatype support new in 1.0.
+-- macaddr8 datatype support new in 10.0.
CREATE FUNCTION gin_extract_value_macaddr8(macaddr8, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
diff --git a/contrib/btree_gin/btree_gin--1.2--1.3.sql b/contrib/btree_gin/btree_gin--1.2--1.3.sql
index f7523a3..fe80983 100644
--- a/contrib/btree_gin/btree_gin--1.2--1.3.sql
+++ b/contrib/btree_gin/btree_gin--1.2--1.3.sql
@@ -117,7 +117,7 @@ RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
-CREATE OPERATOR CLASS anyrange_ops
+CREATE OPERATOR CLASS range_ops
DEFAULT FOR TYPE anyrange USING gin
AS
OPERATOR 1 <,
diff --git a/contrib/btree_gin/btree_gin.c b/contrib/btree_gin/btree_gin.c
index e1206a6..b5b26c9 100644
--- a/contrib/btree_gin/btree_gin.c
+++ b/contrib/btree_gin/btree_gin.c
@@ -510,18 +510,20 @@ leftmostvalue_bool(void)
GIN_SUPPORT(bool, false, leftmostvalue_bool, btboolcmp)
/*
- * Use a similar trick to that used for numeric for anyrange, since we don't
- * know the concrete type. We could try to build a fake empty range, but that
- * seems weaker and more complex than simple using the NULL ref trick.
- *
- * Note that we use CallerFInfoFunctionCall2 here so that range_cmp
- * gets a valid fn_extra to work with. Unlike most other type comparison
- * routines it needs it, so we can't use DirectFunctionCall2.
+ * Similarly to numeric, we don't know the left-most value, although for
+ * different reasons (numeric does not have one, while for anyarray we
+ * don't even know the concrete type). We could try to build a fake empty
+ * range, but we simply use PointerGetDatum(NULL) just like for Numeric.
*/
#define ANYRANGE_IS_LEFTMOST(x) ((x) == NULL)
PG_FUNCTION_INFO_V1(gin_anyrange_cmp);
+/*
+ * Note that we use CallerFInfoFunctionCall2 here so that range_cmp
+ * gets a valid fn_extra to work with. Unlike most other type comparison
+ * routines it needs it, so we can't use DirectFunctionCall2.
+ */
Datum
gin_anyrange_cmp(PG_FUNCTION_ARGS)
{
diff --git a/doc/src/sgml/btree-gin.sgml b/doc/src/sgml/btree-gin.sgml
index a951f86..e1315da 100644
--- a/doc/src/sgml/btree-gin.sgml
+++ b/doc/src/sgml/btree-gin.sgml
@@ -18,7 +18,7 @@
<type>varchar</type>, <type>text</type>, <type>bytea</type>, <type>bit</type>,
<type>varbit</type>, <type>macaddr</type>, <type>macaddr8</type>, <type>inet</type>,
<type>cidr</type>, <type>uuid</type>, <type>name</type>, <type>bool</type>,
- <type>bpchar</type>, and all <type>enum</type> and <type>range</type> types.
+ <type>bpchar</type>, and all <type>enum</type> and <type>anyrange</type> types.
</para>
<para>
Hi all.
Em 4 de mar de 2018 16:00, "Tomas Vondra" <tomas.vondra@2ndquadrant.com>
escreveu:
1) I personally am not that sure GIN indexes on ranges are very useful,
considering those columns are usually queried for containment (i.e. is
this value contained in the range) rather than equality. And we already
have gist/spgist opclasses for ranges, which seems way more useful. We
seem to already have hash opclasses for ranges, but I'm not sure that's
a proof of usefulness.
So I'd cut this, although it's a tiny amount of code.
I pondered that either, and I also haven't thought about a good use case,
but since it has B-Tree support, I thought it should be included on
btree_gin as well, so I did.
If you all decide to remove, I'm totally fine with that.
2) The patch tweaks a couple of .sql files from previous versions. It
modifies a comment in the 1.0--1.1 upgrade script from
-- macaddr8 datatype support new in 10.0.
to
-- macaddr8 datatype support new in 1.0.
which is obviously incorrect, because not only is that in upgrade script
to 1.1. (so it should be "new in 1.1) but the original comment probably
refers to PostgreSQL 10, not the btree_gin version.
I forgot I have changed that, sorry. I think though that 10.0 was a typo,
since it has been introduced way before PostgreSQL 10. But you are right,
it should be 1.1.
It also tweaks \echo in 1.1--1.2 upgrade script to mention 1.2 instead
of 1.1. This change seems correct, but it seems more like a bugfix that
part of this patch.
I can send it later as a bugfix then. Sounds better indeed.
3) The documentation refers to <type>range</type>, which is bogus as
there is no such type. It should say <type>anyrange</type> instead.
I've just followed what has been done for ENUM type, if we are going to
change for range we should also change to use anyenum, no?
4) The opclass is called "anyrange_ops", which is somewhat inconsistent
with the opclasses for btree, hash, gist and spgist. All those index
types use "range_ops" so I suggest using the same name.
Ok.
5) I've tweaked a comment in btree_gin.c a bit, the original wording
seemed a bit unclear to me. And I've moved part of the comment to the
following function (it wasn't really about the left-most value).
My English skills aren't very good, so feel free to tweak any comment or
documentation I have done ;)
Attached is a patch that does all of this, but it may be incomplete (I
haven't really checked if it breaks tests, for example).
I really appreciate your review. I'd like to know what you think about my
comments above.
Thanks a lot.
Best regards,
On 03/08/2018 10:20 AM, Matheus de Oliveira wrote:
Hi all.
Em 4 de mar de 2018 16:00, "Tomas Vondra" <tomas.vondra@2ndquadrant.com
<mailto:tomas.vondra@2ndquadrant.com>> escreveu:1) I personally am not that sure GIN indexes on ranges are very useful,
considering those columns are usually queried for containment (i.e. is
this value contained in the range) rather than equality. And we already
have gist/spgist opclasses for ranges, which seems way more useful. We
seem to already have hash opclasses for ranges, but I'm not sure that's
a proof of usefulness.So I'd cut this, although it's a tiny amount of code.
I pondered that either, and I also haven't thought about a good use
case, but since it has B-Tree support, I thought it should be included
on btree_gin as well, so I did.
AFAIK having a B-tree opclass has other important implications (it kinda
determines important operators etc.), so it may not really mean B-tree
indexes on ranges are somewhat practical.
If you all decide to remove, I'm totally fine with that.
Not sure, but I'd probably cut it - adding opclasses in the future seems
less problematic than removing them.
2) The patch tweaks a couple of .sql files from previous versions. It
modifies a comment in the 1.0--1.1 upgrade script from-- macaddr8 datatype support new in 10.0.
to
-- macaddr8 datatype support new in 1.0.
which is obviously incorrect, because not only is that in upgrade script
to 1.1. (so it should be "new in 1.1) but the original comment probably
refers to PostgreSQL 10, not the btree_gin version.I forgot I have changed that, sorry. I think though that 10.0 was a
typo, since it has been introduced way before PostgreSQL 10. But you are
right, it should be 1.1.It also tweaks \echo in 1.1--1.2 upgrade script to mention 1.2 instead
of 1.1. This change seems correct, but it seems more like a bugfix that
part of this patch.I can send it later as a bugfix then. Sounds better indeed.
Just split the patch in two, and keep it.
3) The documentation refers to <type>range</type>, which is bogus as
there is no such type. It should say <type>anyrange</type> instead.I've just followed what has been done for ENUM type, if we are going to
change for range we should also change to use anyenum, no?
Hmmm, you're right the docs use <type>enum</type> on a couple of places.
But I see there's not a single mention of <type>range</type> but quite a
few references to <type>anyrange</type>. I'm not sure why exactly, but
I'm sure there's a reason.
4) The opclass is called "anyrange_ops", which is somewhat inconsistent
with the opclasses for btree, hash, gist and spgist. All those index
types use "range_ops" so I suggest using the same name.Ok.
5) I've tweaked a comment in btree_gin.c a bit, the original wording
seemed a bit unclear to me. And I've moved part of the comment to the
following function (it wasn't really about the left-most value).My English skills aren't very good, so feel free to tweak any comment or
documentation I have done ;)
Sure, ultimately someone else will do a final check.
Attached is a patch that does all of this, but it may be incomplete (I
haven't really checked if it breaks tests, for example).I really appreciate your review. I'd like to know what you think about
my comments above.
regards
--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Hi Matheus,
Do you plan to post an updated version of the patch, of what is your
response to the points raised last week?
I still haven't made my mind regarding usefulness of range opclasses, so
I suggest to split the patch into two parts - 0001 for the opclasses
we're confident are useful, and 0002 for those extras. The committer
then may apply either 0001 or 0001+0002, depending on his judgment.
regards
--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Hi all.
On Wed, Mar 21, 2018 at 1:47 PM, Tomas Vondra <tomas.vondra@2ndquadrant.com>
wrote:
Do you plan to post an updated version of the patch, of what is your
response to the points raised last week?
Very sorry about the long delay. I've been in a long trip, no time to look
that carefully.
I still haven't made my mind regarding usefulness of range opclasses, so
I suggest to split the patch into two parts - 0001 for the opclasses
we're confident are useful, and 0002 for those extras. The committer
then may apply either 0001 or 0001+0002, depending on his judgment.
I liked the idea. So, follows the patches:
- 0001-btree_gin-uuid--base.v2.patch - all types but anyrange, and with the
adjustments on comments you proposed
- 0002-btree_gin-uuid--anyrange.v2.patch - adding the anyrange type (must
be applied after 0001)
Anything else missing?
Best regards,
--
Matheus de Oliveira
Attachments:
0001-btree_gin-uuid--base.v2.patchtext/x-patch; charset=US-ASCII; name=0001-btree_gin-uuid--base.v2.patchDownload
diff --git a/contrib/btree_gin/Makefile b/contrib/btree_gin/Makefile
index 690e1d7..a9e9925 100644
*** a/contrib/btree_gin/Makefile
--- b/contrib/btree_gin/Makefile
***************
*** 5,17 **** OBJS = btree_gin.o $(WIN32RES)
EXTENSION = btree_gin
DATA = btree_gin--1.0.sql btree_gin--1.0--1.1.sql btree_gin--1.1--1.2.sql \
! btree_gin--unpackaged--1.0.sql
PGFILEDESC = "btree_gin - B-tree equivalent GIN operator classes"
REGRESS = install_btree_gin int2 int4 int8 float4 float8 money oid \
timestamp timestamptz time timetz date interval \
macaddr macaddr8 inet cidr text varchar char bytea bit varbit \
! numeric enum
ifdef USE_PGXS
PG_CONFIG = pg_config
--- 5,17 ----
EXTENSION = btree_gin
DATA = btree_gin--1.0.sql btree_gin--1.0--1.1.sql btree_gin--1.1--1.2.sql \
! btree_gin--1.2--1.3.sql btree_gin--unpackaged--1.0.sql
PGFILEDESC = "btree_gin - B-tree equivalent GIN operator classes"
REGRESS = install_btree_gin int2 int4 int8 float4 float8 money oid \
timestamp timestamptz time timetz date interval \
macaddr macaddr8 inet cidr text varchar char bytea bit varbit \
! numeric enum uuid name bool bpchar
ifdef USE_PGXS
PG_CONFIG = pg_config
diff --git a/contrib/btree_gin/btnew file mode 100644
index 0000000..db675b7
*** /dev/null
--- b/contrib/btree_gin/btree_gin--1.2--1.3.sql
***************
*** 0 ****
--- 1,128 ----
+ /* contrib/btree_gin/btree_gin--1.2--1.3.sql */
+
+ -- complain if script is sourced in psql, rather than via CREATE EXTENSION
+ \echo Use "ALTER EXTENSION btree_gin UPDATE TO '1.3'" to load this file. \quit
+
+ -- uuid datatype support new in 1.3.
+ CREATE FUNCTION gin_extract_value_uuid(uuid, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_compare_prefix_uuid(uuid, uuid, int2, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_extract_query_uuid(uuid, internal, int2, internal, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE OPERATOR CLASS uuid_ops
+ DEFAULT FOR TYPE uuid USING gin
+ AS
+ OPERATOR 1 <,
+ OPERATOR 2 <=,
+ OPERATOR 3 =,
+ OPERATOR 4 >=,
+ OPERATOR 5 >,
+ FUNCTION 1 uuid_cmp(uuid,uuid),
+ FUNCTION 2 gin_extract_value_uuid(uuid, internal),
+ FUNCTION 3 gin_extract_query_uuid(uuid, internal, int2, internal, internal),
+ FUNCTION 4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
+ FUNCTION 5 gin_compare_prefix_uuid(uuid,uuid,int2, internal),
+ STORAGE uuid;
+
+ -- name datatype support new in 1.3.
+ CREATE FUNCTION gin_extract_value_name(name, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_compare_prefix_name(name, name, int2, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_extract_query_name(name, internal, int2, internal, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE OPERATOR CLASS name_ops
+ DEFAULT FOR TYPE name USING gin
+ AS
+ OPERATOR 1 <,
+ OPERATOR 2 <=,
+ OPERATOR 3 =,
+ OPERATOR 4 >=,
+ OPERATOR 5 >,
+ FUNCTION 1 btnamecmp(name,name),
+ FUNCTION 2 gin_extract_value_name(name, internal),
+ FUNCTION 3 gin_extract_query_name(name, internal, int2, internal, internal),
+ FUNCTION 4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
+ FUNCTION 5 gin_compare_prefix_name(name,name,int2, internal),
+ STORAGE name;
+
+ -- bool datatype support new in 1.3.
+ CREATE FUNCTION gin_extract_value_bool(bool, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_compare_prefix_bool(bool, bool, int2, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_extract_query_bool(bool, internal, int2, internal, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE OPERATOR CLASS bool_ops
+ DEFAULT FOR TYPE bool USING gin
+ AS
+ OPERATOR 1 <,
+ OPERATOR 2 <=,
+ OPERATOR 3 =,
+ OPERATOR 4 >=,
+ OPERATOR 5 >,
+ FUNCTION 1 btboolcmp(bool,bool),
+ FUNCTION 2 gin_extract_value_bool(bool, internal),
+ FUNCTION 3 gin_extract_query_bool(bool, internal, int2, internal, internal),
+ FUNCTION 4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
+ FUNCTION 5 gin_compare_prefix_bool(bool,bool,int2, internal),
+ STORAGE bool;
+
+ -- bpchar datatype support new in 1.3.
+ CREATE FUNCTION gin_extract_value_bpchar(bpchar, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_compare_prefix_bpchar(bpchar, bpchar, int2, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_extract_query_bpchar(bpchar, internal, int2, internal, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE OPERATOR CLASS bpchar_ops
+ DEFAULT FOR TYPE bpchar USING gin
+ AS
+ OPERATOR 1 <,
+ OPERATOR 2 <=,
+ OPERATOR 3 =,
+ OPERATOR 4 >=,
+ OPERATOR 5 >,
+ FUNCTION 1 bpcharcmp(bpchar, bpchar),
+ FUNCTION 2 gin_extract_value_bpchar(bpchar, internal),
+ FUNCTION 3 gin_extract_query_bpchar(bpchar, internal, int2, internal, internal),
+ FUNCTION 4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
+ FUNCTION 5 gin_compare_prefix_bpchar(bpchar,bpchar,int2, internal),
+ STORAGE bpchar;
diff --git a/contrib/btree_gin/btree_gin.c b/conindex 2473f79..a660681 100644
*** a/contrib/btree_gin/btree_gin.c
--- b/contrib/btree_gin/btree_gin.c
***************
*** 14,19 ****
--- 14,20 ----
#include "utils/numeric.h"
#include "utils/timestamp.h"
#include "utils/varbit.h"
+ #include "utils/uuid.h"
PG_MODULE_MAGIC;
***************
*** 350,355 **** leftmostvalue_text(void)
--- 351,358 ----
GIN_SUPPORT(text, true, leftmostvalue_text, bttextcmp)
+ GIN_SUPPORT(bpchar, true, leftmostvalue_text, bpcharcmp)
+
static Datum
leftmostvalue_char(void)
{
***************
*** 437,443 **** GIN_SUPPORT(numeric, true, leftmostvalue_numeric, gin_numeric_cmp)
* routines it needs it, so we can't use DirectFunctionCall2.
*/
-
#define ENUM_IS_LEFTMOST(x) ((x) == InvalidOid)
PG_FUNCTION_INFO_V1(gin_enum_cmp);
--- 440,445 ----
diff --git a/contrib/btree_gin/btreeindex 3acc5af..d576da7 100644
*** a/contrib/btree_gin/btree_gin.control
--- b/contrib/btree_gin/btree_gin.control
***************
*** 1,5 ****
# btree_gin extension
comment = 'support for indexing common datatypes in GIN'
! default_version = '1.2'
module_pathname = '$libdir/btree_gin'
relocatable = true
--- 1,5 ----
# btree_gin extension
comment = 'support for indexing common datatypes in GIN'
! default_version = '1.3'
module_pathname = '$libdir/btree_gin'
relocatable = true
diff --git a/contrib/btree_gin/expected/bonew file mode 100644
index 0000000..efb3e1e
*** /dev/null
--- b/contrib/btree_gin/expected/bool.out
***************
*** 0 ****
--- 1,119 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_bool (
+ i boolean
+ );
+ INSERT INTO test_bool VALUES (false),(true),(null);
+ CREATE INDEX idx_bool ON test_bool USING gin (i);
+ SELECT * FROM test_bool WHERE i<true ORDER BY i;
+ i
+ ---
+ f
+ (1 row)
+
+ SELECT * FROM test_bool WHERE i<=true ORDER BY i;
+ i
+ ---
+ f
+ t
+ (2 rows)
+
+ SELECT * FROM test_bool WHERE i=true ORDER BY i;
+ i
+ ---
+ t
+ (1 row)
+
+ SELECT * FROM test_bool WHERE i>=true ORDER BY i;
+ i
+ ---
+ t
+ (1 row)
+
+ SELECT * FROM test_bool WHERE i>true ORDER BY i;
+ i
+ ---
+ (0 rows)
+
+ SELECT * FROM test_bool WHERE i<false ORDER BY i;
+ i
+ ---
+ (0 rows)
+
+ SELECT * FROM test_bool WHERE i<=false ORDER BY i;
+ i
+ ---
+ f
+ (1 row)
+
+ SELECT * FROM test_bool WHERE i=false ORDER BY i;
+ i
+ ---
+ f
+ (1 row)
+
+ SELECT * FROM test_bool WHERE i>=false ORDER BY i;
+ i
+ ---
+ f
+ t
+ (2 rows)
+
+ SELECT * FROM test_bool WHERE i>false ORDER BY i;
+ i
+ ---
+ t
+ (1 row)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i<true ORDER BY i;
+ QUERY PLAN
+ -------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bool
+ Recheck Cond: (i < true)
+ -> Bitmap Index Scan on idx_bool
+ Index Cond: (i < true)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i<=true ORDER BY i;
+ QUERY PLAN
+ -------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bool
+ Recheck Cond: (i <= true)
+ -> Bitmap Index Scan on idx_bool
+ Index Cond: (i <= true)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i=true ORDER BY i;
+ QUERY PLAN
+ -----------------------------
+ Sort
+ Sort Key: i
+ -> Seq Scan on test_bool
+ Filter: i
+ (4 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i>=true ORDER BY i;
+ QUERY PLAN
+ -------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bool
+ Recheck Cond: (i >= true)
+ -> Bitmap Index Scan on idx_bool
+ Index Cond: (i >= true)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i>true ORDER BY i;
+ QUERY PLAN
+ -------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bool
+ Recheck Cond: (i > true)
+ -> Bitmap Index Scan on idx_bool
+ Index Cond: (i > true)
+ (6 rows)
+
diff --git a/contrib/btree_gin/expected/bpnew file mode 100644
index 0000000..2eb8855
*** /dev/null
--- b/contrib/btree_gin/expected/bpchar.out
***************
*** 0 ****
--- 1,109 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_bpchar (
+ i char(10)
+ );
+ INSERT INTO test_bpchar VALUES ('a'),('ab'),('abc'),('abc '),('abb'),('axy'),('xyz'),('xyz ');
+ CREATE INDEX idx_bpchar ON test_bpchar USING gin (i);
+ SELECT * FROM test_bpchar WHERE i<'abc' ORDER BY i;
+ i
+ ------------
+ a
+ ab
+ abb
+ (3 rows)
+
+ SELECT * FROM test_bpchar WHERE i<='abc' ORDER BY i;
+ i
+ ------------
+ a
+ ab
+ abb
+ abc
+ abc
+ (5 rows)
+
+ SELECT * FROM test_bpchar WHERE i='abc' ORDER BY i;
+ i
+ ------------
+ abc
+ abc
+ (2 rows)
+
+ SELECT * FROM test_bpchar WHERE i='abc ' ORDER BY i;
+ i
+ ------------
+ abc
+ abc
+ (2 rows)
+
+ SELECT * FROM test_bpchar WHERE i>='abc' ORDER BY i;
+ i
+ ------------
+ abc
+ abc
+ axy
+ xyz
+ xyz
+ (5 rows)
+
+ SELECT * FROM test_bpchar WHERE i>'abc' ORDER BY i;
+ i
+ ------------
+ axy
+ xyz
+ xyz
+ (3 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i<'abc' ORDER BY i;
+ QUERY PLAN
+ -----------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bpchar
+ Recheck Cond: (i < 'abc'::bpchar)
+ -> Bitmap Index Scan on idx_bpchar
+ Index Cond: (i < 'abc'::bpchar)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i<='abc' ORDER BY i;
+ QUERY PLAN
+ ------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bpchar
+ Recheck Cond: (i <= 'abc'::bpchar)
+ -> Bitmap Index Scan on idx_bpchar
+ Index Cond: (i <= 'abc'::bpchar)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i='abc' ORDER BY i;
+ QUERY PLAN
+ -----------------------------------------
+ Bitmap Heap Scan on test_bpchar
+ Recheck Cond: (i = 'abc'::bpchar)
+ -> Bitmap Index Scan on idx_bpchar
+ Index Cond: (i = 'abc'::bpchar)
+ (4 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i>='abc' ORDER BY i;
+ QUERY PLAN
+ ------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bpchar
+ Recheck Cond: (i >= 'abc'::bpchar)
+ -> Bitmap Index Scan on idx_bpchar
+ Index Cond: (i >= 'abc'::bpchar)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i>'abc' ORDER BY i;
+ QUERY PLAN
+ -----------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bpchar
+ Recheck Cond: (i > 'abc'::bpchar)
+ -> Bitmap Index Scan on idx_bpchar
+ Index Cond: (i > 'abc'::bpchar)
+ (6 rows)
+
diff --git a/contrib/btree_gin/expected/namenew file mode 100644
index 0000000..174de65
*** /dev/null
--- b/contrib/btree_gin/expected/name.out
***************
*** 0 ****
--- 1,97 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_name (
+ i name
+ );
+ INSERT INTO test_name VALUES ('a'),('ab'),('abc'),('abb'),('axy'),('xyz');
+ CREATE INDEX idx_name ON test_name USING gin (i);
+ SELECT * FROM test_name WHERE i<'abc' ORDER BY i;
+ i
+ -----
+ a
+ ab
+ abb
+ (3 rows)
+
+ SELECT * FROM test_name WHERE i<='abc' ORDER BY i;
+ i
+ -----
+ a
+ ab
+ abb
+ abc
+ (4 rows)
+
+ SELECT * FROM test_name WHERE i='abc' ORDER BY i;
+ i
+ -----
+ abc
+ (1 row)
+
+ SELECT * FROM test_name WHERE i>='abc' ORDER BY i;
+ i
+ -----
+ abc
+ axy
+ xyz
+ (3 rows)
+
+ SELECT * FROM test_name WHERE i>'abc' ORDER BY i;
+ i
+ -----
+ axy
+ xyz
+ (2 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i<'abc' ORDER BY i;
+ QUERY PLAN
+ ---------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_name
+ Recheck Cond: (i < 'abc'::name)
+ -> Bitmap Index Scan on idx_name
+ Index Cond: (i < 'abc'::name)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i<='abc' ORDER BY i;
+ QUERY PLAN
+ ----------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_name
+ Recheck Cond: (i <= 'abc'::name)
+ -> Bitmap Index Scan on idx_name
+ Index Cond: (i <= 'abc'::name)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i='abc' ORDER BY i;
+ QUERY PLAN
+ ---------------------------------------
+ Bitmap Heap Scan on test_name
+ Recheck Cond: (i = 'abc'::name)
+ -> Bitmap Index Scan on idx_name
+ Index Cond: (i = 'abc'::name)
+ (4 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i>='abc' ORDER BY i;
+ QUERY PLAN
+ ----------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_name
+ Recheck Cond: (i >= 'abc'::name)
+ -> Bitmap Index Scan on idx_name
+ Index Cond: (i >= 'abc'::name)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i>'abc' ORDER BY i;
+ QUERY PLAN
+ ---------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_name
+ Recheck Cond: (i > 'abc'::name)
+ -> Bitmap Index Scan on idx_name
+ Index Cond: (i > 'abc'::name)
+ (6 rows)
+
diff --git a/contrib/btree_gin/expected/uunew file mode 100644
index 0000000..60fd8d6
*** /dev/null
--- b/contrib/btree_gin/expected/uuid.out
***************
*** 0 ****
--- 1,104 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_uuid (
+ i uuid
+ );
+ INSERT INTO test_uuid VALUES
+ ( '00000000-0000-0000-0000-000000000000' ),
+ ( '299bc99f-2f79-4e3e-bfea-2cbfd62a7c27' ),
+ ( '6264af33-0d43-4337-bf4e-43509b8a4be8' ),
+ ( 'ce41c936-6acb-4feb-8c91-852a673e5a5c' ),
+ ( 'd2ce731f-f2a8-4a2b-be37-8f0ba637427f' ),
+ ( 'ffffffff-ffff-ffff-ffff-ffffffffffff' )
+ ;
+ CREATE INDEX idx_uuid ON test_uuid USING gin (i);
+ SELECT * FROM test_uuid WHERE i<'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ i
+ --------------------------------------
+ 00000000-0000-0000-0000-000000000000
+ 299bc99f-2f79-4e3e-bfea-2cbfd62a7c27
+ 6264af33-0d43-4337-bf4e-43509b8a4be8
+ (3 rows)
+
+ SELECT * FROM test_uuid WHERE i<='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ i
+ --------------------------------------
+ 00000000-0000-0000-0000-000000000000
+ 299bc99f-2f79-4e3e-bfea-2cbfd62a7c27
+ 6264af33-0d43-4337-bf4e-43509b8a4be8
+ ce41c936-6acb-4feb-8c91-852a673e5a5c
+ (4 rows)
+
+ SELECT * FROM test_uuid WHERE i='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ i
+ --------------------------------------
+ ce41c936-6acb-4feb-8c91-852a673e5a5c
+ (1 row)
+
+ SELECT * FROM test_uuid WHERE i>='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ i
+ --------------------------------------
+ ce41c936-6acb-4feb-8c91-852a673e5a5c
+ d2ce731f-f2a8-4a2b-be37-8f0ba637427f
+ ffffffff-ffff-ffff-ffff-ffffffffffff
+ (3 rows)
+
+ SELECT * FROM test_uuid WHERE i>'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ i
+ --------------------------------------
+ d2ce731f-f2a8-4a2b-be37-8f0ba637427f
+ ffffffff-ffff-ffff-ffff-ffffffffffff
+ (2 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i<'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ QUERY PLAN
+ ------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_uuid
+ Recheck Cond: (i < 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ -> Bitmap Index Scan on idx_uuid
+ Index Cond: (i < 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i<='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ QUERY PLAN
+ -------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_uuid
+ Recheck Cond: (i <= 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ -> Bitmap Index Scan on idx_uuid
+ Index Cond: (i <= 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ QUERY PLAN
+ ------------------------------------------------------------------------
+ Bitmap Heap Scan on test_uuid
+ Recheck Cond: (i = 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ -> Bitmap Index Scan on idx_uuid
+ Index Cond: (i = 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ (4 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i>='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ QUERY PLAN
+ -------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_uuid
+ Recheck Cond: (i >= 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ -> Bitmap Index Scan on idx_uuid
+ Index Cond: (i >= 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i>'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ QUERY PLAN
+ ------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_uuid
+ Recheck Cond: (i > 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ -> Bitmap Index Scan on idx_uuid
+ Index Cond: (i > 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ (6 rows)
+
diff --git a/contrib/btree_gin/sql/bool.sqnew file mode 100644
index 0000000..dad2ff3
*** /dev/null
--- b/contrib/btree_gin/sql/bool.sql
***************
*** 0 ****
--- 1,27 ----
+ set enable_seqscan=off;
+
+ CREATE TABLE test_bool (
+ i boolean
+ );
+
+ INSERT INTO test_bool VALUES (false),(true),(null);
+
+ CREATE INDEX idx_bool ON test_bool USING gin (i);
+
+ SELECT * FROM test_bool WHERE i<true ORDER BY i;
+ SELECT * FROM test_bool WHERE i<=true ORDER BY i;
+ SELECT * FROM test_bool WHERE i=true ORDER BY i;
+ SELECT * FROM test_bool WHERE i>=true ORDER BY i;
+ SELECT * FROM test_bool WHERE i>true ORDER BY i;
+
+ SELECT * FROM test_bool WHERE i<false ORDER BY i;
+ SELECT * FROM test_bool WHERE i<=false ORDER BY i;
+ SELECT * FROM test_bool WHERE i=false ORDER BY i;
+ SELECT * FROM test_bool WHERE i>=false ORDER BY i;
+ SELECT * FROM test_bool WHERE i>false ORDER BY i;
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i<true ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i<=true ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i=true ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i>=true ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i>true ORDER BY i;
diff --git a/contrib/btree_gin/sql/bpnew file mode 100644
index 0000000..4c951e3
*** /dev/null
--- b/contrib/btree_gin/sql/bpchar.sql
***************
*** 0 ****
--- 1,22 ----
+ set enable_seqscan=off;
+
+ CREATE TABLE test_bpchar (
+ i char(10)
+ );
+
+ INSERT INTO test_bpchar VALUES ('a'),('ab'),('abc'),('abc '),('abb'),('axy'),('xyz'),('xyz ');
+
+ CREATE INDEX idx_bpchar ON test_bpchar USING gin (i);
+
+ SELECT * FROM test_bpchar WHERE i<'abc' ORDER BY i;
+ SELECT * FROM test_bpchar WHERE i<='abc' ORDER BY i;
+ SELECT * FROM test_bpchar WHERE i='abc' ORDER BY i;
+ SELECT * FROM test_bpchar WHERE i='abc ' ORDER BY i;
+ SELECT * FROM test_bpchar WHERE i>='abc' ORDER BY i;
+ SELECT * FROM test_bpchar WHERE i>'abc' ORDER BY i;
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i<'abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i<='abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i='abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i>='abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i>'abc' ORDER BY i;
diff --git a/contrib/btree_gin/sql/namenew file mode 100644
index 0000000..c11580c
*** /dev/null
--- b/contrib/btree_gin/sql/name.sql
***************
*** 0 ****
--- 1,21 ----
+ set enable_seqscan=off;
+
+ CREATE TABLE test_name (
+ i name
+ );
+
+ INSERT INTO test_name VALUES ('a'),('ab'),('abc'),('abb'),('axy'),('xyz');
+
+ CREATE INDEX idx_name ON test_name USING gin (i);
+
+ SELECT * FROM test_name WHERE i<'abc' ORDER BY i;
+ SELECT * FROM test_name WHERE i<='abc' ORDER BY i;
+ SELECT * FROM test_name WHERE i='abc' ORDER BY i;
+ SELECT * FROM test_name WHERE i>='abc' ORDER BY i;
+ SELECT * FROM test_name WHERE i>'abc' ORDER BY i;
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i<'abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i<='abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i='abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i>='abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i>'abc' ORDER BY i;
diff --git a/contrib/btree_gin/sql/uunew file mode 100644
index 0000000..3c141bd
*** /dev/null
--- b/contrib/btree_gin/sql/uuid.sql
***************
*** 0 ****
--- 1,28 ----
+ set enable_seqscan=off;
+
+ CREATE TABLE test_uuid (
+ i uuid
+ );
+
+ INSERT INTO test_uuid VALUES
+ ( '00000000-0000-0000-0000-000000000000' ),
+ ( '299bc99f-2f79-4e3e-bfea-2cbfd62a7c27' ),
+ ( '6264af33-0d43-4337-bf4e-43509b8a4be8' ),
+ ( 'ce41c936-6acb-4feb-8c91-852a673e5a5c' ),
+ ( 'd2ce731f-f2a8-4a2b-be37-8f0ba637427f' ),
+ ( 'ffffffff-ffff-ffff-ffff-ffffffffffff' )
+ ;
+
+ CREATE INDEX idx_uuid ON test_uuid USING gin (i);
+
+ SELECT * FROM test_uuid WHERE i<'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ SELECT * FROM test_uuid WHERE i<='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ SELECT * FROM test_uuid WHERE i='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ SELECT * FROM test_uuid WHERE i>='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ SELECT * FROM test_uuid WHERE i>'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i<'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i<='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i>='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i>'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
diff --git a/doc/src/sgml/btree-gin.sindex e491fa7..314e001 100644
*** a/doc/src/sgml/btree-gin.sgml
--- b/doc/src/sgml/btree-gin.sgml
***************
*** 17,23 ****
<type>oid</type>, <type>money</type>, <type>"char"</type>,
<type>varchar</type>, <type>text</type>, <type>bytea</type>, <type>bit</type>,
<type>varbit</type>, <type>macaddr</type>, <type>macaddr8</type>, <type>inet</type>,
! <type>cidr</type>, and all <type>enum</type> types.
</para>
<para>
--- 17,24 ----
<type>oid</type>, <type>money</type>, <type>"char"</type>,
<type>varchar</type>, <type>text</type>, <type>bytea</type>, <type>bit</type>,
<type>varbit</type>, <type>macaddr</type>, <type>macaddr8</type>, <type>inet</type>,
! <type>cidr</type>, <type>uuid</type>, <type>name</type>, <type>bool</type>,
! <type>bpchar</type>, and all <type>enum</type> types.
</para>
<para>
0002-btree_gin-uuid--anyrange.v2.patchtext/x-patch; charset=US-ASCII; name=0002-btree_gin-uuid--anyrange.v2.patchDownload
diff --git a/contrib/btree_gin/Makefile b/contrib/btree_gin/Makefile
index a9e9925..d36f5ad 100644
*** a/contrib/btree_gin/Makefile
--- b/contrib/btree_gin/Makefile
***************
*** 11,17 **** PGFILEDESC = "btree_gin - B-tree equivalent GIN operator classes"
REGRESS = install_btree_gin int2 int4 int8 float4 float8 money oid \
timestamp timestamptz time timetz date interval \
macaddr macaddr8 inet cidr text varchar char bytea bit varbit \
! numeric enum uuid name bool bpchar
ifdef USE_PGXS
PG_CONFIG = pg_config
--- 11,17 ----
REGRESS = install_btree_gin int2 int4 int8 float4 float8 money oid \
timestamp timestamptz time timetz date interval \
macaddr macaddr8 inet cidr text varchar char bytea bit varbit \
! numeric enum uuid name bool anyrange bpchar
ifdef USE_PGXS
PG_CONFIG = pg_config
diff --git a/contrib/btree_gin/btindex db675b7..f7523a3 100644
*** a/contrib/btree_gin/btree_gin--1.2--1.3.sql
--- b/contrib/btree_gin/btree_gin--1.2--1.3.sql
***************
*** 96,101 **** AS
--- 96,137 ----
FUNCTION 5 gin_compare_prefix_bool(bool,bool,int2, internal),
STORAGE bool;
+ -- anyrange datatype support new in 1.3.
+ CREATE FUNCTION gin_anyrange_cmp(anyrange, anyrange)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_extract_value_anyrange(anyrange, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_compare_prefix_anyrange(anyrange, anyrange, int2, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_extract_query_anyrange(anyrange, internal, int2, internal, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE OPERATOR CLASS anyrange_ops
+ DEFAULT FOR TYPE anyrange USING gin
+ AS
+ OPERATOR 1 <,
+ OPERATOR 2 <=,
+ OPERATOR 3 =,
+ OPERATOR 4 >=,
+ OPERATOR 5 >,
+ FUNCTION 1 gin_anyrange_cmp(anyrange,anyrange),
+ FUNCTION 2 gin_extract_value_anyrange(anyrange, internal),
+ FUNCTION 3 gin_extract_query_anyrange(anyrange, internal, int2, internal, internal),
+ FUNCTION 4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
+ FUNCTION 5 gin_compare_prefix_anyrange(anyrange,anyrange,int2, internal),
+ STORAGE anyrange;
+
-- bpchar datatype support new in 1.3.
CREATE FUNCTION gin_extract_value_bpchar(bpchar, internal)
RETURNS internal
diff --git a/contrib/btree_gin/btree_gin.c b/conindex a660681..37e0740 100644
*** a/contrib/btree_gin/btree_gin.c
--- b/contrib/btree_gin/btree_gin.c
***************
*** 15,20 ****
--- 15,21 ----
#include "utils/timestamp.h"
#include "utils/varbit.h"
#include "utils/uuid.h"
+ #include "utils/rangetypes.h"
PG_MODULE_MAGIC;
***************
*** 506,508 **** leftmostvalue_bool(void)
--- 507,560 ----
}
GIN_SUPPORT(bool, false, leftmostvalue_bool, btboolcmp)
+
+ /*
+ * Similarly to Numeric, we don't know the left-most value, although for
+ * different reasons (numeric does not have one, while for anyarray we
+ * don't even know the concrete type). We could try to build a fake empty
+ * range, but we simply use PointerGetDatum(NULL) just like for Numeric.
+ */
+ #define ANYRANGE_IS_LEFTMOST(x) ((x) == NULL)
+
+ PG_FUNCTION_INFO_V1(gin_anyrange_cmp);
+
+ /*
+ * Note that we use CallerFInfoFunctionCall2 here so that range_cmp
+ * gets a valid fn_extra to work with. Unlike most other type comparison
+ * routines it needs it, so we can't use DirectFunctionCall2.
+ */
+ Datum
+ gin_anyrange_cmp(PG_FUNCTION_ARGS)
+ {
+ RangeType *a = (RangeType *) PG_GETARG_POINTER(0);
+ RangeType *b = (RangeType *) PG_GETARG_POINTER(1);
+ int res = 0;
+
+ if (ANYRANGE_IS_LEFTMOST(a))
+ {
+ res = (ANYRANGE_IS_LEFTMOST(b)) ? 0 : -1;
+ }
+ else if (ANYRANGE_IS_LEFTMOST(b))
+ {
+ res = 1;
+ }
+ else
+ {
+ res = DatumGetInt32(CallerFInfoFunctionCall2(
+ range_cmp,
+ fcinfo->flinfo,
+ PG_GET_COLLATION(),
+ RangeTypePGetDatum(a),
+ RangeTypePGetDatum(b)));
+ }
+
+ PG_RETURN_INT32(res);
+ }
+
+ static Datum
+ leftmostvalue_anyrange(void)
+ {
+ return PointerGetDatum(NULL);
+ }
+
+ GIN_SUPPORT(anyrange, false, leftmostvalue_anyrange, gin_anyrange_cmp)
diff --git a/contrib/btree_gin/expecnew file mode 100644
index 0000000..93b24f4
*** /dev/null
--- b/contrib/btree_gin/expected/anyrange.out
***************
*** 0 ****
--- 1,113 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_tsrange (
+ i tsrange
+ );
+ INSERT INTO test_tsrange VALUES
+ ( 'empty' ),
+ ( '(,)' ),
+ ( '[2018-02-02 03:55:08,2018-04-02 03:55:08)' ),
+ ( '[2018-02-02 04:55:08,2018-04-02 04:55:08)' ),
+ ( '[2018-02-02 05:55:08,2018-04-02 05:55:08)' ),
+ ( '[2018-02-02 08:55:08,2018-04-02 08:55:08)' ),
+ ( '[2018-02-02 09:55:08,2018-04-02 09:55:08)' ),
+ ( '[2018-02-02 10:55:08,2018-04-02 10:55:08)' ),
+ ( '[infinity,infinity]' )
+ ;
+ CREATE INDEX idx_tsrange ON test_tsrange USING gin (i);
+ SELECT * FROM test_tsrange WHERE i<'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ i
+ ---------------------------------------------------------
+ empty
+ (,)
+ ["Fri Feb 02 03:55:08 2018","Mon Apr 02 03:55:08 2018")
+ ["Fri Feb 02 04:55:08 2018","Mon Apr 02 04:55:08 2018")
+ ["Fri Feb 02 05:55:08 2018","Mon Apr 02 05:55:08 2018")
+ (5 rows)
+
+ SELECT * FROM test_tsrange WHERE i<='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ i
+ ---------------------------------------------------------
+ empty
+ (,)
+ ["Fri Feb 02 03:55:08 2018","Mon Apr 02 03:55:08 2018")
+ ["Fri Feb 02 04:55:08 2018","Mon Apr 02 04:55:08 2018")
+ ["Fri Feb 02 05:55:08 2018","Mon Apr 02 05:55:08 2018")
+ ["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")
+ (6 rows)
+
+ SELECT * FROM test_tsrange WHERE i='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ i
+ ---------------------------------------------------------
+ ["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")
+ (1 row)
+
+ SELECT * FROM test_tsrange WHERE i>='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ i
+ ---------------------------------------------------------
+ ["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")
+ ["Fri Feb 02 09:55:08 2018","Mon Apr 02 09:55:08 2018")
+ ["Fri Feb 02 10:55:08 2018","Mon Apr 02 10:55:08 2018")
+ [infinity,infinity]
+ (4 rows)
+
+ SELECT * FROM test_tsrange WHERE i>'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ i
+ ---------------------------------------------------------
+ ["Fri Feb 02 09:55:08 2018","Mon Apr 02 09:55:08 2018")
+ ["Fri Feb 02 10:55:08 2018","Mon Apr 02 10:55:08 2018")
+ [infinity,infinity]
+ (3 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i<'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ QUERY PLAN
+ ----------------------------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_tsrange
+ Recheck Cond: (i < '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ -> Bitmap Index Scan on idx_tsrange
+ Index Cond: (i < '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i<='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ QUERY PLAN
+ -----------------------------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_tsrange
+ Recheck Cond: (i <= '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ -> Bitmap Index Scan on idx_tsrange
+ Index Cond: (i <= '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ QUERY PLAN
+ ----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on test_tsrange
+ Recheck Cond: (i = '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ -> Bitmap Index Scan on idx_tsrange
+ Index Cond: (i = '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ (4 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i>='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ QUERY PLAN
+ -----------------------------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_tsrange
+ Recheck Cond: (i >= '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ -> Bitmap Index Scan on idx_tsrange
+ Index Cond: (i >= '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i>'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ QUERY PLAN
+ ----------------------------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_tsrange
+ Recheck Cond: (i > '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ -> Bitmap Index Scan on idx_tsrange
+ Index Cond: (i > '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ (6 rows)
+
diff --git a/contrib/btree_gin/sql/anyrange.sqnew file mode 100644
index 0000000..97157ad
*** /dev/null
--- b/contrib/btree_gin/sql/anyrange.sql
***************
*** 0 ****
--- 1,31 ----
+ set enable_seqscan=off;
+
+ CREATE TABLE test_tsrange (
+ i tsrange
+ );
+
+ INSERT INTO test_tsrange VALUES
+ ( 'empty' ),
+ ( '(,)' ),
+ ( '[2018-02-02 03:55:08,2018-04-02 03:55:08)' ),
+ ( '[2018-02-02 04:55:08,2018-04-02 04:55:08)' ),
+ ( '[2018-02-02 05:55:08,2018-04-02 05:55:08)' ),
+ ( '[2018-02-02 08:55:08,2018-04-02 08:55:08)' ),
+ ( '[2018-02-02 09:55:08,2018-04-02 09:55:08)' ),
+ ( '[2018-02-02 10:55:08,2018-04-02 10:55:08)' ),
+ ( '[infinity,infinity]' )
+ ;
+
+ CREATE INDEX idx_tsrange ON test_tsrange USING gin (i);
+
+ SELECT * FROM test_tsrange WHERE i<'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ SELECT * FROM test_tsrange WHERE i<='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ SELECT * FROM test_tsrange WHERE i='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ SELECT * FROM test_tsrange WHERE i>='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ SELECT * FROM test_tsrange WHERE i>'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i<'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i<='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i>='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i>'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
diff --git a/doc/src/sgml/btree-gin.sgml index 314e001..e1315da 100644
*** a/doc/src/sgml/btree-gin.sgml
--- b/doc/src/sgml/btree-gin.sgml
***************
*** 18,24 ****
<type>varchar</type>, <type>text</type>, <type>bytea</type>, <type>bit</type>,
<type>varbit</type>, <type>macaddr</type>, <type>macaddr8</type>, <type>inet</type>,
<type>cidr</type>, <type>uuid</type>, <type>name</type>, <type>bool</type>,
! <type>bpchar</type>, and all <type>enum</type> types.
</para>
<para>
--- 18,24 ----
<type>varchar</type>, <type>text</type>, <type>bytea</type>, <type>bit</type>,
<type>varbit</type>, <type>macaddr</type>, <type>macaddr8</type>, <type>inet</type>,
<type>cidr</type>, <type>uuid</type>, <type>name</type>, <type>bool</type>,
! <type>bpchar</type>, and all <type>enum</type> and <type>anyrange</type> types.
</para>
<para>
On 03/30/2018 10:51 PM, Matheus de Oliveira wrote:
Hi all.
On Wed, Mar 21, 2018 at 1:47 PM, Tomas Vondra
<tomas.vondra@2ndquadrant.com <mailto:tomas.vondra@2ndquadrant.com>> wrote:Do you plan to post an updated version of the patch, of what is your
response to the points raised last week?Very sorry about the long delay. I've been in a long trip, no time to
look that carefully.
I still haven't made my mind regarding usefulness of range opclasses, so
I suggest to split the patch into two parts - 0001 for the opclasses
we're confident are useful, and 0002 for those extras. The committer
then may apply either 0001 or 0001+0002, depending on his judgment.I liked the idea. So, follows the patches:
- 0001-btree_gin-uuid--base.v2.patch - all types but anyrange, and with
the adjustments on comments you proposed
- 0002-btree_gin-uuid--anyrange.v2.patch - adding the anyrange type
(must be applied after 0001)Anything else missing?
I don't think so. I've marked it as RFC, but I have no idea if anyone is
going to push it by the end of this commitfest.
regards
--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
somehow you missed some parts in 0001 patch, at least regression tests fail:
CREATE EXTENSION btree_gin;
+ ERROR: could not find function "gin_extract_value_uuid" in file
"/usr/local/pgsql/lib/btree_gin.so"
Matheus de Oliveira wrote:
Hi all.
On Wed, Mar 21, 2018 at 1:47 PM, Tomas Vondra <tomas.vondra@2ndquadrant.com
<mailto:tomas.vondra@2ndquadrant.com>> wrote:Do you plan to post an updated version of the patch, of what is your
response to the points raised last week?Very sorry about the long delay. I've been in a long trip, no time to look that
carefully.I still haven't made my mind regarding usefulness of range opclasses, so
I suggest to split the patch into two parts - 0001 for the opclasses
we're confident are useful, and 0002 for those extras. The committer
then may apply either 0001 or 0001+0002, depending on his judgment.I liked the idea. So, follows the patches:
- 0001-btree_gin-uuid--base.v2.patch - all types but anyrange, and with the
adjustments on comments you proposed
- 0002-btree_gin-uuid--anyrange.v2.patch - adding the anyrange type (must be
applied after 0001)Anything else missing?
Best regards,
--
Matheus de Oliveira
--
Teodor Sigaev E-mail: teodor@sigaev.ru
WWW: http://www.sigaev.ru/
Damn, I should have noticed that during the last review, but I missed
that somehow. Not sure Matheus will have time to look into it, so here
is a (hopefully) fixed version.
regards
On 4/5/18 1:16 PM, Teodor Sigaev wrote:
somehow you missed some parts in 0001 patch, at least regression tests
fail:О©╫ CREATE EXTENSION btree_gin;
+ ERROR:О©╫ could not find function "gin_extract_value_uuid" in file
"/usr/local/pgsql/lib/btree_gin.so"
--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachments:
0001-Add-support-for-uuid-bool-bpchar-and-name-to-btre-v3.patchtext/x-patch; name=0001-Add-support-for-uuid-bool-bpchar-and-name-to-btre-v3.patchDownload
From e966395ce95de914105f542bc6c5700bcde4b29f Mon Sep 17 00:00:00 2001
From: Tomas Vondra <tomas@2ndquadrant.com>
Date: Thu, 5 Apr 2018 14:02:58 +0200
Subject: [PATCH 1/2] Add support for uuid, bool, bpchar and name to btree_gin
These data types all have a btree opclass, but were unsupported by
btree_gin for some reason.
---
contrib/btree_gin/Makefile | 4 +-
contrib/btree_gin/btree_gin--1.2--1.3.sql | 128 ++++++++++++++++++++++++++++++
contrib/btree_gin/btree_gin.c | 31 +++++++-
contrib/btree_gin/btree_gin.control | 2 +-
contrib/btree_gin/expected/bool.out | 119 +++++++++++++++++++++++++++
contrib/btree_gin/expected/bpchar.out | 109 +++++++++++++++++++++++++
contrib/btree_gin/expected/name.out | 97 ++++++++++++++++++++++
contrib/btree_gin/expected/uuid.out | 104 ++++++++++++++++++++++++
contrib/btree_gin/sql/bool.sql | 27 +++++++
contrib/btree_gin/sql/bpchar.sql | 22 +++++
contrib/btree_gin/sql/name.sql | 21 +++++
contrib/btree_gin/sql/uuid.sql | 28 +++++++
doc/src/sgml/btree-gin.sgml | 3 +-
13 files changed, 690 insertions(+), 5 deletions(-)
create mode 100644 contrib/btree_gin/btree_gin--1.2--1.3.sql
create mode 100644 contrib/btree_gin/expected/bool.out
create mode 100644 contrib/btree_gin/expected/bpchar.out
create mode 100644 contrib/btree_gin/expected/name.out
create mode 100644 contrib/btree_gin/expected/uuid.out
create mode 100644 contrib/btree_gin/sql/bool.sql
create mode 100644 contrib/btree_gin/sql/bpchar.sql
create mode 100644 contrib/btree_gin/sql/name.sql
create mode 100644 contrib/btree_gin/sql/uuid.sql
diff --git a/contrib/btree_gin/Makefile b/contrib/btree_gin/Makefile
index 690e1d7..a9e9925 100644
--- a/contrib/btree_gin/Makefile
+++ b/contrib/btree_gin/Makefile
@@ -5,13 +5,13 @@ OBJS = btree_gin.o $(WIN32RES)
EXTENSION = btree_gin
DATA = btree_gin--1.0.sql btree_gin--1.0--1.1.sql btree_gin--1.1--1.2.sql \
- btree_gin--unpackaged--1.0.sql
+ btree_gin--1.2--1.3.sql btree_gin--unpackaged--1.0.sql
PGFILEDESC = "btree_gin - B-tree equivalent GIN operator classes"
REGRESS = install_btree_gin int2 int4 int8 float4 float8 money oid \
timestamp timestamptz time timetz date interval \
macaddr macaddr8 inet cidr text varchar char bytea bit varbit \
- numeric enum
+ numeric enum uuid name bool bpchar
ifdef USE_PGXS
PG_CONFIG = pg_config
diff --git a/contrib/btree_gin/btree_gin--1.2--1.3.sql b/contrib/btree_gin/btree_gin--1.2--1.3.sql
new file mode 100644
index 0000000..db675b7
--- /dev/null
+++ b/contrib/btree_gin/btree_gin--1.2--1.3.sql
@@ -0,0 +1,128 @@
+/* contrib/btree_gin/btree_gin--1.2--1.3.sql */
+
+-- complain if script is sourced in psql, rather than via CREATE EXTENSION
+\echo Use "ALTER EXTENSION btree_gin UPDATE TO '1.3'" to load this file. \quit
+
+-- uuid datatype support new in 1.3.
+CREATE FUNCTION gin_extract_value_uuid(uuid, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT IMMUTABLE;
+
+CREATE FUNCTION gin_compare_prefix_uuid(uuid, uuid, int2, internal)
+RETURNS int4
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT IMMUTABLE;
+
+CREATE FUNCTION gin_extract_query_uuid(uuid, internal, int2, internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT IMMUTABLE;
+
+CREATE OPERATOR CLASS uuid_ops
+DEFAULT FOR TYPE uuid USING gin
+AS
+ OPERATOR 1 <,
+ OPERATOR 2 <=,
+ OPERATOR 3 =,
+ OPERATOR 4 >=,
+ OPERATOR 5 >,
+ FUNCTION 1 uuid_cmp(uuid,uuid),
+ FUNCTION 2 gin_extract_value_uuid(uuid, internal),
+ FUNCTION 3 gin_extract_query_uuid(uuid, internal, int2, internal, internal),
+ FUNCTION 4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
+ FUNCTION 5 gin_compare_prefix_uuid(uuid,uuid,int2, internal),
+STORAGE uuid;
+
+-- name datatype support new in 1.3.
+CREATE FUNCTION gin_extract_value_name(name, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT IMMUTABLE;
+
+CREATE FUNCTION gin_compare_prefix_name(name, name, int2, internal)
+RETURNS int4
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT IMMUTABLE;
+
+CREATE FUNCTION gin_extract_query_name(name, internal, int2, internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT IMMUTABLE;
+
+CREATE OPERATOR CLASS name_ops
+DEFAULT FOR TYPE name USING gin
+AS
+ OPERATOR 1 <,
+ OPERATOR 2 <=,
+ OPERATOR 3 =,
+ OPERATOR 4 >=,
+ OPERATOR 5 >,
+ FUNCTION 1 btnamecmp(name,name),
+ FUNCTION 2 gin_extract_value_name(name, internal),
+ FUNCTION 3 gin_extract_query_name(name, internal, int2, internal, internal),
+ FUNCTION 4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
+ FUNCTION 5 gin_compare_prefix_name(name,name,int2, internal),
+STORAGE name;
+
+-- bool datatype support new in 1.3.
+CREATE FUNCTION gin_extract_value_bool(bool, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT IMMUTABLE;
+
+CREATE FUNCTION gin_compare_prefix_bool(bool, bool, int2, internal)
+RETURNS int4
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT IMMUTABLE;
+
+CREATE FUNCTION gin_extract_query_bool(bool, internal, int2, internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT IMMUTABLE;
+
+CREATE OPERATOR CLASS bool_ops
+DEFAULT FOR TYPE bool USING gin
+AS
+ OPERATOR 1 <,
+ OPERATOR 2 <=,
+ OPERATOR 3 =,
+ OPERATOR 4 >=,
+ OPERATOR 5 >,
+ FUNCTION 1 btboolcmp(bool,bool),
+ FUNCTION 2 gin_extract_value_bool(bool, internal),
+ FUNCTION 3 gin_extract_query_bool(bool, internal, int2, internal, internal),
+ FUNCTION 4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
+ FUNCTION 5 gin_compare_prefix_bool(bool,bool,int2, internal),
+STORAGE bool;
+
+-- bpchar datatype support new in 1.3.
+CREATE FUNCTION gin_extract_value_bpchar(bpchar, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT IMMUTABLE;
+
+CREATE FUNCTION gin_compare_prefix_bpchar(bpchar, bpchar, int2, internal)
+RETURNS int4
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT IMMUTABLE;
+
+CREATE FUNCTION gin_extract_query_bpchar(bpchar, internal, int2, internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT IMMUTABLE;
+
+CREATE OPERATOR CLASS bpchar_ops
+DEFAULT FOR TYPE bpchar USING gin
+AS
+ OPERATOR 1 <,
+ OPERATOR 2 <=,
+ OPERATOR 3 =,
+ OPERATOR 4 >=,
+ OPERATOR 5 >,
+ FUNCTION 1 bpcharcmp(bpchar, bpchar),
+ FUNCTION 2 gin_extract_value_bpchar(bpchar, internal),
+ FUNCTION 3 gin_extract_query_bpchar(bpchar, internal, int2, internal, internal),
+ FUNCTION 4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
+ FUNCTION 5 gin_compare_prefix_bpchar(bpchar,bpchar,int2, internal),
+STORAGE bpchar;
diff --git a/contrib/btree_gin/btree_gin.c b/contrib/btree_gin/btree_gin.c
index 2473f79..a660681 100644
--- a/contrib/btree_gin/btree_gin.c
+++ b/contrib/btree_gin/btree_gin.c
@@ -14,6 +14,7 @@
#include "utils/numeric.h"
#include "utils/timestamp.h"
#include "utils/varbit.h"
+#include "utils/uuid.h"
PG_MODULE_MAGIC;
@@ -350,6 +351,8 @@ leftmostvalue_text(void)
GIN_SUPPORT(text, true, leftmostvalue_text, bttextcmp)
+GIN_SUPPORT(bpchar, true, leftmostvalue_text, bpcharcmp)
+
static Datum
leftmostvalue_char(void)
{
@@ -437,7 +440,6 @@ GIN_SUPPORT(numeric, true, leftmostvalue_numeric, gin_numeric_cmp)
* routines it needs it, so we can't use DirectFunctionCall2.
*/
-
#define ENUM_IS_LEFTMOST(x) ((x) == InvalidOid)
PG_FUNCTION_INFO_V1(gin_enum_cmp);
@@ -477,3 +479,30 @@ leftmostvalue_enum(void)
}
GIN_SUPPORT(anyenum, false, leftmostvalue_enum, gin_enum_cmp)
+
+static Datum
+leftmostvalue_uuid(void)
+{
+ /* palloc0 will create the UUID with all zeroes: "00000000-0000-0000-0000-000000000000" */
+ pg_uuid_t *retval = (pg_uuid_t *) palloc0(sizeof(pg_uuid_t));
+ return UUIDPGetDatum(retval);
+}
+
+GIN_SUPPORT(uuid, false, leftmostvalue_uuid, uuid_cmp)
+
+static Datum
+leftmostvalue_name(void)
+{
+ NameData* result = (NameData *) palloc0(NAMEDATALEN);
+ return NameGetDatum(result);
+}
+
+GIN_SUPPORT(name, false, leftmostvalue_name, btnamecmp)
+
+static Datum
+leftmostvalue_bool(void)
+{
+ return BoolGetDatum(false);
+}
+
+GIN_SUPPORT(bool, false, leftmostvalue_bool, btboolcmp)
diff --git a/contrib/btree_gin/btree_gin.control b/contrib/btree_gin/btree_gin.control
index 3acc5af..d576da7 100644
--- a/contrib/btree_gin/btree_gin.control
+++ b/contrib/btree_gin/btree_gin.control
@@ -1,5 +1,5 @@
# btree_gin extension
comment = 'support for indexing common datatypes in GIN'
-default_version = '1.2'
+default_version = '1.3'
module_pathname = '$libdir/btree_gin'
relocatable = true
diff --git a/contrib/btree_gin/expected/bool.out b/contrib/btree_gin/expected/bool.out
new file mode 100644
index 0000000..efb3e1e
--- /dev/null
+++ b/contrib/btree_gin/expected/bool.out
@@ -0,0 +1,119 @@
+set enable_seqscan=off;
+CREATE TABLE test_bool (
+ i boolean
+);
+INSERT INTO test_bool VALUES (false),(true),(null);
+CREATE INDEX idx_bool ON test_bool USING gin (i);
+SELECT * FROM test_bool WHERE i<true ORDER BY i;
+ i
+---
+ f
+(1 row)
+
+SELECT * FROM test_bool WHERE i<=true ORDER BY i;
+ i
+---
+ f
+ t
+(2 rows)
+
+SELECT * FROM test_bool WHERE i=true ORDER BY i;
+ i
+---
+ t
+(1 row)
+
+SELECT * FROM test_bool WHERE i>=true ORDER BY i;
+ i
+---
+ t
+(1 row)
+
+SELECT * FROM test_bool WHERE i>true ORDER BY i;
+ i
+---
+(0 rows)
+
+SELECT * FROM test_bool WHERE i<false ORDER BY i;
+ i
+---
+(0 rows)
+
+SELECT * FROM test_bool WHERE i<=false ORDER BY i;
+ i
+---
+ f
+(1 row)
+
+SELECT * FROM test_bool WHERE i=false ORDER BY i;
+ i
+---
+ f
+(1 row)
+
+SELECT * FROM test_bool WHERE i>=false ORDER BY i;
+ i
+---
+ f
+ t
+(2 rows)
+
+SELECT * FROM test_bool WHERE i>false ORDER BY i;
+ i
+---
+ t
+(1 row)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i<true ORDER BY i;
+ QUERY PLAN
+-------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bool
+ Recheck Cond: (i < true)
+ -> Bitmap Index Scan on idx_bool
+ Index Cond: (i < true)
+(6 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i<=true ORDER BY i;
+ QUERY PLAN
+-------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bool
+ Recheck Cond: (i <= true)
+ -> Bitmap Index Scan on idx_bool
+ Index Cond: (i <= true)
+(6 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i=true ORDER BY i;
+ QUERY PLAN
+-----------------------------
+ Sort
+ Sort Key: i
+ -> Seq Scan on test_bool
+ Filter: i
+(4 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i>=true ORDER BY i;
+ QUERY PLAN
+-------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bool
+ Recheck Cond: (i >= true)
+ -> Bitmap Index Scan on idx_bool
+ Index Cond: (i >= true)
+(6 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i>true ORDER BY i;
+ QUERY PLAN
+-------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bool
+ Recheck Cond: (i > true)
+ -> Bitmap Index Scan on idx_bool
+ Index Cond: (i > true)
+(6 rows)
+
diff --git a/contrib/btree_gin/expected/bpchar.out b/contrib/btree_gin/expected/bpchar.out
new file mode 100644
index 0000000..2eb8855
--- /dev/null
+++ b/contrib/btree_gin/expected/bpchar.out
@@ -0,0 +1,109 @@
+set enable_seqscan=off;
+CREATE TABLE test_bpchar (
+ i char(10)
+);
+INSERT INTO test_bpchar VALUES ('a'),('ab'),('abc'),('abc '),('abb'),('axy'),('xyz'),('xyz ');
+CREATE INDEX idx_bpchar ON test_bpchar USING gin (i);
+SELECT * FROM test_bpchar WHERE i<'abc' ORDER BY i;
+ i
+------------
+ a
+ ab
+ abb
+(3 rows)
+
+SELECT * FROM test_bpchar WHERE i<='abc' ORDER BY i;
+ i
+------------
+ a
+ ab
+ abb
+ abc
+ abc
+(5 rows)
+
+SELECT * FROM test_bpchar WHERE i='abc' ORDER BY i;
+ i
+------------
+ abc
+ abc
+(2 rows)
+
+SELECT * FROM test_bpchar WHERE i='abc ' ORDER BY i;
+ i
+------------
+ abc
+ abc
+(2 rows)
+
+SELECT * FROM test_bpchar WHERE i>='abc' ORDER BY i;
+ i
+------------
+ abc
+ abc
+ axy
+ xyz
+ xyz
+(5 rows)
+
+SELECT * FROM test_bpchar WHERE i>'abc' ORDER BY i;
+ i
+------------
+ axy
+ xyz
+ xyz
+(3 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i<'abc' ORDER BY i;
+ QUERY PLAN
+-----------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bpchar
+ Recheck Cond: (i < 'abc'::bpchar)
+ -> Bitmap Index Scan on idx_bpchar
+ Index Cond: (i < 'abc'::bpchar)
+(6 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i<='abc' ORDER BY i;
+ QUERY PLAN
+------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bpchar
+ Recheck Cond: (i <= 'abc'::bpchar)
+ -> Bitmap Index Scan on idx_bpchar
+ Index Cond: (i <= 'abc'::bpchar)
+(6 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i='abc' ORDER BY i;
+ QUERY PLAN
+-----------------------------------------
+ Bitmap Heap Scan on test_bpchar
+ Recheck Cond: (i = 'abc'::bpchar)
+ -> Bitmap Index Scan on idx_bpchar
+ Index Cond: (i = 'abc'::bpchar)
+(4 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i>='abc' ORDER BY i;
+ QUERY PLAN
+------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bpchar
+ Recheck Cond: (i >= 'abc'::bpchar)
+ -> Bitmap Index Scan on idx_bpchar
+ Index Cond: (i >= 'abc'::bpchar)
+(6 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i>'abc' ORDER BY i;
+ QUERY PLAN
+-----------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bpchar
+ Recheck Cond: (i > 'abc'::bpchar)
+ -> Bitmap Index Scan on idx_bpchar
+ Index Cond: (i > 'abc'::bpchar)
+(6 rows)
+
diff --git a/contrib/btree_gin/expected/name.out b/contrib/btree_gin/expected/name.out
new file mode 100644
index 0000000..174de65
--- /dev/null
+++ b/contrib/btree_gin/expected/name.out
@@ -0,0 +1,97 @@
+set enable_seqscan=off;
+CREATE TABLE test_name (
+ i name
+);
+INSERT INTO test_name VALUES ('a'),('ab'),('abc'),('abb'),('axy'),('xyz');
+CREATE INDEX idx_name ON test_name USING gin (i);
+SELECT * FROM test_name WHERE i<'abc' ORDER BY i;
+ i
+-----
+ a
+ ab
+ abb
+(3 rows)
+
+SELECT * FROM test_name WHERE i<='abc' ORDER BY i;
+ i
+-----
+ a
+ ab
+ abb
+ abc
+(4 rows)
+
+SELECT * FROM test_name WHERE i='abc' ORDER BY i;
+ i
+-----
+ abc
+(1 row)
+
+SELECT * FROM test_name WHERE i>='abc' ORDER BY i;
+ i
+-----
+ abc
+ axy
+ xyz
+(3 rows)
+
+SELECT * FROM test_name WHERE i>'abc' ORDER BY i;
+ i
+-----
+ axy
+ xyz
+(2 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i<'abc' ORDER BY i;
+ QUERY PLAN
+---------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_name
+ Recheck Cond: (i < 'abc'::name)
+ -> Bitmap Index Scan on idx_name
+ Index Cond: (i < 'abc'::name)
+(6 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i<='abc' ORDER BY i;
+ QUERY PLAN
+----------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_name
+ Recheck Cond: (i <= 'abc'::name)
+ -> Bitmap Index Scan on idx_name
+ Index Cond: (i <= 'abc'::name)
+(6 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i='abc' ORDER BY i;
+ QUERY PLAN
+---------------------------------------
+ Bitmap Heap Scan on test_name
+ Recheck Cond: (i = 'abc'::name)
+ -> Bitmap Index Scan on idx_name
+ Index Cond: (i = 'abc'::name)
+(4 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i>='abc' ORDER BY i;
+ QUERY PLAN
+----------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_name
+ Recheck Cond: (i >= 'abc'::name)
+ -> Bitmap Index Scan on idx_name
+ Index Cond: (i >= 'abc'::name)
+(6 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i>'abc' ORDER BY i;
+ QUERY PLAN
+---------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_name
+ Recheck Cond: (i > 'abc'::name)
+ -> Bitmap Index Scan on idx_name
+ Index Cond: (i > 'abc'::name)
+(6 rows)
+
diff --git a/contrib/btree_gin/expected/uuid.out b/contrib/btree_gin/expected/uuid.out
new file mode 100644
index 0000000..60fd8d6
--- /dev/null
+++ b/contrib/btree_gin/expected/uuid.out
@@ -0,0 +1,104 @@
+set enable_seqscan=off;
+CREATE TABLE test_uuid (
+ i uuid
+);
+INSERT INTO test_uuid VALUES
+ ( '00000000-0000-0000-0000-000000000000' ),
+ ( '299bc99f-2f79-4e3e-bfea-2cbfd62a7c27' ),
+ ( '6264af33-0d43-4337-bf4e-43509b8a4be8' ),
+ ( 'ce41c936-6acb-4feb-8c91-852a673e5a5c' ),
+ ( 'd2ce731f-f2a8-4a2b-be37-8f0ba637427f' ),
+ ( 'ffffffff-ffff-ffff-ffff-ffffffffffff' )
+;
+CREATE INDEX idx_uuid ON test_uuid USING gin (i);
+SELECT * FROM test_uuid WHERE i<'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ i
+--------------------------------------
+ 00000000-0000-0000-0000-000000000000
+ 299bc99f-2f79-4e3e-bfea-2cbfd62a7c27
+ 6264af33-0d43-4337-bf4e-43509b8a4be8
+(3 rows)
+
+SELECT * FROM test_uuid WHERE i<='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ i
+--------------------------------------
+ 00000000-0000-0000-0000-000000000000
+ 299bc99f-2f79-4e3e-bfea-2cbfd62a7c27
+ 6264af33-0d43-4337-bf4e-43509b8a4be8
+ ce41c936-6acb-4feb-8c91-852a673e5a5c
+(4 rows)
+
+SELECT * FROM test_uuid WHERE i='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ i
+--------------------------------------
+ ce41c936-6acb-4feb-8c91-852a673e5a5c
+(1 row)
+
+SELECT * FROM test_uuid WHERE i>='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ i
+--------------------------------------
+ ce41c936-6acb-4feb-8c91-852a673e5a5c
+ d2ce731f-f2a8-4a2b-be37-8f0ba637427f
+ ffffffff-ffff-ffff-ffff-ffffffffffff
+(3 rows)
+
+SELECT * FROM test_uuid WHERE i>'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ i
+--------------------------------------
+ d2ce731f-f2a8-4a2b-be37-8f0ba637427f
+ ffffffff-ffff-ffff-ffff-ffffffffffff
+(2 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i<'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ QUERY PLAN
+------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_uuid
+ Recheck Cond: (i < 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ -> Bitmap Index Scan on idx_uuid
+ Index Cond: (i < 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+(6 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i<='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ QUERY PLAN
+-------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_uuid
+ Recheck Cond: (i <= 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ -> Bitmap Index Scan on idx_uuid
+ Index Cond: (i <= 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+(6 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ QUERY PLAN
+------------------------------------------------------------------------
+ Bitmap Heap Scan on test_uuid
+ Recheck Cond: (i = 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ -> Bitmap Index Scan on idx_uuid
+ Index Cond: (i = 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+(4 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i>='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ QUERY PLAN
+-------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_uuid
+ Recheck Cond: (i >= 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ -> Bitmap Index Scan on idx_uuid
+ Index Cond: (i >= 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+(6 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i>'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ QUERY PLAN
+------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_uuid
+ Recheck Cond: (i > 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ -> Bitmap Index Scan on idx_uuid
+ Index Cond: (i > 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+(6 rows)
+
diff --git a/contrib/btree_gin/sql/bool.sql b/contrib/btree_gin/sql/bool.sql
new file mode 100644
index 0000000..dad2ff3
--- /dev/null
+++ b/contrib/btree_gin/sql/bool.sql
@@ -0,0 +1,27 @@
+set enable_seqscan=off;
+
+CREATE TABLE test_bool (
+ i boolean
+);
+
+INSERT INTO test_bool VALUES (false),(true),(null);
+
+CREATE INDEX idx_bool ON test_bool USING gin (i);
+
+SELECT * FROM test_bool WHERE i<true ORDER BY i;
+SELECT * FROM test_bool WHERE i<=true ORDER BY i;
+SELECT * FROM test_bool WHERE i=true ORDER BY i;
+SELECT * FROM test_bool WHERE i>=true ORDER BY i;
+SELECT * FROM test_bool WHERE i>true ORDER BY i;
+
+SELECT * FROM test_bool WHERE i<false ORDER BY i;
+SELECT * FROM test_bool WHERE i<=false ORDER BY i;
+SELECT * FROM test_bool WHERE i=false ORDER BY i;
+SELECT * FROM test_bool WHERE i>=false ORDER BY i;
+SELECT * FROM test_bool WHERE i>false ORDER BY i;
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i<true ORDER BY i;
+EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i<=true ORDER BY i;
+EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i=true ORDER BY i;
+EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i>=true ORDER BY i;
+EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i>true ORDER BY i;
diff --git a/contrib/btree_gin/sql/bpchar.sql b/contrib/btree_gin/sql/bpchar.sql
new file mode 100644
index 0000000..4c951e3
--- /dev/null
+++ b/contrib/btree_gin/sql/bpchar.sql
@@ -0,0 +1,22 @@
+set enable_seqscan=off;
+
+CREATE TABLE test_bpchar (
+ i char(10)
+);
+
+INSERT INTO test_bpchar VALUES ('a'),('ab'),('abc'),('abc '),('abb'),('axy'),('xyz'),('xyz ');
+
+CREATE INDEX idx_bpchar ON test_bpchar USING gin (i);
+
+SELECT * FROM test_bpchar WHERE i<'abc' ORDER BY i;
+SELECT * FROM test_bpchar WHERE i<='abc' ORDER BY i;
+SELECT * FROM test_bpchar WHERE i='abc' ORDER BY i;
+SELECT * FROM test_bpchar WHERE i='abc ' ORDER BY i;
+SELECT * FROM test_bpchar WHERE i>='abc' ORDER BY i;
+SELECT * FROM test_bpchar WHERE i>'abc' ORDER BY i;
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i<'abc' ORDER BY i;
+EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i<='abc' ORDER BY i;
+EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i='abc' ORDER BY i;
+EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i>='abc' ORDER BY i;
+EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i>'abc' ORDER BY i;
diff --git a/contrib/btree_gin/sql/name.sql b/contrib/btree_gin/sql/name.sql
new file mode 100644
index 0000000..c11580c
--- /dev/null
+++ b/contrib/btree_gin/sql/name.sql
@@ -0,0 +1,21 @@
+set enable_seqscan=off;
+
+CREATE TABLE test_name (
+ i name
+);
+
+INSERT INTO test_name VALUES ('a'),('ab'),('abc'),('abb'),('axy'),('xyz');
+
+CREATE INDEX idx_name ON test_name USING gin (i);
+
+SELECT * FROM test_name WHERE i<'abc' ORDER BY i;
+SELECT * FROM test_name WHERE i<='abc' ORDER BY i;
+SELECT * FROM test_name WHERE i='abc' ORDER BY i;
+SELECT * FROM test_name WHERE i>='abc' ORDER BY i;
+SELECT * FROM test_name WHERE i>'abc' ORDER BY i;
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i<'abc' ORDER BY i;
+EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i<='abc' ORDER BY i;
+EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i='abc' ORDER BY i;
+EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i>='abc' ORDER BY i;
+EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i>'abc' ORDER BY i;
diff --git a/contrib/btree_gin/sql/uuid.sql b/contrib/btree_gin/sql/uuid.sql
new file mode 100644
index 0000000..3c141bd
--- /dev/null
+++ b/contrib/btree_gin/sql/uuid.sql
@@ -0,0 +1,28 @@
+set enable_seqscan=off;
+
+CREATE TABLE test_uuid (
+ i uuid
+);
+
+INSERT INTO test_uuid VALUES
+ ( '00000000-0000-0000-0000-000000000000' ),
+ ( '299bc99f-2f79-4e3e-bfea-2cbfd62a7c27' ),
+ ( '6264af33-0d43-4337-bf4e-43509b8a4be8' ),
+ ( 'ce41c936-6acb-4feb-8c91-852a673e5a5c' ),
+ ( 'd2ce731f-f2a8-4a2b-be37-8f0ba637427f' ),
+ ( 'ffffffff-ffff-ffff-ffff-ffffffffffff' )
+;
+
+CREATE INDEX idx_uuid ON test_uuid USING gin (i);
+
+SELECT * FROM test_uuid WHERE i<'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+SELECT * FROM test_uuid WHERE i<='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+SELECT * FROM test_uuid WHERE i='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+SELECT * FROM test_uuid WHERE i>='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+SELECT * FROM test_uuid WHERE i>'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i<'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i<='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i>='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i>'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
diff --git a/doc/src/sgml/btree-gin.sgml b/doc/src/sgml/btree-gin.sgml
index e491fa7..314e001 100644
--- a/doc/src/sgml/btree-gin.sgml
+++ b/doc/src/sgml/btree-gin.sgml
@@ -17,7 +17,8 @@
<type>oid</type>, <type>money</type>, <type>"char"</type>,
<type>varchar</type>, <type>text</type>, <type>bytea</type>, <type>bit</type>,
<type>varbit</type>, <type>macaddr</type>, <type>macaddr8</type>, <type>inet</type>,
- <type>cidr</type>, and all <type>enum</type> types.
+ <type>cidr</type>, <type>uuid</type>, <type>name</type>, <type>bool</type>,
+ <type>bpchar</type>, and all <type>enum</type> types.
</para>
<para>
--
2.9.5
0002-Add-support-for-anyrange-to-btree_gin-v3.patchtext/x-patch; name=0002-Add-support-for-anyrange-to-btree_gin-v3.patchDownload
From 2d1e75c80096b97397ffa14ca2d24a3eda59d90b Mon Sep 17 00:00:00 2001
From: Tomas Vondra <tomas@2ndquadrant.com>
Date: Thu, 5 Apr 2018 14:06:29 +0200
Subject: [PATCH 2/2] Add support for anyrange to btree_gin
---
contrib/btree_gin/Makefile | 2 +-
contrib/btree_gin/btree_gin--1.2--1.3.sql | 36 ++++++++++
contrib/btree_gin/btree_gin.c | 52 ++++++++++++++
contrib/btree_gin/expected/anyrange.out | 113 ++++++++++++++++++++++++++++++
contrib/btree_gin/sql/anyrange.sql | 31 ++++++++
doc/src/sgml/btree-gin.sgml | 2 +-
6 files changed, 234 insertions(+), 2 deletions(-)
create mode 100644 contrib/btree_gin/expected/anyrange.out
create mode 100644 contrib/btree_gin/sql/anyrange.sql
diff --git a/contrib/btree_gin/Makefile b/contrib/btree_gin/Makefile
index a9e9925..d36f5ad 100644
--- a/contrib/btree_gin/Makefile
+++ b/contrib/btree_gin/Makefile
@@ -11,7 +11,7 @@ PGFILEDESC = "btree_gin - B-tree equivalent GIN operator classes"
REGRESS = install_btree_gin int2 int4 int8 float4 float8 money oid \
timestamp timestamptz time timetz date interval \
macaddr macaddr8 inet cidr text varchar char bytea bit varbit \
- numeric enum uuid name bool bpchar
+ numeric enum uuid name bool anyrange bpchar
ifdef USE_PGXS
PG_CONFIG = pg_config
diff --git a/contrib/btree_gin/btree_gin--1.2--1.3.sql b/contrib/btree_gin/btree_gin--1.2--1.3.sql
index db675b7..f7523a3 100644
--- a/contrib/btree_gin/btree_gin--1.2--1.3.sql
+++ b/contrib/btree_gin/btree_gin--1.2--1.3.sql
@@ -96,6 +96,42 @@ AS
FUNCTION 5 gin_compare_prefix_bool(bool,bool,int2, internal),
STORAGE bool;
+-- anyrange datatype support new in 1.3.
+CREATE FUNCTION gin_anyrange_cmp(anyrange, anyrange)
+RETURNS int4
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT IMMUTABLE;
+
+CREATE FUNCTION gin_extract_value_anyrange(anyrange, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT IMMUTABLE;
+
+CREATE FUNCTION gin_compare_prefix_anyrange(anyrange, anyrange, int2, internal)
+RETURNS int4
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT IMMUTABLE;
+
+CREATE FUNCTION gin_extract_query_anyrange(anyrange, internal, int2, internal, internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT IMMUTABLE;
+
+CREATE OPERATOR CLASS anyrange_ops
+DEFAULT FOR TYPE anyrange USING gin
+AS
+ OPERATOR 1 <,
+ OPERATOR 2 <=,
+ OPERATOR 3 =,
+ OPERATOR 4 >=,
+ OPERATOR 5 >,
+ FUNCTION 1 gin_anyrange_cmp(anyrange,anyrange),
+ FUNCTION 2 gin_extract_value_anyrange(anyrange, internal),
+ FUNCTION 3 gin_extract_query_anyrange(anyrange, internal, int2, internal, internal),
+ FUNCTION 4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
+ FUNCTION 5 gin_compare_prefix_anyrange(anyrange,anyrange,int2, internal),
+STORAGE anyrange;
+
-- bpchar datatype support new in 1.3.
CREATE FUNCTION gin_extract_value_bpchar(bpchar, internal)
RETURNS internal
diff --git a/contrib/btree_gin/btree_gin.c b/contrib/btree_gin/btree_gin.c
index a660681..37e0740 100644
--- a/contrib/btree_gin/btree_gin.c
+++ b/contrib/btree_gin/btree_gin.c
@@ -15,6 +15,7 @@
#include "utils/timestamp.h"
#include "utils/varbit.h"
#include "utils/uuid.h"
+#include "utils/rangetypes.h"
PG_MODULE_MAGIC;
@@ -506,3 +507,54 @@ leftmostvalue_bool(void)
}
GIN_SUPPORT(bool, false, leftmostvalue_bool, btboolcmp)
+
+/*
+ * Similarly to Numeric, we don't know the left-most value, although for
+ * different reasons (numeric does not have one, while for anyarray we
+ * don't even know the concrete type). We could try to build a fake empty
+ * range, but we simply use PointerGetDatum(NULL) just like for Numeric.
+ */
+#define ANYRANGE_IS_LEFTMOST(x) ((x) == NULL)
+
+PG_FUNCTION_INFO_V1(gin_anyrange_cmp);
+
+/*
+ * Note that we use CallerFInfoFunctionCall2 here so that range_cmp
+ * gets a valid fn_extra to work with. Unlike most other type comparison
+ * routines it needs it, so we can't use DirectFunctionCall2.
+ */
+Datum
+gin_anyrange_cmp(PG_FUNCTION_ARGS)
+{
+ RangeType *a = (RangeType *) PG_GETARG_POINTER(0);
+ RangeType *b = (RangeType *) PG_GETARG_POINTER(1);
+ int res = 0;
+
+ if (ANYRANGE_IS_LEFTMOST(a))
+ {
+ res = (ANYRANGE_IS_LEFTMOST(b)) ? 0 : -1;
+ }
+ else if (ANYRANGE_IS_LEFTMOST(b))
+ {
+ res = 1;
+ }
+ else
+ {
+ res = DatumGetInt32(CallerFInfoFunctionCall2(
+ range_cmp,
+ fcinfo->flinfo,
+ PG_GET_COLLATION(),
+ RangeTypePGetDatum(a),
+ RangeTypePGetDatum(b)));
+ }
+
+ PG_RETURN_INT32(res);
+}
+
+static Datum
+leftmostvalue_anyrange(void)
+{
+ return PointerGetDatum(NULL);
+}
+
+GIN_SUPPORT(anyrange, false, leftmostvalue_anyrange, gin_anyrange_cmp)
diff --git a/contrib/btree_gin/expected/anyrange.out b/contrib/btree_gin/expected/anyrange.out
new file mode 100644
index 0000000..93b24f4
--- /dev/null
+++ b/contrib/btree_gin/expected/anyrange.out
@@ -0,0 +1,113 @@
+set enable_seqscan=off;
+CREATE TABLE test_tsrange (
+ i tsrange
+);
+INSERT INTO test_tsrange VALUES
+ ( 'empty' ),
+ ( '(,)' ),
+ ( '[2018-02-02 03:55:08,2018-04-02 03:55:08)' ),
+ ( '[2018-02-02 04:55:08,2018-04-02 04:55:08)' ),
+ ( '[2018-02-02 05:55:08,2018-04-02 05:55:08)' ),
+ ( '[2018-02-02 08:55:08,2018-04-02 08:55:08)' ),
+ ( '[2018-02-02 09:55:08,2018-04-02 09:55:08)' ),
+ ( '[2018-02-02 10:55:08,2018-04-02 10:55:08)' ),
+ ( '[infinity,infinity]' )
+;
+CREATE INDEX idx_tsrange ON test_tsrange USING gin (i);
+SELECT * FROM test_tsrange WHERE i<'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ i
+---------------------------------------------------------
+ empty
+ (,)
+ ["Fri Feb 02 03:55:08 2018","Mon Apr 02 03:55:08 2018")
+ ["Fri Feb 02 04:55:08 2018","Mon Apr 02 04:55:08 2018")
+ ["Fri Feb 02 05:55:08 2018","Mon Apr 02 05:55:08 2018")
+(5 rows)
+
+SELECT * FROM test_tsrange WHERE i<='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ i
+---------------------------------------------------------
+ empty
+ (,)
+ ["Fri Feb 02 03:55:08 2018","Mon Apr 02 03:55:08 2018")
+ ["Fri Feb 02 04:55:08 2018","Mon Apr 02 04:55:08 2018")
+ ["Fri Feb 02 05:55:08 2018","Mon Apr 02 05:55:08 2018")
+ ["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")
+(6 rows)
+
+SELECT * FROM test_tsrange WHERE i='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ i
+---------------------------------------------------------
+ ["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")
+(1 row)
+
+SELECT * FROM test_tsrange WHERE i>='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ i
+---------------------------------------------------------
+ ["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")
+ ["Fri Feb 02 09:55:08 2018","Mon Apr 02 09:55:08 2018")
+ ["Fri Feb 02 10:55:08 2018","Mon Apr 02 10:55:08 2018")
+ [infinity,infinity]
+(4 rows)
+
+SELECT * FROM test_tsrange WHERE i>'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ i
+---------------------------------------------------------
+ ["Fri Feb 02 09:55:08 2018","Mon Apr 02 09:55:08 2018")
+ ["Fri Feb 02 10:55:08 2018","Mon Apr 02 10:55:08 2018")
+ [infinity,infinity]
+(3 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i<'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ QUERY PLAN
+----------------------------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_tsrange
+ Recheck Cond: (i < '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ -> Bitmap Index Scan on idx_tsrange
+ Index Cond: (i < '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+(6 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i<='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ QUERY PLAN
+-----------------------------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_tsrange
+ Recheck Cond: (i <= '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ -> Bitmap Index Scan on idx_tsrange
+ Index Cond: (i <= '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+(6 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ QUERY PLAN
+----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on test_tsrange
+ Recheck Cond: (i = '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ -> Bitmap Index Scan on idx_tsrange
+ Index Cond: (i = '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+(4 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i>='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ QUERY PLAN
+-----------------------------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_tsrange
+ Recheck Cond: (i >= '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ -> Bitmap Index Scan on idx_tsrange
+ Index Cond: (i >= '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+(6 rows)
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i>'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ QUERY PLAN
+----------------------------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_tsrange
+ Recheck Cond: (i > '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ -> Bitmap Index Scan on idx_tsrange
+ Index Cond: (i > '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+(6 rows)
+
diff --git a/contrib/btree_gin/sql/anyrange.sql b/contrib/btree_gin/sql/anyrange.sql
new file mode 100644
index 0000000..97157ad
--- /dev/null
+++ b/contrib/btree_gin/sql/anyrange.sql
@@ -0,0 +1,31 @@
+set enable_seqscan=off;
+
+CREATE TABLE test_tsrange (
+ i tsrange
+);
+
+INSERT INTO test_tsrange VALUES
+ ( 'empty' ),
+ ( '(,)' ),
+ ( '[2018-02-02 03:55:08,2018-04-02 03:55:08)' ),
+ ( '[2018-02-02 04:55:08,2018-04-02 04:55:08)' ),
+ ( '[2018-02-02 05:55:08,2018-04-02 05:55:08)' ),
+ ( '[2018-02-02 08:55:08,2018-04-02 08:55:08)' ),
+ ( '[2018-02-02 09:55:08,2018-04-02 09:55:08)' ),
+ ( '[2018-02-02 10:55:08,2018-04-02 10:55:08)' ),
+ ( '[infinity,infinity]' )
+;
+
+CREATE INDEX idx_tsrange ON test_tsrange USING gin (i);
+
+SELECT * FROM test_tsrange WHERE i<'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+SELECT * FROM test_tsrange WHERE i<='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+SELECT * FROM test_tsrange WHERE i='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+SELECT * FROM test_tsrange WHERE i>='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+SELECT * FROM test_tsrange WHERE i>'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+
+EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i<'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i<='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i>='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i>'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
diff --git a/doc/src/sgml/btree-gin.sgml b/doc/src/sgml/btree-gin.sgml
index 314e001..e1315da 100644
--- a/doc/src/sgml/btree-gin.sgml
+++ b/doc/src/sgml/btree-gin.sgml
@@ -18,7 +18,7 @@
<type>varchar</type>, <type>text</type>, <type>bytea</type>, <type>bit</type>,
<type>varbit</type>, <type>macaddr</type>, <type>macaddr8</type>, <type>inet</type>,
<type>cidr</type>, <type>uuid</type>, <type>name</type>, <type>bool</type>,
- <type>bpchar</type>, and all <type>enum</type> types.
+ <type>bpchar</type>, and all <type>enum</type> and <type>anyrange</type> types.
</para>
<para>
--
2.9.5
On Thu, Apr 5, 2018 at 8:16 AM, Teodor Sigaev <teodor@sigaev.ru> wrote:
somehow you missed some parts in 0001 patch, at least regression tests
fail:CREATE EXTENSION btree_gin;
+ ERROR: could not find function "gin_extract_value_uuid" in file
"/usr/local/pgsql/lib/btree_gin.so"
Ouch... My fault, filterdiff is acting weird for some reason...
Here is the corrected versions... I tested here applying on a clean master
just to be sure, all looks good.
Very sorry about that mess. I hope it can get in v11, it is a patch so
simple, but so useful for many people.
Best regards,
--
Matheus de Oliveira
Attachments:
0001-btree_gin-uuid--base.v2.patchtext/x-patch; charset=US-ASCII; name=0001-btree_gin-uuid--base.v2.patchDownload
diff --git a/contrib/btree_gin/Makefile b/contrib/btree_gin/Makefile
new file mode 100644
index 690e1d7..a9e9925
*** a/contrib/btree_gin/Makefile
--- b/contrib/btree_gin/Makefile
*************** OBJS = btree_gin.o $(WIN32RES)
*** 5,17 ****
EXTENSION = btree_gin
DATA = btree_gin--1.0.sql btree_gin--1.0--1.1.sql btree_gin--1.1--1.2.sql \
! btree_gin--unpackaged--1.0.sql
PGFILEDESC = "btree_gin - B-tree equivalent GIN operator classes"
REGRESS = install_btree_gin int2 int4 int8 float4 float8 money oid \
timestamp timestamptz time timetz date interval \
macaddr macaddr8 inet cidr text varchar char bytea bit varbit \
! numeric enum
ifdef USE_PGXS
PG_CONFIG = pg_config
--- 5,17 ----
EXTENSION = btree_gin
DATA = btree_gin--1.0.sql btree_gin--1.0--1.1.sql btree_gin--1.1--1.2.sql \
! btree_gin--1.2--1.3.sql btree_gin--unpackaged--1.0.sql
PGFILEDESC = "btree_gin - B-tree equivalent GIN operator classes"
REGRESS = install_btree_gin int2 int4 int8 float4 float8 money oid \
timestamp timestamptz time timetz date interval \
macaddr macaddr8 inet cidr text varchar char bytea bit varbit \
! numeric enum uuid name bool bpchar
ifdef USE_PGXS
PG_CONFIG = pg_config
diff --git a/contrib/btree_gin/btree_gin--1.2--1.3.sql b/contrib/btree_gin/btree_gin--1.2--1.3.sql
new file mode 100644
index ...db675b7
*** a/contrib/btree_gin/btree_gin--1.2--1.3.sql
--- b/contrib/btree_gin/btree_gin--1.2--1.3.sql
***************
*** 0 ****
--- 1,128 ----
+ /* contrib/btree_gin/btree_gin--1.2--1.3.sql */
+
+ -- complain if script is sourced in psql, rather than via CREATE EXTENSION
+ \echo Use "ALTER EXTENSION btree_gin UPDATE TO '1.3'" to load this file. \quit
+
+ -- uuid datatype support new in 1.3.
+ CREATE FUNCTION gin_extract_value_uuid(uuid, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_compare_prefix_uuid(uuid, uuid, int2, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_extract_query_uuid(uuid, internal, int2, internal, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE OPERATOR CLASS uuid_ops
+ DEFAULT FOR TYPE uuid USING gin
+ AS
+ OPERATOR 1 <,
+ OPERATOR 2 <=,
+ OPERATOR 3 =,
+ OPERATOR 4 >=,
+ OPERATOR 5 >,
+ FUNCTION 1 uuid_cmp(uuid,uuid),
+ FUNCTION 2 gin_extract_value_uuid(uuid, internal),
+ FUNCTION 3 gin_extract_query_uuid(uuid, internal, int2, internal, internal),
+ FUNCTION 4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
+ FUNCTION 5 gin_compare_prefix_uuid(uuid,uuid,int2, internal),
+ STORAGE uuid;
+
+ -- name datatype support new in 1.3.
+ CREATE FUNCTION gin_extract_value_name(name, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_compare_prefix_name(name, name, int2, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_extract_query_name(name, internal, int2, internal, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE OPERATOR CLASS name_ops
+ DEFAULT FOR TYPE name USING gin
+ AS
+ OPERATOR 1 <,
+ OPERATOR 2 <=,
+ OPERATOR 3 =,
+ OPERATOR 4 >=,
+ OPERATOR 5 >,
+ FUNCTION 1 btnamecmp(name,name),
+ FUNCTION 2 gin_extract_value_name(name, internal),
+ FUNCTION 3 gin_extract_query_name(name, internal, int2, internal, internal),
+ FUNCTION 4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
+ FUNCTION 5 gin_compare_prefix_name(name,name,int2, internal),
+ STORAGE name;
+
+ -- bool datatype support new in 1.3.
+ CREATE FUNCTION gin_extract_value_bool(bool, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_compare_prefix_bool(bool, bool, int2, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_extract_query_bool(bool, internal, int2, internal, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE OPERATOR CLASS bool_ops
+ DEFAULT FOR TYPE bool USING gin
+ AS
+ OPERATOR 1 <,
+ OPERATOR 2 <=,
+ OPERATOR 3 =,
+ OPERATOR 4 >=,
+ OPERATOR 5 >,
+ FUNCTION 1 btboolcmp(bool,bool),
+ FUNCTION 2 gin_extract_value_bool(bool, internal),
+ FUNCTION 3 gin_extract_query_bool(bool, internal, int2, internal, internal),
+ FUNCTION 4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
+ FUNCTION 5 gin_compare_prefix_bool(bool,bool,int2, internal),
+ STORAGE bool;
+
+ -- bpchar datatype support new in 1.3.
+ CREATE FUNCTION gin_extract_value_bpchar(bpchar, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_compare_prefix_bpchar(bpchar, bpchar, int2, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_extract_query_bpchar(bpchar, internal, int2, internal, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE OPERATOR CLASS bpchar_ops
+ DEFAULT FOR TYPE bpchar USING gin
+ AS
+ OPERATOR 1 <,
+ OPERATOR 2 <=,
+ OPERATOR 3 =,
+ OPERATOR 4 >=,
+ OPERATOR 5 >,
+ FUNCTION 1 bpcharcmp(bpchar, bpchar),
+ FUNCTION 2 gin_extract_value_bpchar(bpchar, internal),
+ FUNCTION 3 gin_extract_query_bpchar(bpchar, internal, int2, internal, internal),
+ FUNCTION 4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
+ FUNCTION 5 gin_compare_prefix_bpchar(bpchar,bpchar,int2, internal),
+ STORAGE bpchar;
diff --git a/contrib/btree_gin/btree_gin.c b/contrib/btree_gin/btree_gin.c
new file mode 100644
index 2473f79..a660681
*** a/contrib/btree_gin/btree_gin.c
--- b/contrib/btree_gin/btree_gin.c
***************
*** 14,19 ****
--- 14,20 ----
#include "utils/numeric.h"
#include "utils/timestamp.h"
#include "utils/varbit.h"
+ #include "utils/uuid.h"
PG_MODULE_MAGIC;
*************** leftmostvalue_text(void)
*** 350,355 ****
--- 351,358 ----
GIN_SUPPORT(text, true, leftmostvalue_text, bttextcmp)
+ GIN_SUPPORT(bpchar, true, leftmostvalue_text, bpcharcmp)
+
static Datum
leftmostvalue_char(void)
{
*************** GIN_SUPPORT(numeric, true, leftmostvalue
*** 437,443 ****
* routines it needs it, so we can't use DirectFunctionCall2.
*/
-
#define ENUM_IS_LEFTMOST(x) ((x) == InvalidOid)
PG_FUNCTION_INFO_V1(gin_enum_cmp);
--- 440,445 ----
*************** leftmostvalue_enum(void)
*** 477,479 ****
--- 479,508 ----
}
GIN_SUPPORT(anyenum, false, leftmostvalue_enum, gin_enum_cmp)
+
+ static Datum
+ leftmostvalue_uuid(void)
+ {
+ /* palloc0 will create the UUID with all zeroes: "00000000-0000-0000-0000-000000000000" */
+ pg_uuid_t *retval = (pg_uuid_t *) palloc0(sizeof(pg_uuid_t));
+ return UUIDPGetDatum(retval);
+ }
+
+ GIN_SUPPORT(uuid, false, leftmostvalue_uuid, uuid_cmp)
+
+ static Datum
+ leftmostvalue_name(void)
+ {
+ NameData* result = (NameData *) palloc0(NAMEDATALEN);
+ return NameGetDatum(result);
+ }
+
+ GIN_SUPPORT(name, false, leftmostvalue_name, btnamecmp)
+
+ static Datum
+ leftmostvalue_bool(void)
+ {
+ return BoolGetDatum(false);
+ }
+
+ GIN_SUPPORT(bool, false, leftmostvalue_bool, btboolcmp)
diff --git a/contrib/btree_gin/btree_gin.control b/contrib/btree_gin/btree_gin.control
new file mode 100644
index 3acc5af..d576da7
*** a/contrib/btree_gin/btree_gin.control
--- b/contrib/btree_gin/btree_gin.control
***************
*** 1,5 ****
# btree_gin extension
comment = 'support for indexing common datatypes in GIN'
! default_version = '1.2'
module_pathname = '$libdir/btree_gin'
relocatable = true
--- 1,5 ----
# btree_gin extension
comment = 'support for indexing common datatypes in GIN'
! default_version = '1.3'
module_pathname = '$libdir/btree_gin'
relocatable = true
diff --git a/contrib/btree_gin/expected/bool.out b/contrib/btree_gin/expected/bool.out
new file mode 100644
index ...efb3e1e
*** a/contrib/btree_gin/expected/bool.out
--- b/contrib/btree_gin/expected/bool.out
***************
*** 0 ****
--- 1,119 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_bool (
+ i boolean
+ );
+ INSERT INTO test_bool VALUES (false),(true),(null);
+ CREATE INDEX idx_bool ON test_bool USING gin (i);
+ SELECT * FROM test_bool WHERE i<true ORDER BY i;
+ i
+ ---
+ f
+ (1 row)
+
+ SELECT * FROM test_bool WHERE i<=true ORDER BY i;
+ i
+ ---
+ f
+ t
+ (2 rows)
+
+ SELECT * FROM test_bool WHERE i=true ORDER BY i;
+ i
+ ---
+ t
+ (1 row)
+
+ SELECT * FROM test_bool WHERE i>=true ORDER BY i;
+ i
+ ---
+ t
+ (1 row)
+
+ SELECT * FROM test_bool WHERE i>true ORDER BY i;
+ i
+ ---
+ (0 rows)
+
+ SELECT * FROM test_bool WHERE i<false ORDER BY i;
+ i
+ ---
+ (0 rows)
+
+ SELECT * FROM test_bool WHERE i<=false ORDER BY i;
+ i
+ ---
+ f
+ (1 row)
+
+ SELECT * FROM test_bool WHERE i=false ORDER BY i;
+ i
+ ---
+ f
+ (1 row)
+
+ SELECT * FROM test_bool WHERE i>=false ORDER BY i;
+ i
+ ---
+ f
+ t
+ (2 rows)
+
+ SELECT * FROM test_bool WHERE i>false ORDER BY i;
+ i
+ ---
+ t
+ (1 row)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i<true ORDER BY i;
+ QUERY PLAN
+ -------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bool
+ Recheck Cond: (i < true)
+ -> Bitmap Index Scan on idx_bool
+ Index Cond: (i < true)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i<=true ORDER BY i;
+ QUERY PLAN
+ -------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bool
+ Recheck Cond: (i <= true)
+ -> Bitmap Index Scan on idx_bool
+ Index Cond: (i <= true)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i=true ORDER BY i;
+ QUERY PLAN
+ -----------------------------
+ Sort
+ Sort Key: i
+ -> Seq Scan on test_bool
+ Filter: i
+ (4 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i>=true ORDER BY i;
+ QUERY PLAN
+ -------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bool
+ Recheck Cond: (i >= true)
+ -> Bitmap Index Scan on idx_bool
+ Index Cond: (i >= true)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i>true ORDER BY i;
+ QUERY PLAN
+ -------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bool
+ Recheck Cond: (i > true)
+ -> Bitmap Index Scan on idx_bool
+ Index Cond: (i > true)
+ (6 rows)
+
diff --git a/contrib/btree_gin/expected/bpchar.out b/contrib/btree_gin/expected/bpchar.out
new file mode 100644
index ...2eb8855
*** a/contrib/btree_gin/expected/bpchar.out
--- b/contrib/btree_gin/expected/bpchar.out
***************
*** 0 ****
--- 1,109 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_bpchar (
+ i char(10)
+ );
+ INSERT INTO test_bpchar VALUES ('a'),('ab'),('abc'),('abc '),('abb'),('axy'),('xyz'),('xyz ');
+ CREATE INDEX idx_bpchar ON test_bpchar USING gin (i);
+ SELECT * FROM test_bpchar WHERE i<'abc' ORDER BY i;
+ i
+ ------------
+ a
+ ab
+ abb
+ (3 rows)
+
+ SELECT * FROM test_bpchar WHERE i<='abc' ORDER BY i;
+ i
+ ------------
+ a
+ ab
+ abb
+ abc
+ abc
+ (5 rows)
+
+ SELECT * FROM test_bpchar WHERE i='abc' ORDER BY i;
+ i
+ ------------
+ abc
+ abc
+ (2 rows)
+
+ SELECT * FROM test_bpchar WHERE i='abc ' ORDER BY i;
+ i
+ ------------
+ abc
+ abc
+ (2 rows)
+
+ SELECT * FROM test_bpchar WHERE i>='abc' ORDER BY i;
+ i
+ ------------
+ abc
+ abc
+ axy
+ xyz
+ xyz
+ (5 rows)
+
+ SELECT * FROM test_bpchar WHERE i>'abc' ORDER BY i;
+ i
+ ------------
+ axy
+ xyz
+ xyz
+ (3 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i<'abc' ORDER BY i;
+ QUERY PLAN
+ -----------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bpchar
+ Recheck Cond: (i < 'abc'::bpchar)
+ -> Bitmap Index Scan on idx_bpchar
+ Index Cond: (i < 'abc'::bpchar)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i<='abc' ORDER BY i;
+ QUERY PLAN
+ ------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bpchar
+ Recheck Cond: (i <= 'abc'::bpchar)
+ -> Bitmap Index Scan on idx_bpchar
+ Index Cond: (i <= 'abc'::bpchar)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i='abc' ORDER BY i;
+ QUERY PLAN
+ -----------------------------------------
+ Bitmap Heap Scan on test_bpchar
+ Recheck Cond: (i = 'abc'::bpchar)
+ -> Bitmap Index Scan on idx_bpchar
+ Index Cond: (i = 'abc'::bpchar)
+ (4 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i>='abc' ORDER BY i;
+ QUERY PLAN
+ ------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bpchar
+ Recheck Cond: (i >= 'abc'::bpchar)
+ -> Bitmap Index Scan on idx_bpchar
+ Index Cond: (i >= 'abc'::bpchar)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i>'abc' ORDER BY i;
+ QUERY PLAN
+ -----------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_bpchar
+ Recheck Cond: (i > 'abc'::bpchar)
+ -> Bitmap Index Scan on idx_bpchar
+ Index Cond: (i > 'abc'::bpchar)
+ (6 rows)
+
diff --git a/contrib/btree_gin/expected/name.out b/contrib/btree_gin/expected/name.out
new file mode 100644
index ...174de65
*** a/contrib/btree_gin/expected/name.out
--- b/contrib/btree_gin/expected/name.out
***************
*** 0 ****
--- 1,97 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_name (
+ i name
+ );
+ INSERT INTO test_name VALUES ('a'),('ab'),('abc'),('abb'),('axy'),('xyz');
+ CREATE INDEX idx_name ON test_name USING gin (i);
+ SELECT * FROM test_name WHERE i<'abc' ORDER BY i;
+ i
+ -----
+ a
+ ab
+ abb
+ (3 rows)
+
+ SELECT * FROM test_name WHERE i<='abc' ORDER BY i;
+ i
+ -----
+ a
+ ab
+ abb
+ abc
+ (4 rows)
+
+ SELECT * FROM test_name WHERE i='abc' ORDER BY i;
+ i
+ -----
+ abc
+ (1 row)
+
+ SELECT * FROM test_name WHERE i>='abc' ORDER BY i;
+ i
+ -----
+ abc
+ axy
+ xyz
+ (3 rows)
+
+ SELECT * FROM test_name WHERE i>'abc' ORDER BY i;
+ i
+ -----
+ axy
+ xyz
+ (2 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i<'abc' ORDER BY i;
+ QUERY PLAN
+ ---------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_name
+ Recheck Cond: (i < 'abc'::name)
+ -> Bitmap Index Scan on idx_name
+ Index Cond: (i < 'abc'::name)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i<='abc' ORDER BY i;
+ QUERY PLAN
+ ----------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_name
+ Recheck Cond: (i <= 'abc'::name)
+ -> Bitmap Index Scan on idx_name
+ Index Cond: (i <= 'abc'::name)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i='abc' ORDER BY i;
+ QUERY PLAN
+ ---------------------------------------
+ Bitmap Heap Scan on test_name
+ Recheck Cond: (i = 'abc'::name)
+ -> Bitmap Index Scan on idx_name
+ Index Cond: (i = 'abc'::name)
+ (4 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i>='abc' ORDER BY i;
+ QUERY PLAN
+ ----------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_name
+ Recheck Cond: (i >= 'abc'::name)
+ -> Bitmap Index Scan on idx_name
+ Index Cond: (i >= 'abc'::name)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i>'abc' ORDER BY i;
+ QUERY PLAN
+ ---------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_name
+ Recheck Cond: (i > 'abc'::name)
+ -> Bitmap Index Scan on idx_name
+ Index Cond: (i > 'abc'::name)
+ (6 rows)
+
diff --git a/contrib/btree_gin/expected/uuid.out b/contrib/btree_gin/expected/uuid.out
new file mode 100644
index ...60fd8d6
*** a/contrib/btree_gin/expected/uuid.out
--- b/contrib/btree_gin/expected/uuid.out
***************
*** 0 ****
--- 1,104 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_uuid (
+ i uuid
+ );
+ INSERT INTO test_uuid VALUES
+ ( '00000000-0000-0000-0000-000000000000' ),
+ ( '299bc99f-2f79-4e3e-bfea-2cbfd62a7c27' ),
+ ( '6264af33-0d43-4337-bf4e-43509b8a4be8' ),
+ ( 'ce41c936-6acb-4feb-8c91-852a673e5a5c' ),
+ ( 'd2ce731f-f2a8-4a2b-be37-8f0ba637427f' ),
+ ( 'ffffffff-ffff-ffff-ffff-ffffffffffff' )
+ ;
+ CREATE INDEX idx_uuid ON test_uuid USING gin (i);
+ SELECT * FROM test_uuid WHERE i<'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ i
+ --------------------------------------
+ 00000000-0000-0000-0000-000000000000
+ 299bc99f-2f79-4e3e-bfea-2cbfd62a7c27
+ 6264af33-0d43-4337-bf4e-43509b8a4be8
+ (3 rows)
+
+ SELECT * FROM test_uuid WHERE i<='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ i
+ --------------------------------------
+ 00000000-0000-0000-0000-000000000000
+ 299bc99f-2f79-4e3e-bfea-2cbfd62a7c27
+ 6264af33-0d43-4337-bf4e-43509b8a4be8
+ ce41c936-6acb-4feb-8c91-852a673e5a5c
+ (4 rows)
+
+ SELECT * FROM test_uuid WHERE i='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ i
+ --------------------------------------
+ ce41c936-6acb-4feb-8c91-852a673e5a5c
+ (1 row)
+
+ SELECT * FROM test_uuid WHERE i>='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ i
+ --------------------------------------
+ ce41c936-6acb-4feb-8c91-852a673e5a5c
+ d2ce731f-f2a8-4a2b-be37-8f0ba637427f
+ ffffffff-ffff-ffff-ffff-ffffffffffff
+ (3 rows)
+
+ SELECT * FROM test_uuid WHERE i>'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ i
+ --------------------------------------
+ d2ce731f-f2a8-4a2b-be37-8f0ba637427f
+ ffffffff-ffff-ffff-ffff-ffffffffffff
+ (2 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i<'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ QUERY PLAN
+ ------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_uuid
+ Recheck Cond: (i < 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ -> Bitmap Index Scan on idx_uuid
+ Index Cond: (i < 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i<='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ QUERY PLAN
+ -------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_uuid
+ Recheck Cond: (i <= 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ -> Bitmap Index Scan on idx_uuid
+ Index Cond: (i <= 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ QUERY PLAN
+ ------------------------------------------------------------------------
+ Bitmap Heap Scan on test_uuid
+ Recheck Cond: (i = 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ -> Bitmap Index Scan on idx_uuid
+ Index Cond: (i = 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ (4 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i>='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ QUERY PLAN
+ -------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_uuid
+ Recheck Cond: (i >= 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ -> Bitmap Index Scan on idx_uuid
+ Index Cond: (i >= 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i>'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ QUERY PLAN
+ ------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_uuid
+ Recheck Cond: (i > 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ -> Bitmap Index Scan on idx_uuid
+ Index Cond: (i > 'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid)
+ (6 rows)
+
diff --git a/contrib/btree_gin/sql/bool.sql b/contrib/btree_gin/sql/bool.sql
new file mode 100644
index ...dad2ff3
*** a/contrib/btree_gin/sql/bool.sql
--- b/contrib/btree_gin/sql/bool.sql
***************
*** 0 ****
--- 1,27 ----
+ set enable_seqscan=off;
+
+ CREATE TABLE test_bool (
+ i boolean
+ );
+
+ INSERT INTO test_bool VALUES (false),(true),(null);
+
+ CREATE INDEX idx_bool ON test_bool USING gin (i);
+
+ SELECT * FROM test_bool WHERE i<true ORDER BY i;
+ SELECT * FROM test_bool WHERE i<=true ORDER BY i;
+ SELECT * FROM test_bool WHERE i=true ORDER BY i;
+ SELECT * FROM test_bool WHERE i>=true ORDER BY i;
+ SELECT * FROM test_bool WHERE i>true ORDER BY i;
+
+ SELECT * FROM test_bool WHERE i<false ORDER BY i;
+ SELECT * FROM test_bool WHERE i<=false ORDER BY i;
+ SELECT * FROM test_bool WHERE i=false ORDER BY i;
+ SELECT * FROM test_bool WHERE i>=false ORDER BY i;
+ SELECT * FROM test_bool WHERE i>false ORDER BY i;
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i<true ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i<=true ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i=true ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i>=true ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i>true ORDER BY i;
diff --git a/contrib/btree_gin/sql/bpchar.sql b/contrib/btree_gin/sql/bpchar.sql
new file mode 100644
index ...4c951e3
*** a/contrib/btree_gin/sql/bpchar.sql
--- b/contrib/btree_gin/sql/bpchar.sql
***************
*** 0 ****
--- 1,22 ----
+ set enable_seqscan=off;
+
+ CREATE TABLE test_bpchar (
+ i char(10)
+ );
+
+ INSERT INTO test_bpchar VALUES ('a'),('ab'),('abc'),('abc '),('abb'),('axy'),('xyz'),('xyz ');
+
+ CREATE INDEX idx_bpchar ON test_bpchar USING gin (i);
+
+ SELECT * FROM test_bpchar WHERE i<'abc' ORDER BY i;
+ SELECT * FROM test_bpchar WHERE i<='abc' ORDER BY i;
+ SELECT * FROM test_bpchar WHERE i='abc' ORDER BY i;
+ SELECT * FROM test_bpchar WHERE i='abc ' ORDER BY i;
+ SELECT * FROM test_bpchar WHERE i>='abc' ORDER BY i;
+ SELECT * FROM test_bpchar WHERE i>'abc' ORDER BY i;
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i<'abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i<='abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i='abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i>='abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_bpchar WHERE i>'abc' ORDER BY i;
diff --git a/contrib/btree_gin/sql/name.sql b/contrib/btree_gin/sql/name.sql
new file mode 100644
index ...c11580c
*** a/contrib/btree_gin/sql/name.sql
--- b/contrib/btree_gin/sql/name.sql
***************
*** 0 ****
--- 1,21 ----
+ set enable_seqscan=off;
+
+ CREATE TABLE test_name (
+ i name
+ );
+
+ INSERT INTO test_name VALUES ('a'),('ab'),('abc'),('abb'),('axy'),('xyz');
+
+ CREATE INDEX idx_name ON test_name USING gin (i);
+
+ SELECT * FROM test_name WHERE i<'abc' ORDER BY i;
+ SELECT * FROM test_name WHERE i<='abc' ORDER BY i;
+ SELECT * FROM test_name WHERE i='abc' ORDER BY i;
+ SELECT * FROM test_name WHERE i>='abc' ORDER BY i;
+ SELECT * FROM test_name WHERE i>'abc' ORDER BY i;
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i<'abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i<='abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i='abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i>='abc' ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_name WHERE i>'abc' ORDER BY i;
diff --git a/contrib/btree_gin/sql/uuid.sql b/contrib/btree_gin/sql/uuid.sql
new file mode 100644
index ...3c141bd
*** a/contrib/btree_gin/sql/uuid.sql
--- b/contrib/btree_gin/sql/uuid.sql
***************
*** 0 ****
--- 1,28 ----
+ set enable_seqscan=off;
+
+ CREATE TABLE test_uuid (
+ i uuid
+ );
+
+ INSERT INTO test_uuid VALUES
+ ( '00000000-0000-0000-0000-000000000000' ),
+ ( '299bc99f-2f79-4e3e-bfea-2cbfd62a7c27' ),
+ ( '6264af33-0d43-4337-bf4e-43509b8a4be8' ),
+ ( 'ce41c936-6acb-4feb-8c91-852a673e5a5c' ),
+ ( 'd2ce731f-f2a8-4a2b-be37-8f0ba637427f' ),
+ ( 'ffffffff-ffff-ffff-ffff-ffffffffffff' )
+ ;
+
+ CREATE INDEX idx_uuid ON test_uuid USING gin (i);
+
+ SELECT * FROM test_uuid WHERE i<'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ SELECT * FROM test_uuid WHERE i<='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ SELECT * FROM test_uuid WHERE i='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ SELECT * FROM test_uuid WHERE i>='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ SELECT * FROM test_uuid WHERE i>'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i<'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i<='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i>='ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_uuid WHERE i>'ce41c936-6acb-4feb-8c91-852a673e5a5c'::uuid ORDER BY i;
diff --git a/doc/src/sgml/btree-gin.sgml b/doc/src/sgml/btree-gin.sgml
new file mode 100644
index e491fa7..314e001
*** a/doc/src/sgml/btree-gin.sgml
--- b/doc/src/sgml/btree-gin.sgml
***************
*** 17,23 ****
<type>oid</type>, <type>money</type>, <type>"char"</type>,
<type>varchar</type>, <type>text</type>, <type>bytea</type>, <type>bit</type>,
<type>varbit</type>, <type>macaddr</type>, <type>macaddr8</type>, <type>inet</type>,
! <type>cidr</type>, and all <type>enum</type> types.
</para>
<para>
--- 17,24 ----
<type>oid</type>, <type>money</type>, <type>"char"</type>,
<type>varchar</type>, <type>text</type>, <type>bytea</type>, <type>bit</type>,
<type>varbit</type>, <type>macaddr</type>, <type>macaddr8</type>, <type>inet</type>,
! <type>cidr</type>, <type>uuid</type>, <type>name</type>, <type>bool</type>,
! <type>bpchar</type>, and all <type>enum</type> types.
</para>
<para>
0002-btree_gin-uuid--base.v2.patchtext/x-patch; charset=US-ASCII; name=0002-btree_gin-uuid--base.v2.patchDownload
diff --git a/contrib/btree_gin/Makefile b/contrib/btree_gin/Makefile
new file mode 100644
index a9e9925..d36f5ad
*** a/contrib/btree_gin/Makefile
--- b/contrib/btree_gin/Makefile
*************** PGFILEDESC = "btree_gin - B-tree equival
*** 11,17 ****
REGRESS = install_btree_gin int2 int4 int8 float4 float8 money oid \
timestamp timestamptz time timetz date interval \
macaddr macaddr8 inet cidr text varchar char bytea bit varbit \
! numeric enum uuid name bool bpchar
ifdef USE_PGXS
PG_CONFIG = pg_config
--- 11,17 ----
REGRESS = install_btree_gin int2 int4 int8 float4 float8 money oid \
timestamp timestamptz time timetz date interval \
macaddr macaddr8 inet cidr text varchar char bytea bit varbit \
! numeric enum uuid name bool anyrange bpchar
ifdef USE_PGXS
PG_CONFIG = pg_config
diff --git a/contrib/btree_gin/btree_gin--1.2--1.3.sql b/contrib/btree_gin/btree_gin--1.2--1.3.sql
new file mode 100644
index db675b7..f7523a3
*** a/contrib/btree_gin/btree_gin--1.2--1.3.sql
--- b/contrib/btree_gin/btree_gin--1.2--1.3.sql
*************** AS
*** 96,101 ****
--- 96,137 ----
FUNCTION 5 gin_compare_prefix_bool(bool,bool,int2, internal),
STORAGE bool;
+ -- anyrange datatype support new in 1.3.
+ CREATE FUNCTION gin_anyrange_cmp(anyrange, anyrange)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_extract_value_anyrange(anyrange, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_compare_prefix_anyrange(anyrange, anyrange, int2, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE FUNCTION gin_extract_query_anyrange(anyrange, internal, int2, internal, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C STRICT IMMUTABLE;
+
+ CREATE OPERATOR CLASS anyrange_ops
+ DEFAULT FOR TYPE anyrange USING gin
+ AS
+ OPERATOR 1 <,
+ OPERATOR 2 <=,
+ OPERATOR 3 =,
+ OPERATOR 4 >=,
+ OPERATOR 5 >,
+ FUNCTION 1 gin_anyrange_cmp(anyrange,anyrange),
+ FUNCTION 2 gin_extract_value_anyrange(anyrange, internal),
+ FUNCTION 3 gin_extract_query_anyrange(anyrange, internal, int2, internal, internal),
+ FUNCTION 4 gin_btree_consistent(internal, int2, anyelement, int4, internal, internal),
+ FUNCTION 5 gin_compare_prefix_anyrange(anyrange,anyrange,int2, internal),
+ STORAGE anyrange;
+
-- bpchar datatype support new in 1.3.
CREATE FUNCTION gin_extract_value_bpchar(bpchar, internal)
RETURNS internal
diff --git a/contrib/btree_gin/btree_gin.c b/contrib/btree_gin/btree_gin.c
new file mode 100644
index a660681..37e0740
*** a/contrib/btree_gin/btree_gin.c
--- b/contrib/btree_gin/btree_gin.c
***************
*** 15,20 ****
--- 15,21 ----
#include "utils/timestamp.h"
#include "utils/varbit.h"
#include "utils/uuid.h"
+ #include "utils/rangetypes.h"
PG_MODULE_MAGIC;
*************** leftmostvalue_bool(void)
*** 506,508 ****
--- 507,560 ----
}
GIN_SUPPORT(bool, false, leftmostvalue_bool, btboolcmp)
+
+ /*
+ * Similarly to Numeric, we don't know the left-most value, although for
+ * different reasons (numeric does not have one, while for anyarray we
+ * don't even know the concrete type). We could try to build a fake empty
+ * range, but we simply use PointerGetDatum(NULL) just like for Numeric.
+ */
+ #define ANYRANGE_IS_LEFTMOST(x) ((x) == NULL)
+
+ PG_FUNCTION_INFO_V1(gin_anyrange_cmp);
+
+ /*
+ * Note that we use CallerFInfoFunctionCall2 here so that range_cmp
+ * gets a valid fn_extra to work with. Unlike most other type comparison
+ * routines it needs it, so we can't use DirectFunctionCall2.
+ */
+ Datum
+ gin_anyrange_cmp(PG_FUNCTION_ARGS)
+ {
+ RangeType *a = (RangeType *) PG_GETARG_POINTER(0);
+ RangeType *b = (RangeType *) PG_GETARG_POINTER(1);
+ int res = 0;
+
+ if (ANYRANGE_IS_LEFTMOST(a))
+ {
+ res = (ANYRANGE_IS_LEFTMOST(b)) ? 0 : -1;
+ }
+ else if (ANYRANGE_IS_LEFTMOST(b))
+ {
+ res = 1;
+ }
+ else
+ {
+ res = DatumGetInt32(CallerFInfoFunctionCall2(
+ range_cmp,
+ fcinfo->flinfo,
+ PG_GET_COLLATION(),
+ RangeTypePGetDatum(a),
+ RangeTypePGetDatum(b)));
+ }
+
+ PG_RETURN_INT32(res);
+ }
+
+ static Datum
+ leftmostvalue_anyrange(void)
+ {
+ return PointerGetDatum(NULL);
+ }
+
+ GIN_SUPPORT(anyrange, false, leftmostvalue_anyrange, gin_anyrange_cmp)
diff --git a/contrib/btree_gin/expected/anyrange.out b/contrib/btree_gin/expected/anyrange.out
new file mode 100644
index ...93b24f4
*** a/contrib/btree_gin/expected/anyrange.out
--- b/contrib/btree_gin/expected/anyrange.out
***************
*** 0 ****
--- 1,113 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_tsrange (
+ i tsrange
+ );
+ INSERT INTO test_tsrange VALUES
+ ( 'empty' ),
+ ( '(,)' ),
+ ( '[2018-02-02 03:55:08,2018-04-02 03:55:08)' ),
+ ( '[2018-02-02 04:55:08,2018-04-02 04:55:08)' ),
+ ( '[2018-02-02 05:55:08,2018-04-02 05:55:08)' ),
+ ( '[2018-02-02 08:55:08,2018-04-02 08:55:08)' ),
+ ( '[2018-02-02 09:55:08,2018-04-02 09:55:08)' ),
+ ( '[2018-02-02 10:55:08,2018-04-02 10:55:08)' ),
+ ( '[infinity,infinity]' )
+ ;
+ CREATE INDEX idx_tsrange ON test_tsrange USING gin (i);
+ SELECT * FROM test_tsrange WHERE i<'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ i
+ ---------------------------------------------------------
+ empty
+ (,)
+ ["Fri Feb 02 03:55:08 2018","Mon Apr 02 03:55:08 2018")
+ ["Fri Feb 02 04:55:08 2018","Mon Apr 02 04:55:08 2018")
+ ["Fri Feb 02 05:55:08 2018","Mon Apr 02 05:55:08 2018")
+ (5 rows)
+
+ SELECT * FROM test_tsrange WHERE i<='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ i
+ ---------------------------------------------------------
+ empty
+ (,)
+ ["Fri Feb 02 03:55:08 2018","Mon Apr 02 03:55:08 2018")
+ ["Fri Feb 02 04:55:08 2018","Mon Apr 02 04:55:08 2018")
+ ["Fri Feb 02 05:55:08 2018","Mon Apr 02 05:55:08 2018")
+ ["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")
+ (6 rows)
+
+ SELECT * FROM test_tsrange WHERE i='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ i
+ ---------------------------------------------------------
+ ["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")
+ (1 row)
+
+ SELECT * FROM test_tsrange WHERE i>='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ i
+ ---------------------------------------------------------
+ ["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")
+ ["Fri Feb 02 09:55:08 2018","Mon Apr 02 09:55:08 2018")
+ ["Fri Feb 02 10:55:08 2018","Mon Apr 02 10:55:08 2018")
+ [infinity,infinity]
+ (4 rows)
+
+ SELECT * FROM test_tsrange WHERE i>'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ i
+ ---------------------------------------------------------
+ ["Fri Feb 02 09:55:08 2018","Mon Apr 02 09:55:08 2018")
+ ["Fri Feb 02 10:55:08 2018","Mon Apr 02 10:55:08 2018")
+ [infinity,infinity]
+ (3 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i<'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ QUERY PLAN
+ ----------------------------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_tsrange
+ Recheck Cond: (i < '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ -> Bitmap Index Scan on idx_tsrange
+ Index Cond: (i < '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i<='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ QUERY PLAN
+ -----------------------------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_tsrange
+ Recheck Cond: (i <= '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ -> Bitmap Index Scan on idx_tsrange
+ Index Cond: (i <= '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ QUERY PLAN
+ ----------------------------------------------------------------------------------------------
+ Bitmap Heap Scan on test_tsrange
+ Recheck Cond: (i = '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ -> Bitmap Index Scan on idx_tsrange
+ Index Cond: (i = '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ (4 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i>='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ QUERY PLAN
+ -----------------------------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_tsrange
+ Recheck Cond: (i >= '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ -> Bitmap Index Scan on idx_tsrange
+ Index Cond: (i >= '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ (6 rows)
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i>'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ QUERY PLAN
+ ----------------------------------------------------------------------------------------------------
+ Sort
+ Sort Key: i
+ -> Bitmap Heap Scan on test_tsrange
+ Recheck Cond: (i > '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ -> Bitmap Index Scan on idx_tsrange
+ Index Cond: (i > '["Fri Feb 02 08:55:08 2018","Mon Apr 02 08:55:08 2018")'::tsrange)
+ (6 rows)
+
diff --git a/contrib/btree_gin/sql/anyrange.sql b/contrib/btree_gin/sql/anyrange.sql
new file mode 100644
index ...97157ad
*** a/contrib/btree_gin/sql/anyrange.sql
--- b/contrib/btree_gin/sql/anyrange.sql
***************
*** 0 ****
--- 1,31 ----
+ set enable_seqscan=off;
+
+ CREATE TABLE test_tsrange (
+ i tsrange
+ );
+
+ INSERT INTO test_tsrange VALUES
+ ( 'empty' ),
+ ( '(,)' ),
+ ( '[2018-02-02 03:55:08,2018-04-02 03:55:08)' ),
+ ( '[2018-02-02 04:55:08,2018-04-02 04:55:08)' ),
+ ( '[2018-02-02 05:55:08,2018-04-02 05:55:08)' ),
+ ( '[2018-02-02 08:55:08,2018-04-02 08:55:08)' ),
+ ( '[2018-02-02 09:55:08,2018-04-02 09:55:08)' ),
+ ( '[2018-02-02 10:55:08,2018-04-02 10:55:08)' ),
+ ( '[infinity,infinity]' )
+ ;
+
+ CREATE INDEX idx_tsrange ON test_tsrange USING gin (i);
+
+ SELECT * FROM test_tsrange WHERE i<'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ SELECT * FROM test_tsrange WHERE i<='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ SELECT * FROM test_tsrange WHERE i='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ SELECT * FROM test_tsrange WHERE i>='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ SELECT * FROM test_tsrange WHERE i>'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i<'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i<='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i>='[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
+ EXPLAIN (COSTS OFF) SELECT * FROM test_tsrange WHERE i>'[2018-02-02 08:55:08,2018-04-02 08:55:08)'::tsrange ORDER BY i;
diff --git a/doc/src/sgml/btree-gin.sgml b/doc/src/sgml/btree-gin.sgml
new file mode 100644
index 314e001..e1315da
*** a/doc/src/sgml/btree-gin.sgml
--- b/doc/src/sgml/btree-gin.sgml
***************
*** 18,24 ****
<type>varchar</type>, <type>text</type>, <type>bytea</type>, <type>bit</type>,
<type>varbit</type>, <type>macaddr</type>, <type>macaddr8</type>, <type>inet</type>,
<type>cidr</type>, <type>uuid</type>, <type>name</type>, <type>bool</type>,
! <type>bpchar</type>, and all <type>enum</type> types.
</para>
<para>
--- 18,24 ----
<type>varchar</type>, <type>text</type>, <type>bytea</type>, <type>bit</type>,
<type>varbit</type>, <type>macaddr</type>, <type>macaddr8</type>, <type>inet</type>,
<type>cidr</type>, <type>uuid</type>, <type>name</type>, <type>bool</type>,
! <type>bpchar</type>, and all <type>enum</type> and <type>anyrange</type> types.
</para>
<para>
Thanks to everyone, first patch is pushed.
Range opclass seems unusable because comparing function is close to dummy and
BTree opclass is only useful to implement unique check constraint. So, for range
it should different index structure to be useful.
Matheus de Oliveira wrote:
On Thu, Apr 5, 2018 at 8:16 AM, Teodor Sigaev <teodor@sigaev.ru
<mailto:teodor@sigaev.ru>> wrote:somehow you missed some parts in 0001 patch, at least regression tests fail:
О©╫ CREATE EXTENSION btree_gin;
+ ERROR:О©╫ could not find function "gin_extract_value_uuid" in file
"/usr/local/pgsql/lib/btree_gin.so"Ouch... My fault, filterdiff is acting weird for some reason...
Here is the corrected versions... I tested here applying on a clean master just
to be sure, all looks good.Very sorry about that mess. I hope it can get in v11, it is a patch so simple,
but so useful for many people.Best regards,
--
Matheus de Oliveira
--
Teodor Sigaev E-mail: teodor@sigaev.ru
WWW: http://www.sigaev.ru/
On Thu, Apr 5, 2018 at 12:23 PM, Teodor Sigaev <teodor@sigaev.ru> wrote:
Thanks to everyone, first patch is pushed.
Range opclass seems unusable because comparing function is close to dummy
and BTree opclass is only useful to implement unique check constraint. So,
for range it should different index structure to be useful.
Makes sense. Better leave it out then ;)
Thanks a lot you all for the hard work and patience with me!
Best regards,
--
Matheus de Oliveira