@@ -25,7 +25,6 @@ typedef struct QueryInfo
25
25
Datum (* typecmp ) (FunctionCallInfo );
26
26
} QueryInfo ;
27
27
28
-
29
28
/*** GIN support functions shared by all datatypes ***/
30
29
31
30
static Datum
@@ -112,13 +111,14 @@ gin_btree_compare_prefix(FunctionCallInfo fcinfo)
112
111
int32 res ,
113
112
cmp ;
114
113
115
- cmp = DatumGetInt32 (DirectFunctionCall2Coll (
116
- data -> typecmp ,
117
- PG_GET_COLLATION (),
118
- (data -> strategy == BTLessStrategyNumber ||
119
- data -> strategy == BTLessEqualStrategyNumber )
120
- ? data -> datum : a ,
121
- b ));
114
+ cmp = DatumGetInt32 (CallerFInfoFunctionCall2 (
115
+ data -> typecmp ,
116
+ fcinfo -> flinfo ,
117
+ PG_GET_COLLATION (),
118
+ (data -> strategy == BTLessStrategyNumber ||
119
+ data -> strategy == BTLessEqualStrategyNumber )
120
+ ? data -> datum : a ,
121
+ b ));
122
122
123
123
switch (data -> strategy )
124
124
{
@@ -426,3 +426,54 @@ leftmostvalue_numeric(void)
426
426
}
427
427
428
428
GIN_SUPPORT (numeric , true, leftmostvalue_numeric , gin_numeric_cmp )
429
+
430
+ /*
431
+ * Use a similar trick to that used for numeric for enums, since we don't
432
+ * actually know the leftmost value of any enum without knowing the concrete
433
+ * type, so we use a dummy leftmost value of InvalidOid.
434
+ *
435
+ * Note that we use CallerFInfoFunctionCall2 here so that enum_cmp
436
+ * gets a valid fn_extra to work with. Unlike most other type comparison
437
+ * routines it needs it, so we can't use DirectFunctionCall2.
438
+ */
439
+
440
+
441
+ #define ENUM_IS_LEFTMOST (x ) ((x) == InvalidOid)
442
+
443
+ PG_FUNCTION_INFO_V1 (gin_enum_cmp );
444
+
445
+ Datum
446
+ gin_enum_cmp (PG_FUNCTION_ARGS )
447
+ {
448
+ Oid a = PG_GETARG_OID (0 );
449
+ Oid b = PG_GETARG_OID (1 );
450
+ int res = 0 ;
451
+
452
+ if (ENUM_IS_LEFTMOST (a ))
453
+ {
454
+ res = (ENUM_IS_LEFTMOST (b )) ? 0 : -1 ;
455
+ }
456
+ else if (ENUM_IS_LEFTMOST (b ))
457
+ {
458
+ res = 1 ;
459
+ }
460
+ else
461
+ {
462
+ res = DatumGetInt32 (CallerFInfoFunctionCall2 (
463
+ enum_cmp ,
464
+ fcinfo -> flinfo ,
465
+ PG_GET_COLLATION (),
466
+ ObjectIdGetDatum (a ),
467
+ ObjectIdGetDatum (b )));
468
+ }
469
+
470
+ PG_RETURN_INT32 (res );
471
+ }
472
+
473
+ static Datum
474
+ leftmostvalue_enum (void )
475
+ {
476
+ return ObjectIdGetDatum (InvalidOid );
477
+ }
478
+
479
+ GIN_SUPPORT (anyenum , false, leftmostvalue_enum , gin_enum_cmp )
0 commit comments