@@ -105,11 +105,6 @@ brininsert(PG_FUNCTION_ARGS)
105
105
BrinMemTuple * dtup ;
106
106
BlockNumber heapBlk ;
107
107
int keyno ;
108
- #ifdef USE_ASSERT_CHECKING
109
- BrinTuple * tmptup ;
110
- BrinMemTuple * tmpdtup ;
111
- Size tmpsiz ;
112
- #endif
113
108
114
109
CHECK_FOR_INTERRUPTS ();
115
110
@@ -137,45 +132,6 @@ brininsert(PG_FUNCTION_ARGS)
137
132
138
133
dtup = brin_deform_tuple (bdesc , brtup );
139
134
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
-
179
135
/*
180
136
* Compare the key values of the new tuple to the stored index values;
181
137
* our deformed tuple will get updated if the new tuple doesn't fit
@@ -202,20 +158,6 @@ brininsert(PG_FUNCTION_ARGS)
202
158
need_insert |= DatumGetBool (result );
203
159
}
204
160
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
-
219
161
if (!need_insert )
220
162
{
221
163
/*
@@ -323,8 +265,6 @@ brinbeginscan(PG_FUNCTION_ARGS)
323
265
* If a TID from the revmap is read as InvalidTID, we know that range is
324
266
* unsummarized. Pages in those ranges need to be returned regardless of scan
325
267
* keys.
326
- *
327
- * XXX see _bt_first on what to do about sk_subtype.
328
268
*/
329
269
Datum
330
270
bringetbitmap (PG_FUNCTION_ARGS )
@@ -340,7 +280,6 @@ bringetbitmap(PG_FUNCTION_ARGS)
340
280
BlockNumber nblocks ;
341
281
BlockNumber heapBlk ;
342
282
int totalpages = 0 ;
343
- int keyno ;
344
283
FmgrInfo * consistentFn ;
345
284
MemoryContext oldcxt ;
346
285
MemoryContext perRangeCxt ;
@@ -359,18 +298,11 @@ bringetbitmap(PG_FUNCTION_ARGS)
359
298
heap_close (heapRel , AccessShareLock );
360
299
361
300
/*
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 .
365
304
*/
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 );
374
306
375
307
/*
376
308
* Setup and use a per-range memory context, which is reset every time we
@@ -418,7 +350,6 @@ bringetbitmap(PG_FUNCTION_ARGS)
418
350
else
419
351
{
420
352
BrinMemTuple * dtup ;
421
- int keyno ;
422
353
423
354
dtup = brin_deform_tuple (bdesc , tup );
424
355
if (dtup -> bt_placeholder )
@@ -431,6 +362,8 @@ bringetbitmap(PG_FUNCTION_ARGS)
431
362
}
432
363
else
433
364
{
365
+ int keyno ;
366
+
434
367
/*
435
368
* Compare scan keys with summary values stored for the range.
436
369
* If scan keys are matched, the page range must be added to
@@ -456,6 +389,17 @@ bringetbitmap(PG_FUNCTION_ARGS)
456
389
(key -> sk_collation ==
457
390
bdesc -> bd_tupdesc -> attrs [keyattno - 1 ]-> attcollation ));
458
391
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
+
459
403
/*
460
404
* Check whether the scan key is consistent with the page
461
405
* range values; if so, have the pages in the range added
0 commit comments