Skip to content

Commit 52b2086

Browse files
committed
Remove FDW tables support from update node functions
1 parent 338f057 commit 52b2086

File tree

8 files changed

+11
-203
lines changed

8 files changed

+11
-203
lines changed

hash.sql

-4
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,6 @@ BEGIN
138138
@extschema@.build_check_constraint_name(new_partition::REGCLASS),
139139
old_constr_def);
140140

141-
IF @extschema@.is_relation_foreign(new_partition) THEN
142-
PERFORM @extschema@.create_single_nop_trigger(parent_relid, new_partition);
143-
END IF;
144-
145141
/* Fetch init_callback from 'params' table */
146142
WITH stub_callback(stub) as (values (0))
147143
SELECT init_callback

init.sql

-25
Original file line numberDiff line numberDiff line change
@@ -737,23 +737,6 @@ CREATE OR REPLACE FUNCTION @extschema@.has_update_trigger(
737737
RETURNS BOOL AS 'pg_pathman', 'has_update_trigger'
738738
LANGUAGE C STRICT;
739739

740-
/*
741-
* Function for NOP triggers.
742-
* NOP trigger is a trigger that we use to turn off direct modify of FDW tables
743-
*/
744-
CREATE OR REPLACE FUNCTION @extschema@.pathman_nop_trigger_func()
745-
RETURNS TRIGGER AS 'pg_pathman', 'pathman_nop_trigger_func'
746-
LANGUAGE C STRICT;
747-
748-
/*
749-
* Creates single NOP trigger.
750-
*/
751-
CREATE OR REPLACE FUNCTION @extschema@.create_single_nop_trigger(
752-
parent_relid REGCLASS,
753-
partition_relid REGCLASS)
754-
RETURNS VOID AS 'pg_pathman', 'create_single_nop_trigger'
755-
LANGUAGE C STRICT;
756-
757740
/*
758741
* Partitioning key
759742
*/
@@ -946,11 +929,3 @@ LANGUAGE C STRICT;
946929
CREATE OR REPLACE FUNCTION @extschema@.get_pathman_lib_version()
947930
RETURNS CSTRING AS 'pg_pathman', 'get_pathman_lib_version'
948931
LANGUAGE C STRICT;
949-
950-
/*
951-
* Check if relation is foreign table
952-
*/
953-
CREATE OR REPLACE FUNCTION @extschema@.is_relation_foreign(
954-
relid REGCLASS)
955-
RETURNS BOOL AS 'pg_pathman', 'is_relation_foreign'
956-
LANGUAGE C STRICT;

range.sql

-5
Original file line numberDiff line numberDiff line change
@@ -952,11 +952,6 @@ BEGIN
952952
PERFORM @extschema@.create_single_update_trigger(parent_relid, partition_relid);
953953
END IF;
954954

955-
/*
956-
IF @extschema@.is_relation_foreign(partition_relid) THEN
957-
PERFORM @extschema@.create_single_nop_trigger(parent_relid, partition_relid);
958-
END IF; */
959-
960955
/* Invoke an initialization callback */
961956
PERFORM @extschema@.invoke_on_partition_created_callback(parent_relid,
962957
partition_relid,

src/include/partition_update.h

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ typedef struct PartitionUpdateState
2929
CustomScanState css;
3030

3131
Oid partitioned_table;
32-
List *returning_list;
3332
ResultRelInfo *resultRelInfo;
3433
JunkFilter *saved_junkFilter;
3534
Plan *subplan; /* proxy variable to store subplan */

src/init.c

-11
Original file line numberDiff line numberDiff line change
@@ -583,17 +583,6 @@ build_update_trigger_name_internal(Oid relid)
583583
return psprintf("%s_upd_trig", get_rel_name(relid));
584584
}
585585

586-
/*
587-
* Generate name for NOP trigger.
588-
* NOTE: this function does not perform sanity checks at all.
589-
*/
590-
char *
591-
build_nop_trigger_name_internal(Oid relid)
592-
{
593-
AssertArg(OidIsValid(relid));
594-
return psprintf("%s_nop_trig", get_rel_name(relid));
595-
}
596-
597586
/*
598587
* Generate name for update trigger's function.
599588
* NOTE: this function does not perform sanity checks at all.

src/partition_creation.c

-35
Original file line numberDiff line numberDiff line change
@@ -1830,38 +1830,3 @@ has_update_trigger_internal(Oid parent_relid)
18301830
trigname = build_update_trigger_name_internal(parent_relid);
18311831
return has_trigger_internal(parent_relid, trigname);
18321832
}
1833-
1834-
/* Create trigger for partition that does nothing */
1835-
void
1836-
create_single_nop_trigger_internal(Oid relid,
1837-
const char *trigname,
1838-
List *columns)
1839-
{
1840-
CreateTrigStmt *stmt;
1841-
List *func;
1842-
1843-
/* do nothing if relation has trigger already */
1844-
if (has_trigger_internal(relid, trigname))
1845-
return;
1846-
1847-
func = list_make2(makeString(get_namespace_name(get_pathman_schema())),
1848-
makeString(CppAsString(pathman_nop_trigger_func)));
1849-
1850-
stmt = makeNode(CreateTrigStmt);
1851-
stmt->trigname = (char *) trigname;
1852-
stmt->relation = makeRangeVarFromRelid(relid);
1853-
stmt->funcname = func;
1854-
stmt->args = NIL;
1855-
stmt->row = true;
1856-
stmt->timing = TRIGGER_TYPE_BEFORE;
1857-
stmt->events = TRIGGER_TYPE_UPDATE;
1858-
stmt->columns = columns;
1859-
stmt->whenClause = NULL;
1860-
stmt->isconstraint = false;
1861-
stmt->deferrable = false;
1862-
stmt->initdeferred = false;
1863-
stmt->constrrel = NULL;
1864-
1865-
(void) CreateTrigger(stmt, NULL, InvalidOid, InvalidOid,
1866-
InvalidOid, InvalidOid, false);
1867-
}

src/partition_update.c

+11-56
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ CustomScanMethods partition_update_plan_methods;
2828
CustomExecMethods partition_update_exec_methods;
2929

3030
static TupleTableSlot *ExecDeleteInternal(ItemPointer tupleid,
31-
HeapTuple oldtuple,
3231
TupleTableSlot *planSlot,
3332
EPQState *epqstate,
3433
EState *estate);
@@ -138,15 +137,12 @@ partition_update_exec(CustomScanState *node)
138137
if (!TupIsNull(slot))
139138
{
140139
Datum datum;
141-
bool isNull;
142140
char relkind;
143141
ResultRelInfo *resultRelInfo,
144142
*sourceRelInfo;
145143
ItemPointer tupleid = NULL;
146144
ItemPointerData tuple_ctid;
147145
EPQState epqstate;
148-
HeapTupleData oldtupdata;
149-
HeapTuple oldtuple = NULL;
150146
PartitionFilterState *child_state;
151147
JunkFilter *junkfilter;
152148

@@ -178,28 +174,9 @@ partition_update_exec(CustomScanState *node)
178174
tupleid = &tuple_ctid;
179175
}
180176
else if (relkind == RELKIND_FOREIGN_TABLE)
181-
{
182-
if (AttributeNumberIsValid(junkfilter->jf_junkAttNo))
183-
{
184-
datum = ExecGetJunkAttribute(child_state->subplan_slot,
185-
junkfilter->jf_junkAttNo,
186-
&isNull);
187-
/* shouldn't ever get a null result... */
188-
if (isNull)
189-
elog(ERROR, "wholerow is NULL");
190-
191-
oldtupdata.t_data = DatumGetHeapTupleHeader(datum);
192-
oldtupdata.t_len =
193-
HeapTupleHeaderGetDatumLength(oldtupdata.t_data);
194-
ItemPointerSetInvalid(&(oldtupdata.t_self));
195-
196-
/* Historically, view triggers see invalid t_tableOid. */
197-
oldtupdata.t_tableOid = RelationGetRelid(resultRelInfo->ri_RelationDesc);
198-
oldtuple = &oldtupdata;
199-
}
200-
}
177+
elog(ERROR, "update node is not supported for foreign tables");
201178
else
202-
elog(ERROR, "got unexpected type of relation");
179+
elog(ERROR, "got unexpected type of relation for update");
203180

204181
/*
205182
* Clean from junk attributes before INSERT,
@@ -209,14 +186,9 @@ partition_update_exec(CustomScanState *node)
209186
slot = ExecFilterJunk(junkfilter, slot);
210187
}
211188

212-
/*
213-
* Delete old tuple. We have two cases here:
214-
* 1) local tables - tupleid points to actual tuple
215-
* 2) foreign tables - tupleid is invalid, slot is required
216-
*/
189+
/* Delete old tuple */
217190
estate->es_result_relation_info = sourceRelInfo;
218-
ExecDeleteInternal(tupleid, oldtuple, child_state->subplan_slot,
219-
&epqstate, estate);
191+
ExecDeleteInternal(tupleid, child_state->subplan_slot, &epqstate, estate);
220192

221193
/* we've got the slot that can be inserted to child partition */
222194
estate->es_result_relation_info = resultRelInfo;
@@ -254,15 +226,14 @@ partition_update_explain(CustomScanState *node, List *ancestors, ExplainState *e
254226
*/
255227
static TupleTableSlot *
256228
ExecDeleteInternal(ItemPointer tupleid,
257-
HeapTuple oldtuple,
258229
TupleTableSlot *planSlot,
259230
EPQState *epqstate,
260231
EState *estate)
261232
{
262-
ResultRelInfo *resultRelInfo;
263-
Relation resultRelationDesc;
264-
HTSU_Result result;
265-
HeapUpdateFailureData hufd;
233+
ResultRelInfo *resultRelInfo;
234+
Relation resultRelationDesc;
235+
HTSU_Result result;
236+
HeapUpdateFailureData hufd;
266237

267238
/*
268239
* get information on the (current) result relation
@@ -277,29 +248,13 @@ ExecDeleteInternal(ItemPointer tupleid,
277248
bool dodelete;
278249

279250
dodelete = ExecBRDeleteTriggers(estate, epqstate, resultRelInfo,
280-
tupleid, oldtuple);
251+
tupleid, NULL);
281252

282253
if (!dodelete)
283254
elog(ERROR, "the old row always should be deleted from child table");
284255
}
285256

286-
if (resultRelInfo->ri_FdwRoutine)
287-
{
288-
TupleTableSlot *slot = MakeSingleTupleTableSlot(RelationGetDescr(resultRelationDesc));
289-
290-
/*
291-
* delete from foreign table: let the FDW do it
292-
*/
293-
ExecSetSlotDescriptor(slot, RelationGetDescr(resultRelationDesc));
294-
resultRelInfo->ri_FdwRoutine->ExecForeignDelete(estate,
295-
resultRelInfo,
296-
slot,
297-
planSlot);
298-
299-
/* we don't need slot anymore */
300-
ExecDropSingleTupleTableSlot(slot);
301-
}
302-
else if (tupleid != NULL)
257+
if (tupleid != NULL)
303258
{
304259
/* delete the tuple */
305260
ldelete:;
@@ -358,7 +313,7 @@ ldelete:;
358313
elog(ERROR, "tupleid should be specified for deletion");
359314

360315
/* AFTER ROW DELETE Triggers */
361-
ExecARDeleteTriggers(estate, resultRelInfo, tupleid, oldtuple);
316+
ExecARDeleteTriggers(estate, resultRelInfo, tupleid, NULL);
362317

363318
return NULL;
364319
}

src/pl_funcs.c

-66
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,8 @@ PG_FUNCTION_INFO_V1( check_security_policy );
7171

7272
PG_FUNCTION_INFO_V1( create_update_triggers );
7373
PG_FUNCTION_INFO_V1( pathman_update_trigger_func );
74-
PG_FUNCTION_INFO_V1( pathman_nop_trigger_func );
7574
PG_FUNCTION_INFO_V1( create_single_update_trigger );
7675
PG_FUNCTION_INFO_V1( has_update_trigger );
77-
PG_FUNCTION_INFO_V1( is_relation_foreign );
78-
79-
PG_FUNCTION_INFO_V1( create_single_nop_trigger );
8076

8177
PG_FUNCTION_INFO_V1( debug_capture );
8278
PG_FUNCTION_INFO_V1( get_pathman_lib_version );
@@ -1217,24 +1213,6 @@ pathman_update_trigger_func(PG_FUNCTION_ARGS)
12171213
PG_RETURN_POINTER(new_tuple);
12181214
}
12191215

1220-
Datum
1221-
pathman_nop_trigger_func(PG_FUNCTION_ARGS)
1222-
{
1223-
TriggerData *trigdata = (TriggerData *) fcinfo->context;
1224-
1225-
/* Handle user calls */
1226-
if (!CALLED_AS_TRIGGER(fcinfo))
1227-
elog(ERROR, "this function should not be called directly");
1228-
1229-
/* Handle wrong fire mode */
1230-
if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
1231-
elog(ERROR, "%s: must be fired for row",
1232-
trigdata->tg_trigger->tgname);
1233-
1234-
/* Just return NEW tuple */
1235-
PG_RETURN_POINTER(trigdata->tg_newtuple);
1236-
}
1237-
12381216
struct replace_vars_cxt
12391217
{
12401218
HeapTuple new_tuple;
@@ -1478,50 +1456,6 @@ has_update_trigger(PG_FUNCTION_ARGS)
14781456
PG_RETURN_BOOL(has_update_trigger_internal(parent_relid));
14791457
}
14801458

1481-
/* Check if relation is foreign table */
1482-
Datum
1483-
is_relation_foreign(PG_FUNCTION_ARGS)
1484-
{
1485-
Oid relid = PG_GETARG_OID(0);
1486-
Relation rel;
1487-
bool res;
1488-
1489-
/* Check that relation exists */
1490-
if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(relid)))
1491-
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1492-
errmsg("relation \"%u\" does not exist", relid)));
1493-
1494-
rel = heap_open(relid, NoLock);
1495-
res = (rel->rd_rel->relkind == RELKIND_FOREIGN_TABLE);
1496-
heap_close(rel, NoLock);
1497-
PG_RETURN_BOOL(res);
1498-
}
1499-
1500-
/* Create a trigger for partition that does nothing */
1501-
Datum
1502-
create_single_nop_trigger(PG_FUNCTION_ARGS)
1503-
{
1504-
Oid parent = PG_GETARG_OID(0);
1505-
Oid child = PG_GETARG_OID(1);
1506-
const char *trigname;
1507-
const PartRelationInfo *prel;
1508-
List *columns;
1509-
1510-
/* Check that table is partitioned */
1511-
prel = get_pathman_relation_info(parent);
1512-
shout_if_prel_is_invalid(parent, prel, PT_ANY);
1513-
1514-
/* Acquire trigger and attribute names */
1515-
trigname = build_nop_trigger_name_internal(parent);
1516-
1517-
/* Generate list of columns used in expression */
1518-
columns = PrelExpressionColumnNames(prel);
1519-
create_single_nop_trigger_internal(child, trigname, columns);
1520-
1521-
PG_RETURN_VOID();
1522-
}
1523-
1524-
15251459
/*
15261460
* -------
15271461
* DEBUG

0 commit comments

Comments
 (0)