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

