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

Commit50c19fc

Browse files
committed
Fix contrib/postgres_fdw's handling of column defaults.
Adopt the position that only locally-defined defaults matter. Any defaultsdefined in the remote database do not affect insertions performed througha foreign table (unless they are for columns not known to the foreigntable). While it'd arguably be more useful to permit remote defaults to beused, making that work in a consistent fashion requires far more work thanseems possible for 9.3.
1 parenta0c6dfe commit50c19fc

File tree

5 files changed

+205
-202
lines changed

5 files changed

+205
-202
lines changed

‎contrib/postgres_fdw/deparse.c

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static void deparseReturningList(StringInfo buf, PlannerInfo *root,
7777
List*returningList);
7878
staticvoiddeparseColumnRef(StringInfobuf,intvarno,intvarattno,
7979
PlannerInfo*root);
80-
staticvoiddeparseRelation(StringInfobuf,Oidrelid);
80+
staticvoiddeparseRelation(StringInfobuf,Relationrel);
8181
staticvoiddeparseStringLiteral(StringInfobuf,constchar*val);
8282
staticvoiddeparseExpr(StringInfobuf,Expr*expr,PlannerInfo*root);
8383
staticvoiddeparseVar(StringInfobuf,Var*node,PlannerInfo*root);
@@ -387,7 +387,7 @@ deparseSelectSql(StringInfo buf,
387387
* Construct FROM clause
388388
*/
389389
appendStringInfoString(buf," FROM ");
390-
deparseRelation(buf,RelationGetRelid(rel));
390+
deparseRelation(buf,rel);
391391

392392
heap_close(rel,NoLock);
393393
}
@@ -499,18 +499,16 @@ appendWhereClause(StringInfo buf,
499499
* deparse remote INSERT statement
500500
*/
501501
void
502-
deparseInsertSql(StringInfobuf,PlannerInfo*root,Indexrtindex,
502+
deparseInsertSql(StringInfobuf,PlannerInfo*root,
503+
Indexrtindex,Relationrel,
503504
List*targetAttrs,List*returningList)
504505
{
505-
RangeTblEntry*rte=planner_rt_fetch(rtindex,root);
506-
Relationrel=heap_open(rte->relid,NoLock);
507-
TupleDesctupdesc=RelationGetDescr(rel);
508506
AttrNumberpindex;
509507
boolfirst;
510508
ListCell*lc;
511509

512510
appendStringInfoString(buf,"INSERT INTO ");
513-
deparseRelation(buf,rte->relid);
511+
deparseRelation(buf,rel);
514512

515513
if (targetAttrs)
516514
{
@@ -520,9 +518,6 @@ deparseInsertSql(StringInfo buf, PlannerInfo *root, Index rtindex,
520518
foreach(lc,targetAttrs)
521519
{
522520
intattnum=lfirst_int(lc);
523-
Form_pg_attributeattr=tupdesc->attrs[attnum-1];
524-
525-
Assert(!attr->attisdropped);
526521

527522
if (!first)
528523
appendStringInfoString(buf,", ");
@@ -552,36 +547,29 @@ deparseInsertSql(StringInfo buf, PlannerInfo *root, Index rtindex,
552547

553548
if (returningList)
554549
deparseReturningList(buf,root,rtindex,rel,returningList);
555-
556-
heap_close(rel,NoLock);
557550
}
558551

559552
/*
560553
* deparse remote UPDATE statement
561554
*/
562555
void
563-
deparseUpdateSql(StringInfobuf,PlannerInfo*root,Indexrtindex,
556+
deparseUpdateSql(StringInfobuf,PlannerInfo*root,
557+
Indexrtindex,Relationrel,
564558
List*targetAttrs,List*returningList)
565559
{
566-
RangeTblEntry*rte=planner_rt_fetch(rtindex,root);
567-
Relationrel=heap_open(rte->relid,NoLock);
568-
TupleDesctupdesc=RelationGetDescr(rel);
569560
AttrNumberpindex;
570561
boolfirst;
571562
ListCell*lc;
572563

573564
appendStringInfoString(buf,"UPDATE ");
574-
deparseRelation(buf,rte->relid);
565+
deparseRelation(buf,rel);
575566
appendStringInfoString(buf," SET ");
576567

577568
pindex=2;/* ctid is always the first param */
578569
first= true;
579570
foreach(lc,targetAttrs)
580571
{
581572
intattnum=lfirst_int(lc);
582-
Form_pg_attributeattr=tupdesc->attrs[attnum-1];
583-
584-
Assert(!attr->attisdropped);
585573

586574
if (!first)
587575
appendStringInfoString(buf,", ");
@@ -595,30 +583,22 @@ deparseUpdateSql(StringInfo buf, PlannerInfo *root, Index rtindex,
595583

596584
if (returningList)
597585
deparseReturningList(buf,root,rtindex,rel,returningList);
598-
599-
heap_close(rel,NoLock);
600586
}
601587

602588
/*
603589
* deparse remote DELETE statement
604590
*/
605591
void
606-
deparseDeleteSql(StringInfobuf,PlannerInfo*root,Indexrtindex,
592+
deparseDeleteSql(StringInfobuf,PlannerInfo*root,
593+
Indexrtindex,Relationrel,
607594
List*returningList)
608595
{
609-
RangeTblEntry*rte=planner_rt_fetch(rtindex,root);
610-
611596
appendStringInfoString(buf,"DELETE FROM ");
612-
deparseRelation(buf,rte->relid);
597+
deparseRelation(buf,rel);
613598
appendStringInfoString(buf," WHERE ctid = $1");
614599

615600
if (returningList)
616-
{
617-
Relationrel=heap_open(rte->relid,NoLock);
618-
619601
deparseReturningList(buf,root,rtindex,rel,returningList);
620-
heap_close(rel,NoLock);
621-
}
622602
}
623603

624604
/*
@@ -653,12 +633,11 @@ deparseReturningList(StringInfo buf, PlannerInfo *root,
653633
void
654634
deparseAnalyzeSizeSql(StringInfobuf,Relationrel)
655635
{
656-
Oidrelid=RelationGetRelid(rel);
657636
StringInfoDatarelname;
658637

659638
/* We'll need the remote relation name as a literal. */
660639
initStringInfo(&relname);
661-
deparseRelation(&relname,relid);
640+
deparseRelation(&relname,rel);
662641

663642
appendStringInfo(buf,"SELECT pg_catalog.pg_relation_size(");
664643
deparseStringLiteral(buf,relname.data);
@@ -718,7 +697,7 @@ deparseAnalyzeSql(StringInfo buf, Relation rel)
718697
* Construct FROM clause
719698
*/
720699
appendStringInfoString(buf," FROM ");
721-
deparseRelation(buf,relid);
700+
deparseRelation(buf,rel);
722701
}
723702

724703
/*
@@ -771,15 +750,15 @@ deparseColumnRef(StringInfo buf, int varno, int varattno, PlannerInfo *root)
771750
* Similarly, schema_name FDW option overrides schema name.
772751
*/
773752
staticvoid
774-
deparseRelation(StringInfobuf,Oidrelid)
753+
deparseRelation(StringInfobuf,Relationrel)
775754
{
776755
ForeignTable*table;
777756
constchar*nspname=NULL;
778757
constchar*relname=NULL;
779758
ListCell*lc;
780759

781760
/* obtain additional catalog information. */
782-
table=GetForeignTable(relid);
761+
table=GetForeignTable(RelationGetRelid(rel));
783762

784763
/*
785764
* Use value of FDW options if any, instead of the name of object itself.
@@ -799,9 +778,9 @@ deparseRelation(StringInfo buf, Oid relid)
799778
* that doesn't seem worth the trouble.
800779
*/
801780
if (nspname==NULL)
802-
nspname=get_namespace_name(get_rel_namespace(relid));
781+
nspname=get_namespace_name(RelationGetNamespace(rel));
803782
if (relname==NULL)
804-
relname=get_rel_name(relid);
783+
relname=RelationGetRelationName(rel);
805784

806785
appendStringInfo(buf,"%s.%s",
807786
quote_identifier(nspname),quote_identifier(relname));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp