diff -c -r -N src.orig/backend/access/gin/ginget.c src/backend/access/gin/ginget.c
*** src.orig/backend/access/gin/ginget.c	2009-01-19 19:58:24.000000000 +0300
--- src/backend/access/gin/ginget.c	2009-01-19 20:03:44.000000000 +0300
***************
*** 172,178 ****
      	cmp = DatumGetInt32(FunctionCall3(&btree->ginstate->comparePartialFn[scanEntry->attnum-1],
  										  scanEntry->entry,
  										  idatum,
! 										  UInt16GetDatum(scanEntry->strategy)));
  
  		if ( cmp > 0 )
  			return true;
--- 172,178 ----
      	cmp = DatumGetInt32(FunctionCall3(&btree->ginstate->comparePartialFn[scanEntry->attnum-1],
  										  scanEntry->entry,
  										  idatum,
! 										  PointerGetDatum(scanEntry->extra_data)));
  
  		if ( cmp > 0 )
  			return true;
***************
*** 665,675 ****
  		*keyrecheck = true;
  
  		oldCtx = MemoryContextSwitchTo(tempCtx);
! 		res = DatumGetBool(FunctionCall4(&ginstate->consistentFn[key->attnum-1],
  										 PointerGetDatum(key->entryRes),
  										 UInt16GetDatum(key->strategy),
  										 key->query,
! 										 PointerGetDatum(keyrecheck)));
  		MemoryContextSwitchTo(oldCtx);
  		MemoryContextReset(tempCtx);
  	} while (!res);
--- 665,676 ----
  		*keyrecheck = true;
  
  		oldCtx = MemoryContextSwitchTo(tempCtx);
! 		res = DatumGetBool(FunctionCall5(&ginstate->consistentFn[key->attnum-1],
  										 PointerGetDatum(key->entryRes),
  										 UInt16GetDatum(key->strategy),
  										 key->query,
! 										 PointerGetDatum(keyrecheck),
! 										 PointerGetDatum(key->extra_data)));
  		MemoryContextSwitchTo(oldCtx);
  		MemoryContextReset(tempCtx);
  	} while (!res);
diff -c -r -N src.orig/backend/access/gin/ginscan.c src/backend/access/gin/ginscan.c
*** src.orig/backend/access/gin/ginscan.c	2009-01-19 19:58:24.000000000 +0300
--- src/backend/access/gin/ginscan.c	2009-01-19 20:03:44.000000000 +0300
***************
*** 38,44 ****
  static void
  fillScanKey(GinState *ginstate, GinScanKey key, OffsetNumber attnum, Datum query,
  			Datum *entryValues, bool *partial_matches, uint32 nEntryValues, 
! 			StrategyNumber strategy)
  {
  	uint32		i,
  				j;
--- 38,44 ----
  static void
  fillScanKey(GinState *ginstate, GinScanKey key, OffsetNumber attnum, Datum query,
  			Datum *entryValues, bool *partial_matches, uint32 nEntryValues, 
! 			StrategyNumber strategy, void **extra_data)
  {
  	uint32		i,
  				j;
***************
*** 48,53 ****
--- 48,54 ----
  	key->scanEntry = (GinScanEntry) palloc(sizeof(GinScanEntryData) * nEntryValues);
  	key->strategy = strategy;
  	key->attnum = attnum;
+ 	key->extra_data = extra_data;
  	key->query = query;
  	key->firstCall = TRUE;
  	ItemPointerSet(&(key->curItem), InvalidBlockNumber, InvalidOffsetNumber);
***************
*** 57,62 ****
--- 58,64 ----
  		key->scanEntry[i].pval = key->entryRes + i;
  		key->scanEntry[i].entry = entryValues[i];
  		key->scanEntry[i].attnum = attnum;
+ 		key->scanEntry[i].extra_data = (extra_data) ? extra_data[i] : NULL;
  		ItemPointerSet(&(key->scanEntry[i].curItem), InvalidBlockNumber, InvalidOffsetNumber);
  		key->scanEntry[i].offset = InvalidOffsetNumber;
  		key->scanEntry[i].buffer = InvalidBuffer;
***************
*** 170,187 ****
  		Datum	   *entryValues;
  		int32		nEntryValues;
  		bool		*partial_matches = NULL;
  
  		/* XXX can't we treat nulls by just setting isVoidRes? */
  		/* This would amount to assuming that all GIN operators are strict */
  		if (scankey[i].sk_flags & SK_ISNULL)
  			elog(ERROR, "GIN doesn't support NULL as scan key");
  
! 		entryValues = (Datum *) DatumGetPointer(FunctionCall4(
  												&so->ginstate.extractQueryFn[scankey[i].sk_attno - 1],
  												scankey[i].sk_argument,
  												PointerGetDatum(&nEntryValues),
  												UInt16GetDatum(scankey[i].sk_strategy),
! 												PointerGetDatum(&partial_matches)));
  		if (nEntryValues < 0)
  		{
  			/*
--- 172,191 ----
  		Datum	   *entryValues;
  		int32		nEntryValues;
  		bool		*partial_matches = NULL;
+ 		void		**extra_data = NULL;
  
  		/* XXX can't we treat nulls by just setting isVoidRes? */
  		/* This would amount to assuming that all GIN operators are strict */
  		if (scankey[i].sk_flags & SK_ISNULL)
  			elog(ERROR, "GIN doesn't support NULL as scan key");
  
! 		entryValues = (Datum *) DatumGetPointer(FunctionCall5(
  												&so->ginstate.extractQueryFn[scankey[i].sk_attno - 1],
  												scankey[i].sk_argument,
  												PointerGetDatum(&nEntryValues),
  												UInt16GetDatum(scankey[i].sk_strategy),
! 												PointerGetDatum(&partial_matches),
! 												PointerGetDatum(&extra_data)));
  		if (nEntryValues < 0)
  		{
  			/*
***************
*** 200,206 ****
  			continue;
  
  		fillScanKey(&so->ginstate, &(so->keys[nkeys]), scankey[i].sk_attno, scankey[i].sk_argument,
! 					entryValues, partial_matches, nEntryValues, scankey[i].sk_strategy);
  		nkeys++;
  	}
  
--- 204,210 ----
  			continue;
  
  		fillScanKey(&so->ginstate, &(so->keys[nkeys]), scankey[i].sk_attno, scankey[i].sk_argument,
! 					entryValues, partial_matches, nEntryValues, scankey[i].sk_strategy, extra_data);
  		nkeys++;
  	}
  
diff -c -r -N src.orig/backend/utils/adt/tsginidx.c src/backend/utils/adt/tsginidx.c
*** src.orig/backend/utils/adt/tsginidx.c	2009-01-19 19:58:25.000000000 +0300
--- src/backend/utils/adt/tsginidx.c	2009-01-19 20:03:44.000000000 +0300
***************
*** 42,48 ****
  	text    *a = PG_GETARG_TEXT_PP(0);
  	text    *b = PG_GETARG_TEXT_PP(1);
  #ifdef NOT_USED
! 	StrategyNumber strategy = PG_GETARG_UINT16(2);
  #endif
  	int     cmp;
  
--- 42,48 ----
  	text    *a = PG_GETARG_TEXT_PP(0);
  	text    *b = PG_GETARG_TEXT_PP(1);
  #ifdef NOT_USED
! 	void 	*extra_data = PG_GETARG_POINTER(2);
  #endif
  	int     cmp;
  
***************
*** 96,101 ****
--- 96,102 ----
  	int32	   *nentries = (int32 *) PG_GETARG_POINTER(1);
  	/* StrategyNumber strategy = PG_GETARG_UINT16(2); */
  	bool      **ptr_partialmatch = (bool**) PG_GETARG_POINTER(3);
+ 	void	  ***extra_data = (void ***) PG_GETARG_POINTER(4);
  	Datum	   *entries = NULL;
  	bool       *partialmatch;
  
***************
*** 124,129 ****
--- 125,136 ----
  
  		entries = (Datum *) palloc(sizeof(Datum) * (*nentries));
  		partialmatch = *ptr_partialmatch = (bool*) palloc(sizeof(bool) * (*nentries));
+ 		/*
+ 		 * Allocate memory for GinChkVal.mapped_check to prevent
+ 		 * allocation in gin_tsquery_consistent().
+ 		 * Suppose sizeof(void*)>=sizeof(bool).
+ 		 */
+ 		*extra_data = (void**) palloc(sizeof(void*)*(*nentries));
  
  		for (i = 0; i < query->size; i++)
  			if (item[i].type == QI_VAL)
***************
*** 174,179 ****
--- 181,187 ----
  	/* StrategyNumber strategy = PG_GETARG_UINT16(1); */
  	TSQuery		query = PG_GETARG_TSQUERY(2);
  	bool	   *recheck = (bool *) PG_GETARG_POINTER(3);
+ 	void	   **extra_data = (void **) PG_GETARG_POINTER(4);
  	bool		res = FALSE;
  
  	/* The query requires recheck only if it involves weights */
***************
*** 195,201 ****
  		 */
  
  		gcv.frst = item = GETQUERY(query);
! 		gcv.mapped_check = (bool *) palloc(sizeof(bool) * query->size);
  		gcv.need_recheck = recheck;
  
  		for (i = 0; i < query->size; i++)
--- 203,209 ----
  		 */
  
  		gcv.frst = item = GETQUERY(query);
! 		gcv.mapped_check = (bool *) extra_data;
  		gcv.need_recheck = recheck;
  
  		for (i = 0; i < query->size; i++)
diff -c -r -N src.orig/include/access/gin.h src/include/access/gin.h
*** src.orig/include/access/gin.h	2009-01-19 19:58:31.000000000 +0300
--- src/include/access/gin.h	2009-01-19 20:03:44.000000000 +0300
***************
*** 370,375 ****
--- 370,376 ----
  	/* entry, got from extractQueryFn */
  	Datum		entry;
  	OffsetNumber	attnum;
+ 	void			*extra_data;
  
  	/* Current page in posting tree */
  	Buffer		buffer;
***************
*** 404,409 ****
--- 405,411 ----
  
  	/* array of scans per entry */
  	GinScanEntry scanEntry;
+ 	void		 **extra_data;
  
  	/* for calling consistentFn(GinScanKey->entryRes, strategy, query) */
  	StrategyNumber strategy;
diff -c -r -N src.orig/include/catalog/pg_proc.h src/include/catalog/pg_proc.h
*** src.orig/include/catalog/pg_proc.h	2009-01-19 19:58:30.000000000 +0300
--- src/include/catalog/pg_proc.h	2009-01-19 20:03:44.000000000 +0300
***************
*** 4175,4183 ****
  /* GIN array support */
  DATA(insert OID = 2743 (  ginarrayextract	 PGNSP PGUID 12 1 0 0 f f f t f i 2 0 2281 "2277 2281" _null_ _null_ _null_ _null_	ginarrayextract _null_ _null_ _null_ ));
  DESCR("GIN array support");
! DATA(insert OID = 2774 (  ginqueryarrayextract	PGNSP PGUID 12 1 0 0 f f f t f i 4 0 2281 "2277 2281 21 2281" _null_ _null_ _null_ _null_ ginqueryarrayextract _null_ _null_ _null_ ));
  DESCR("GIN array support");
! DATA(insert OID = 2744 (  ginarrayconsistent PGNSP PGUID 12 1 0 0 f f f t f i 4 0 16 "2281 21 2281 2281" _null_ _null_ _null_ _null_	ginarrayconsistent _null_ _null_ _null_ ));
  DESCR("GIN array support");
  
  /* overlap/contains/contained */
--- 4175,4183 ----
  /* GIN array support */
  DATA(insert OID = 2743 (  ginarrayextract	 PGNSP PGUID 12 1 0 0 f f f t f i 2 0 2281 "2277 2281" _null_ _null_ _null_ _null_	ginarrayextract _null_ _null_ _null_ ));
  DESCR("GIN array support");
! DATA(insert OID = 2774 (  ginqueryarrayextract	PGNSP PGUID 12 1 0 0 f f f t f i 5 0 2281 "2277 2281 21 2281 2281" _null_ _null_ _null_ _null_ ginqueryarrayextract _null_ _null_ _null_ ));
  DESCR("GIN array support");
! DATA(insert OID = 2744 (  ginarrayconsistent PGNSP PGUID 12 1 0 0 f f f t f i 5 0 16 "2281 21 2281 2281 2281" _null_ _null_ _null_ _null_	ginarrayconsistent _null_ _null_ _null_ ));
  DESCR("GIN array support");
  
  /* overlap/contains/contained */
***************
*** 4416,4428 ****
  
  DATA(insert OID = 3656 (  gin_extract_tsvector	PGNSP PGUID 12 1 0 0 f f f t f i 2 0 2281 "3614 2281" _null_ _null_ _null_ _null_	gin_extract_tsvector _null_ _null_ _null_ ));
  DESCR("GIN tsvector support");
! DATA(insert OID = 3657 (  gin_extract_tsquery	PGNSP PGUID 12 1 0 0 f f f t f i 4 0 2281 "3615 2281 21 2281" _null_ _null_ _null_ _null_ gin_extract_tsquery _null_ _null_ _null_ ));
  DESCR("GIN tsvector support");
! DATA(insert OID = 3658 (  gin_tsquery_consistent PGNSP PGUID 12 1 0 0 f f f t f i 4 0 16 "2281 21 3615 2281" _null_ _null_ _null_ _null_	gin_tsquery_consistent _null_ _null_ _null_ ));
  DESCR("GIN tsvector support");
  DATA(insert OID = 3724 (  gin_cmp_tslexeme      PGNSP PGUID 12 1 0 0 f f f t f i 2 0 23 "25 25" _null_ _null_ _null_ _null_ gin_cmp_tslexeme _null_ _null_ _null_ ));
  DESCR("GIN tsvector support");
! DATA(insert OID = 2700 (  gin_cmp_prefix        PGNSP PGUID 12 1 0 0 f f f t f i 3 0 23 "25 25 21" _null_ _null_ _null_ _null_ gin_cmp_prefix _null_ _null_ _null_ ));
  DESCR("GIN tsvector support");
  
  DATA(insert OID = 3662 (  tsquery_lt			PGNSP PGUID 12 1 0 0 f f f t f i 2 0 16 "3615 3615" _null_ _null_ _null_ _null_ tsquery_lt _null_ _null_ _null_ ));
--- 4416,4428 ----
  
  DATA(insert OID = 3656 (  gin_extract_tsvector	PGNSP PGUID 12 1 0 0 f f f t f i 2 0 2281 "3614 2281" _null_ _null_ _null_ _null_	gin_extract_tsvector _null_ _null_ _null_ ));
  DESCR("GIN tsvector support");
! DATA(insert OID = 3657 (  gin_extract_tsquery	PGNSP PGUID 12 1 0 0 f f f t f i 5 0 2281 "3615 2281 21 2281 2281" _null_ _null_ _null_ _null_ gin_extract_tsquery _null_ _null_ _null_ ));
  DESCR("GIN tsvector support");
! DATA(insert OID = 3658 (  gin_tsquery_consistent PGNSP PGUID 12 1 0 0 f f f t f i 5 0 16 "2281 21 3615 2281 2281" _null_ _null_ _null_ _null_	gin_tsquery_consistent _null_ _null_ _null_ ));
  DESCR("GIN tsvector support");
  DATA(insert OID = 3724 (  gin_cmp_tslexeme      PGNSP PGUID 12 1 0 0 f f f t f i 2 0 23 "25 25" _null_ _null_ _null_ _null_ gin_cmp_tslexeme _null_ _null_ _null_ ));
  DESCR("GIN tsvector support");
! DATA(insert OID = 2700 (  gin_cmp_prefix        PGNSP PGUID 12 1 0 0 f f f t f i 3 0 23 "25 25 2281" _null_ _null_ _null_ _null_ gin_cmp_prefix _null_ _null_ _null_ ));
  DESCR("GIN tsvector support");
  
  DATA(insert OID = 3662 (  tsquery_lt			PGNSP PGUID 12 1 0 0 f f f t f i 2 0 16 "3615 3615" _null_ _null_ _null_ _null_ tsquery_lt _null_ _null_ _null_ ));
diff -c -r -N contrib.orig/Makefile contrib/Makefile
*** contrib.orig/Makefile	2009-01-19 19:58:35.000000000 +0300
--- contrib/Makefile	2009-01-19 20:03:44.000000000 +0300
***************
*** 8,13 ****
--- 8,14 ----
  		adminpack	\
  		auto_explain	\
  		btree_gist	\
+ 		btree_gin	\
  		chkpass		\
  		citext		\
  		cube		\
diff -c -r -N contrib.orig/README contrib/README
*** contrib.orig/README	2009-01-19 19:58:35.000000000 +0300
--- contrib/README	2009-01-19 20:03:44.000000000 +0300
***************
*** 32,37 ****
--- 32,41 ----
  	Log EXPLAIN output for long-running queries
  	by Takahiro Itagaki <itagaki.takahiro@oss.ntt.co.jp>
  
+ btree_gin -
+ 	Support for emulating BTREE indexing in GIN
+ 	by Oleg Bartunov <oleg@sai.msu.su> and Teodor Sigaev <teodor@sigaev.ru>
+ 
  btree_gist -
  	Support for emulating BTREE indexing in GiST
  	by Oleg Bartunov <oleg@sai.msu.su> and Teodor Sigaev <teodor@sigaev.ru>
diff -c -r -N contrib.orig/btree_gin/Makefile contrib/btree_gin/Makefile
*** contrib.orig/btree_gin/Makefile	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/Makefile	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,16 ----
+ MODULE_big = btree_gin
+ OBJS = btree_gin.o 
+ 
+ DATA_built = btree_gin.sql
+ DATA = uninstall_btree_gin.sql
+ REGRESS = btree_gin int2 int4 int8 float4 float8 money oid \
+ 	timestamp timestamptz time timetz date interval \
+ 	macaddr inet cidr text varchar char bytea bit varbit \
+ 	numeric
+ 
+ 
+ subdir = contrib/btree_gin
+ top_builddir = ../..
+ include $(top_builddir)/src/Makefile.global
+ 
+ include $(top_srcdir)/contrib/contrib-global.mk
diff -c -r -N contrib.orig/btree_gin/btree_gin.c contrib/btree_gin/btree_gin.c
*** contrib.orig/btree_gin/btree_gin.c	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/btree_gin.c	2009-01-19 20:09:08.000000000 +0300
***************
*** 0 ****
--- 1,399 ----
+ #include <postgres.h>
+ #include <fmgr.h>
+ #include <access/skey.h>
+ #include <utils/builtins.h>
+ #include <utils/cash.h>
+ #include <utils/date.h>
+ #include <utils/inet.h>
+ #include <utils/numeric.h>
+ #include <utils/timestamp.h>
+ #include <utils/varbit.h>
+ #include <limits.h>
+ 
+ PG_MODULE_MAGIC;
+ 
+ static Datum entries[1];
+ 
+ typedef struct TypeInfo {
+     bool    is_varlena;
+ 	Datum   (*leftmostvalue)();
+ 	Datum   (*typecmp)(FunctionCallInfo);
+ } TypeInfo;
+ 
+ typedef struct QueryInfo {
+ 	StrategyNumber		strategy;
+ 	Datum				datum;
+ } QueryInfo;
+ 
+ #define  GIN_EXTRACT_VALUE(type)												\
+ PG_FUNCTION_INFO_V1(gin_extract_value_##type);									\
+ Datum       gin_extract_value_##type(PG_FUNCTION_ARGS);							\
+ Datum																			\
+ gin_extract_value_##type(PG_FUNCTION_ARGS)										\
+ {																				\
+ 	Datum datum = PG_GETARG_DATUM(0);											\
+ 	int32 *nentries = (int32 *) PG_GETARG_POINTER(1);							\
+ 																				\
+ 	if ( TypeInfo_##type.is_varlena )											\
+ 		datum = PointerGetDatum(PG_DETOAST_DATUM(datum));						\
+ 	entries[0] = datum;															\
+ 																				\
+ 	*nentries = 1;																\
+ 																				\
+ 	PG_RETURN_POINTER(entries);													\
+ }
+ 
+ /*
+  * For BTGreaterEqualStrategyNumber, BTGreaterStrategyNumber, and
+  * BTEqualStrategyNumber we want to start the index scan at the
+  * supplied query datum, and work forward. For BTLessStrategyNumber
+  * and BTLessEqualStrategyNumber, we need to start at the leftmost
+  * key, and work forward until the supplied query datum (which must be
+  * sent along inside the QueryInfo structure).
+  */
+ 
+ #define GIN_EXTRACT_QUERY(type)													\
+ PG_FUNCTION_INFO_V1(gin_extract_query_##type);									\
+ Datum       gin_extract_query_##type(PG_FUNCTION_ARGS);							\
+ Datum																			\
+ gin_extract_query_##type(PG_FUNCTION_ARGS)										\
+ {																				\
+ 	Datum datum = PG_GETARG_DATUM(0);											\
+ 	int32 *nentries = (int32 *) PG_GETARG_POINTER(1);							\
+ 	StrategyNumber strategy = PG_GETARG_UINT16(2);								\
+ 	bool	**partialmatch = (bool**) PG_GETARG_POINTER(3);						\
+ 	bool	*ptr_partialmatch;													\
+ 	void	***extra_data= (void***) PG_GETARG_POINTER(4);						\
+ 	QueryInfo	*data = (QueryInfo*)palloc(sizeof(QueryInfo));					\
+ 																				\
+ 	*nentries = 1;																\
+ 	ptr_partialmatch = *partialmatch = palloc(sizeof(bool));					\
+ 	*ptr_partialmatch = false;													\
+ 	if ( TypeInfo_##type.is_varlena )											\
+ 			datum = PointerGetDatum(PG_DETOAST_DATUM(datum));					\
+ 	data->strategy = strategy;													\
+ 	data->datum = datum;														\
+ 	*extra_data = (void**) palloc(sizeof(void*));								\
+ 	**extra_data = data;														\
+ 																				\
+ 	switch(strategy) {															\
+ 		case	BTLessStrategyNumber:											\
+ 		case	BTLessEqualStrategyNumber:										\
+ 			entries[0] = TypeInfo_##type.leftmostvalue();						\
+ 			*ptr_partialmatch = true;											\
+ 			break;																\
+ 		case	BTGreaterEqualStrategyNumber:									\
+ 		case	BTGreaterStrategyNumber:										\
+ 			*ptr_partialmatch = true;											\
+ 		case	BTEqualStrategyNumber:											\
+ 			entries[0] = datum;													\
+ 			break;																\
+ 		default:																\
+ 			elog(ERROR,"unknown strategy number: %d", strategy);				\
+ 	}																			\
+ 																				\
+ 	PG_RETURN_POINTER(entries);													\
+ }
+ 			
+ #define GIN_COMPARE_PREFIX(type)												\
+ PG_FUNCTION_INFO_V1(gin_compare_prefix_##type);									\
+ Datum       gin_compare_prefix_##type(PG_FUNCTION_ARGS);						\
+ Datum																			\
+ gin_compare_prefix_##type(PG_FUNCTION_ARGS)										\
+ {																				\
+ 	Datum 	a = PG_GETARG_DATUM(0);												\
+ 	Datum 	b = PG_GETARG_DATUM(1);												\
+ 	QueryInfo *data = (QueryInfo*)PG_GETARG_POINTER(2);							\
+ 	int32	res;																\
+ 																				\
+ 	res = DatumGetInt32(DirectFunctionCall2(									\
+ 				TypeInfo_##type.typecmp, 										\
+ 				(data->strategy == BTLessStrategyNumber || 						\
+ 					data->strategy == BTLessEqualStrategyNumber )				\
+ 						? PointerGetDatum(data->datum) : a, 					\
+ 				b																\
+ 		));																		\
+ 																				\
+ 	switch(data->strategy) {													\
+ 		case	BTLessStrategyNumber:											\
+ 			if ( res > 0 )														\
+ 				res = 0;														\
+ 			else																\
+ 				res = 1;														\
+ 			break;																\
+ 		case	BTLessEqualStrategyNumber:										\
+ 			if ( res >= 0 )														\
+ 				res = 0;														\
+ 			else																\
+ 				res = 1;														\
+ 			break;																\
+ 		case	BTEqualStrategyNumber:											\
+ 			if ( res != 0 )														\
+ 				res = 1;														\
+ 			break;																\
+ 		case	BTGreaterEqualStrategyNumber:									\
+ 			if ( res <= 0 )														\
+ 				res = 0;														\
+ 			else																\
+ 				res = 1;														\
+ 			break;																\
+ 		case	BTGreaterStrategyNumber:										\
+ 			if ( res < 0 )														\
+ 				res = 0;														\
+ 			else if ( res == 0 )												\
+ 				res = -1;														\
+ 			else																\
+ 				res = 1;														\
+ 			break;																\
+ 		default:																\
+ 			elog(ERROR,"unknown strategy number: %d", data->strategy);			\
+ 	}																			\
+ 																				\
+ 	PG_RETURN_INT32(res);														\
+ }
+ 
+ #define GIN_SUPPORT(type)			\
+ 	GIN_EXTRACT_VALUE(type)			\
+ 	GIN_EXTRACT_QUERY(type)			\
+ 	GIN_COMPARE_PREFIX(type)
+ 
+ 
+ PG_FUNCTION_INFO_V1(gin_btree_consistent);
+ Datum       gin_btree_consistent(PG_FUNCTION_ARGS);
+ Datum
+ gin_btree_consistent(PG_FUNCTION_ARGS)
+ {
+ 	bool       *recheck = (bool *) PG_GETARG_POINTER(3);
+ 	*recheck = false;
+ 	PG_RETURN_BOOL(true);
+ }
+ 
+ static Datum 
+ leftmostvalue_int2()
+ {
+ 	return Int16GetDatum(SHRT_MIN);
+ }
+ static TypeInfo TypeInfo_int2 = {false, leftmostvalue_int2, btint2cmp};
+ GIN_SUPPORT(int2)
+ 
+ static Datum 
+ leftmostvalue_int4()
+ {
+ 	return Int32GetDatum(INT_MIN);
+ }
+ static TypeInfo TypeInfo_int4 = {false, leftmostvalue_int4, btint4cmp};
+ GIN_SUPPORT(int4)
+ 
+ static Datum 
+ leftmostvalue_int8()
+ {
+ 	/* 
+ 	 * Use sequence's definition to keep compatibility.
+ 	 * Another way may make a problem with INT64_IS_BUSTED 
+ 	 */
+ 	return Int64GetDatum(SEQ_MINVALUE); 
+ }
+ static TypeInfo TypeInfo_int8 = {false, leftmostvalue_int8, btint8cmp};
+ GIN_SUPPORT(int8)
+ 
+ static Datum 
+ leftmostvalue_float4()
+ {
+ 	return Float4GetDatum(-get_float4_infinity());
+ }
+ static TypeInfo TypeInfo_float4 = {false, leftmostvalue_float4, btfloat4cmp};
+ GIN_SUPPORT(float4)
+ 
+ static Datum 
+ leftmostvalue_float8()
+ {
+ 	return Float8GetDatum(-get_float8_infinity());
+ }
+ static TypeInfo TypeInfo_float8 = {false, leftmostvalue_float8, btfloat8cmp};
+ GIN_SUPPORT(float8)
+ 
+ static Datum 
+ leftmostvalue_money()
+ {
+ 	/* 
+ 	 * Use sequence's definition to keep compatibility.
+ 	 * Another way may make a problem with INT64_IS_BUSTED 
+ 	 */
+ 	return Int64GetDatum(SEQ_MINVALUE); 
+ }
+ static TypeInfo TypeInfo_money = {false, leftmostvalue_money, cash_cmp};
+ GIN_SUPPORT(money)
+ 
+ static Datum 
+ leftmostvalue_oid()
+ {
+ 	return ObjectIdGetDatum(0);
+ }
+ static TypeInfo TypeInfo_oid = {false, leftmostvalue_oid, btoidcmp};
+ GIN_SUPPORT(oid)
+ 
+ static Datum 
+ leftmostvalue_timestamp()
+ {
+ 	return TimestampGetDatum(DT_NOBEGIN);
+ }
+ static TypeInfo TypeInfo_timestamp = {false, leftmostvalue_timestamp, timestamp_cmp};
+ GIN_SUPPORT(timestamp)
+ 
+ static TypeInfo TypeInfo_timestamptz = {false, leftmostvalue_timestamp, timestamp_cmp};
+ GIN_SUPPORT(timestamptz)
+ 
+ static Datum 
+ leftmostvalue_time()
+ {
+ 	return TimeADTGetDatum(0);
+ }
+ static TypeInfo TypeInfo_time = {false, leftmostvalue_time, time_cmp};
+ GIN_SUPPORT(time)
+ 
+ static Datum 
+ leftmostvalue_timetz()
+ {
+ 	TimeTzADT	*v = palloc(sizeof(TimeTzADT));
+ 
+ 	v->time = 0;
+ 	v->zone = -24*3600; /* XXX is that true? */
+ 
+ 	return TimeTzADTPGetDatum(v);
+ }
+ static TypeInfo TypeInfo_timetz = {false, leftmostvalue_timetz, timetz_cmp};
+ GIN_SUPPORT(timetz)
+ 
+ static Datum 
+ leftmostvalue_date()
+ {
+ 	return DateADTGetDatum(DATEVAL_NOBEGIN);
+ }
+ static TypeInfo TypeInfo_date = {false, leftmostvalue_date, date_cmp};
+ GIN_SUPPORT(date)
+ 
+ static Datum 
+ leftmostvalue_interval()
+ {
+ 	Interval *v = palloc(sizeof(Interval));
+ 
+ 	v->time = DT_NOBEGIN;
+ 	v->day = 0;
+ 	v->month = 0;
+ 	return IntervalPGetDatum(v);
+ }
+ static TypeInfo TypeInfo_interval = {false, leftmostvalue_interval, interval_cmp};
+ GIN_SUPPORT(interval)
+ 
+ static Datum 
+ leftmostvalue_macaddr()
+ {
+ 	macaddr *v = palloc0(sizeof(macaddr));
+ 
+ 	return MacaddrPGetDatum(v);
+ }
+ static TypeInfo TypeInfo_macaddr = {false, leftmostvalue_macaddr, macaddr_cmp};
+ GIN_SUPPORT(macaddr)
+ 
+ static Datum
+ leftmostvalue_inet()
+ {
+ 	return DirectFunctionCall3(inet_in, 
+ 						CStringGetDatum("0.0.0.0/0"),
+ 						ObjectIdGetDatum(0),
+ 						Int32GetDatum(-1));
+ }
+ static TypeInfo TypeInfo_inet = {true, leftmostvalue_inet, network_cmp};
+ GIN_SUPPORT(inet)
+ 
+ static TypeInfo TypeInfo_cidr = {true, leftmostvalue_inet, network_cmp};
+ GIN_SUPPORT(cidr)
+ 
+ static Datum
+ leftmostvalue_text()
+ {
+ 	return PointerGetDatum(cstring_to_text_with_len("", 0));
+ }
+ static TypeInfo TypeInfo_text = {true, leftmostvalue_text, bttextcmp};
+ GIN_SUPPORT(text)
+ 
+ static Datum 
+ leftmostvalue_char()
+ {
+ 	return CharGetDatum(SCHAR_MIN);
+ }
+ static TypeInfo TypeInfo_char = {false, leftmostvalue_char, btcharcmp};
+ GIN_SUPPORT(char)
+ 
+ static TypeInfo TypeInfo_bytea = {true, leftmostvalue_text, byteacmp};
+ GIN_SUPPORT(bytea)
+ 
+ static Datum
+ leftmostvalue_bit()
+ {
+ 	return DirectFunctionCall3(bit_in, 
+ 						CStringGetDatum(""),
+ 						ObjectIdGetDatum(0),
+ 						Int32GetDatum(-1));
+ }
+ static TypeInfo TypeInfo_bit = {true, leftmostvalue_bit, bitcmp};
+ GIN_SUPPORT(bit)
+ 
+ static Datum
+ leftmostvalue_varbit()
+ {
+ 	return DirectFunctionCall3(varbit_in, 
+ 						CStringGetDatum(""),
+ 						ObjectIdGetDatum(0),
+ 						Int32GetDatum(-1));
+ }
+ static TypeInfo TypeInfo_varbit = {true, leftmostvalue_varbit, bitcmp};
+ GIN_SUPPORT(varbit)
+ 
+ /*
+  * Numeric type hasn't applicable left-most value, so NULL
+  * is used as it. NULL will never be an argument for 
+  * numeric function except gin_numeric_cmp and it will not stored 
+  * somewhere and it could not be returned in any user SQL query.
+  */
+ 
+ #define NUMERIC_IS_LEFTMOST(x)	( (x) == NULL )
+ 
+ PG_FUNCTION_INFO_V1(gin_numeric_cmp);
+ Datum       gin_numeric_cmp(PG_FUNCTION_ARGS);
+ Datum
+ gin_numeric_cmp(PG_FUNCTION_ARGS)
+ {
+ 	Numeric	a = (Numeric)PG_GETARG_DATUM(0); 
+ 	Numeric	b = (Numeric)PG_GETARG_DATUM(1); 
+ 	int		res = 0;
+ 
+ 	if ( NUMERIC_IS_LEFTMOST(a) )
+ 	{
+ 		res = ( NUMERIC_IS_LEFTMOST(b) ) ? 0 : -1;
+ 	} 
+ 	else if ( NUMERIC_IS_LEFTMOST(b) )
+ 	{
+ 		res = 1;
+ 	}
+ 	else
+ 	{
+ 		res = DatumGetInt32(DirectFunctionCall2(
+ 				numeric_cmp,
+ 				NumericGetDatum(a),
+ 				NumericGetDatum(b) ));
+ 	}
+ 
+ 	PG_RETURN_INT32(res);
+ }
+ 
+ static Datum
+ leftmostvalue_numeric()
+ {
+ 	return NumericGetDatum(NULL); 
+ }
+ 
+ static TypeInfo TypeInfo_numeric = {true, leftmostvalue_numeric, gin_numeric_cmp};
+ GIN_SUPPORT(numeric)
+ 
+ 
diff -c -r -N contrib.orig/btree_gin/btree_gin.sql.in contrib/btree_gin/btree_gin.sql.in
*** contrib.orig/btree_gin/btree_gin.sql.in	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/btree_gin.sql.in	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,688 ----
+ BEGIN;
+ 
+ CREATE OR REPLACE FUNCTION gin_btree_consistent(internal, int2, anyelement)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_int2(int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_int2(int2, int2, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_int2(int2, internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS int2_ops
+ DEFAULT FOR TYPE int2 USING gin
+ AS
+     OPERATOR        1       <,
+     OPERATOR        2       <=,
+     OPERATOR        3       =,
+     OPERATOR        4       >=,
+     OPERATOR        5       >,
+ 	FUNCTION        1       btint2cmp(int2,int2),
+ 	FUNCTION        2       gin_extract_value_int2(int2, internal),
+ 	FUNCTION        3       gin_extract_query_int2(int2, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_int2(int2,int2,internal),
+ STORAGE         int2;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_int4(int4, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_int4(int4, int4, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_int4(int4, internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS int4_ops
+ DEFAULT FOR TYPE int4 USING gin
+ AS
+     OPERATOR        1       <,
+     OPERATOR        2       <=,
+     OPERATOR        3       =,
+     OPERATOR        4       >=,
+     OPERATOR        5       >,
+ 	FUNCTION        1       btint4cmp(int4,int4),
+ 	FUNCTION        2       gin_extract_value_int4(int4, internal),
+ 	FUNCTION        3       gin_extract_query_int4(int4, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_int4(int4,int4,internal),
+ STORAGE         int4;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_int8(int8, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_int8(int8, int8, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_int8(int8, internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS int8_ops
+ DEFAULT FOR TYPE int8 USING gin
+ AS
+     OPERATOR        1       <,
+     OPERATOR        2       <=,
+     OPERATOR        3       =,
+     OPERATOR        4       >=,
+     OPERATOR        5       >,
+ 	FUNCTION        1       btint8cmp(int8,int8),
+ 	FUNCTION        2       gin_extract_value_int8(int8, internal),
+ 	FUNCTION        3       gin_extract_query_int8(int8, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_int8(int8,int8,internal),
+ STORAGE         int8;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_float4(float4, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_float4(float4, float4, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_float4(float4, internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS float4_ops
+ DEFAULT FOR TYPE float4 USING gin
+ AS
+     OPERATOR        1       <,
+     OPERATOR        2       <=,
+     OPERATOR        3       =,
+     OPERATOR        4       >=,
+     OPERATOR        5       >,
+ 	FUNCTION        1       btfloat4cmp(float4,float4),
+ 	FUNCTION        2       gin_extract_value_float4(float4, internal),
+ 	FUNCTION        3       gin_extract_query_float4(float4, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_float4(float4,float4,internal),
+ STORAGE         float4;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_float8(float8, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_float8(float8, float8, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_float8(float8, internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS float8_ops
+ DEFAULT FOR TYPE float8 USING gin
+ AS
+     OPERATOR        1       <,
+     OPERATOR        2       <=,
+     OPERATOR        3       =,
+     OPERATOR        4       >=,
+     OPERATOR        5       >,
+ 	FUNCTION        1       btfloat8cmp(float8,float8),
+ 	FUNCTION        2       gin_extract_value_float8(float8, internal),
+ 	FUNCTION        3       gin_extract_query_float8(float8, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_float8(float8,float8,internal),
+ STORAGE         float8;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_money(money, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_money(money, money, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_money(money, internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS money_ops
+ DEFAULT FOR TYPE money USING gin
+ AS
+     OPERATOR        1       <,
+     OPERATOR        2       <=,
+     OPERATOR        3       =,
+     OPERATOR        4       >=,
+     OPERATOR        5       >,
+ 	FUNCTION        1       cash_cmp(money,money),
+ 	FUNCTION        2       gin_extract_value_money(money, internal),
+ 	FUNCTION        3       gin_extract_query_money(money, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_money(money,money,internal),
+ STORAGE         money;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_oid(oid, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_oid(oid, oid, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_oid(oid, internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS oid_ops
+ DEFAULT FOR TYPE oid USING gin
+ AS
+     OPERATOR        1       <,
+     OPERATOR        2       <=,
+     OPERATOR        3       =,
+     OPERATOR        4       >=,
+     OPERATOR        5       >,
+ 	FUNCTION        1       btoidcmp(oid,oid),
+ 	FUNCTION        2       gin_extract_value_oid(oid, internal),
+ 	FUNCTION        3       gin_extract_query_oid(oid, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_oid(oid,oid,internal),
+ STORAGE         oid;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_timestamp(timestamp, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_timestamp(timestamp, timestamp, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_timestamp(timestamp, internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS timestamp_ops
+ DEFAULT FOR TYPE timestamp USING gin
+ AS
+     OPERATOR        1       <,
+     OPERATOR        2       <=,
+     OPERATOR        3       =,
+     OPERATOR        4       >=,
+     OPERATOR        5       >,
+ 	FUNCTION        1       timestamp_cmp(timestamp,timestamp),
+ 	FUNCTION        2       gin_extract_value_timestamp(timestamp, internal),
+ 	FUNCTION        3       gin_extract_query_timestamp(timestamp, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_timestamp(timestamp,timestamp,internal),
+ STORAGE         timestamp;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_timestamptz(timestamptz, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_timestamptz(timestamptz, timestamptz, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_timestamptz(timestamptz, internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS timestamptz_ops
+ DEFAULT FOR TYPE timestamptz USING gin
+ AS
+     OPERATOR        1       <,
+     OPERATOR        2       <=,
+     OPERATOR        3       =,
+     OPERATOR        4       >=,
+     OPERATOR        5       >,
+ 	FUNCTION        1       timestamptz_cmp(timestamptz,timestamptz),
+ 	FUNCTION        2       gin_extract_value_timestamptz(timestamptz, internal),
+ 	FUNCTION        3       gin_extract_query_timestamptz(timestamptz, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_timestamptz(timestamptz,timestamptz,internal),
+ STORAGE         timestamptz;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_time(time, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_time(time, time, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_time(time, internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS time_ops
+ DEFAULT FOR TYPE time USING gin
+ AS
+     OPERATOR        1       <,
+     OPERATOR        2       <=,
+     OPERATOR        3       =,
+     OPERATOR        4       >=,
+     OPERATOR        5       >,
+ 	FUNCTION        1       time_cmp(time,time),
+ 	FUNCTION        2       gin_extract_value_time(time, internal),
+ 	FUNCTION        3       gin_extract_query_time(time, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_time(time,time,internal),
+ STORAGE         time;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_timetz(timetz, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_timetz(timetz, timetz, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_timetz(timetz, internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS timetz_ops
+ DEFAULT FOR TYPE timetz USING gin
+ AS
+     OPERATOR        1       <,
+     OPERATOR        2       <=,
+     OPERATOR        3       =,
+     OPERATOR        4       >=,
+     OPERATOR        5       >,
+ 	FUNCTION        1       timetz_cmp(timetz,timetz),
+ 	FUNCTION        2       gin_extract_value_timetz(timetz, internal),
+ 	FUNCTION        3       gin_extract_query_timetz(timetz, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_timetz(timetz,timetz,internal),
+ STORAGE         timetz;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_date(date, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_date(date, date, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_date(date, internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS date_ops
+ DEFAULT FOR TYPE date USING gin
+ AS
+     OPERATOR        1       <,
+     OPERATOR        2       <=,
+     OPERATOR        3       =,
+     OPERATOR        4       >=,
+     OPERATOR        5       >,
+ 	FUNCTION        1       date_cmp(date,date),
+ 	FUNCTION        2       gin_extract_value_date(date, internal),
+ 	FUNCTION        3       gin_extract_query_date(date, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_date(date,date,internal),
+ STORAGE         date;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_interval(interval, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_interval(interval, interval, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_interval(interval, internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS interval_ops
+ DEFAULT FOR TYPE interval USING gin
+ AS
+     OPERATOR        1       <,
+     OPERATOR        2       <=,
+     OPERATOR        3       =,
+     OPERATOR        4       >=,
+     OPERATOR        5       >,
+ 	FUNCTION        1       interval_cmp(interval,interval),
+ 	FUNCTION        2       gin_extract_value_interval(interval, internal),
+ 	FUNCTION        3       gin_extract_query_interval(interval, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_interval(interval,interval,internal),
+ STORAGE         interval;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_macaddr(macaddr, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_macaddr(macaddr, macaddr, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_macaddr(macaddr, internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS macaddr_ops
+ DEFAULT FOR TYPE macaddr USING gin
+ AS
+     OPERATOR        1       <,
+     OPERATOR        2       <=,
+     OPERATOR        3       =,
+     OPERATOR        4       >=,
+     OPERATOR        5       >,
+ 	FUNCTION        1       macaddr_cmp(macaddr,macaddr),
+ 	FUNCTION        2       gin_extract_value_macaddr(macaddr, internal),
+ 	FUNCTION        3       gin_extract_query_macaddr(macaddr, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_macaddr(macaddr,macaddr,internal),
+ STORAGE         macaddr;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_inet(inet, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_inet(inet, inet, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_inet(inet, internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS inet_ops
+ DEFAULT FOR TYPE inet USING gin
+ AS
+     OPERATOR        1       <,
+     OPERATOR        2       <=,
+     OPERATOR        3       =,
+     OPERATOR        4       >=,
+     OPERATOR        5       >,
+ 	FUNCTION        1       network_cmp(inet,inet),
+ 	FUNCTION        2       gin_extract_value_inet(inet, internal),
+ 	FUNCTION        3       gin_extract_query_inet(inet, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_inet(inet,inet,internal),
+ STORAGE         inet;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_cidr(cidr, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_cidr(cidr, cidr, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_cidr(cidr, internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS cidr_ops
+ DEFAULT FOR TYPE cidr USING gin
+ AS
+     OPERATOR        1       <(inet,inet),
+     OPERATOR        2       <=(inet,inet),
+     OPERATOR        3       =(inet,inet),
+     OPERATOR        4       >=(inet,inet),
+     OPERATOR        5       >(inet,inet),
+ 	FUNCTION        1       network_cmp(inet,inet),
+ 	FUNCTION        2       gin_extract_value_cidr(cidr, internal),
+ 	FUNCTION        3       gin_extract_query_cidr(cidr, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_cidr(cidr,cidr,internal),
+ STORAGE         cidr;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_text(text, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_text(text, text, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_text(text, internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS text_ops
+ DEFAULT FOR TYPE text USING gin
+ AS
+     OPERATOR        1       <,
+     OPERATOR        2       <=,
+     OPERATOR        3       =,
+     OPERATOR        4       >=,
+     OPERATOR        5       >,
+ 	FUNCTION        1       bttextcmp(text,text),
+ 	FUNCTION        2       gin_extract_value_text(text, internal),
+ 	FUNCTION        3       gin_extract_query_text(text, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_text(text,text,internal),
+ STORAGE         text;
+ 
+ CREATE OPERATOR CLASS varchar_ops
+ DEFAULT FOR TYPE varchar USING gin
+ AS
+     OPERATOR        1       <(text,text),
+     OPERATOR        2       <=(text,text),
+     OPERATOR        3       =(text,text),
+     OPERATOR        4       >=(text,text),
+     OPERATOR        5       >(text,text),
+ 	FUNCTION        1       bttextcmp(text,text),
+ 	FUNCTION        2       gin_extract_value_text(text, internal),
+ 	FUNCTION        3       gin_extract_query_text(text, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_text(text,text,internal),
+ STORAGE         varchar;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_char("char", internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_char("char", "char", internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_char("char", internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS char_ops
+ DEFAULT FOR TYPE "char" USING gin
+ AS
+     OPERATOR        1       <,
+     OPERATOR        2       <=,
+     OPERATOR        3       =,
+     OPERATOR        4       >=,
+     OPERATOR        5       >,
+ 	FUNCTION        1       btcharcmp("char","char"),
+ 	FUNCTION        2       gin_extract_value_char("char", internal),
+ 	FUNCTION        3       gin_extract_query_char("char", internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_char("char","char",internal),
+ STORAGE         "char";
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_bytea(bytea, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_bytea(bytea, bytea, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_bytea(bytea, internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS bytea_ops
+ DEFAULT FOR TYPE bytea USING gin
+ AS
+     OPERATOR        1       <,
+     OPERATOR        2       <=,
+     OPERATOR        3       =,
+     OPERATOR        4       >=,
+     OPERATOR        5       >,
+ 	FUNCTION        1       byteacmp(bytea,bytea),
+ 	FUNCTION        2       gin_extract_value_bytea(bytea, internal),
+ 	FUNCTION        3       gin_extract_query_bytea(bytea, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_bytea(bytea,bytea,internal),
+ STORAGE         bytea;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_bit(bit, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_bit(bit, bit, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_bit(bit, internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS bit_ops
+ DEFAULT FOR TYPE bit USING gin
+ AS
+     OPERATOR        1       <,
+     OPERATOR        2       <=,
+     OPERATOR        3       =,
+     OPERATOR        4       >=,
+     OPERATOR        5       >,
+ 	FUNCTION        1       bitcmp(bit,bit),
+ 	FUNCTION        2       gin_extract_value_bit(bit, internal),
+ 	FUNCTION        3       gin_extract_query_bit(bit, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_bit(bit,bit,internal),
+ STORAGE         bit;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_varbit(varbit, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_varbit(varbit, varbit, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_varbit(varbit, internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS varbit_ops
+ DEFAULT FOR TYPE varbit USING gin
+ AS
+     OPERATOR        1       <,
+     OPERATOR        2       <=,
+     OPERATOR        3       =,
+     OPERATOR        4       >=,
+     OPERATOR        5       >,
+ 	FUNCTION        1       varbitcmp(varbit,varbit),
+ 	FUNCTION        2       gin_extract_value_varbit(varbit, internal),
+ 	FUNCTION        3       gin_extract_query_varbit(varbit, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_varbit(varbit,varbit,internal),
+ STORAGE         varbit;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_value_numeric(numeric, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_compare_prefix_numeric(numeric, numeric, internal)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_extract_query_numeric(numeric, internal, int2, internal)
+ RETURNS internal
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OR REPLACE FUNCTION gin_numeric_cmp(numeric, numeric)
+ RETURNS int4
+ AS 'MODULE_PATHNAME'
+ LANGUAGE C IMMUTABLE;
+ 
+ CREATE OPERATOR CLASS numeric_ops
+ DEFAULT FOR TYPE numeric USING gin
+ AS
+     OPERATOR        1       <,
+     OPERATOR        2       <=,
+     OPERATOR        3       =,
+     OPERATOR        4       >=,
+     OPERATOR        5       >,
+ 	FUNCTION        1       gin_numeric_cmp(numeric,numeric),
+ 	FUNCTION        2       gin_extract_value_numeric(numeric, internal),
+ 	FUNCTION        3       gin_extract_query_numeric(numeric, internal, int2, internal),
+ 	FUNCTION        4       gin_btree_consistent(internal, int2, anyelement),
+ 	FUNCTION        5       gin_compare_prefix_numeric(numeric,numeric,internal),
+ STORAGE         numeric;
+ 
+ COMMIT;
diff -c -r -N contrib.orig/btree_gin/expected/bit.out contrib/btree_gin/expected/bit.out
*** contrib.orig/btree_gin/expected/bit.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/bit.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,44 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_bit (
+ 	i bit(3)
+ );
+ INSERT INTO test_bit VALUES ('001'),('010'),('011'),('100'),('101'),('110');
+ CREATE INDEX idx_bit ON test_bit USING gin (i);
+ SELECT * FROM test_bit WHERE i<'100'::bit(3) ORDER BY i;
+   i  
+ -----
+  001
+  010
+  011
+ (3 rows)
+ 
+ SELECT * FROM test_bit WHERE i<='100'::bit(3) ORDER BY i;
+   i  
+ -----
+  001
+  010
+  011
+  100
+ (4 rows)
+ 
+ SELECT * FROM test_bit WHERE i='100'::bit(3) ORDER BY i;
+   i  
+ -----
+  100
+ (1 row)
+ 
+ SELECT * FROM test_bit WHERE i>='100'::bit(3) ORDER BY i;
+   i  
+ -----
+  100
+  101
+  110
+ (3 rows)
+ 
+ SELECT * FROM test_bit WHERE i>'100'::bit(3) ORDER BY i;
+   i  
+ -----
+  101
+  110
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/btree_gin.out contrib/btree_gin/expected/btree_gin.out
*** contrib.orig/btree_gin/expected/btree_gin.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/btree_gin.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,3 ----
+ SET client_min_messages = warning;
+ \set ECHO none
+ RESET client_min_messages;
diff -c -r -N contrib.orig/btree_gin/expected/bytea.out contrib/btree_gin/expected/bytea.out
*** contrib.orig/btree_gin/expected/bytea.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/bytea.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,44 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_bytea (
+ 	i bytea
+ );
+ INSERT INTO test_bytea VALUES ('aaa'),('a'),('abc'),('abb'),('axy'),('xyz');
+ CREATE INDEX idx_bytea ON test_bytea USING gin (i);
+ SELECT * FROM test_bytea WHERE i<'abc'::bytea ORDER BY i;
+   i  
+ -----
+  a
+  aaa
+  abb
+ (3 rows)
+ 
+ SELECT * FROM test_bytea WHERE i<='abc'::bytea ORDER BY i;
+   i  
+ -----
+  a
+  aaa
+  abb
+  abc
+ (4 rows)
+ 
+ SELECT * FROM test_bytea WHERE i='abc'::bytea ORDER BY i;
+   i  
+ -----
+  abc
+ (1 row)
+ 
+ SELECT * FROM test_bytea WHERE i>='abc'::bytea ORDER BY i;
+   i  
+ -----
+  abc
+  axy
+  xyz
+ (3 rows)
+ 
+ SELECT * FROM test_bytea WHERE i>'abc'::bytea ORDER BY i;
+   i  
+ -----
+  axy
+  xyz
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/char.out contrib/btree_gin/expected/char.out
*** contrib.orig/btree_gin/expected/char.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/char.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,37 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_char (
+ 	i "char"
+ );
+ INSERT INTO test_char VALUES ('a'),('b'),('c'),('d'),('e'),('f');
+ CREATE INDEX idx_char ON test_char USING gin (i);
+ SELECT * FROM test_char WHERE i<'d'::"char" ORDER BY i;
+  i 
+ ---
+ (0 rows)
+ 
+ SELECT * FROM test_char WHERE i<='d'::"char" ORDER BY i;
+  i 
+ ---
+ (0 rows)
+ 
+ SELECT * FROM test_char WHERE i='d'::"char" ORDER BY i;
+  i 
+ ---
+  d
+ (1 row)
+ 
+ SELECT * FROM test_char WHERE i>='d'::"char" ORDER BY i;
+  i 
+ ---
+  d
+  e
+  f
+ (3 rows)
+ 
+ SELECT * FROM test_char WHERE i>'d'::"char" ORDER BY i;
+  i 
+ ---
+  e
+  f
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/cidr.out contrib/btree_gin/expected/cidr.out
*** contrib.orig/btree_gin/expected/cidr.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/cidr.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,51 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_cidr (
+ 	i cidr
+ );
+ INSERT INTO test_cidr VALUES 
+ 	( '1.2.3.4' ),
+ 	( '1.2.4.4' ),
+ 	( '1.2.5.4' ),
+ 	( '1.2.6.4' ),
+ 	( '1.2.7.4' ),
+ 	( '1.2.8.4' )
+ ;
+ CREATE INDEX idx_cidr ON test_cidr USING gin (i);
+ SELECT * FROM test_cidr WHERE i<'1.2.6.4'::cidr ORDER BY i;
+      i      
+ ------------
+  1.2.3.4/32
+  1.2.4.4/32
+  1.2.5.4/32
+ (3 rows)
+ 
+ SELECT * FROM test_cidr WHERE i<='1.2.6.4'::cidr ORDER BY i;
+      i      
+ ------------
+  1.2.3.4/32
+  1.2.4.4/32
+  1.2.5.4/32
+  1.2.6.4/32
+ (4 rows)
+ 
+ SELECT * FROM test_cidr WHERE i='1.2.6.4'::cidr ORDER BY i;
+      i      
+ ------------
+  1.2.6.4/32
+ (1 row)
+ 
+ SELECT * FROM test_cidr WHERE i>='1.2.6.4'::cidr ORDER BY i;
+      i      
+ ------------
+  1.2.6.4/32
+  1.2.7.4/32
+  1.2.8.4/32
+ (3 rows)
+ 
+ SELECT * FROM test_cidr WHERE i>'1.2.6.4'::cidr ORDER BY i;
+      i      
+ ------------
+  1.2.7.4/32
+  1.2.8.4/32
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/date.out contrib/btree_gin/expected/date.out
*** contrib.orig/btree_gin/expected/date.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/date.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,51 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_date (
+ 	i date
+ );
+ INSERT INTO test_date VALUES 
+ 	( '2004-10-23' ),
+ 	( '2004-10-24' ),
+ 	( '2004-10-25' ),
+ 	( '2004-10-26' ),
+ 	( '2004-10-27' ),
+ 	( '2004-10-28' )
+ ;
+ CREATE INDEX idx_date ON test_date USING gin (i);
+ SELECT * FROM test_date WHERE i<'2004-10-26'::date ORDER BY i;
+      i      
+ ------------
+  10-23-2004
+  10-24-2004
+  10-25-2004
+ (3 rows)
+ 
+ SELECT * FROM test_date WHERE i<='2004-10-26'::date ORDER BY i;
+      i      
+ ------------
+  10-23-2004
+  10-24-2004
+  10-25-2004
+  10-26-2004
+ (4 rows)
+ 
+ SELECT * FROM test_date WHERE i='2004-10-26'::date ORDER BY i;
+      i      
+ ------------
+  10-26-2004
+ (1 row)
+ 
+ SELECT * FROM test_date WHERE i>='2004-10-26'::date ORDER BY i;
+      i      
+ ------------
+  10-26-2004
+  10-27-2004
+  10-28-2004
+ (3 rows)
+ 
+ SELECT * FROM test_date WHERE i>'2004-10-26'::date ORDER BY i;
+      i      
+ ------------
+  10-27-2004
+  10-28-2004
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/float4.out contrib/btree_gin/expected/float4.out
*** contrib.orig/btree_gin/expected/float4.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/float4.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,44 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_float4 (
+ 	i float4
+ );
+ INSERT INTO test_float4 VALUES (-2),(-1),(0),(1),(2),(3);
+ CREATE INDEX idx_float4 ON test_float4 USING gin (i);
+ SELECT * FROM test_float4 WHERE i<1::float4 ORDER BY i;
+  i  
+ ----
+  -2
+  -1
+   0
+ (3 rows)
+ 
+ SELECT * FROM test_float4 WHERE i<=1::float4 ORDER BY i;
+  i  
+ ----
+  -2
+  -1
+   0
+   1
+ (4 rows)
+ 
+ SELECT * FROM test_float4 WHERE i=1::float4 ORDER BY i;
+  i 
+ ---
+  1
+ (1 row)
+ 
+ SELECT * FROM test_float4 WHERE i>=1::float4 ORDER BY i;
+  i 
+ ---
+  1
+  2
+  3
+ (3 rows)
+ 
+ SELECT * FROM test_float4 WHERE i>1::float4 ORDER BY i;
+  i 
+ ---
+  2
+  3
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/float8.out contrib/btree_gin/expected/float8.out
*** contrib.orig/btree_gin/expected/float8.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/float8.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,44 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_float8 (
+ 	i float8
+ );
+ INSERT INTO test_float8 VALUES (-2),(-1),(0),(1),(2),(3);
+ CREATE INDEX idx_float8 ON test_float8 USING gin (i);
+ SELECT * FROM test_float8 WHERE i<1::float8 ORDER BY i;
+  i  
+ ----
+  -2
+  -1
+   0
+ (3 rows)
+ 
+ SELECT * FROM test_float8 WHERE i<=1::float8 ORDER BY i;
+  i  
+ ----
+  -2
+  -1
+   0
+   1
+ (4 rows)
+ 
+ SELECT * FROM test_float8 WHERE i=1::float8 ORDER BY i;
+  i 
+ ---
+  1
+ (1 row)
+ 
+ SELECT * FROM test_float8 WHERE i>=1::float8 ORDER BY i;
+  i 
+ ---
+  1
+  2
+  3
+ (3 rows)
+ 
+ SELECT * FROM test_float8 WHERE i>1::float8 ORDER BY i;
+  i 
+ ---
+  2
+  3
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/inet.out contrib/btree_gin/expected/inet.out
*** contrib.orig/btree_gin/expected/inet.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/inet.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,51 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_inet (
+ 	i inet
+ );
+ INSERT INTO test_inet VALUES 
+ 	( '1.2.3.4/16' ),
+ 	( '1.2.4.4/16' ),
+ 	( '1.2.5.4/16' ),
+ 	( '1.2.6.4/16' ),
+ 	( '1.2.7.4/16' ),
+ 	( '1.2.8.4/16' )
+ ;
+ CREATE INDEX idx_inet ON test_inet USING gin (i);
+ SELECT * FROM test_inet WHERE i<'1.2.6.4/16'::inet ORDER BY i;
+      i      
+ ------------
+  1.2.3.4/16
+  1.2.4.4/16
+  1.2.5.4/16
+ (3 rows)
+ 
+ SELECT * FROM test_inet WHERE i<='1.2.6.4/16'::inet ORDER BY i;
+      i      
+ ------------
+  1.2.3.4/16
+  1.2.4.4/16
+  1.2.5.4/16
+  1.2.6.4/16
+ (4 rows)
+ 
+ SELECT * FROM test_inet WHERE i='1.2.6.4/16'::inet ORDER BY i;
+      i      
+ ------------
+  1.2.6.4/16
+ (1 row)
+ 
+ SELECT * FROM test_inet WHERE i>='1.2.6.4/16'::inet ORDER BY i;
+      i      
+ ------------
+  1.2.6.4/16
+  1.2.7.4/16
+  1.2.8.4/16
+ (3 rows)
+ 
+ SELECT * FROM test_inet WHERE i>'1.2.6.4/16'::inet ORDER BY i;
+      i      
+ ------------
+  1.2.7.4/16
+  1.2.8.4/16
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/int2.out contrib/btree_gin/expected/int2.out
*** contrib.orig/btree_gin/expected/int2.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/int2.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,44 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_int2 (
+ 	i int2
+ );
+ INSERT INTO test_int2 VALUES (-2),(-1),(0),(1),(2),(3);
+ CREATE INDEX idx_int2 ON test_int2 USING gin (i);
+ SELECT * FROM test_int2 WHERE i<1::int2 ORDER BY i;
+  i  
+ ----
+  -2
+  -1
+   0
+ (3 rows)
+ 
+ SELECT * FROM test_int2 WHERE i<=1::int2 ORDER BY i;
+  i  
+ ----
+  -2
+  -1
+   0
+   1
+ (4 rows)
+ 
+ SELECT * FROM test_int2 WHERE i=1::int2 ORDER BY i;
+  i 
+ ---
+  1
+ (1 row)
+ 
+ SELECT * FROM test_int2 WHERE i>=1::int2 ORDER BY i;
+  i 
+ ---
+  1
+  2
+  3
+ (3 rows)
+ 
+ SELECT * FROM test_int2 WHERE i>1::int2 ORDER BY i;
+  i 
+ ---
+  2
+  3
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/int4.out contrib/btree_gin/expected/int4.out
*** contrib.orig/btree_gin/expected/int4.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/int4.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,44 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_int4 (
+ 	i int4
+ );
+ INSERT INTO test_int4 VALUES (-2),(-1),(0),(1),(2),(3);
+ CREATE INDEX idx_int4 ON test_int4 USING gin (i);
+ SELECT * FROM test_int4 WHERE i<1::int4 ORDER BY i;
+  i  
+ ----
+  -2
+  -1
+   0
+ (3 rows)
+ 
+ SELECT * FROM test_int4 WHERE i<=1::int4 ORDER BY i;
+  i  
+ ----
+  -2
+  -1
+   0
+   1
+ (4 rows)
+ 
+ SELECT * FROM test_int4 WHERE i=1::int4 ORDER BY i;
+  i 
+ ---
+  1
+ (1 row)
+ 
+ SELECT * FROM test_int4 WHERE i>=1::int4 ORDER BY i;
+  i 
+ ---
+  1
+  2
+  3
+ (3 rows)
+ 
+ SELECT * FROM test_int4 WHERE i>1::int4 ORDER BY i;
+  i 
+ ---
+  2
+  3
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/int8.out contrib/btree_gin/expected/int8.out
*** contrib.orig/btree_gin/expected/int8.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/int8.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,44 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_int8 (
+ 	i int8
+ );
+ INSERT INTO test_int8 VALUES (-2),(-1),(0),(1),(2),(3);
+ CREATE INDEX idx_int8 ON test_int8 USING gin (i);
+ SELECT * FROM test_int8 WHERE i<1::int8 ORDER BY i;
+  i  
+ ----
+  -2
+  -1
+   0
+ (3 rows)
+ 
+ SELECT * FROM test_int8 WHERE i<=1::int8 ORDER BY i;
+  i  
+ ----
+  -2
+  -1
+   0
+   1
+ (4 rows)
+ 
+ SELECT * FROM test_int8 WHERE i=1::int8 ORDER BY i;
+  i 
+ ---
+  1
+ (1 row)
+ 
+ SELECT * FROM test_int8 WHERE i>=1::int8 ORDER BY i;
+  i 
+ ---
+  1
+  2
+  3
+ (3 rows)
+ 
+ SELECT * FROM test_int8 WHERE i>1::int8 ORDER BY i;
+  i 
+ ---
+  2
+  3
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/interval.out contrib/btree_gin/expected/interval.out
*** contrib.orig/btree_gin/expected/interval.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/interval.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,51 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_interval (
+ 	i interval
+ );
+ INSERT INTO test_interval VALUES 
+ 	( '03:55:08' ),
+ 	( '04:55:08' ),
+ 	( '05:55:08' ),
+ 	( '08:55:08' ),
+ 	( '09:55:08' ),
+ 	( '10:55:08' )
+ ;
+ CREATE INDEX idx_interval ON test_interval USING gin (i);
+ SELECT * FROM test_interval WHERE i<'08:55:08'::interval ORDER BY i;
+             i             
+ --------------------------
+  @ 3 hours 55 mins 8 secs
+  @ 4 hours 55 mins 8 secs
+  @ 5 hours 55 mins 8 secs
+ (3 rows)
+ 
+ SELECT * FROM test_interval WHERE i<='08:55:08'::interval ORDER BY i;
+             i             
+ --------------------------
+  @ 3 hours 55 mins 8 secs
+  @ 4 hours 55 mins 8 secs
+  @ 5 hours 55 mins 8 secs
+  @ 8 hours 55 mins 8 secs
+ (4 rows)
+ 
+ SELECT * FROM test_interval WHERE i='08:55:08'::interval ORDER BY i;
+             i             
+ --------------------------
+  @ 8 hours 55 mins 8 secs
+ (1 row)
+ 
+ SELECT * FROM test_interval WHERE i>='08:55:08'::interval ORDER BY i;
+              i             
+ ---------------------------
+  @ 8 hours 55 mins 8 secs
+  @ 9 hours 55 mins 8 secs
+  @ 10 hours 55 mins 8 secs
+ (3 rows)
+ 
+ SELECT * FROM test_interval WHERE i>'08:55:08'::interval ORDER BY i;
+              i             
+ ---------------------------
+  @ 9 hours 55 mins 8 secs
+  @ 10 hours 55 mins 8 secs
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/macaddr.out contrib/btree_gin/expected/macaddr.out
*** contrib.orig/btree_gin/expected/macaddr.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/macaddr.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,51 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_macaddr (
+ 	i macaddr
+ );
+ INSERT INTO test_macaddr VALUES 
+ 	( '22:00:5c:03:55:08' ),
+ 	( '22:00:5c:04:55:08' ),
+ 	( '22:00:5c:05:55:08' ),
+ 	( '22:00:5c:08:55:08' ),
+ 	( '22:00:5c:09:55:08' ),
+ 	( '22:00:5c:10:55:08' )
+ ;
+ CREATE INDEX idx_macaddr ON test_macaddr USING gin (i);
+ SELECT * FROM test_macaddr WHERE i<'22:00:5c:08:55:08'::macaddr ORDER BY i;
+          i         
+ -------------------
+  22:00:5c:03:55:08
+  22:00:5c:04:55:08
+  22:00:5c:05:55:08
+ (3 rows)
+ 
+ SELECT * FROM test_macaddr WHERE i<='22:00:5c:08:55:08'::macaddr ORDER BY i;
+          i         
+ -------------------
+  22:00:5c:03:55:08
+  22:00:5c:04:55:08
+  22:00:5c:05:55:08
+  22:00:5c:08:55:08
+ (4 rows)
+ 
+ SELECT * FROM test_macaddr WHERE i='22:00:5c:08:55:08'::macaddr ORDER BY i;
+          i         
+ -------------------
+  22:00:5c:08:55:08
+ (1 row)
+ 
+ SELECT * FROM test_macaddr WHERE i>='22:00:5c:08:55:08'::macaddr ORDER BY i;
+          i         
+ -------------------
+  22:00:5c:08:55:08
+  22:00:5c:09:55:08
+  22:00:5c:10:55:08
+ (3 rows)
+ 
+ SELECT * FROM test_macaddr WHERE i>'22:00:5c:08:55:08'::macaddr ORDER BY i;
+          i         
+ -------------------
+  22:00:5c:09:55:08
+  22:00:5c:10:55:08
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/money.out contrib/btree_gin/expected/money.out
*** contrib.orig/btree_gin/expected/money.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/money.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,44 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_money (
+ 	i money
+ );
+ INSERT INTO test_money VALUES ('-2'),('-1'),('0'),('1'),('2'),('3');
+ CREATE INDEX idx_money ON test_money USING gin (i);
+ SELECT * FROM test_money WHERE i<'1'::money ORDER BY i;
+    i    
+ --------
+  -$2.00
+  -$1.00
+   $0.00
+ (3 rows)
+ 
+ SELECT * FROM test_money WHERE i<='1'::money ORDER BY i;
+    i    
+ --------
+  -$2.00
+  -$1.00
+   $0.00
+   $1.00
+ (4 rows)
+ 
+ SELECT * FROM test_money WHERE i='1'::money ORDER BY i;
+    i   
+ -------
+  $1.00
+ (1 row)
+ 
+ SELECT * FROM test_money WHERE i>='1'::money ORDER BY i;
+    i   
+ -------
+  $1.00
+  $2.00
+  $3.00
+ (3 rows)
+ 
+ SELECT * FROM test_money WHERE i>'1'::money ORDER BY i;
+    i   
+ -------
+  $2.00
+  $3.00
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/numeric.out contrib/btree_gin/expected/numeric.out
*** contrib.orig/btree_gin/expected/numeric.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/numeric.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,44 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_numeric (
+ 	i numeric
+ );
+ INSERT INTO test_numeric VALUES (-2),(-1),(0),(1),(2),(3);
+ CREATE INDEX idx_numeric ON test_numeric USING gin (i);
+ SELECT * FROM test_numeric WHERE i<'1'::numeric ORDER BY i;
+  i  
+ ----
+  -2
+  -1
+   0
+ (3 rows)
+ 
+ SELECT * FROM test_numeric WHERE i<='1'::numeric ORDER BY i;
+  i  
+ ----
+  -2
+  -1
+   0
+   1
+ (4 rows)
+ 
+ SELECT * FROM test_numeric WHERE i='1'::numeric ORDER BY i;
+  i 
+ ---
+  1
+ (1 row)
+ 
+ SELECT * FROM test_numeric WHERE i>='1'::numeric ORDER BY i;
+  i 
+ ---
+  1
+  2
+  3
+ (3 rows)
+ 
+ SELECT * FROM test_numeric WHERE i>'1'::numeric ORDER BY i;
+  i 
+ ---
+  2
+  3
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/oid.out contrib/btree_gin/expected/oid.out
*** contrib.orig/btree_gin/expected/oid.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/oid.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,44 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_oid (
+ 	i oid
+ );
+ INSERT INTO test_oid VALUES (0),(1),(2),(3),(4),(5);
+ CREATE INDEX idx_oid ON test_oid USING gin (i);
+ SELECT * FROM test_oid WHERE i<3::oid ORDER BY i;
+  i 
+ ---
+  0
+  1
+  2
+ (3 rows)
+ 
+ SELECT * FROM test_oid WHERE i<=3::oid ORDER BY i;
+  i 
+ ---
+  0
+  1
+  2
+  3
+ (4 rows)
+ 
+ SELECT * FROM test_oid WHERE i=3::oid ORDER BY i;
+  i 
+ ---
+  3
+ (1 row)
+ 
+ SELECT * FROM test_oid WHERE i>=3::oid ORDER BY i;
+  i 
+ ---
+  3
+  4
+  5
+ (3 rows)
+ 
+ SELECT * FROM test_oid WHERE i>3::oid ORDER BY i;
+  i 
+ ---
+  4
+  5
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/text.out contrib/btree_gin/expected/text.out
*** contrib.orig/btree_gin/expected/text.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/text.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,44 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_text (
+ 	i text
+ );
+ INSERT INTO test_text VALUES ('aaa'),('a'),('abc'),('abb'),('axy'),('xyz');
+ CREATE INDEX idx_text ON test_text USING gin (i);
+ SELECT * FROM test_text WHERE i<'abc' ORDER BY i;
+   i  
+ -----
+  a
+  aaa
+  abb
+ (3 rows)
+ 
+ SELECT * FROM test_text WHERE i<='abc' ORDER BY i;
+   i  
+ -----
+  a
+  aaa
+  abb
+  abc
+ (4 rows)
+ 
+ SELECT * FROM test_text WHERE i='abc' ORDER BY i;
+   i  
+ -----
+  abc
+ (1 row)
+ 
+ SELECT * FROM test_text WHERE i>='abc' ORDER BY i;
+   i  
+ -----
+  abc
+  axy
+  xyz
+ (3 rows)
+ 
+ SELECT * FROM test_text WHERE i>'abc' ORDER BY i;
+   i  
+ -----
+  axy
+  xyz
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/time.out contrib/btree_gin/expected/time.out
*** contrib.orig/btree_gin/expected/time.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/time.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,51 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_time (
+ 	i time
+ );
+ INSERT INTO test_time VALUES 
+ 	( '03:55:08' ),
+ 	( '04:55:08' ),
+ 	( '05:55:08' ),
+ 	( '08:55:08' ),
+ 	( '09:55:08' ),
+ 	( '10:55:08' )
+ ;
+ CREATE INDEX idx_time ON test_time USING gin (i);
+ SELECT * FROM test_time WHERE i<'08:55:08'::time ORDER BY i;
+     i     
+ ----------
+  03:55:08
+  04:55:08
+  05:55:08
+ (3 rows)
+ 
+ SELECT * FROM test_time WHERE i<='08:55:08'::time ORDER BY i;
+     i     
+ ----------
+  03:55:08
+  04:55:08
+  05:55:08
+  08:55:08
+ (4 rows)
+ 
+ SELECT * FROM test_time WHERE i='08:55:08'::time ORDER BY i;
+     i     
+ ----------
+  08:55:08
+ (1 row)
+ 
+ SELECT * FROM test_time WHERE i>='08:55:08'::time ORDER BY i;
+     i     
+ ----------
+  08:55:08
+  09:55:08
+  10:55:08
+ (3 rows)
+ 
+ SELECT * FROM test_time WHERE i>'08:55:08'::time ORDER BY i;
+     i     
+ ----------
+  09:55:08
+  10:55:08
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/timestamp.out contrib/btree_gin/expected/timestamp.out
*** contrib.orig/btree_gin/expected/timestamp.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/timestamp.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,51 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_timestamp (
+ 	i timestamp
+ );
+ INSERT INTO test_timestamp VALUES 
+ 	( '2004-10-26 03:55:08' ),
+ 	( '2004-10-26 04:55:08' ),
+ 	( '2004-10-26 05:55:08' ),
+ 	( '2004-10-26 08:55:08' ),
+ 	( '2004-10-26 09:55:08' ),
+ 	( '2004-10-26 10:55:08' )
+ ;
+ CREATE INDEX idx_timestamp ON test_timestamp USING gin (i);
+ SELECT * FROM test_timestamp WHERE i<'2004-10-26 08:55:08'::timestamp ORDER BY i;
+             i             
+ --------------------------
+  Tue Oct 26 03:55:08 2004
+  Tue Oct 26 04:55:08 2004
+  Tue Oct 26 05:55:08 2004
+ (3 rows)
+ 
+ SELECT * FROM test_timestamp WHERE i<='2004-10-26 08:55:08'::timestamp ORDER BY i;
+             i             
+ --------------------------
+  Tue Oct 26 03:55:08 2004
+  Tue Oct 26 04:55:08 2004
+  Tue Oct 26 05:55:08 2004
+  Tue Oct 26 08:55:08 2004
+ (4 rows)
+ 
+ SELECT * FROM test_timestamp WHERE i='2004-10-26 08:55:08'::timestamp ORDER BY i;
+             i             
+ --------------------------
+  Tue Oct 26 08:55:08 2004
+ (1 row)
+ 
+ SELECT * FROM test_timestamp WHERE i>='2004-10-26 08:55:08'::timestamp ORDER BY i;
+             i             
+ --------------------------
+  Tue Oct 26 08:55:08 2004
+  Tue Oct 26 09:55:08 2004
+  Tue Oct 26 10:55:08 2004
+ (3 rows)
+ 
+ SELECT * FROM test_timestamp WHERE i>'2004-10-26 08:55:08'::timestamp ORDER BY i;
+             i             
+ --------------------------
+  Tue Oct 26 09:55:08 2004
+  Tue Oct 26 10:55:08 2004
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/timestamptz.out contrib/btree_gin/expected/timestamptz.out
*** contrib.orig/btree_gin/expected/timestamptz.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/timestamptz.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,51 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_timestamptz (
+ 	i timestamptz
+ );
+ INSERT INTO test_timestamptz VALUES 
+ 	( '2004-10-26 03:55:08' ),
+ 	( '2004-10-26 04:55:08' ),
+ 	( '2004-10-26 05:55:08' ),
+ 	( '2004-10-26 08:55:08' ),
+ 	( '2004-10-26 09:55:08' ),
+ 	( '2004-10-26 10:55:08' )
+ ;
+ CREATE INDEX idx_timestamptz ON test_timestamptz USING gin (i);
+ SELECT * FROM test_timestamptz WHERE i<'2004-10-26 08:55:08'::timestamptz ORDER BY i;
+               i               
+ ------------------------------
+  Tue Oct 26 03:55:08 2004 PDT
+  Tue Oct 26 04:55:08 2004 PDT
+  Tue Oct 26 05:55:08 2004 PDT
+ (3 rows)
+ 
+ SELECT * FROM test_timestamptz WHERE i<='2004-10-26 08:55:08'::timestamptz ORDER BY i;
+               i               
+ ------------------------------
+  Tue Oct 26 03:55:08 2004 PDT
+  Tue Oct 26 04:55:08 2004 PDT
+  Tue Oct 26 05:55:08 2004 PDT
+  Tue Oct 26 08:55:08 2004 PDT
+ (4 rows)
+ 
+ SELECT * FROM test_timestamptz WHERE i='2004-10-26 08:55:08'::timestamptz ORDER BY i;
+               i               
+ ------------------------------
+  Tue Oct 26 08:55:08 2004 PDT
+ (1 row)
+ 
+ SELECT * FROM test_timestamptz WHERE i>='2004-10-26 08:55:08'::timestamptz ORDER BY i;
+               i               
+ ------------------------------
+  Tue Oct 26 08:55:08 2004 PDT
+  Tue Oct 26 09:55:08 2004 PDT
+  Tue Oct 26 10:55:08 2004 PDT
+ (3 rows)
+ 
+ SELECT * FROM test_timestamptz WHERE i>'2004-10-26 08:55:08'::timestamptz ORDER BY i;
+               i               
+ ------------------------------
+  Tue Oct 26 09:55:08 2004 PDT
+  Tue Oct 26 10:55:08 2004 PDT
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/timetz.out contrib/btree_gin/expected/timetz.out
*** contrib.orig/btree_gin/expected/timetz.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/timetz.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,51 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_timetz (
+ 	i timetz
+ );
+ INSERT INTO test_timetz VALUES 
+ 	( '03:55:08 GMT+2' ),
+ 	( '04:55:08 GMT+2' ),
+ 	( '05:55:08 GMT+2' ),
+ 	( '08:55:08 GMT+2' ),
+ 	( '09:55:08 GMT+2' ),
+ 	( '10:55:08 GMT+2' )
+ ;
+ CREATE INDEX idx_timetz ON test_timetz USING gin (i);
+ SELECT * FROM test_timetz WHERE i<'08:55:08 GMT+2'::timetz ORDER BY i;
+       i      
+ -------------
+  03:55:08-02
+  04:55:08-02
+  05:55:08-02
+ (3 rows)
+ 
+ SELECT * FROM test_timetz WHERE i<='08:55:08 GMT+2'::timetz ORDER BY i;
+       i      
+ -------------
+  03:55:08-02
+  04:55:08-02
+  05:55:08-02
+  08:55:08-02
+ (4 rows)
+ 
+ SELECT * FROM test_timetz WHERE i='08:55:08 GMT+2'::timetz ORDER BY i;
+       i      
+ -------------
+  08:55:08-02
+ (1 row)
+ 
+ SELECT * FROM test_timetz WHERE i>='08:55:08 GMT+2'::timetz ORDER BY i;
+       i      
+ -------------
+  08:55:08-02
+  09:55:08-02
+  10:55:08-02
+ (3 rows)
+ 
+ SELECT * FROM test_timetz WHERE i>'08:55:08 GMT+2'::timetz ORDER BY i;
+       i      
+ -------------
+  09:55:08-02
+  10:55:08-02
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/varbit.out contrib/btree_gin/expected/varbit.out
*** contrib.orig/btree_gin/expected/varbit.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/varbit.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,44 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_varbit (
+ 	i varbit
+ );
+ INSERT INTO test_varbit VALUES ('001'),('010'),('011'),('100'),('101'),('110');
+ CREATE INDEX idx_varbit ON test_varbit USING gin (i);
+ SELECT * FROM test_varbit WHERE i<'100'::varbit ORDER BY i;
+   i  
+ -----
+  001
+  010
+  011
+ (3 rows)
+ 
+ SELECT * FROM test_varbit WHERE i<='100'::varbit ORDER BY i;
+   i  
+ -----
+  001
+  010
+  011
+  100
+ (4 rows)
+ 
+ SELECT * FROM test_varbit WHERE i='100'::varbit ORDER BY i;
+   i  
+ -----
+  100
+ (1 row)
+ 
+ SELECT * FROM test_varbit WHERE i>='100'::varbit ORDER BY i;
+   i  
+ -----
+  100
+  101
+  110
+ (3 rows)
+ 
+ SELECT * FROM test_varbit WHERE i>'100'::varbit ORDER BY i;
+   i  
+ -----
+  101
+  110
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/expected/varchar.out contrib/btree_gin/expected/varchar.out
*** contrib.orig/btree_gin/expected/varchar.out	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/expected/varchar.out	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,44 ----
+ set enable_seqscan=off;
+ CREATE TABLE test_varchar (
+ 	i varchar
+ );
+ INSERT INTO test_varchar VALUES ('aaa'),('a'),('abc'),('abb'),('axy'),('xyz');
+ CREATE INDEX idx_varchar ON test_varchar USING gin (i);
+ SELECT * FROM test_varchar WHERE i<'abc'::varchar ORDER BY i;
+   i  
+ -----
+  a
+  aaa
+  abb
+ (3 rows)
+ 
+ SELECT * FROM test_varchar WHERE i<='abc'::varchar ORDER BY i;
+   i  
+ -----
+  a
+  aaa
+  abb
+  abc
+ (4 rows)
+ 
+ SELECT * FROM test_varchar WHERE i='abc'::varchar ORDER BY i;
+   i  
+ -----
+  abc
+ (1 row)
+ 
+ SELECT * FROM test_varchar WHERE i>='abc'::varchar ORDER BY i;
+   i  
+ -----
+  abc
+  axy
+  xyz
+ (3 rows)
+ 
+ SELECT * FROM test_varchar WHERE i>'abc'::varchar ORDER BY i;
+   i  
+ -----
+  axy
+  xyz
+ (2 rows)
+ 
diff -c -r -N contrib.orig/btree_gin/sql/bit.sql contrib/btree_gin/sql/bit.sql
*** contrib.orig/btree_gin/sql/bit.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/bit.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,15 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_bit (
+ 	i bit(3)
+ );
+ 
+ INSERT INTO test_bit VALUES ('001'),('010'),('011'),('100'),('101'),('110');
+ 
+ CREATE INDEX idx_bit ON test_bit USING gin (i);
+ 
+ SELECT * FROM test_bit WHERE i<'100'::bit(3) ORDER BY i;
+ SELECT * FROM test_bit WHERE i<='100'::bit(3) ORDER BY i;
+ SELECT * FROM test_bit WHERE i='100'::bit(3) ORDER BY i;
+ SELECT * FROM test_bit WHERE i>='100'::bit(3) ORDER BY i;
+ SELECT * FROM test_bit WHERE i>'100'::bit(3) ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/btree_gin.sql contrib/btree_gin/sql/btree_gin.sql
*** contrib.orig/btree_gin/sql/btree_gin.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/btree_gin.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,6 ----
+ SET client_min_messages = warning;
+ \set ECHO none
+ \i btree_gin.sql
+ \set ECHO all
+ RESET client_min_messages;
+ 
diff -c -r -N contrib.orig/btree_gin/sql/bytea.sql contrib/btree_gin/sql/bytea.sql
*** contrib.orig/btree_gin/sql/bytea.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/bytea.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,15 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_bytea (
+ 	i bytea
+ );
+ 
+ INSERT INTO test_bytea VALUES ('aaa'),('a'),('abc'),('abb'),('axy'),('xyz');
+ 
+ CREATE INDEX idx_bytea ON test_bytea USING gin (i);
+ 
+ SELECT * FROM test_bytea WHERE i<'abc'::bytea ORDER BY i;
+ SELECT * FROM test_bytea WHERE i<='abc'::bytea ORDER BY i;
+ SELECT * FROM test_bytea WHERE i='abc'::bytea ORDER BY i;
+ SELECT * FROM test_bytea WHERE i>='abc'::bytea ORDER BY i;
+ SELECT * FROM test_bytea WHERE i>'abc'::bytea ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/char.sql contrib/btree_gin/sql/char.sql
*** contrib.orig/btree_gin/sql/char.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/char.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,15 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_char (
+ 	i "char"
+ );
+ 
+ INSERT INTO test_char VALUES ('a'),('b'),('c'),('d'),('e'),('f');
+ 
+ CREATE INDEX idx_char ON test_char USING gin (i);
+ 
+ SELECT * FROM test_char WHERE i<'d'::"char" ORDER BY i;
+ SELECT * FROM test_char WHERE i<='d'::"char" ORDER BY i;
+ SELECT * FROM test_char WHERE i='d'::"char" ORDER BY i;
+ SELECT * FROM test_char WHERE i>='d'::"char" ORDER BY i;
+ SELECT * FROM test_char WHERE i>'d'::"char" ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/cidr.sql contrib/btree_gin/sql/cidr.sql
*** contrib.orig/btree_gin/sql/cidr.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/cidr.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,22 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_cidr (
+ 	i cidr
+ );
+ 
+ INSERT INTO test_cidr VALUES 
+ 	( '1.2.3.4' ),
+ 	( '1.2.4.4' ),
+ 	( '1.2.5.4' ),
+ 	( '1.2.6.4' ),
+ 	( '1.2.7.4' ),
+ 	( '1.2.8.4' )
+ ;
+ 
+ CREATE INDEX idx_cidr ON test_cidr USING gin (i);
+ 
+ SELECT * FROM test_cidr WHERE i<'1.2.6.4'::cidr ORDER BY i;
+ SELECT * FROM test_cidr WHERE i<='1.2.6.4'::cidr ORDER BY i;
+ SELECT * FROM test_cidr WHERE i='1.2.6.4'::cidr ORDER BY i;
+ SELECT * FROM test_cidr WHERE i>='1.2.6.4'::cidr ORDER BY i;
+ SELECT * FROM test_cidr WHERE i>'1.2.6.4'::cidr ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/date.sql contrib/btree_gin/sql/date.sql
*** contrib.orig/btree_gin/sql/date.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/date.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,22 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_date (
+ 	i date
+ );
+ 
+ INSERT INTO test_date VALUES 
+ 	( '2004-10-23' ),
+ 	( '2004-10-24' ),
+ 	( '2004-10-25' ),
+ 	( '2004-10-26' ),
+ 	( '2004-10-27' ),
+ 	( '2004-10-28' )
+ ;
+ 
+ CREATE INDEX idx_date ON test_date USING gin (i);
+ 
+ SELECT * FROM test_date WHERE i<'2004-10-26'::date ORDER BY i;
+ SELECT * FROM test_date WHERE i<='2004-10-26'::date ORDER BY i;
+ SELECT * FROM test_date WHERE i='2004-10-26'::date ORDER BY i;
+ SELECT * FROM test_date WHERE i>='2004-10-26'::date ORDER BY i;
+ SELECT * FROM test_date WHERE i>'2004-10-26'::date ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/float4.sql contrib/btree_gin/sql/float4.sql
*** contrib.orig/btree_gin/sql/float4.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/float4.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,15 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_float4 (
+ 	i float4
+ );
+ 
+ INSERT INTO test_float4 VALUES (-2),(-1),(0),(1),(2),(3);
+ 
+ CREATE INDEX idx_float4 ON test_float4 USING gin (i);
+ 
+ SELECT * FROM test_float4 WHERE i<1::float4 ORDER BY i;
+ SELECT * FROM test_float4 WHERE i<=1::float4 ORDER BY i;
+ SELECT * FROM test_float4 WHERE i=1::float4 ORDER BY i;
+ SELECT * FROM test_float4 WHERE i>=1::float4 ORDER BY i;
+ SELECT * FROM test_float4 WHERE i>1::float4 ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/float8.sql contrib/btree_gin/sql/float8.sql
*** contrib.orig/btree_gin/sql/float8.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/float8.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,15 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_float8 (
+ 	i float8
+ );
+ 
+ INSERT INTO test_float8 VALUES (-2),(-1),(0),(1),(2),(3);
+ 
+ CREATE INDEX idx_float8 ON test_float8 USING gin (i);
+ 
+ SELECT * FROM test_float8 WHERE i<1::float8 ORDER BY i;
+ SELECT * FROM test_float8 WHERE i<=1::float8 ORDER BY i;
+ SELECT * FROM test_float8 WHERE i=1::float8 ORDER BY i;
+ SELECT * FROM test_float8 WHERE i>=1::float8 ORDER BY i;
+ SELECT * FROM test_float8 WHERE i>1::float8 ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/inet.sql contrib/btree_gin/sql/inet.sql
*** contrib.orig/btree_gin/sql/inet.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/inet.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,22 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_inet (
+ 	i inet
+ );
+ 
+ INSERT INTO test_inet VALUES 
+ 	( '1.2.3.4/16' ),
+ 	( '1.2.4.4/16' ),
+ 	( '1.2.5.4/16' ),
+ 	( '1.2.6.4/16' ),
+ 	( '1.2.7.4/16' ),
+ 	( '1.2.8.4/16' )
+ ;
+ 
+ CREATE INDEX idx_inet ON test_inet USING gin (i);
+ 
+ SELECT * FROM test_inet WHERE i<'1.2.6.4/16'::inet ORDER BY i;
+ SELECT * FROM test_inet WHERE i<='1.2.6.4/16'::inet ORDER BY i;
+ SELECT * FROM test_inet WHERE i='1.2.6.4/16'::inet ORDER BY i;
+ SELECT * FROM test_inet WHERE i>='1.2.6.4/16'::inet ORDER BY i;
+ SELECT * FROM test_inet WHERE i>'1.2.6.4/16'::inet ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/int2.sql contrib/btree_gin/sql/int2.sql
*** contrib.orig/btree_gin/sql/int2.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/int2.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,15 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_int2 (
+ 	i int2
+ );
+ 
+ INSERT INTO test_int2 VALUES (-2),(-1),(0),(1),(2),(3);
+ 
+ CREATE INDEX idx_int2 ON test_int2 USING gin (i);
+ 
+ SELECT * FROM test_int2 WHERE i<1::int2 ORDER BY i;
+ SELECT * FROM test_int2 WHERE i<=1::int2 ORDER BY i;
+ SELECT * FROM test_int2 WHERE i=1::int2 ORDER BY i;
+ SELECT * FROM test_int2 WHERE i>=1::int2 ORDER BY i;
+ SELECT * FROM test_int2 WHERE i>1::int2 ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/int4.sql contrib/btree_gin/sql/int4.sql
*** contrib.orig/btree_gin/sql/int4.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/int4.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,15 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_int4 (
+ 	i int4
+ );
+ 
+ INSERT INTO test_int4 VALUES (-2),(-1),(0),(1),(2),(3);
+ 
+ CREATE INDEX idx_int4 ON test_int4 USING gin (i);
+ 
+ SELECT * FROM test_int4 WHERE i<1::int4 ORDER BY i;
+ SELECT * FROM test_int4 WHERE i<=1::int4 ORDER BY i;
+ SELECT * FROM test_int4 WHERE i=1::int4 ORDER BY i;
+ SELECT * FROM test_int4 WHERE i>=1::int4 ORDER BY i;
+ SELECT * FROM test_int4 WHERE i>1::int4 ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/int8.sql contrib/btree_gin/sql/int8.sql
*** contrib.orig/btree_gin/sql/int8.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/int8.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,15 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_int8 (
+ 	i int8
+ );
+ 
+ INSERT INTO test_int8 VALUES (-2),(-1),(0),(1),(2),(3);
+ 
+ CREATE INDEX idx_int8 ON test_int8 USING gin (i);
+ 
+ SELECT * FROM test_int8 WHERE i<1::int8 ORDER BY i;
+ SELECT * FROM test_int8 WHERE i<=1::int8 ORDER BY i;
+ SELECT * FROM test_int8 WHERE i=1::int8 ORDER BY i;
+ SELECT * FROM test_int8 WHERE i>=1::int8 ORDER BY i;
+ SELECT * FROM test_int8 WHERE i>1::int8 ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/interval.sql contrib/btree_gin/sql/interval.sql
*** contrib.orig/btree_gin/sql/interval.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/interval.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,22 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_interval (
+ 	i interval
+ );
+ 
+ INSERT INTO test_interval VALUES 
+ 	( '03:55:08' ),
+ 	( '04:55:08' ),
+ 	( '05:55:08' ),
+ 	( '08:55:08' ),
+ 	( '09:55:08' ),
+ 	( '10:55:08' )
+ ;
+ 
+ CREATE INDEX idx_interval ON test_interval USING gin (i);
+ 
+ SELECT * FROM test_interval WHERE i<'08:55:08'::interval ORDER BY i;
+ SELECT * FROM test_interval WHERE i<='08:55:08'::interval ORDER BY i;
+ SELECT * FROM test_interval WHERE i='08:55:08'::interval ORDER BY i;
+ SELECT * FROM test_interval WHERE i>='08:55:08'::interval ORDER BY i;
+ SELECT * FROM test_interval WHERE i>'08:55:08'::interval ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/macaddr.sql contrib/btree_gin/sql/macaddr.sql
*** contrib.orig/btree_gin/sql/macaddr.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/macaddr.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,22 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_macaddr (
+ 	i macaddr
+ );
+ 
+ INSERT INTO test_macaddr VALUES 
+ 	( '22:00:5c:03:55:08' ),
+ 	( '22:00:5c:04:55:08' ),
+ 	( '22:00:5c:05:55:08' ),
+ 	( '22:00:5c:08:55:08' ),
+ 	( '22:00:5c:09:55:08' ),
+ 	( '22:00:5c:10:55:08' )
+ ;
+ 
+ CREATE INDEX idx_macaddr ON test_macaddr USING gin (i);
+ 
+ SELECT * FROM test_macaddr WHERE i<'22:00:5c:08:55:08'::macaddr ORDER BY i;
+ SELECT * FROM test_macaddr WHERE i<='22:00:5c:08:55:08'::macaddr ORDER BY i;
+ SELECT * FROM test_macaddr WHERE i='22:00:5c:08:55:08'::macaddr ORDER BY i;
+ SELECT * FROM test_macaddr WHERE i>='22:00:5c:08:55:08'::macaddr ORDER BY i;
+ SELECT * FROM test_macaddr WHERE i>'22:00:5c:08:55:08'::macaddr ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/money.sql contrib/btree_gin/sql/money.sql
*** contrib.orig/btree_gin/sql/money.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/money.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,15 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_money (
+ 	i money
+ );
+ 
+ INSERT INTO test_money VALUES ('-2'),('-1'),('0'),('1'),('2'),('3');
+ 
+ CREATE INDEX idx_money ON test_money USING gin (i);
+ 
+ SELECT * FROM test_money WHERE i<'1'::money ORDER BY i;
+ SELECT * FROM test_money WHERE i<='1'::money ORDER BY i;
+ SELECT * FROM test_money WHERE i='1'::money ORDER BY i;
+ SELECT * FROM test_money WHERE i>='1'::money ORDER BY i;
+ SELECT * FROM test_money WHERE i>'1'::money ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/numeric.sql contrib/btree_gin/sql/numeric.sql
*** contrib.orig/btree_gin/sql/numeric.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/numeric.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,15 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_numeric (
+ 	i numeric
+ );
+ 
+ INSERT INTO test_numeric VALUES (-2),(-1),(0),(1),(2),(3);
+ 
+ CREATE INDEX idx_numeric ON test_numeric USING gin (i);
+ 
+ SELECT * FROM test_numeric WHERE i<'1'::numeric ORDER BY i;
+ SELECT * FROM test_numeric WHERE i<='1'::numeric ORDER BY i;
+ SELECT * FROM test_numeric WHERE i='1'::numeric ORDER BY i;
+ SELECT * FROM test_numeric WHERE i>='1'::numeric ORDER BY i;
+ SELECT * FROM test_numeric WHERE i>'1'::numeric ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/oid.sql contrib/btree_gin/sql/oid.sql
*** contrib.orig/btree_gin/sql/oid.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/oid.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,15 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_oid (
+ 	i oid
+ );
+ 
+ INSERT INTO test_oid VALUES (0),(1),(2),(3),(4),(5);
+ 
+ CREATE INDEX idx_oid ON test_oid USING gin (i);
+ 
+ SELECT * FROM test_oid WHERE i<3::oid ORDER BY i;
+ SELECT * FROM test_oid WHERE i<=3::oid ORDER BY i;
+ SELECT * FROM test_oid WHERE i=3::oid ORDER BY i;
+ SELECT * FROM test_oid WHERE i>=3::oid ORDER BY i;
+ SELECT * FROM test_oid WHERE i>3::oid ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/text.sql contrib/btree_gin/sql/text.sql
*** contrib.orig/btree_gin/sql/text.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/text.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,15 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_text (
+ 	i text
+ );
+ 
+ INSERT INTO test_text VALUES ('aaa'),('a'),('abc'),('abb'),('axy'),('xyz');
+ 
+ CREATE INDEX idx_text ON test_text USING gin (i);
+ 
+ SELECT * FROM test_text WHERE i<'abc' ORDER BY i;
+ SELECT * FROM test_text WHERE i<='abc' ORDER BY i;
+ SELECT * FROM test_text WHERE i='abc' ORDER BY i;
+ SELECT * FROM test_text WHERE i>='abc' ORDER BY i;
+ SELECT * FROM test_text WHERE i>'abc' ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/time.sql contrib/btree_gin/sql/time.sql
*** contrib.orig/btree_gin/sql/time.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/time.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,22 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_time (
+ 	i time
+ );
+ 
+ INSERT INTO test_time VALUES 
+ 	( '03:55:08' ),
+ 	( '04:55:08' ),
+ 	( '05:55:08' ),
+ 	( '08:55:08' ),
+ 	( '09:55:08' ),
+ 	( '10:55:08' )
+ ;
+ 
+ CREATE INDEX idx_time ON test_time USING gin (i);
+ 
+ SELECT * FROM test_time WHERE i<'08:55:08'::time ORDER BY i;
+ SELECT * FROM test_time WHERE i<='08:55:08'::time ORDER BY i;
+ SELECT * FROM test_time WHERE i='08:55:08'::time ORDER BY i;
+ SELECT * FROM test_time WHERE i>='08:55:08'::time ORDER BY i;
+ SELECT * FROM test_time WHERE i>'08:55:08'::time ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/timestamp.sql contrib/btree_gin/sql/timestamp.sql
*** contrib.orig/btree_gin/sql/timestamp.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/timestamp.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,22 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_timestamp (
+ 	i timestamp
+ );
+ 
+ INSERT INTO test_timestamp VALUES 
+ 	( '2004-10-26 03:55:08' ),
+ 	( '2004-10-26 04:55:08' ),
+ 	( '2004-10-26 05:55:08' ),
+ 	( '2004-10-26 08:55:08' ),
+ 	( '2004-10-26 09:55:08' ),
+ 	( '2004-10-26 10:55:08' )
+ ;
+ 
+ CREATE INDEX idx_timestamp ON test_timestamp USING gin (i);
+ 
+ SELECT * FROM test_timestamp WHERE i<'2004-10-26 08:55:08'::timestamp ORDER BY i;
+ SELECT * FROM test_timestamp WHERE i<='2004-10-26 08:55:08'::timestamp ORDER BY i;
+ SELECT * FROM test_timestamp WHERE i='2004-10-26 08:55:08'::timestamp ORDER BY i;
+ SELECT * FROM test_timestamp WHERE i>='2004-10-26 08:55:08'::timestamp ORDER BY i;
+ SELECT * FROM test_timestamp WHERE i>'2004-10-26 08:55:08'::timestamp ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/timestamptz.sql contrib/btree_gin/sql/timestamptz.sql
*** contrib.orig/btree_gin/sql/timestamptz.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/timestamptz.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,22 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_timestamptz (
+ 	i timestamptz
+ );
+ 
+ INSERT INTO test_timestamptz VALUES 
+ 	( '2004-10-26 03:55:08' ),
+ 	( '2004-10-26 04:55:08' ),
+ 	( '2004-10-26 05:55:08' ),
+ 	( '2004-10-26 08:55:08' ),
+ 	( '2004-10-26 09:55:08' ),
+ 	( '2004-10-26 10:55:08' )
+ ;
+ 
+ CREATE INDEX idx_timestamptz ON test_timestamptz USING gin (i);
+ 
+ SELECT * FROM test_timestamptz WHERE i<'2004-10-26 08:55:08'::timestamptz ORDER BY i;
+ SELECT * FROM test_timestamptz WHERE i<='2004-10-26 08:55:08'::timestamptz ORDER BY i;
+ SELECT * FROM test_timestamptz WHERE i='2004-10-26 08:55:08'::timestamptz ORDER BY i;
+ SELECT * FROM test_timestamptz WHERE i>='2004-10-26 08:55:08'::timestamptz ORDER BY i;
+ SELECT * FROM test_timestamptz WHERE i>'2004-10-26 08:55:08'::timestamptz ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/timetz.sql contrib/btree_gin/sql/timetz.sql
*** contrib.orig/btree_gin/sql/timetz.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/timetz.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,22 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_timetz (
+ 	i timetz
+ );
+ 
+ INSERT INTO test_timetz VALUES 
+ 	( '03:55:08 GMT+2' ),
+ 	( '04:55:08 GMT+2' ),
+ 	( '05:55:08 GMT+2' ),
+ 	( '08:55:08 GMT+2' ),
+ 	( '09:55:08 GMT+2' ),
+ 	( '10:55:08 GMT+2' )
+ ;
+ 
+ CREATE INDEX idx_timetz ON test_timetz USING gin (i);
+ 
+ SELECT * FROM test_timetz WHERE i<'08:55:08 GMT+2'::timetz ORDER BY i;
+ SELECT * FROM test_timetz WHERE i<='08:55:08 GMT+2'::timetz ORDER BY i;
+ SELECT * FROM test_timetz WHERE i='08:55:08 GMT+2'::timetz ORDER BY i;
+ SELECT * FROM test_timetz WHERE i>='08:55:08 GMT+2'::timetz ORDER BY i;
+ SELECT * FROM test_timetz WHERE i>'08:55:08 GMT+2'::timetz ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/varbit.sql contrib/btree_gin/sql/varbit.sql
*** contrib.orig/btree_gin/sql/varbit.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/varbit.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,15 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_varbit (
+ 	i varbit
+ );
+ 
+ INSERT INTO test_varbit VALUES ('001'),('010'),('011'),('100'),('101'),('110');
+ 
+ CREATE INDEX idx_varbit ON test_varbit USING gin (i);
+ 
+ SELECT * FROM test_varbit WHERE i<'100'::varbit ORDER BY i;
+ SELECT * FROM test_varbit WHERE i<='100'::varbit ORDER BY i;
+ SELECT * FROM test_varbit WHERE i='100'::varbit ORDER BY i;
+ SELECT * FROM test_varbit WHERE i>='100'::varbit ORDER BY i;
+ SELECT * FROM test_varbit WHERE i>'100'::varbit ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/sql/varchar.sql contrib/btree_gin/sql/varchar.sql
*** contrib.orig/btree_gin/sql/varchar.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/sql/varchar.sql	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,15 ----
+ set enable_seqscan=off;
+ 
+ CREATE TABLE test_varchar (
+ 	i varchar
+ );
+ 
+ INSERT INTO test_varchar VALUES ('aaa'),('a'),('abc'),('abb'),('axy'),('xyz');
+ 
+ CREATE INDEX idx_varchar ON test_varchar USING gin (i);
+ 
+ SELECT * FROM test_varchar WHERE i<'abc'::varchar ORDER BY i;
+ SELECT * FROM test_varchar WHERE i<='abc'::varchar ORDER BY i;
+ SELECT * FROM test_varchar WHERE i='abc'::varchar ORDER BY i;
+ SELECT * FROM test_varchar WHERE i>='abc'::varchar ORDER BY i;
+ SELECT * FROM test_varchar WHERE i>'abc'::varchar ORDER BY i;
diff -c -r -N contrib.orig/btree_gin/uninstall_btree_gin.sql contrib/btree_gin/uninstall_btree_gin.sql
*** contrib.orig/btree_gin/uninstall_btree_gin.sql	1970-01-01 03:00:00.000000000 +0300
--- contrib/btree_gin/uninstall_btree_gin.sql	2009-01-19 20:09:57.000000000 +0300
***************
*** 0 ****
--- 1,96 ----
+ BEGIN;
+ 
+ DROP OPERATOR FAMILY IF EXISTS int2_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS int4_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS int8_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS float4_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS float8_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS money_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS oid_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS timestamp_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS timestamptz_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS time_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS timetz_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS date_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS interval_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS macaddr_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS inet_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS cidr_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS text_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS varchar_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS char_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS bytea_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS bit_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS varbit_ops USING gin CASCADE;
+ DROP OPERATOR FAMILY IF EXISTS numeric_ops USING gin CASCADE;
+ 
+ DROP FUNCTION IF EXISTS gin_btree_consistent(internal, int2, anyelement) CASCADE;
+ 
+ DROP FUNCTION IF EXISTS gin_extract_value_int2(int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_int2(int2, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_int2(int2, internal, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_value_int4(int4, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_int4(int4, int4, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_int4(int4, internal, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_value_int8(int8, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_int8(int8, int8, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_int8(int8, internal, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_value_float4(float4, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_float4(float4, float4, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_float4(float4, internal, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_value_float8(float8, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_float8(float8, float8, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_float8(float8, internal, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_value_money(money, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_money(money, money, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_money(money, internal, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_value_oid(oid, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_oid(oid, oid, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_oid(oid, internal, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_value_timestamp(timestamp, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_timestamp(timestamp, timestamp, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_timestamp(timestamp, internal, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_value_timestamptz(timestamptz, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_timestamptz(timestamptz, timestamptz, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_timestamptz(timestamptz, internal, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_value_time(time, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_time(time, time, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_time(time, internal, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_value_timetz(timetz, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_timetz(timetz, timetz, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_timetz(timetz, internal, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_value_date(date, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_date(date, date, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_date(date, internal, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_value_interval(interval, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_interval(interval, interval, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_interval(interval, internal, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_value_macaddr(macaddr, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_macaddr(macaddr, macaddr, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_macaddr(macaddr, internal, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_value_inet(inet, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_inet(inet, inet, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_inet(inet, internal, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_value_cidr(cidr, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_cidr(cidr, cidr, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_cidr(cidr, internal, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_value_text(text, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_text(text, text, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_text(text, internal, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_value_char("char", internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_char("char", "char", internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_char("char", internal, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_value_bytea(bytea, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_bytea(bytea, bytea, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_bytea(bytea, internal, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_value_bit(bit, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_bit(bit, bit, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_bit(bit, internal, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_value_varbit(varbit, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_varbit(varbit, varbit, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_varbit(varbit, internal, int2, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_value_numeric(numeric, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_compare_prefix_numeric(numeric, numeric, internal) CASCADE;
+ DROP FUNCTION IF EXISTS gin_extract_query_numeric(numeric, internal, int2, internal) CASCADE;
+ 
+ COMMIT;
diff -c -r -N contrib.orig/pg_trgm/pg_trgm.sql.in contrib/pg_trgm/pg_trgm.sql.in
*** contrib.orig/pg_trgm/pg_trgm.sql.in	2009-01-19 19:58:35.000000000 +0300
--- contrib/pg_trgm/pg_trgm.sql.in	2009-01-19 20:03:44.000000000 +0300
***************
*** 110,121 ****
  AS 'MODULE_PATHNAME'
  LANGUAGE C IMMUTABLE;
  
! CREATE OR REPLACE FUNCTION gin_extract_trgm(text, internal, internal)
  RETURNS internal
  AS 'MODULE_PATHNAME'
  LANGUAGE C IMMUTABLE;
  
! CREATE OR REPLACE FUNCTION gin_trgm_consistent(internal, int2, text, internal)
  RETURNS internal
  AS 'MODULE_PATHNAME'
  LANGUAGE C IMMUTABLE;
--- 110,121 ----
  AS 'MODULE_PATHNAME'
  LANGUAGE C IMMUTABLE;
  
! CREATE OR REPLACE FUNCTION gin_extract_trgm(text, internal, internal, internal, internal)
  RETURNS internal
  AS 'MODULE_PATHNAME'
  LANGUAGE C IMMUTABLE;
  
! CREATE OR REPLACE FUNCTION gin_trgm_consistent(internal, int2, text, internal, internal)
  RETURNS internal
  AS 'MODULE_PATHNAME'
  LANGUAGE C IMMUTABLE;
***************
*** 127,132 ****
          OPERATOR        1       % (text, text),
          FUNCTION        1       btint4cmp (int4, int4),
          FUNCTION        2       gin_extract_trgm (text, internal),
!         FUNCTION        3       gin_extract_trgm (text, internal, internal),
!         FUNCTION        4       gin_trgm_consistent (internal, int2, text, internal),
          STORAGE         int4;
--- 127,132 ----
          OPERATOR        1       % (text, text),
          FUNCTION        1       btint4cmp (int4, int4),
          FUNCTION        2       gin_extract_trgm (text, internal),
!         FUNCTION        3       gin_extract_trgm (text, internal, internal, internal, internal),
!         FUNCTION        4       gin_trgm_consistent (internal, int2, text, internal, internal),
          STORAGE         int4;
diff -c -r -N contrib.orig/pg_trgm/trgm_gin.c contrib/pg_trgm/trgm_gin.c
*** contrib.orig/pg_trgm/trgm_gin.c	2009-01-19 19:58:35.000000000 +0300
--- contrib/pg_trgm/trgm_gin.c	2009-01-19 20:03:44.000000000 +0300
***************
*** 47,67 ****
  
  			ptr++;
  		}
  	}
  
  	PG_RETURN_POINTER(entries);
  }
  
- /*
-  * Per call strage for consistent functions to
-  * cache computed value from query
-  */
- typedef struct PerCallConsistentStorage {
- 	int		trglen;
- 	text	data[1]; /* query */
- } PerCallConsistentStorage;
- #define PCCSHDR_SZ  offsetof(PerCallConsistentStorage, data)
- 
  Datum
  gin_trgm_consistent(PG_FUNCTION_ARGS)
  {
--- 47,68 ----
  
  			ptr++;
  		}
+ 		if ( PG_NARGS() > 2 )
+ 		{
+ 			/*
+ 			 * Function called from query extracting
+ 			 */
+ 			void      ***extra_data = (void ***) PG_GETARG_POINTER(4);
+ 
+ 			*extra_data = (void**) palloc(sizeof(void*)*(*nentries));
+ 
+ 			*(int32*)(*extra_data) = trglen;
+ 		}
  	}
  
  	PG_RETURN_POINTER(entries);
  }
  
  Datum
  gin_trgm_consistent(PG_FUNCTION_ARGS)
  {
***************
*** 69,99 ****
  	/* StrategyNumber strategy = PG_GETARG_UINT16(1); */
  	text	   *query = PG_GETARG_TEXT_P(2);
  	bool	   *recheck = (bool *) PG_GETARG_POINTER(3);
  	bool		res = FALSE;
  	int4		i,
  				trglen,
  				ntrue = 0;
- 	PerCallConsistentStorage  *pccs = (PerCallConsistentStorage*) fcinfo->flinfo->fn_extra;
  
  	/* All cases served by this function are inexact */
  	*recheck = true;
  
! 	if ( pccs == NULL || VARSIZE(pccs->data) != VARSIZE(query) || memcmp( pccs->data, query, VARSIZE(query) ) !=0  )
! 	{
! 		TRGM	   *trg = generate_trgm(VARDATA(query), VARSIZE(query) - VARHDRSZ);
! 
! 		if ( pccs )
! 			pfree(pccs);
! 
! 		fcinfo->flinfo->fn_extra = MemoryContextAlloc(fcinfo->flinfo->fn_mcxt, 
! 									VARSIZE(query) + PCCSHDR_SZ);
! 		pccs = (PerCallConsistentStorage*) fcinfo->flinfo->fn_extra;
! 
! 		pccs->trglen = ARRNELEM(trg);
! 		memcpy( pccs->data, query, VARSIZE(query) );
! 	}
! 
! 	trglen = pccs->trglen;
  
  	for (i = 0; i < trglen; i++)
  		if (check[i])
--- 70,85 ----
  	/* StrategyNumber strategy = PG_GETARG_UINT16(1); */
  	text	   *query = PG_GETARG_TEXT_P(2);
  	bool	   *recheck = (bool *) PG_GETARG_POINTER(3);
+ 	void       **extra_data = (void **) PG_GETARG_POINTER(4);
  	bool		res = FALSE;
  	int4		i,
  				trglen,
  				ntrue = 0;
  
  	/* All cases served by this function are inexact */
  	*recheck = true;
  
! 	trglen = *(int32*)extra_data;
  
  	for (i = 0; i < trglen; i++)
  		if (check[i])
diff -c -r -N doc.orig/src/sgml/btree-gin.sgml doc/src/sgml/btree-gin.sgml
*** doc.orig/src/sgml/btree-gin.sgml	1970-01-01 03:00:00.000000000 +0300
--- doc/src/sgml/btree-gin.sgml	2009-01-19 20:03:44.000000000 +0300
***************
*** 0 ****
--- 1,56 ----
+ <!-- $PostgreSQL$ -->
+ 
+ <sect1 id="btree-gin">
+  <title>btree_gin</title>
+ 
+  <indexterm zone="btree-gin">
+   <primary>btree_gin</primary>
+  </indexterm>
+ 
+  <para>
+   <filename>btree_gin</> provides sample GIN operator classes that
+   implement B-Tree equivalent behavior for the data types
+   <type>int2</>, <type>int4</>, <type>int8</>, <type>float4</>,
+   <type>float8</>, <type>timestamp with time zone</>,
+   <type>timestamp without time zone</>, <type>time with time zone</>,
+   <type>time without time zone</>, <type>date</>, <type>interval</>,
+   <type>oid</>, <type>money</>, <type>char</>,
+   <type>varchar</>, <type>text</>, <type>bytea</>, <type>bit</>,
+   <type>varbit</>, <type>macaddr</>, <type>inet</>, and <type>cidr</>.
+  </para>
+ 
+  <para>
+   In general, these operator classes will not outperform the equivalent
+   standard btree index methods, and they lack one major feature of the
+   standard btree code: the ability to enforce uniqueness.  However,
+   they are useful for GIN testing and as a base for developing other
+   GIN operator classes.
+  </para>
+ 
+  <sect2>
+   <title>Example usage</title>
+ 
+ <programlisting>
+ CREATE TABLE test (a int4);
+ -- create index
+ CREATE INDEX testidx ON test USING gin (a);
+ -- query
+ SELECT * FROM test WHERE a &lt; 10;
+ </programlisting>
+ 
+  </sect2>
+ 
+  <sect2>
+   <title>Authors</title>
+ 
+   <para>
+    Teodor Sigaev (<email>teodor@stack.net</email>) ,
+    Oleg Bartunov (<email>oleg@sai.msu.su</email>), and
+    Janko Richter (<email>jankorichter@yahoo.de</email>).  See
+    <ulink url="http://www.sai.msu.su/~megera/oddmuse/index.cgi/Gin"></ulink>
+    for additional information.
+   </para>
+ 
+  </sect2>
+ 
+ </sect1>
diff -c -r -N doc.orig/src/sgml/contrib.sgml doc/src/sgml/contrib.sgml
*** doc.orig/src/sgml/contrib.sgml	2009-01-19 19:58:34.000000000 +0300
--- doc/src/sgml/contrib.sgml	2009-01-19 20:03:44.000000000 +0300
***************
*** 80,85 ****
--- 80,86 ----
  
   &adminpack;
   &auto-explain;
+  &btree-gin;
   &btree-gist;
   &chkpass;
   &citext;
diff -c -r -N doc.orig/src/sgml/filelist.sgml doc/src/sgml/filelist.sgml
*** doc.orig/src/sgml/filelist.sgml	2009-01-19 19:58:34.000000000 +0300
--- doc/src/sgml/filelist.sgml	2009-01-19 20:03:44.000000000 +0300
***************
*** 93,98 ****
--- 93,99 ----
  <!entity contrib         SYSTEM "contrib.sgml">
  <!entity adminpack       SYSTEM "adminpack.sgml">
  <!entity auto-explain    SYSTEM "auto-explain.sgml">
+ <!entity btree-gin       SYSTEM "btree-gin.sgml">
  <!entity btree-gist      SYSTEM "btree-gist.sgml">
  <!entity chkpass         SYSTEM "chkpass.sgml">
  <!entity citext          SYSTEM "citext.sgml">
diff -c -r -N doc.orig/src/sgml/gin.sgml doc/src/sgml/gin.sgml
*** doc.orig/src/sgml/gin.sgml	2009-01-19 19:58:34.000000000 +0300
--- doc/src/sgml/gin.sgml	2009-01-19 20:03:44.000000000 +0300
***************
*** 88,94 ****
  
      <varlistentry>
       <term>Datum *extractQuery(Datum query, int32 *nkeys,
!         StrategyNumber n, bool **pmatch)</term>
       <listitem>
        <para>
         Returns an array of keys given a value to be queried; that is,
--- 88,94 ----
  
      <varlistentry>
       <term>Datum *extractQuery(Datum query, int32 *nkeys,
!         StrategyNumber n, bool *pmatch[], void ** extra_data[])</term>
       <listitem>
        <para>
         Returns an array of keys given a value to be queried; that is,
***************
*** 114,126 ****
         is not required.  The variable is initialized to NULL before call,
         so this argument can simply be ignored by operator classes that do
         not support partial match.
        </para>
  
       </listitem>
      </varlistentry>
  
      <varlistentry>
!      <term>bool consistent(bool check[], StrategyNumber n, Datum query, bool *recheck)</term>
       <listitem>
        <para>
         Returns TRUE if the indexed value satisfies the query operator with
--- 114,131 ----
         is not required.  The variable is initialized to NULL before call,
         so this argument can simply be ignored by operator classes that do
         not support partial match.
+ 	   <literal>extra_data</> is an output  array of additional data. The whole array
+ 	   is an argument for <function>consistent</> method, and each element as a
+ 	   third argument for <function>comparePartial</> method. To use it, 
+ 	   <function>extractQuery</> must allocate  an array of <literal>*nkeys</> 
+ 	   pointers and store it in *extra_data. 
        </para>
  
       </listitem>
      </varlistentry>
  
      <varlistentry>
!      <term>bool consistent(bool check[], StrategyNumber n, Datum query, bool *recheck, void *extra_data[])</term>
       <listitem>
        <para>
         Returns TRUE if the indexed value satisfies the query operator with
***************
*** 135,141 ****
         passed in case the <function>consistent</> method needs to consult it.
         On success, <literal>*recheck</> should be set to TRUE if the heap
         tuple needs to be rechecked against the query operator, or FALSE if
!        the index test is exact.
        </para>
       </listitem>
      </varlistentry>
--- 140,147 ----
         passed in case the <function>consistent</> method needs to consult it.
         On success, <literal>*recheck</> should be set to TRUE if the heap
         tuple needs to be rechecked against the query operator, or FALSE if
!        the index test is exact. <literal>extra_data</> is exactly the
! 	   same array as it was made by <function>extractQuery</>
        </para>
       </listitem>
      </varlistentry>
***************
*** 150,156 ****
    <variablelist>
  
      <varlistentry>
!      <term>int comparePartial(Datum partial_key, Datum key, StrategyNumber n)</term>
       <listitem>
        <para>
         Compare a partial-match query to an index key.  Returns an integer
--- 156,162 ----
    <variablelist>
  
      <varlistentry>
!      <term>int comparePartial(Datum partial_key, Datum key, void *extra_data)</term>
       <listitem>
        <para>
         Compare a partial-match query to an index key.  Returns an integer
***************
*** 158,166 ****
         does not match the query, but the index scan should continue; zero
         means that the index key does match the query; greater than zero
         indicates that the index scan should stop because no more matches
!        are possible.  The strategy number <literal>n</> of the operator
!        that generated the partial match query is provided, in case its
!        semantics are needed to determine when to end the scan.
        </para>
       </listitem>
      </varlistentry>
--- 164,171 ----
         does not match the query, but the index scan should continue; zero
         means that the index key does match the query; greater than zero
         indicates that the index scan should stop because no more matches
!        are possible. <literal>extra_data</> is a correspoding element of 
! 	   array made by <function>extractQuery</>.  
        </para>
       </listitem>
      </varlistentry>
***************
*** 331,336 ****
--- 336,348 ----
  
   <variablelist>
    <varlistentry>
+    <term>btree-gin</term>
+    <listitem>
+     <para>B-Tree equivalent functionality for several data types</para>
+    </listitem>
+   </varlistentry>
+ 
+   <varlistentry>
     <term>hstore</term>
     <listitem>
      <para>Module for storing (key, value) pairs</para>
