@@ -82,7 +82,7 @@ typedef struct InclusionOpaque
82
82
} InclusionOpaque ;
83
83
84
84
static FmgrInfo * inclusion_get_procinfo (BrinDesc * bdesc , uint16 attno ,
85
- uint16 procnum );
85
+ uint16 procnum , bool missing_ok );
86
86
static FmgrInfo * inclusion_get_strategy_procinfo (BrinDesc * bdesc , uint16 attno ,
87
87
Oid subtype , uint16 strategynum );
88
88
@@ -179,7 +179,7 @@ brin_inclusion_add_value(PG_FUNCTION_ARGS)
179
179
* new value for emptiness; if it returns true, we need to set the
180
180
* "contains empty" flag in the element (unless already set).
181
181
*/
182
- finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_EMPTY );
182
+ finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_EMPTY , true );
183
183
if (finfo != NULL && DatumGetBool (FunctionCall1Coll (finfo , colloid , newval )))
184
184
{
185
185
if (!DatumGetBool (column -> bv_values [INCLUSION_CONTAINS_EMPTY ]))
@@ -195,7 +195,7 @@ brin_inclusion_add_value(PG_FUNCTION_ARGS)
195
195
PG_RETURN_BOOL (true);
196
196
197
197
/* Check if the new value is already contained. */
198
- finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_CONTAINS );
198
+ finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_CONTAINS , true );
199
199
if (finfo != NULL &&
200
200
DatumGetBool (FunctionCall2Coll (finfo , colloid ,
201
201
column -> bv_values [INCLUSION_UNION ],
@@ -210,7 +210,7 @@ brin_inclusion_add_value(PG_FUNCTION_ARGS)
210
210
* it's not going to be used any longer. However, the BRIN framework
211
211
* doesn't allow for the value not being present. Improve someday.
212
212
*/
213
- finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_MERGEABLE );
213
+ finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_MERGEABLE , true );
214
214
if (finfo != NULL &&
215
215
!DatumGetBool (FunctionCall2Coll (finfo , colloid ,
216
216
column -> bv_values [INCLUSION_UNION ],
@@ -221,8 +221,7 @@ brin_inclusion_add_value(PG_FUNCTION_ARGS)
221
221
}
222
222
223
223
/* Finally, merge the new value to the existing union. */
224
- finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_MERGE );
225
- Assert (finfo != NULL );
224
+ finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_MERGE , false);
226
225
result = FunctionCall2Coll (finfo , colloid ,
227
226
column -> bv_values [INCLUSION_UNION ], newval );
228
227
if (!attr -> attbyval &&
@@ -506,7 +505,7 @@ brin_inclusion_union(PG_FUNCTION_ARGS)
506
505
}
507
506
508
507
/* Check if A and B are mergeable; if not, mark A unmergeable. */
509
- finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_MERGEABLE );
508
+ finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_MERGEABLE , true );
510
509
if (finfo != NULL &&
511
510
!DatumGetBool (FunctionCall2Coll (finfo , colloid ,
512
511
col_a -> bv_values [INCLUSION_UNION ],
@@ -517,8 +516,7 @@ brin_inclusion_union(PG_FUNCTION_ARGS)
517
516
}
518
517
519
518
/* Finally, merge B to A. */
520
- finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_MERGE );
521
- Assert (finfo != NULL );
519
+ finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_MERGE , false);
522
520
result = FunctionCall2Coll (finfo , colloid ,
523
521
col_a -> bv_values [INCLUSION_UNION ],
524
522
col_b -> bv_values [INCLUSION_UNION ]);
@@ -539,10 +537,12 @@ brin_inclusion_union(PG_FUNCTION_ARGS)
539
537
* Cache and return inclusion opclass support procedure
540
538
*
541
539
* Return the procedure corresponding to the given function support number
542
- * or null if it is not exists.
540
+ * or null if it is not exists. If missing_ok is true and the procedure
541
+ * isn't set up for this opclass, return NULL instead of raising an error.
543
542
*/
544
543
static FmgrInfo *
545
- inclusion_get_procinfo (BrinDesc * bdesc , uint16 attno , uint16 procnum )
544
+ inclusion_get_procinfo (BrinDesc * bdesc , uint16 attno , uint16 procnum ,
545
+ bool missing_ok )
546
546
{
547
547
InclusionOpaque * opaque ;
548
548
uint16 basenum = procnum - PROCNUM_BASE ;
@@ -564,13 +564,18 @@ inclusion_get_procinfo(BrinDesc *bdesc, uint16 attno, uint16 procnum)
564
564
{
565
565
if (RegProcedureIsValid (index_getprocid (bdesc -> bd_index , attno ,
566
566
procnum )))
567
- {
568
567
fmgr_info_copy (& opaque -> extra_procinfos [basenum ],
569
568
index_getprocinfo (bdesc -> bd_index , attno , procnum ),
570
569
bdesc -> bd_context );
571
- }
572
570
else
573
571
{
572
+ if (!missing_ok )
573
+ ereport (ERROR ,
574
+ errcode (ERRCODE_INVALID_OBJECT_DEFINITION ),
575
+ errmsg_internal ("invalid opclass definition" ),
576
+ errdetail_internal ("The operator class is missing support function %d for column %d." ,
577
+ procnum , attno ));
578
+
574
579
opaque -> extra_proc_missing [basenum ] = true;
575
580
return NULL ;
576
581
}
0 commit comments