@@ -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
@@ -189,7 +189,7 @@ brin_inclusion_add_value(PG_FUNCTION_ARGS)
189
189
* new value for emptiness; if it returns true, we need to set the
190
190
* "contains empty" flag in the element (unless already set).
191
191
*/
192
- finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_EMPTY );
192
+ finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_EMPTY , true );
193
193
if (finfo != NULL && DatumGetBool (FunctionCall1Coll (finfo , colloid , newval )))
194
194
{
195
195
if (!DatumGetBool (column -> bv_values [INCLUSION_CONTAINS_EMPTY ]))
@@ -205,7 +205,7 @@ brin_inclusion_add_value(PG_FUNCTION_ARGS)
205
205
PG_RETURN_BOOL (true);
206
206
207
207
/* Check if the new value is already contained. */
208
- finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_CONTAINS );
208
+ finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_CONTAINS , true );
209
209
if (finfo != NULL &&
210
210
DatumGetBool (FunctionCall2Coll (finfo , colloid ,
211
211
column -> bv_values [INCLUSION_UNION ],
@@ -220,7 +220,7 @@ brin_inclusion_add_value(PG_FUNCTION_ARGS)
220
220
* it's not going to be used any longer. However, the BRIN framework
221
221
* doesn't allow for the value not being present. Improve someday.
222
222
*/
223
- finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_MERGEABLE );
223
+ finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_MERGEABLE , true );
224
224
if (finfo != NULL &&
225
225
!DatumGetBool (FunctionCall2Coll (finfo , colloid ,
226
226
column -> bv_values [INCLUSION_UNION ],
@@ -231,8 +231,7 @@ brin_inclusion_add_value(PG_FUNCTION_ARGS)
231
231
}
232
232
233
233
/* Finally, merge the new value to the existing union. */
234
- finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_MERGE );
235
- Assert (finfo != NULL );
234
+ finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_MERGE , false);
236
235
result = FunctionCall2Coll (finfo , colloid ,
237
236
column -> bv_values [INCLUSION_UNION ], newval );
238
237
if (!attr -> attbyval &&
@@ -572,7 +571,7 @@ brin_inclusion_union(PG_FUNCTION_ARGS)
572
571
}
573
572
574
573
/* Check if A and B are mergeable; if not, mark A unmergeable. */
575
- finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_MERGEABLE );
574
+ finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_MERGEABLE , true );
576
575
if (finfo != NULL &&
577
576
!DatumGetBool (FunctionCall2Coll (finfo , colloid ,
578
577
col_a -> bv_values [INCLUSION_UNION ],
@@ -583,8 +582,7 @@ brin_inclusion_union(PG_FUNCTION_ARGS)
583
582
}
584
583
585
584
/* Finally, merge B to A. */
586
- finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_MERGE );
587
- Assert (finfo != NULL );
585
+ finfo = inclusion_get_procinfo (bdesc , attno , PROCNUM_MERGE , false);
588
586
result = FunctionCall2Coll (finfo , colloid ,
589
587
col_a -> bv_values [INCLUSION_UNION ],
590
588
col_b -> bv_values [INCLUSION_UNION ]);
@@ -605,10 +603,12 @@ brin_inclusion_union(PG_FUNCTION_ARGS)
605
603
* Cache and return inclusion opclass support procedure
606
604
*
607
605
* Return the procedure corresponding to the given function support number
608
- * or null if it is not exists.
606
+ * or null if it is not exists. If missing_ok is true and the procedure
607
+ * isn't set up for this opclass, return NULL instead of raising an error.
609
608
*/
610
609
static FmgrInfo *
611
- inclusion_get_procinfo (BrinDesc * bdesc , uint16 attno , uint16 procnum )
610
+ inclusion_get_procinfo (BrinDesc * bdesc , uint16 attno , uint16 procnum ,
611
+ bool missing_ok )
612
612
{
613
613
InclusionOpaque * opaque ;
614
614
uint16 basenum = procnum - PROCNUM_BASE ;
@@ -630,13 +630,18 @@ inclusion_get_procinfo(BrinDesc *bdesc, uint16 attno, uint16 procnum)
630
630
{
631
631
if (RegProcedureIsValid (index_getprocid (bdesc -> bd_index , attno ,
632
632
procnum )))
633
- {
634
633
fmgr_info_copy (& opaque -> extra_procinfos [basenum ],
635
634
index_getprocinfo (bdesc -> bd_index , attno , procnum ),
636
635
bdesc -> bd_context );
637
- }
638
636
else
639
637
{
638
+ if (!missing_ok )
639
+ ereport (ERROR ,
640
+ errcode (ERRCODE_INVALID_OBJECT_DEFINITION ),
641
+ errmsg_internal ("invalid opclass definition" ),
642
+ errdetail_internal ("The operator class is missing support function %d for column %d." ,
643
+ procnum , attno ));
644
+
640
645
opaque -> extra_proc_missing [basenum ] = true;
641
646
return NULL ;
642
647
}
0 commit comments