@@ -77,7 +77,7 @@ static void deparseReturningList(StringInfo buf, PlannerInfo *root,
7777List * returningList );
7878static void deparseColumnRef (StringInfo buf ,int varno ,int varattno ,
7979PlannerInfo * root );
80- static void deparseRelation (StringInfo buf ,Oid relid );
80+ static void deparseRelation (StringInfo buf ,Relation rel );
8181static void deparseStringLiteral (StringInfo buf ,const char * val );
8282static void deparseExpr (StringInfo buf ,Expr * expr ,PlannerInfo * root );
8383static void deparseVar (StringInfo buf ,Var * node ,PlannerInfo * root );
@@ -387,7 +387,7 @@ deparseSelectSql(StringInfo buf,
387387 * Construct FROM clause
388388 */
389389appendStringInfoString (buf ," FROM " );
390- deparseRelation (buf ,RelationGetRelid ( rel ) );
390+ deparseRelation (buf ,rel );
391391
392392heap_close (rel ,NoLock );
393393}
@@ -499,18 +499,16 @@ appendWhereClause(StringInfo buf,
499499 * deparse remote INSERT statement
500500 */
501501void
502- deparseInsertSql (StringInfo buf ,PlannerInfo * root ,Index rtindex ,
502+ deparseInsertSql (StringInfo buf ,PlannerInfo * root ,
503+ Index rtindex ,Relation rel ,
503504List * targetAttrs ,List * returningList )
504505{
505- RangeTblEntry * rte = planner_rt_fetch (rtindex ,root );
506- Relation rel = heap_open (rte -> relid ,NoLock );
507- TupleDesc tupdesc = RelationGetDescr (rel );
508506AttrNumber pindex ;
509507bool first ;
510508ListCell * lc ;
511509
512510appendStringInfoString (buf ,"INSERT INTO " );
513- deparseRelation (buf ,rte -> relid );
511+ deparseRelation (buf ,rel );
514512
515513if (targetAttrs )
516514{
@@ -520,9 +518,6 @@ deparseInsertSql(StringInfo buf, PlannerInfo *root, Index rtindex,
520518foreach (lc ,targetAttrs )
521519{
522520int attnum = lfirst_int (lc );
523- Form_pg_attribute attr = tupdesc -> attrs [attnum - 1 ];
524-
525- Assert (!attr -> attisdropped );
526521
527522if (!first )
528523appendStringInfoString (buf ,", " );
@@ -552,36 +547,29 @@ deparseInsertSql(StringInfo buf, PlannerInfo *root, Index rtindex,
552547
553548if (returningList )
554549deparseReturningList (buf ,root ,rtindex ,rel ,returningList );
555-
556- heap_close (rel ,NoLock );
557550}
558551
559552/*
560553 * deparse remote UPDATE statement
561554 */
562555void
563- deparseUpdateSql (StringInfo buf ,PlannerInfo * root ,Index rtindex ,
556+ deparseUpdateSql (StringInfo buf ,PlannerInfo * root ,
557+ Index rtindex ,Relation rel ,
564558List * targetAttrs ,List * returningList )
565559{
566- RangeTblEntry * rte = planner_rt_fetch (rtindex ,root );
567- Relation rel = heap_open (rte -> relid ,NoLock );
568- TupleDesc tupdesc = RelationGetDescr (rel );
569560AttrNumber pindex ;
570561bool first ;
571562ListCell * lc ;
572563
573564appendStringInfoString (buf ,"UPDATE " );
574- deparseRelation (buf ,rte -> relid );
565+ deparseRelation (buf ,rel );
575566appendStringInfoString (buf ," SET " );
576567
577568pindex = 2 ;/* ctid is always the first param */
578569first = true;
579570foreach (lc ,targetAttrs )
580571{
581572int attnum = lfirst_int (lc );
582- Form_pg_attribute attr = tupdesc -> attrs [attnum - 1 ];
583-
584- Assert (!attr -> attisdropped );
585573
586574if (!first )
587575appendStringInfoString (buf ,", " );
@@ -595,30 +583,22 @@ deparseUpdateSql(StringInfo buf, PlannerInfo *root, Index rtindex,
595583
596584if (returningList )
597585deparseReturningList (buf ,root ,rtindex ,rel ,returningList );
598-
599- heap_close (rel ,NoLock );
600586}
601587
602588/*
603589 * deparse remote DELETE statement
604590 */
605591void
606- deparseDeleteSql (StringInfo buf ,PlannerInfo * root ,Index rtindex ,
592+ deparseDeleteSql (StringInfo buf ,PlannerInfo * root ,
593+ Index rtindex ,Relation rel ,
607594List * returningList )
608595{
609- RangeTblEntry * rte = planner_rt_fetch (rtindex ,root );
610-
611596appendStringInfoString (buf ,"DELETE FROM " );
612- deparseRelation (buf ,rte -> relid );
597+ deparseRelation (buf ,rel );
613598appendStringInfoString (buf ," WHERE ctid = $1" );
614599
615600if (returningList )
616- {
617- Relation rel = heap_open (rte -> relid ,NoLock );
618-
619601deparseReturningList (buf ,root ,rtindex ,rel ,returningList );
620- heap_close (rel ,NoLock );
621- }
622602}
623603
624604/*
@@ -653,12 +633,11 @@ deparseReturningList(StringInfo buf, PlannerInfo *root,
653633void
654634deparseAnalyzeSizeSql (StringInfo buf ,Relation rel )
655635{
656- Oid relid = RelationGetRelid (rel );
657636StringInfoData relname ;
658637
659638/* We'll need the remote relation name as a literal. */
660639initStringInfo (& relname );
661- deparseRelation (& relname ,relid );
640+ deparseRelation (& relname ,rel );
662641
663642appendStringInfo (buf ,"SELECT pg_catalog.pg_relation_size(" );
664643deparseStringLiteral (buf ,relname .data );
@@ -718,7 +697,7 @@ deparseAnalyzeSql(StringInfo buf, Relation rel)
718697 * Construct FROM clause
719698 */
720699appendStringInfoString (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 */
773752static void
774- deparseRelation (StringInfo buf ,Oid relid )
753+ deparseRelation (StringInfo buf ,Relation rel )
775754{
776755ForeignTable * table ;
777756const char * nspname = NULL ;
778757const char * relname = NULL ;
779758ListCell * 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 */
801780if (nspname == NULL )
802- nspname = get_namespace_name (get_rel_namespace ( relid ));
781+ nspname = get_namespace_name (RelationGetNamespace ( rel ));
803782if (relname == NULL )
804- relname = get_rel_name ( relid );
783+ relname = RelationGetRelationName ( rel );
805784
806785appendStringInfo (buf ,"%s.%s" ,
807786quote_identifier (nspname ),quote_identifier (relname ));