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

Commit7cbe57c

Browse files
committed
Offer triggers on foreign tables.
This covers all the SQL-standard trigger types supported for regulartables; it does not cover constraint triggers. The approach foracquiring the old row mirrors that for view INSTEAD OF triggers. ForAFTER ROW triggers, we spool the foreign tuples to a tuplestore.This changes the FDW API contract; when deciding which columns topopulate in the slot returned from data modification callbacks, writableFDWs will need to check for AFTER ROW triggers in addition to checkingfor a RETURNING clause.In support of the feature addition, refactor the TriggerFlags bits andthe assembly of old tuples in ModifyTable.Ronan Dunklau, reviewed by KaiGai Kohei; some additional hacking by me.
1 parent6115480 commit7cbe57c

File tree

14 files changed

+1145
-202
lines changed

14 files changed

+1145
-202
lines changed

‎contrib/postgres_fdw/deparse.c

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ static void deparseTargetList(StringInfo buf,
110110
List**retrieved_attrs);
111111
staticvoiddeparseReturningList(StringInfobuf,PlannerInfo*root,
112112
Indexrtindex,Relationrel,
113+
booltrig_after_row,
113114
List*returningList,
114115
List**retrieved_attrs);
115116
staticvoiddeparseColumnRef(StringInfobuf,intvarno,intvarattno,
@@ -875,11 +876,9 @@ deparseInsertSql(StringInfo buf, PlannerInfo *root,
875876
else
876877
appendStringInfoString(buf," DEFAULT VALUES");
877878

878-
if (returningList)
879-
deparseReturningList(buf,root,rtindex,rel,returningList,
880-
retrieved_attrs);
881-
else
882-
*retrieved_attrs=NIL;
879+
deparseReturningList(buf,root,rtindex,rel,
880+
rel->trigdesc&&rel->trigdesc->trig_insert_after_row,
881+
returningList,retrieved_attrs);
883882
}
884883

885884
/*
@@ -919,11 +918,9 @@ deparseUpdateSql(StringInfo buf, PlannerInfo *root,
919918
}
920919
appendStringInfoString(buf," WHERE ctid = $1");
921920

922-
if (returningList)
923-
deparseReturningList(buf,root,rtindex,rel,returningList,
924-
retrieved_attrs);
925-
else
926-
*retrieved_attrs=NIL;
921+
deparseReturningList(buf,root,rtindex,rel,
922+
rel->trigdesc&&rel->trigdesc->trig_update_after_row,
923+
returningList,retrieved_attrs);
927924
}
928925

929926
/*
@@ -943,34 +940,48 @@ deparseDeleteSql(StringInfo buf, PlannerInfo *root,
943940
deparseRelation(buf,rel);
944941
appendStringInfoString(buf," WHERE ctid = $1");
945942

946-
if (returningList)
947-
deparseReturningList(buf,root,rtindex,rel,returningList,
948-
retrieved_attrs);
949-
else
950-
*retrieved_attrs=NIL;
943+
deparseReturningList(buf,root,rtindex,rel,
944+
rel->trigdesc&&rel->trigdesc->trig_delete_after_row,
945+
returningList,retrieved_attrs);
951946
}
952947

953948
/*
954-
*deparseRETURNING clause ofINSERT/UPDATE/DELETE
949+
*Add aRETURNING clause, if needed, to anINSERT/UPDATE/DELETE.
955950
*/
956951
staticvoid
957952
deparseReturningList(StringInfobuf,PlannerInfo*root,
958953
Indexrtindex,Relationrel,
954+
booltrig_after_row,
959955
List*returningList,
960956
List**retrieved_attrs)
961957
{
962-
Bitmapset*attrs_used;
958+
Bitmapset*attrs_used=NULL;
963959

964-
/*
965-
* We need the attrs mentioned in the query's RETURNING list.
966-
*/
967-
attrs_used=NULL;
968-
pull_varattnos((Node*)returningList,rtindex,
969-
&attrs_used);
960+
if (trig_after_row)
961+
{
962+
/* whole-row reference acquires all non-system columns */
963+
attrs_used=
964+
bms_make_singleton(0-FirstLowInvalidHeapAttributeNumber);
965+
}
970966

971-
appendStringInfoString(buf," RETURNING ");
972-
deparseTargetList(buf,root,rtindex,rel,attrs_used,
973-
retrieved_attrs);
967+
if (returningList!=NIL)
968+
{
969+
/*
970+
* We need the attrs, non-system and system, mentioned in the local
971+
* query's RETURNING list.
972+
*/
973+
pull_varattnos((Node*)returningList,rtindex,
974+
&attrs_used);
975+
}
976+
977+
if (attrs_used!=NULL)
978+
{
979+
appendStringInfoString(buf," RETURNING ");
980+
deparseTargetList(buf,root,rtindex,rel,attrs_used,
981+
retrieved_attrs);
982+
}
983+
else
984+
*retrieved_attrs=NIL;
974985
}
975986

976987
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp