Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0740cbd

Browse files
committed
Refactor ON CONFLICT index inference parse tree representation.
Defer lookup of opfamily and input type of a of a user specified opclassuntil the optimizer selects among available unique indexes; and storethe opclass in the parse analyzed tree instead. The primary reason fordoing this is that for rule deparsing it's easier to use the opclassthan the previous representation.While at it also rename a variable in the inference code to better fitit's purpose.This is separate from the actual fixes for deparsing to make revieweasier.
1 parentb48437d commit0740cbd

File tree

8 files changed

+31
-35
lines changed

8 files changed

+31
-35
lines changed

‎contrib/pg_stat_statements/pg_stat_statements.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,8 +2645,7 @@ JumbleExpr(pgssJumbleState *jstate, Node *node)
26452645
InferenceElem*ie= (InferenceElem*)node;
26462646

26472647
APP_JUMB(ie->infercollid);
2648-
APP_JUMB(ie->inferopfamily);
2649-
APP_JUMB(ie->inferopcinputtype);
2648+
APP_JUMB(ie->inferopclass);
26502649
JumbleExpr(jstate,ie->expr);
26512650
}
26522651
break;

‎src/backend/nodes/copyfuncs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,8 +1839,7 @@ _copyInferenceElem(const InferenceElem *from)
18391839

18401840
COPY_NODE_FIELD(expr);
18411841
COPY_SCALAR_FIELD(infercollid);
1842-
COPY_SCALAR_FIELD(inferopfamily);
1843-
COPY_SCALAR_FIELD(inferopcinputtype);
1842+
COPY_SCALAR_FIELD(inferopclass);
18441843

18451844
returnnewnode;
18461845
}

‎src/backend/nodes/equalfuncs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,7 @@ _equalInferenceElem(const InferenceElem *a, const InferenceElem *b)
702702
{
703703
COMPARE_NODE_FIELD(expr);
704704
COMPARE_SCALAR_FIELD(infercollid);
705-
COMPARE_SCALAR_FIELD(inferopfamily);
706-
COMPARE_SCALAR_FIELD(inferopcinputtype);
705+
COMPARE_SCALAR_FIELD(inferopclass);
707706

708707
return true;
709708
}

‎src/backend/nodes/outfuncs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,8 +1474,7 @@ _outInferenceElem(StringInfo str, const InferenceElem *node)
14741474

14751475
WRITE_NODE_FIELD(expr);
14761476
WRITE_OID_FIELD(infercollid);
1477-
WRITE_OID_FIELD(inferopfamily);
1478-
WRITE_OID_FIELD(inferopcinputtype);
1477+
WRITE_OID_FIELD(inferopclass);
14791478
}
14801479

14811480
staticvoid

‎src/backend/nodes/readfuncs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,8 +1214,7 @@ _readInferenceElem(void)
12141214

12151215
READ_NODE_FIELD(expr);
12161216
READ_OID_FIELD(infercollid);
1217-
READ_OID_FIELD(inferopfamily);
1218-
READ_OID_FIELD(inferopcinputtype);
1217+
READ_OID_FIELD(inferopclass);
12191218

12201219
READ_DONE();
12211220
}

‎src/backend/optimizer/util/plancat.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,8 @@ infer_arbiter_indexes(PlannerInfo *root)
438438
Bitmapset*inferAttrs=NULL;
439439
List*inferElems=NIL;
440440

441-
/*Result */
442-
List*candidates=NIL;
441+
/*Results */
442+
List*results=NIL;
443443

444444
/*
445445
* Quickly return NIL for ON CONFLICT DO NOTHING without an inference
@@ -565,11 +565,11 @@ infer_arbiter_indexes(PlannerInfo *root)
565565
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
566566
errmsg("ON CONFLICT DO UPDATE not supported with exclusion constraints")));
567567

568-
candidates=lappend_oid(candidates,idxForm->indexrelid);
568+
results=lappend_oid(results,idxForm->indexrelid);
569569
list_free(indexList);
570570
index_close(idxRel,NoLock);
571571
heap_close(relation,NoLock);
572-
returncandidates;
572+
returnresults;
573573
}
574574
elseif (indexOidFromConstraint!=InvalidOid)
575575
{
@@ -633,7 +633,7 @@ infer_arbiter_indexes(PlannerInfo *root)
633633
* index definition.
634634
*/
635635
if (elem->infercollid!=InvalidOid||
636-
elem->inferopfamily!=InvalidOid||
636+
elem->inferopclass!=InvalidOid||
637637
list_member(idxExprs,elem->expr))
638638
continue;
639639

@@ -660,20 +660,20 @@ infer_arbiter_indexes(PlannerInfo *root)
660660
if (!predicate_implied_by(predExprs,whereExplicit))
661661
gotonext;
662662

663-
candidates=lappend_oid(candidates,idxForm->indexrelid);
663+
results=lappend_oid(results,idxForm->indexrelid);
664664
next:
665665
index_close(idxRel,NoLock);
666666
}
667667

668668
list_free(indexList);
669669
heap_close(relation,NoLock);
670670

671-
if (candidates==NIL)
671+
if (results==NIL)
672672
ereport(ERROR,
673673
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
674674
errmsg("there is no unique or exclusion constraint matching the ON CONFLICT specification")));
675675

676-
returncandidates;
676+
returnresults;
677677
}
678678

679679
/*
@@ -709,23 +709,33 @@ infer_collation_opclass_match(InferenceElem *elem, Relation idxRel,
709709
Bitmapset*inferAttrs,List*idxExprs)
710710
{
711711
AttrNumbernatt;
712+
Oidinferopfamily=InvalidOid;/* OID of att opfamily */
713+
Oidinferopcinputtype=InvalidOid;/* OID of att opfamily */
712714

713715
/*
714716
* If inference specification element lacks collation/opclass, then no
715717
* need to check for exact match.
716718
*/
717-
if (elem->infercollid==InvalidOid&&elem->inferopfamily==InvalidOid)
719+
if (elem->infercollid==InvalidOid&&elem->inferopclass==InvalidOid)
718720
return true;
719721

722+
/*
723+
* Lookup opfamily and input type, for matching indexes
724+
*/
725+
if (elem->inferopclass)
726+
{
727+
inferopfamily=get_opclass_family(elem->inferopclass);
728+
inferopcinputtype=get_opclass_input_type(elem->inferopclass);
729+
}
730+
720731
for (natt=1;natt <=idxRel->rd_att->natts;natt++)
721732
{
722733
Oidopfamily=idxRel->rd_opfamily[natt-1];
723734
Oidopcinputtype=idxRel->rd_opcintype[natt-1];
724735
Oidcollation=idxRel->rd_indcollation[natt-1];
725736

726-
if (elem->inferopfamily!=InvalidOid&&
727-
(elem->inferopfamily!=opfamily||
728-
elem->inferopcinputtype!=opcinputtype))
737+
if (elem->inferopclass!=InvalidOid&&
738+
(inferopfamily!=opfamily||inferopcinputtype!=opcinputtype))
729739
{
730740
/* Attribute needed to match opclass, but didn't */
731741
continue;

‎src/backend/parser/parse_clause.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,18 +2730,10 @@ resolve_unique_index_expr(ParseState *pstate, InferClause *infer,
27302730
exprLocation(pInfer->expr));
27312731

27322732
if (!ielem->opclass)
2733-
{
2734-
pInfer->inferopfamily=InvalidOid;
2735-
pInfer->inferopcinputtype=InvalidOid;
2736-
}
2733+
pInfer->inferopclass=InvalidOid;
27372734
else
2738-
{
2739-
Oidopclass=get_opclass_oid(BTREE_AM_OID,ielem->opclass,
2740-
false);
2741-
2742-
pInfer->inferopfamily=get_opclass_family(opclass);
2743-
pInfer->inferopcinputtype=get_opclass_input_type(opclass);
2744-
}
2735+
pInfer->inferopclass=get_opclass_oid(BTREE_AM_OID,
2736+
ielem->opclass, false);
27452737

27462738
result=lappend(result,pInfer);
27472739
}

‎src/include/nodes/primnodes.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,8 +1198,7 @@ typedef struct InferenceElem
11981198
Exprxpr;
11991199
Node*expr;/* expression to infer from, or NULL */
12001200
Oidinfercollid;/* OID of collation, or InvalidOid */
1201-
Oidinferopfamily;/* OID of att opfamily, or InvalidOid */
1202-
Oidinferopcinputtype;/* OID of att input type, or InvalidOid */
1201+
Oidinferopclass;/* OID of att opclass, or InvalidOid */
12031202
}InferenceElem;
12041203

12051204
/*--------------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp