Commit 38ad5ba
committed
Support distribution key update in MERGE for partitioned tables
Previously, MERGE ... WHEN MATCHED THEN UPDATE SET <dist_key> = ...
was rejected with "cannot update column in merge with distributed
column". This commit adds support by extending the SplitMerge node
to handle distribution key updates via DELETE + INSERT routing.
Key changes:
Planner (preptlist.c, createplan.c, setrefs.c, cdbpath.c):
- Detect distribution key modification in MERGE UPDATE actions and
set merge_need_split_update flag
- Add all target table columns to subplan targetlist so SplitMerge
can project complete rows for INSERT
- Expand UPDATE action targetlists to include all columns (not just
SET columns) using expand_insert_targetlist
- Build SplitMerge targetlist in N+M+1 format: N target table columns
+ M subplan columns + 1 DMLAction column
- Always use root table action lists (not per-partition adjusted lists)
to ensure hashAttnos match root attribute numbers
- Add set_splitmerge_tlist_references for proper OUTER_VAR conversion
Executor (nodeSplitMerge.c, nodeModifyTable.c):
- SplitMerge splits MATCHED UPDATE into DELETE + INSERT tuple pair,
each routed to the correct segment via hash computation
- NOT MATCHED rows get PASSTHROUGH action for normal ExecMerge processing
- ModifyTable handles DMLAction-tagged tuples from SplitMerge output
- Support lazy partition routing for CMD_MERGE DML_INSERT
Refactoring (nodeSplitMerge.c):
- Extract computeTargetSegment(), SwitchResultRelForPartition(),
BuildRootUpdateTupleDesc() helper functions
- Define SPLITMERGE_ACTION_PASSTHROUGH constant
- Remove dead code and consolidate duplicated logic1 parent 7e96c27 commit 38ad5ba
18 files changed
Lines changed: 1201 additions & 228 deletions
File tree
- contrib/pax_storage/src/test/regress/expected
- src
- backend
- cdb
- executor
- nodes
- optimizer
- plan
- prep
- include
- nodes
- optimizer
- test/regress
- expected
- sql
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1018 | 1018 | | |
1019 | 1019 | | |
1020 | 1020 | | |
1021 | | - | |
| 1021 | + | |
1022 | 1022 | | |
1023 | 1023 | | |
1024 | 1024 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
| 78 | + | |
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| |||
2798 | 2798 | | |
2799 | 2799 | | |
2800 | 2800 | | |
2801 | | - | |
2802 | | - | |
| 2801 | + | |
| 2802 | + | |
| 2803 | + | |
2803 | 2804 | | |
2804 | 2805 | | |
2805 | 2806 | | |
2806 | 2807 | | |
2807 | | - | |
| 2808 | + | |
2808 | 2809 | | |
2809 | 2810 | | |
2810 | 2811 | | |
2811 | 2812 | | |
2812 | 2813 | | |
2813 | 2814 | | |
| 2815 | + | |
| 2816 | + | |
| 2817 | + | |
| 2818 | + | |
| 2819 | + | |
| 2820 | + | |
| 2821 | + | |
| 2822 | + | |
| 2823 | + | |
| 2824 | + | |
| 2825 | + | |
| 2826 | + | |
| 2827 | + | |
| 2828 | + | |
| 2829 | + | |
2814 | 2830 | | |
2815 | 2831 | | |
2816 | 2832 | | |
| |||
2820 | 2836 | | |
2821 | 2837 | | |
2822 | 2838 | | |
2823 | | - | |
| 2839 | + | |
2824 | 2840 | | |
2825 | 2841 | | |
2826 | 2842 | | |
| |||
2923 | 2939 | | |
2924 | 2940 | | |
2925 | 2941 | | |
2926 | | - | |
| 2942 | + | |
2927 | 2943 | | |
2928 | 2944 | | |
2929 | 2945 | | |
2930 | 2946 | | |
2931 | 2947 | | |
2932 | 2948 | | |
2933 | | - | |
| 2949 | + | |
| 2950 | + | |
| 2951 | + | |
| 2952 | + | |
| 2953 | + | |
| 2954 | + | |
| 2955 | + | |
| 2956 | + | |
2934 | 2957 | | |
2935 | 2958 | | |
2936 | 2959 | | |
| |||
2947 | 2970 | | |
2948 | 2971 | | |
2949 | 2972 | | |
| 2973 | + | |
2950 | 2974 | | |
2951 | 2975 | | |
2952 | 2976 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1095 | 1095 | | |
1096 | 1096 | | |
1097 | 1097 | | |
1098 | | - | |
| 1098 | + | |
1099 | 1099 | | |
1100 | 1100 | | |
1101 | 1101 | | |
| |||
4372 | 4372 | | |
4373 | 4373 | | |
4374 | 4374 | | |
4375 | | - | |
| 4375 | + | |
| 4376 | + | |
| 4377 | + | |
| 4378 | + | |
| 4379 | + | |
| 4380 | + | |
| 4381 | + | |
| 4382 | + | |
| 4383 | + | |
| 4384 | + | |
| 4385 | + | |
| 4386 | + | |
| 4387 | + | |
| 4388 | + | |
| 4389 | + | |
| 4390 | + | |
| 4391 | + | |
| 4392 | + | |
| 4393 | + | |
| 4394 | + | |
| 4395 | + | |
| 4396 | + | |
| 4397 | + | |
| 4398 | + | |
| 4399 | + | |
| 4400 | + | |
| 4401 | + | |
| 4402 | + | |
| 4403 | + | |
| 4404 | + | |
| 4405 | + | |
| 4406 | + | |
| 4407 | + | |
| 4408 | + | |
| 4409 | + | |
| 4410 | + | |
| 4411 | + | |
| 4412 | + | |
| 4413 | + | |
| 4414 | + | |
| 4415 | + | |
| 4416 | + | |
| 4417 | + | |
| 4418 | + | |
| 4419 | + | |
| 4420 | + | |
| 4421 | + | |
| 4422 | + | |
| 4423 | + | |
| 4424 | + | |
| 4425 | + | |
| 4426 | + | |
| 4427 | + | |
| 4428 | + | |
| 4429 | + | |
| 4430 | + | |
| 4431 | + | |
| 4432 | + | |
| 4433 | + | |
| 4434 | + | |
| 4435 | + | |
| 4436 | + | |
| 4437 | + | |
| 4438 | + | |
| 4439 | + | |
| 4440 | + | |
| 4441 | + | |
| 4442 | + | |
| 4443 | + | |
| 4444 | + | |
| 4445 | + | |
4376 | 4446 | | |
4377 | 4447 | | |
4378 | 4448 | | |
| |||
4661 | 4731 | | |
4662 | 4732 | | |
4663 | 4733 | | |
| 4734 | + | |
| 4735 | + | |
| 4736 | + | |
| 4737 | + | |
| 4738 | + | |
4664 | 4739 | | |
4665 | 4740 | | |
4666 | 4741 | | |
| |||
0 commit comments