mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-29 22:49:41 +03:00 
			
		
		
		
	This is support function 12 for the GiST AM and translates
"well-known" RT*StrategyNumber values into whatever strategy number is
used by the opclass (since no particular numbers are actually
required).  We will use this to support temporal PRIMARY
KEY/UNIQUE/FOREIGN KEY/FOR PORTION OF functionality.
This commit adds two implementations, one for internal GiST opclasses
(just an identity function) and another for btree_gist opclasses.  It
updates btree_gist from 1.7 to 1.8, adding the support function for
all its opclasses.
(previously committed as 6db4598fcb, reverted by 8aee330af55; this is
essentially unchanged from those)
Author: Paul A. Jungwirth <pj@illuminatedcomputing.com>
Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by: jian he <jian.universality@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CA+renyUApHgSZF9-nd-a0+OPGharLQLO=mDHcY4_qQ0+noCUVg@mail.gmail.com
		
	
		
			
				
	
	
		
			81 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			81 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /*
 | |
|  * contrib/btree_gist/btree_gist.c
 | |
|  */
 | |
| #include "postgres.h"
 | |
| 
 | |
| #include "access/stratnum.h"
 | |
| #include "utils/builtins.h"
 | |
| 
 | |
| PG_MODULE_MAGIC;
 | |
| 
 | |
| PG_FUNCTION_INFO_V1(gbt_decompress);
 | |
| PG_FUNCTION_INFO_V1(gbtreekey_in);
 | |
| PG_FUNCTION_INFO_V1(gbtreekey_out);
 | |
| PG_FUNCTION_INFO_V1(gist_stratnum_btree);
 | |
| 
 | |
| /**************************************************
 | |
|  * In/Out for keys
 | |
|  **************************************************/
 | |
| 
 | |
| 
 | |
| Datum
 | |
| gbtreekey_in(PG_FUNCTION_ARGS)
 | |
| {
 | |
| 	Oid			typioparam = PG_GETARG_OID(1);
 | |
| 
 | |
| 	ereport(ERROR,
 | |
| 			(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
 | |
| 			 errmsg("cannot accept a value of type %s",
 | |
| 					format_type_extended(typioparam, -1,
 | |
| 										 FORMAT_TYPE_ALLOW_INVALID))));
 | |
| 
 | |
| 	PG_RETURN_VOID();			/* keep compiler quiet */
 | |
| }
 | |
| 
 | |
| Datum
 | |
| gbtreekey_out(PG_FUNCTION_ARGS)
 | |
| {
 | |
| 	/* Sadly, we do not receive any indication of the specific type */
 | |
| 	ereport(ERROR,
 | |
| 			(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
 | |
| 			 errmsg("cannot display a value of type %s", "gbtreekey?")));
 | |
| 
 | |
| 	PG_RETURN_VOID();			/* keep compiler quiet */
 | |
| }
 | |
| 
 | |
| 
 | |
| /*
 | |
| ** GiST DeCompress methods
 | |
| ** do not do anything.
 | |
| */
 | |
| Datum
 | |
| gbt_decompress(PG_FUNCTION_ARGS)
 | |
| {
 | |
| 	PG_RETURN_POINTER(PG_GETARG_POINTER(0));
 | |
| }
 | |
| 
 | |
| /*
 | |
|  * Returns the btree number for supported operators, otherwise invalid.
 | |
|  */
 | |
| Datum
 | |
| gist_stratnum_btree(PG_FUNCTION_ARGS)
 | |
| {
 | |
| 	StrategyNumber strat = PG_GETARG_UINT16(0);
 | |
| 
 | |
| 	switch (strat)
 | |
| 	{
 | |
| 		case RTEqualStrategyNumber:
 | |
| 			PG_RETURN_UINT16(BTEqualStrategyNumber);
 | |
| 		case RTLessStrategyNumber:
 | |
| 			PG_RETURN_UINT16(BTLessStrategyNumber);
 | |
| 		case RTLessEqualStrategyNumber:
 | |
| 			PG_RETURN_UINT16(BTLessEqualStrategyNumber);
 | |
| 		case RTGreaterStrategyNumber:
 | |
| 			PG_RETURN_UINT16(BTGreaterStrategyNumber);
 | |
| 		case RTGreaterEqualStrategyNumber:
 | |
| 			PG_RETURN_UINT16(BTGreaterEqualStrategyNumber);
 | |
| 		default:
 | |
| 			PG_RETURN_UINT16(InvalidStrategy);
 | |
| 	}
 | |
| }
 |