@@ -113,6 +113,7 @@ static void pathman_update_trigger_func_move_tuple(Relation source_rel,
113
113
HeapTuple old_tuple ,
114
114
HeapTuple new_tuple );
115
115
116
+ static void collect_update_trigger_columns (Oid relid , List * * columns );
116
117
static Oid find_target_partition (Relation source_rel , HeapTuple tuple );
117
118
static Oid find_topmost_parent (Oid partition );
118
119
static Oid find_deepest_partition (Oid parent , Relation source_rel , HeapTuple tuple );
@@ -1087,30 +1088,12 @@ Datum
1087
1088
pathman_update_trigger_func (PG_FUNCTION_ARGS )
1088
1089
{
1089
1090
TriggerData * trigdata = (TriggerData * ) fcinfo -> context ;
1090
-
1091
1091
Relation source_rel ;
1092
-
1093
- // Oid parent_relid,
1094
1092
Oid source_relid ,
1095
1093
target_relid ;
1096
-
1097
1094
HeapTuple old_tuple ,
1098
1095
new_tuple ;
1099
1096
1100
- // Datum value;
1101
- // Oid value_type;
1102
- // bool isnull;
1103
- // ExprDoneCond itemIsDone;
1104
-
1105
- // Oid *parts;
1106
- // int nparts;
1107
-
1108
- // ExprContext *econtext;
1109
- // ExprState *expr_state;
1110
- // MemoryContext old_mcxt;
1111
- // PartParentSearch parent_search;
1112
- // const PartRelationInfo *prel;
1113
-
1114
1097
/* Handle user calls */
1115
1098
if (!CALLED_AS_TRIGGER (fcinfo ))
1116
1099
elog (ERROR , "this function should not be called directly" );
@@ -1132,54 +1115,11 @@ pathman_update_trigger_func(PG_FUNCTION_ARGS)
1132
1115
old_tuple = trigdata -> tg_trigtuple ;
1133
1116
new_tuple = trigdata -> tg_newtuple ;
1134
1117
1135
- // /* Find parent relation and partitioning info */
1136
- // parent_relid = get_parent_of_partition(source_relid, &parent_search);
1137
- // if (parent_search != PPS_ENTRY_PART_PARENT)
1138
- // elog(ERROR, "relation \"%s\" is not a partition",
1139
- // RelationGetRelationName(source_rel));
1140
-
1141
- // /* Fetch partition dispatch info */
1142
- // prel = get_pathman_relation_info(parent_relid);
1143
- // shout_if_prel_is_invalid(parent_relid, prel, PT_ANY);
1144
-
1145
- // /* Execute partitioning expression */
1146
- // econtext = CreateStandaloneExprContext();
1147
- // old_mcxt = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
1148
- // expr_state = pathman_update_trigger_build_expr_state(prel,
1149
- // source_rel,
1150
- // new_tuple,
1151
- // &value_type);
1152
- // value = ExecEvalExpr(expr_state, econtext, &isnull, &itemIsDone);
1153
- // MemoryContextSwitchTo(old_mcxt);
1154
-
1155
- // if (isnull)
1156
- // elog(ERROR, ERR_PART_ATTR_NULL);
1157
-
1158
- // if (itemIsDone != ExprSingleResult)
1159
- // elog(ERROR, ERR_PART_ATTR_MULTIPLE_RESULTS);
1160
-
1161
- // /* Search for matching partitions */
1162
- // parts = find_partitions_for_value(value, value_type, prel, &nparts);
1163
-
1164
-
1165
- // /* We can free expression context now */
1166
- // FreeExprContext(econtext, false);
1167
-
1168
- // if (nparts > 1)
1169
- // elog(ERROR, ERR_PART_ATTR_MULTIPLE);
1170
- // else if (nparts == 0)
1171
- // {
1172
- // target_relid = create_partitions_for_value(PrelParentRelid(prel),
1173
- // value, value_type);
1174
-
1175
- // /* get_pathman_relation_info() will refresh this entry */
1176
- // invalidate_pathman_relation_info(PrelParentRelid(prel), NULL);
1177
- // }
1178
- // else target_relid = parts[0];
1179
-
1180
- // pfree(parts);
1118
+ /* Find (or create) target partition */
1181
1119
target_relid = find_target_partition (source_rel , new_tuple );
1182
1120
1121
+ /* TODO: check for InvalidOid */
1122
+
1183
1123
/* Convert tuple if target partition has changed */
1184
1124
if (target_relid != source_relid )
1185
1125
{
@@ -1549,7 +1489,7 @@ create_update_triggers(PG_FUNCTION_ARGS)
1549
1489
const char * trigname ;
1550
1490
const PartRelationInfo * prel ;
1551
1491
uint32 i ;
1552
- List * columns ;
1492
+ List * columns = NIL ;
1553
1493
1554
1494
/* Check that table is partitioned */
1555
1495
prel = get_pathman_relation_info (parent );
@@ -1559,7 +1499,8 @@ create_update_triggers(PG_FUNCTION_ARGS)
1559
1499
trigname = build_update_trigger_name_internal (parent );
1560
1500
1561
1501
/* Create trigger for parent */
1562
- columns = PrelExpressionColumnNames (prel );
1502
+ // columns = PrelExpressionColumnNames(prel);
1503
+ collect_update_trigger_columns (parent , & columns );
1563
1504
create_single_update_trigger_internal (parent , trigname , columns );
1564
1505
1565
1506
/* Fetch children array */
@@ -1572,6 +1513,28 @@ create_update_triggers(PG_FUNCTION_ARGS)
1572
1513
PG_RETURN_VOID ();
1573
1514
}
1574
1515
1516
+ static void
1517
+ collect_update_trigger_columns (Oid relid , List * * columns )
1518
+ {
1519
+ const PartRelationInfo * prel ;
1520
+ Oid parent ;
1521
+ PartParentSearch parent_search ;
1522
+
1523
+ prel = get_pathman_relation_info (relid );
1524
+ if (!prel )
1525
+ return ;
1526
+
1527
+ /* Collect columns from current level */
1528
+ * columns = list_concat (* columns , PrelExpressionColumnNames (prel ));
1529
+
1530
+ /* Collect columns from parent */
1531
+ parent = get_parent_of_partition (relid , & parent_search );
1532
+ if (parent_search != PPS_ENTRY_PART_PARENT )
1533
+ return ;
1534
+
1535
+ collect_update_trigger_columns (parent , columns );
1536
+ }
1537
+
1575
1538
/* Create an UPDATE trigger for partition */
1576
1539
Datum
1577
1540
create_single_update_trigger (PG_FUNCTION_ARGS )
0 commit comments