@@ -558,41 +558,32 @@ infer_arbiter_indexes(PlannerInfo *root)
558
558
559
559
/*
560
560
* Build normalized/BMS representation of plain indexed attributes, as
561
- * well as direct list of inference elements . This is required for
562
- * matching the cataloged definition of indexes.
561
+ * well as a separate list of expression items . This simplifies matching
562
+ * the cataloged definition of indexes.
563
563
*/
564
564
foreach (l , onconflict -> arbiterElems )
565
565
{
566
- InferenceElem * elem ;
566
+ InferenceElem * elem = ( InferenceElem * ) lfirst ( l ) ;
567
567
Var * var ;
568
568
int attno ;
569
569
570
- elem = (InferenceElem * ) lfirst (l );
571
-
572
- /*
573
- * Parse analysis of inference elements performs full parse analysis
574
- * of Vars, even for non-expression indexes (in contrast with utility
575
- * command related use of IndexElem). However, indexes are cataloged
576
- * with simple attribute numbers for non-expression indexes. Those
577
- * are handled later.
578
- */
579
570
if (!IsA (elem -> expr , Var ))
580
571
{
572
+ /* If not a plain Var, just shove it in inferElems for now */
581
573
inferElems = lappend (inferElems , elem -> expr );
582
574
continue ;
583
575
}
584
576
585
577
var = (Var * ) elem -> expr ;
586
578
attno = var -> varattno ;
587
579
588
- if (attno < 0 )
580
+ if (attno == 0 )
589
581
ereport (ERROR ,
590
- (errcode (ERRCODE_INVALID_COLUMN_REFERENCE ),
591
- errmsg ("system columns cannot be used in an ON CONFLICT clause" )));
592
- else if (attno == 0 )
593
- elog (ERROR , "whole row unique index inference specifications are not valid" );
582
+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
583
+ errmsg ("whole row unique index inference specifications are not supported" )));
594
584
595
- inferAttrs = bms_add_member (inferAttrs , attno );
585
+ inferAttrs = bms_add_member (inferAttrs ,
586
+ attno - FirstLowInvalidHeapAttributeNumber );
596
587
}
597
588
598
589
/*
@@ -609,18 +600,18 @@ infer_arbiter_indexes(PlannerInfo *root)
609
600
errmsg ("constraint in ON CONFLICT clause has no associated index" )));
610
601
}
611
602
612
- indexList = RelationGetIndexList (relation );
613
-
614
603
/*
615
604
* Using that representation, iterate through the list of indexes on the
616
605
* target relation to try and find a match
617
606
*/
607
+ indexList = RelationGetIndexList (relation );
608
+
618
609
foreach (l , indexList )
619
610
{
620
611
Oid indexoid = lfirst_oid (l );
621
612
Relation idxRel ;
622
613
Form_pg_index idxForm ;
623
- Bitmapset * indexedAttrs = NULL ;
614
+ Bitmapset * indexedAttrs ;
624
615
List * idxExprs ;
625
616
List * predExprs ;
626
617
AttrNumber natt ;
@@ -679,17 +670,15 @@ infer_arbiter_indexes(PlannerInfo *root)
679
670
if (!idxForm -> indisunique )
680
671
goto next ;
681
672
682
- /* Build BMS representation of cataloged index attributes */
673
+ /* Build BMS representation of plain (non expression) index attrs */
674
+ indexedAttrs = NULL ;
683
675
for (natt = 0 ; natt < idxForm -> indnatts ; natt ++ )
684
676
{
685
677
int attno = idxRel -> rd_index -> indkey .values [natt ];
686
678
687
- /* XXX broken */
688
- if (attno < 0 )
689
- elog (ERROR , "system column in index" );
690
-
691
679
if (attno != 0 )
692
- indexedAttrs = bms_add_member (indexedAttrs , attno );
680
+ indexedAttrs = bms_add_member (indexedAttrs ,
681
+ attno - FirstLowInvalidHeapAttributeNumber );
693
682
}
694
683
695
684
/* Non-expression attributes (if any) must match */
0 commit comments