@@ -77,7 +77,7 @@ static void deparseReturningList(StringInfo buf, PlannerInfo *root,
77
77
List * returningList );
78
78
static void deparseColumnRef (StringInfo buf , int varno , int varattno ,
79
79
PlannerInfo * root );
80
- static void deparseRelation (StringInfo buf , Oid relid );
80
+ static void deparseRelation (StringInfo buf , Relation rel );
81
81
static void deparseStringLiteral (StringInfo buf , const char * val );
82
82
static void deparseExpr (StringInfo buf , Expr * expr , PlannerInfo * root );
83
83
static void deparseVar (StringInfo buf , Var * node , PlannerInfo * root );
@@ -387,7 +387,7 @@ deparseSelectSql(StringInfo buf,
387
387
* Construct FROM clause
388
388
*/
389
389
appendStringInfoString (buf , " FROM " );
390
- deparseRelation (buf , RelationGetRelid ( rel ) );
390
+ deparseRelation (buf , rel );
391
391
392
392
heap_close (rel , NoLock );
393
393
}
@@ -499,18 +499,16 @@ appendWhereClause(StringInfo buf,
499
499
* deparse remote INSERT statement
500
500
*/
501
501
void
502
- deparseInsertSql (StringInfo buf , PlannerInfo * root , Index rtindex ,
502
+ deparseInsertSql (StringInfo buf , PlannerInfo * root ,
503
+ Index rtindex , Relation rel ,
503
504
List * targetAttrs , List * returningList )
504
505
{
505
- RangeTblEntry * rte = planner_rt_fetch (rtindex , root );
506
- Relation rel = heap_open (rte -> relid , NoLock );
507
- TupleDesc tupdesc = RelationGetDescr (rel );
508
506
AttrNumber pindex ;
509
507
bool first ;
510
508
ListCell * lc ;
511
509
512
510
appendStringInfoString (buf , "INSERT INTO " );
513
- deparseRelation (buf , rte -> relid );
511
+ deparseRelation (buf , rel );
514
512
515
513
if (targetAttrs )
516
514
{
@@ -520,9 +518,6 @@ deparseInsertSql(StringInfo buf, PlannerInfo *root, Index rtindex,
520
518
foreach (lc , targetAttrs )
521
519
{
522
520
int attnum = lfirst_int (lc );
523
- Form_pg_attribute attr = tupdesc -> attrs [attnum - 1 ];
524
-
525
- Assert (!attr -> attisdropped );
526
521
527
522
if (!first )
528
523
appendStringInfoString (buf , ", " );
@@ -552,36 +547,29 @@ deparseInsertSql(StringInfo buf, PlannerInfo *root, Index rtindex,
552
547
553
548
if (returningList )
554
549
deparseReturningList (buf , root , rtindex , rel , returningList );
555
-
556
- heap_close (rel , NoLock );
557
550
}
558
551
559
552
/*
560
553
* deparse remote UPDATE statement
561
554
*/
562
555
void
563
- deparseUpdateSql (StringInfo buf , PlannerInfo * root , Index rtindex ,
556
+ deparseUpdateSql (StringInfo buf , PlannerInfo * root ,
557
+ Index rtindex , Relation rel ,
564
558
List * targetAttrs , List * returningList )
565
559
{
566
- RangeTblEntry * rte = planner_rt_fetch (rtindex , root );
567
- Relation rel = heap_open (rte -> relid , NoLock );
568
- TupleDesc tupdesc = RelationGetDescr (rel );
569
560
AttrNumber pindex ;
570
561
bool first ;
571
562
ListCell * lc ;
572
563
573
564
appendStringInfoString (buf , "UPDATE " );
574
- deparseRelation (buf , rte -> relid );
565
+ deparseRelation (buf , rel );
575
566
appendStringInfoString (buf , " SET " );
576
567
577
568
pindex = 2 ; /* ctid is always the first param */
578
569
first = true;
579
570
foreach (lc , targetAttrs )
580
571
{
581
572
int attnum = lfirst_int (lc );
582
- Form_pg_attribute attr = tupdesc -> attrs [attnum - 1 ];
583
-
584
- Assert (!attr -> attisdropped );
585
573
586
574
if (!first )
587
575
appendStringInfoString (buf , ", " );
@@ -595,30 +583,22 @@ deparseUpdateSql(StringInfo buf, PlannerInfo *root, Index rtindex,
595
583
596
584
if (returningList )
597
585
deparseReturningList (buf , root , rtindex , rel , returningList );
598
-
599
- heap_close (rel , NoLock );
600
586
}
601
587
602
588
/*
603
589
* deparse remote DELETE statement
604
590
*/
605
591
void
606
- deparseDeleteSql (StringInfo buf , PlannerInfo * root , Index rtindex ,
592
+ deparseDeleteSql (StringInfo buf , PlannerInfo * root ,
593
+ Index rtindex , Relation rel ,
607
594
List * returningList )
608
595
{
609
- RangeTblEntry * rte = planner_rt_fetch (rtindex , root );
610
-
611
596
appendStringInfoString (buf , "DELETE FROM " );
612
- deparseRelation (buf , rte -> relid );
597
+ deparseRelation (buf , rel );
613
598
appendStringInfoString (buf , " WHERE ctid = $1" );
614
599
615
600
if (returningList )
616
- {
617
- Relation rel = heap_open (rte -> relid , NoLock );
618
-
619
601
deparseReturningList (buf , root , rtindex , rel , returningList );
620
- heap_close (rel , NoLock );
621
- }
622
602
}
623
603
624
604
/*
@@ -653,12 +633,11 @@ deparseReturningList(StringInfo buf, PlannerInfo *root,
653
633
void
654
634
deparseAnalyzeSizeSql (StringInfo buf , Relation rel )
655
635
{
656
- Oid relid = RelationGetRelid (rel );
657
636
StringInfoData relname ;
658
637
659
638
/* We'll need the remote relation name as a literal. */
660
639
initStringInfo (& relname );
661
- deparseRelation (& relname , relid );
640
+ deparseRelation (& relname , rel );
662
641
663
642
appendStringInfo (buf , "SELECT pg_catalog.pg_relation_size(" );
664
643
deparseStringLiteral (buf , relname .data );
@@ -718,7 +697,7 @@ deparseAnalyzeSql(StringInfo buf, Relation rel)
718
697
* Construct FROM clause
719
698
*/
720
699
appendStringInfoString (buf , " FROM " );
721
- deparseRelation (buf , relid );
700
+ deparseRelation (buf , rel );
722
701
}
723
702
724
703
/*
@@ -771,15 +750,15 @@ deparseColumnRef(StringInfo buf, int varno, int varattno, PlannerInfo *root)
771
750
* Similarly, schema_name FDW option overrides schema name.
772
751
*/
773
752
static void
774
- deparseRelation (StringInfo buf , Oid relid )
753
+ deparseRelation (StringInfo buf , Relation rel )
775
754
{
776
755
ForeignTable * table ;
777
756
const char * nspname = NULL ;
778
757
const char * relname = NULL ;
779
758
ListCell * lc ;
780
759
781
760
/* obtain additional catalog information. */
782
- table = GetForeignTable (relid );
761
+ table = GetForeignTable (RelationGetRelid ( rel ) );
783
762
784
763
/*
785
764
* Use value of FDW options if any, instead of the name of object itself.
@@ -799,9 +778,9 @@ deparseRelation(StringInfo buf, Oid relid)
799
778
* that doesn't seem worth the trouble.
800
779
*/
801
780
if (nspname == NULL )
802
- nspname = get_namespace_name (get_rel_namespace ( relid ));
781
+ nspname = get_namespace_name (RelationGetNamespace ( rel ));
803
782
if (relname == NULL )
804
- relname = get_rel_name ( relid );
783
+ relname = RelationGetRelationName ( rel );
805
784
806
785
appendStringInfo (buf , "%s.%s" ,
807
786
quote_identifier (nspname ), quote_identifier (relname ));
0 commit comments