@@ -85,8 +85,6 @@ static FmgrInfo *inclusion_get_procinfo(BrinDesc *bdesc, uint16 attno,
85
85
uint16 procnum );
86
86
static FmgrInfo * inclusion_get_strategy_procinfo (BrinDesc * bdesc , uint16 attno ,
87
87
Oid subtype , uint16 strategynum );
88
- static bool inclusion_consistent_key (BrinDesc * bdesc , BrinValues * column ,
89
- ScanKey key , Oid colloid );
90
88
91
89
92
90
/*
@@ -243,9 +241,9 @@ brin_inclusion_add_value(PG_FUNCTION_ARGS)
243
241
/*
244
242
* BRIN inclusion consistent function
245
243
*
246
- * We inspect the IS NULL scan keys first, which allows us to make a decision
247
- * without looking at the contents of the page range. Only when the page range
248
- * matches the IS NULL keys, we check the regular scan keys.
244
+ * We're no longer dealing with NULL keys in the consistent function, that is
245
+ * now handled by the AM code. That means we should not get any all-NULL ranges
246
+ * either, because those can't be consistent with regular (not [IS] NULL) keys.
249
247
*
250
248
* All of the strategies are optional.
251
249
*/
@@ -254,63 +252,29 @@ brin_inclusion_consistent(PG_FUNCTION_ARGS)
254
252
{
255
253
BrinDesc * bdesc = (BrinDesc * ) PG_GETARG_POINTER (0 );
256
254
BrinValues * column = (BrinValues * ) PG_GETARG_POINTER (1 );
257
- ScanKey * keys = (ScanKey * ) PG_GETARG_POINTER (2 );
258
- int nkeys = PG_GETARG_INT32 (3 );
259
- Oid colloid = PG_GET_COLLATION ();
260
- int keyno ;
255
+ ScanKey key = (ScanKey ) PG_GETARG_POINTER (2 );
256
+ Oid colloid = PG_GET_COLLATION (),
257
+ subtype ;
258
+ Datum unionval ;
259
+ AttrNumber attno ;
260
+ Datum query ;
261
+ FmgrInfo * finfo ;
262
+ Datum result ;
261
263
262
- /* make sure we got some scan keys */
263
- Assert (( nkeys > 0 ) && ( keys != NULL ) );
264
+ /* This opclass uses the old signature with only three arguments. */
265
+ Assert (PG_NARGS () == 3 );
264
266
265
- /*
266
- * If is all nulls, it cannot possibly be consistent (at this point we
267
- * know there are at least some regular scan keys).
268
- */
269
- if (column -> bv_allnulls )
270
- PG_RETURN_BOOL (false);
267
+ /* Should not be dealing with all-NULL ranges. */
268
+ Assert (!column -> bv_allnulls );
271
269
272
270
/* It has to be checked, if it contains elements that are not mergeable. */
273
271
if (DatumGetBool (column -> bv_values [INCLUSION_UNMERGEABLE ]))
274
272
PG_RETURN_BOOL (true);
275
273
276
- /* Check that the range is consistent with all regular scan keys. */
277
- for (keyno = 0 ; keyno < nkeys ; keyno ++ )
278
- {
279
- ScanKey key = keys [keyno ];
280
-
281
- /* NULL keys are handled and filtered-out in bringetbitmap */
282
- Assert (!(key -> sk_flags & SK_ISNULL ));
283
-
284
- /*
285
- * When there are multiple scan keys, failure to meet the criteria for
286
- * a single one of them is enough to discard the range as a whole, so
287
- * break out of the loop as soon as a false return value is obtained.
288
- */
289
- if (!inclusion_consistent_key (bdesc , column , key , colloid ))
290
- PG_RETURN_BOOL (false);
291
- }
292
-
293
- PG_RETURN_BOOL (true);
294
- }
295
-
296
- /*
297
- * inclusion_consistent_key
298
- * Determine if the range is consistent with a single scan key.
299
- */
300
- static bool
301
- inclusion_consistent_key (BrinDesc * bdesc , BrinValues * column , ScanKey key ,
302
- Oid colloid )
303
- {
304
- FmgrInfo * finfo ;
305
- AttrNumber attno = key -> sk_attno ;
306
- Oid subtype = key -> sk_subtype ;
307
- Datum query = key -> sk_argument ;
308
- Datum unionval = column -> bv_values [INCLUSION_UNION ];
309
- Datum result ;
310
-
311
- /* This should be called only for regular keys, not for IS [NOT] NULL. */
312
- Assert (!(key -> sk_flags & SK_ISNULL ));
313
-
274
+ attno = key -> sk_attno ;
275
+ subtype = key -> sk_subtype ;
276
+ query = key -> sk_argument ;
277
+ unionval = column -> bv_values [INCLUSION_UNION ];
314
278
switch (key -> sk_strategy )
315
279
{
316
280
/*
@@ -330,49 +294,49 @@ inclusion_consistent_key(BrinDesc *bdesc, BrinValues *column, ScanKey key,
330
294
finfo = inclusion_get_strategy_procinfo (bdesc , attno , subtype ,
331
295
RTOverRightStrategyNumber );
332
296
result = FunctionCall2Coll (finfo , colloid , unionval , query );
333
- return !DatumGetBool (result );
297
+ PG_RETURN_BOOL ( !DatumGetBool (result ) );
334
298
335
299
case RTOverLeftStrategyNumber :
336
300
finfo = inclusion_get_strategy_procinfo (bdesc , attno , subtype ,
337
301
RTRightStrategyNumber );
338
302
result = FunctionCall2Coll (finfo , colloid , unionval , query );
339
- return !DatumGetBool (result );
303
+ PG_RETURN_BOOL ( !DatumGetBool (result ) );
340
304
341
305
case RTOverRightStrategyNumber :
342
306
finfo = inclusion_get_strategy_procinfo (bdesc , attno , subtype ,
343
307
RTLeftStrategyNumber );
344
308
result = FunctionCall2Coll (finfo , colloid , unionval , query );
345
- return !DatumGetBool (result );
309
+ PG_RETURN_BOOL ( !DatumGetBool (result ) );
346
310
347
311
case RTRightStrategyNumber :
348
312
finfo = inclusion_get_strategy_procinfo (bdesc , attno , subtype ,
349
313
RTOverLeftStrategyNumber );
350
314
result = FunctionCall2Coll (finfo , colloid , unionval , query );
351
- return !DatumGetBool (result );
315
+ PG_RETURN_BOOL ( !DatumGetBool (result ) );
352
316
353
317
case RTBelowStrategyNumber :
354
318
finfo = inclusion_get_strategy_procinfo (bdesc , attno , subtype ,
355
319
RTOverAboveStrategyNumber );
356
320
result = FunctionCall2Coll (finfo , colloid , unionval , query );
357
- return !DatumGetBool (result );
321
+ PG_RETURN_BOOL ( !DatumGetBool (result ) );
358
322
359
323
case RTOverBelowStrategyNumber :
360
324
finfo = inclusion_get_strategy_procinfo (bdesc , attno , subtype ,
361
325
RTAboveStrategyNumber );
362
326
result = FunctionCall2Coll (finfo , colloid , unionval , query );
363
- return !DatumGetBool (result );
327
+ PG_RETURN_BOOL ( !DatumGetBool (result ) );
364
328
365
329
case RTOverAboveStrategyNumber :
366
330
finfo = inclusion_get_strategy_procinfo (bdesc , attno , subtype ,
367
331
RTBelowStrategyNumber );
368
332
result = FunctionCall2Coll (finfo , colloid , unionval , query );
369
- return !DatumGetBool (result );
333
+ PG_RETURN_BOOL ( !DatumGetBool (result ) );
370
334
371
335
case RTAboveStrategyNumber :
372
336
finfo = inclusion_get_strategy_procinfo (bdesc , attno , subtype ,
373
337
RTOverBelowStrategyNumber );
374
338
result = FunctionCall2Coll (finfo , colloid , unionval , query );
375
- return !DatumGetBool (result );
339
+ PG_RETURN_BOOL ( !DatumGetBool (result ) );
376
340
377
341
/*
378
342
* Overlap and contains strategies
@@ -390,7 +354,7 @@ inclusion_consistent_key(BrinDesc *bdesc, BrinValues *column, ScanKey key,
390
354
finfo = inclusion_get_strategy_procinfo (bdesc , attno , subtype ,
391
355
key -> sk_strategy );
392
356
result = FunctionCall2Coll (finfo , colloid , unionval , query );
393
- return DatumGetBool (result );
357
+ PG_RETURN_DATUM (result );
394
358
395
359
/*
396
360
* Contained by strategies
@@ -410,9 +374,9 @@ inclusion_consistent_key(BrinDesc *bdesc, BrinValues *column, ScanKey key,
410
374
RTOverlapStrategyNumber );
411
375
result = FunctionCall2Coll (finfo , colloid , unionval , query );
412
376
if (DatumGetBool (result ))
413
- return true;
377
+ PG_RETURN_BOOL ( true) ;
414
378
415
- return DatumGetBool (column -> bv_values [INCLUSION_CONTAINS_EMPTY ]);
379
+ PG_RETURN_DATUM (column -> bv_values [INCLUSION_CONTAINS_EMPTY ]);
416
380
417
381
/*
418
382
* Adjacent strategy
@@ -429,12 +393,12 @@ inclusion_consistent_key(BrinDesc *bdesc, BrinValues *column, ScanKey key,
429
393
RTOverlapStrategyNumber );
430
394
result = FunctionCall2Coll (finfo , colloid , unionval , query );
431
395
if (DatumGetBool (result ))
432
- return true;
396
+ PG_RETURN_BOOL ( true) ;
433
397
434
398
finfo = inclusion_get_strategy_procinfo (bdesc , attno , subtype ,
435
399
RTAdjacentStrategyNumber );
436
400
result = FunctionCall2Coll (finfo , colloid , unionval , query );
437
- return DatumGetBool (result );
401
+ PG_RETURN_DATUM (result );
438
402
439
403
/*
440
404
* Basic comparison strategies
@@ -464,40 +428,40 @@ inclusion_consistent_key(BrinDesc *bdesc, BrinValues *column, ScanKey key,
464
428
RTRightStrategyNumber );
465
429
result = FunctionCall2Coll (finfo , colloid , unionval , query );
466
430
if (!DatumGetBool (result ))
467
- return true;
431
+ PG_RETURN_BOOL ( true) ;
468
432
469
- return DatumGetBool (column -> bv_values [INCLUSION_CONTAINS_EMPTY ]);
433
+ PG_RETURN_DATUM (column -> bv_values [INCLUSION_CONTAINS_EMPTY ]);
470
434
471
435
case RTSameStrategyNumber :
472
436
case RTEqualStrategyNumber :
473
437
finfo = inclusion_get_strategy_procinfo (bdesc , attno , subtype ,
474
438
RTContainsStrategyNumber );
475
439
result = FunctionCall2Coll (finfo , colloid , unionval , query );
476
440
if (DatumGetBool (result ))
477
- return true;
441
+ PG_RETURN_BOOL ( true) ;
478
442
479
- return DatumGetBool (column -> bv_values [INCLUSION_CONTAINS_EMPTY ]);
443
+ PG_RETURN_DATUM (column -> bv_values [INCLUSION_CONTAINS_EMPTY ]);
480
444
481
445
case RTGreaterEqualStrategyNumber :
482
446
finfo = inclusion_get_strategy_procinfo (bdesc , attno , subtype ,
483
447
RTLeftStrategyNumber );
484
448
result = FunctionCall2Coll (finfo , colloid , unionval , query );
485
449
if (!DatumGetBool (result ))
486
- return true;
450
+ PG_RETURN_BOOL ( true) ;
487
451
488
- return DatumGetBool (column -> bv_values [INCLUSION_CONTAINS_EMPTY ]);
452
+ PG_RETURN_DATUM (column -> bv_values [INCLUSION_CONTAINS_EMPTY ]);
489
453
490
454
case RTGreaterStrategyNumber :
491
455
/* no need to check for empty elements */
492
456
finfo = inclusion_get_strategy_procinfo (bdesc , attno , subtype ,
493
457
RTLeftStrategyNumber );
494
458
result = FunctionCall2Coll (finfo , colloid , unionval , query );
495
- return !DatumGetBool (result );
459
+ PG_RETURN_BOOL ( !DatumGetBool (result ) );
496
460
497
461
default :
498
462
/* shouldn't happen */
499
463
elog (ERROR , "invalid strategy number %d" , key -> sk_strategy );
500
- return false;
464
+ PG_RETURN_BOOL ( false) ;
501
465
}
502
466
}
503
467
0 commit comments