@@ -105,11 +105,6 @@ brininsert(PG_FUNCTION_ARGS)
105105 BrinMemTuple * dtup ;
106106 BlockNumber heapBlk ;
107107 int keyno ;
108- #ifdef USE_ASSERT_CHECKING
109- BrinTuple * tmptup ;
110- BrinMemTuple * tmpdtup ;
111- Size tmpsiz ;
112- #endif
113108
114109 CHECK_FOR_INTERRUPTS ();
115110
@@ -137,45 +132,6 @@ brininsert(PG_FUNCTION_ARGS)
137132
138133 dtup = brin_deform_tuple (bdesc , brtup );
139134
140- #ifdef USE_ASSERT_CHECKING
141- {
142- /*
143- * When assertions are enabled, we use this as an opportunity to
144- * test the "union" method, which would otherwise be used very
145- * rarely: first create a placeholder tuple, and addValue the
146- * value we just got into it. Then union the existing index tuple
147- * with the updated placeholder tuple. The tuple resulting from
148- * that union should be identical to the one resulting from the
149- * regular operation (straight addValue) below.
150- *
151- * Here we create the tuple to compare with; the actual comparison
152- * is below.
153- */
154- tmptup = brin_form_placeholder_tuple (bdesc , heapBlk , & tmpsiz );
155- tmpdtup = brin_deform_tuple (bdesc , tmptup );
156- for (keyno = 0 ; keyno < bdesc -> bd_tupdesc -> natts ; keyno ++ )
157- {
158- BrinValues * bval ;
159- FmgrInfo * addValue ;
160-
161- bval = & tmpdtup -> bt_columns [keyno ];
162- addValue = index_getprocinfo (idxRel , keyno + 1 ,
163- BRIN_PROCNUM_ADDVALUE );
164- FunctionCall4Coll (addValue ,
165- idxRel -> rd_indcollation [keyno ],
166- PointerGetDatum (bdesc ),
167- PointerGetDatum (bval ),
168- values [keyno ],
169- nulls [keyno ]);
170- }
171-
172- union_tuples (bdesc , tmpdtup , brtup );
173-
174- tmpdtup -> bt_placeholder = dtup -> bt_placeholder ;
175- tmptup = brin_form_tuple (bdesc , heapBlk , tmpdtup , & tmpsiz );
176- }
177- #endif
178-
179135 /*
180136 * Compare the key values of the new tuple to the stored index values;
181137 * our deformed tuple will get updated if the new tuple doesn't fit
@@ -202,20 +158,6 @@ brininsert(PG_FUNCTION_ARGS)
202158 need_insert |= DatumGetBool (result );
203159 }
204160
205- #ifdef USE_ASSERT_CHECKING
206- {
207- /*
208- * Now we can compare the tuple produced by the union function
209- * with the one from plain addValue.
210- */
211- BrinTuple * cmptup ;
212- Size cmpsz ;
213-
214- cmptup = brin_form_tuple (bdesc , heapBlk , dtup , & cmpsz );
215- Assert (brin_tuples_equal (tmptup , tmpsiz , cmptup , cmpsz ));
216- }
217- #endif
218-
219161 if (!need_insert )
220162 {
221163 /*
@@ -323,8 +265,6 @@ brinbeginscan(PG_FUNCTION_ARGS)
323265 * If a TID from the revmap is read as InvalidTID, we know that range is
324266 * unsummarized. Pages in those ranges need to be returned regardless of scan
325267 * keys.
326- *
327- * XXX see _bt_first on what to do about sk_subtype.
328268 */
329269Datum
330270bringetbitmap (PG_FUNCTION_ARGS )
@@ -340,7 +280,6 @@ bringetbitmap(PG_FUNCTION_ARGS)
340280 BlockNumber nblocks ;
341281 BlockNumber heapBlk ;
342282 int totalpages = 0 ;
343- int keyno ;
344283 FmgrInfo * consistentFn ;
345284 MemoryContext oldcxt ;
346285 MemoryContext perRangeCxt ;
@@ -359,18 +298,11 @@ bringetbitmap(PG_FUNCTION_ARGS)
359298 heap_close (heapRel , AccessShareLock );
360299
361300 /*
362- * Obtain consistent functions for all indexed column . Maybe it'd be
363- * possible to do this lazily only the first time we see a scan key that
364- * involves each particular attribute .
301+ * Make room for the consistent support procedures of indexed columns . We
302+ * don't look them up here; we do that lazily the first time we see a scan
303+ * key reference each of them. We rely on zeroing fn_oid to InvalidOid .
365304 */
366- consistentFn = palloc (sizeof (FmgrInfo ) * bdesc -> bd_tupdesc -> natts );
367- for (keyno = 0 ; keyno < bdesc -> bd_tupdesc -> natts ; keyno ++ )
368- {
369- FmgrInfo * tmp ;
370-
371- tmp = index_getprocinfo (idxRel , keyno + 1 , BRIN_PROCNUM_CONSISTENT );
372- fmgr_info_copy (& consistentFn [keyno ], tmp , CurrentMemoryContext );
373- }
305+ consistentFn = palloc0 (sizeof (FmgrInfo ) * bdesc -> bd_tupdesc -> natts );
374306
375307 /*
376308 * Setup and use a per-range memory context, which is reset every time we
@@ -418,7 +350,6 @@ bringetbitmap(PG_FUNCTION_ARGS)
418350 else
419351 {
420352 BrinMemTuple * dtup ;
421- int keyno ;
422353
423354 dtup = brin_deform_tuple (bdesc , tup );
424355 if (dtup -> bt_placeholder )
@@ -431,6 +362,8 @@ bringetbitmap(PG_FUNCTION_ARGS)
431362 }
432363 else
433364 {
365+ int keyno ;
366+
434367 /*
435368 * Compare scan keys with summary values stored for the range.
436369 * If scan keys are matched, the page range must be added to
@@ -456,6 +389,17 @@ bringetbitmap(PG_FUNCTION_ARGS)
456389 (key -> sk_collation ==
457390 bdesc -> bd_tupdesc -> attrs [keyattno - 1 ]-> attcollation ));
458391
392+ /* First time this column? look up consistent function */
393+ if (consistentFn [keyattno - 1 ].fn_oid == InvalidOid )
394+ {
395+ FmgrInfo * tmp ;
396+
397+ tmp = index_getprocinfo (idxRel , keyattno ,
398+ BRIN_PROCNUM_CONSISTENT );
399+ fmgr_info_copy (& consistentFn [keyattno - 1 ], tmp ,
400+ CurrentMemoryContext );
401+ }
402+
459403 /*
460404 * Check whether the scan key is consistent with the page
461405 * range values; if so, have the pages in the range added
0 commit comments