@@ -465,41 +465,32 @@ infer_arbiter_indexes(PlannerInfo *root)
465
465
466
466
/*
467
467
* Build normalized/BMS representation of plain indexed attributes, as
468
- * well as direct list of inference elements . This is required for
469
- * matching the cataloged definition of indexes.
468
+ * well as a separate list of expression items . This simplifies matching
469
+ * the cataloged definition of indexes.
470
470
*/
471
471
foreach (l , onconflict -> arbiterElems )
472
472
{
473
- InferenceElem * elem ;
473
+ InferenceElem * elem = ( InferenceElem * ) lfirst ( l ) ;
474
474
Var * var ;
475
475
int attno ;
476
476
477
- elem = (InferenceElem * ) lfirst (l );
478
-
479
- /*
480
- * Parse analysis of inference elements performs full parse analysis
481
- * of Vars, even for non-expression indexes (in contrast with utility
482
- * command related use of IndexElem). However, indexes are cataloged
483
- * with simple attribute numbers for non-expression indexes. Those
484
- * are handled later.
485
- */
486
477
if (!IsA (elem -> expr , Var ))
487
478
{
479
+ /* If not a plain Var, just shove it in inferElems for now */
488
480
inferElems = lappend (inferElems , elem -> expr );
489
481
continue ;
490
482
}
491
483
492
484
var = (Var * ) elem -> expr ;
493
485
attno = var -> varattno ;
494
486
495
- if (attno < 0 )
487
+ if (attno == 0 )
496
488
ereport (ERROR ,
497
- (errcode (ERRCODE_INVALID_COLUMN_REFERENCE ),
498
- errmsg ("system columns cannot be used in an ON CONFLICT clause" )));
499
- else if (attno == 0 )
500
- elog (ERROR , "whole row unique index inference specifications are not valid" );
489
+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
490
+ errmsg ("whole row unique index inference specifications are not supported" )));
501
491
502
- inferAttrs = bms_add_member (inferAttrs , attno );
492
+ inferAttrs = bms_add_member (inferAttrs ,
493
+ attno - FirstLowInvalidHeapAttributeNumber );
503
494
}
504
495
505
496
/*
@@ -516,18 +507,18 @@ infer_arbiter_indexes(PlannerInfo *root)
516
507
errmsg ("constraint in ON CONFLICT clause has no associated index" )));
517
508
}
518
509
519
- indexList = RelationGetIndexList (relation );
520
-
521
510
/*
522
511
* Using that representation, iterate through the list of indexes on the
523
512
* target relation to try and find a match
524
513
*/
514
+ indexList = RelationGetIndexList (relation );
515
+
525
516
foreach (l , indexList )
526
517
{
527
518
Oid indexoid = lfirst_oid (l );
528
519
Relation idxRel ;
529
520
Form_pg_index idxForm ;
530
- Bitmapset * indexedAttrs = NULL ;
521
+ Bitmapset * indexedAttrs ;
531
522
List * idxExprs ;
532
523
List * predExprs ;
533
524
AttrNumber natt ;
@@ -586,17 +577,15 @@ infer_arbiter_indexes(PlannerInfo *root)
586
577
if (!idxForm -> indisunique )
587
578
goto next ;
588
579
589
- /* Build BMS representation of cataloged index attributes */
580
+ /* Build BMS representation of plain (non expression) index attrs */
581
+ indexedAttrs = NULL ;
590
582
for (natt = 0 ; natt < idxForm -> indnatts ; natt ++ )
591
583
{
592
584
int attno = idxRel -> rd_index -> indkey .values [natt ];
593
585
594
- /* XXX broken */
595
- if (attno < 0 )
596
- elog (ERROR , "system column in index" );
597
-
598
586
if (attno != 0 )
599
- indexedAttrs = bms_add_member (indexedAttrs , attno );
587
+ indexedAttrs = bms_add_member (indexedAttrs ,
588
+ attno - FirstLowInvalidHeapAttributeNumber );
600
589
}
601
590
602
591
/* Non-expression attributes (if any) must match */
0 commit comments