Commit f0ed4c9
committed
Fix MERGE ON CREATE/MATCH SET crash when RHS references a bound variable
When MERGE has a previous clause (e.g. MATCH, UNWIND), transform_cypher_merge
takes the lateral-left-join path via transform_merge_make_lateral_join. That
helper called addRangeTableEntryForJoin with nscolumns=NULL, leaving the join
ParseNamespaceItem's p_nscolumns unset. For queries that did not subsequently
resolve a column reference against that nsitem (e.g. RETURN, which runs in a
fresh namespace built by handle_prev_clause), the NULL was harmless.
Our ON CREATE / ON MATCH SET transform runs in-line, before the MERGE query
becomes a subquery, so transform_cypher_set_item_list consulted the join's
nsitem directly. colNameToVar -> scanNSItemForColumn then dereferenced
p_nscolumns[attnum-1] = NULL[0] and the backend segfaulted on any ON SET
whose RHS referenced a bound variable. Reported by MuhammadTahaNaveed on
PR #2347.
Populate the join's p_nscolumns from res_colvars. The Var we end up
producing for a bound entity lives inside prop_expr, which is opaque to
the planner, so it is not rewritten to match the plan's output slots. At
ExecEvalScalarVar time only varattno is consulted, and scantuple's layout
mirrors the join's eref->colnames (via make_target_list_from_join). Use
the join rtindex and 1-based eref position so scantuple[varattno - 1]
resolves to the correct entity column at runtime; without this, Vars for
a (varno=l_rte) and b (varno=r_rte) with varattno=1 both hit
scantuple[0] and b.id evaluated to a.id.
Also initialise apply_update_list's new_property_value at its declaration.
All control paths reach the single alter_property_value call with the
variable set, but -Wmaybe-uninitialized fires at -O2 because the compiler
cannot prove remove_property == isnull when prop_expr is non-NULL.
Regression: six new cases in cypher_merge covering outer-ref RHS, self-ref
RHS with a previous clause (the silent-wrong-value variant we initially
missed), UNWIND-driven MERGE with self-ref (Muhammad's second reproducer),
multi-item ON CREATE SET mixing reference kinds, and ON MATCH SET with a
variable RHS on the match-branch second run. Cassert installcheck: 33/33.1 parent 39a2cc8 commit f0ed4c9
4 files changed
Lines changed: 176 additions & 5 deletions
File tree
- regress
- expected
- sql
- src/backend
- executor
- parser
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2160 | 2160 | | |
2161 | 2161 | | |
2162 | 2162 | | |
| 2163 | + | |
| 2164 | + | |
| 2165 | + | |
| 2166 | + | |
| 2167 | + | |
| 2168 | + | |
| 2169 | + | |
| 2170 | + | |
| 2171 | + | |
| 2172 | + | |
| 2173 | + | |
| 2174 | + | |
| 2175 | + | |
| 2176 | + | |
| 2177 | + | |
| 2178 | + | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
| 2183 | + | |
| 2184 | + | |
| 2185 | + | |
| 2186 | + | |
| 2187 | + | |
| 2188 | + | |
| 2189 | + | |
| 2190 | + | |
| 2191 | + | |
| 2192 | + | |
| 2193 | + | |
| 2194 | + | |
| 2195 | + | |
| 2196 | + | |
| 2197 | + | |
| 2198 | + | |
| 2199 | + | |
| 2200 | + | |
| 2201 | + | |
| 2202 | + | |
| 2203 | + | |
| 2204 | + | |
| 2205 | + | |
| 2206 | + | |
| 2207 | + | |
| 2208 | + | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
| 2212 | + | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
| 2216 | + | |
| 2217 | + | |
| 2218 | + | |
| 2219 | + | |
| 2220 | + | |
| 2221 | + | |
| 2222 | + | |
| 2223 | + | |
| 2224 | + | |
| 2225 | + | |
| 2226 | + | |
| 2227 | + | |
| 2228 | + | |
| 2229 | + | |
| 2230 | + | |
| 2231 | + | |
| 2232 | + | |
| 2233 | + | |
2163 | 2234 | | |
2164 | 2235 | | |
2165 | 2236 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1038 | 1038 | | |
1039 | 1039 | | |
1040 | 1040 | | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
1041 | 1088 | | |
1042 | 1089 | | |
1043 | 1090 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
440 | 440 | | |
441 | 441 | | |
442 | 442 | | |
443 | | - | |
| 443 | + | |
444 | 444 | | |
445 | 445 | | |
446 | 446 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7509 | 7509 | | |
7510 | 7510 | | |
7511 | 7511 | | |
7512 | | - | |
7513 | | - | |
7514 | | - | |
7515 | | - | |
| 7512 | + | |
| 7513 | + | |
| 7514 | + | |
| 7515 | + | |
| 7516 | + | |
| 7517 | + | |
| 7518 | + | |
| 7519 | + | |
| 7520 | + | |
| 7521 | + | |
| 7522 | + | |
| 7523 | + | |
| 7524 | + | |
| 7525 | + | |
| 7526 | + | |
| 7527 | + | |
| 7528 | + | |
| 7529 | + | |
| 7530 | + | |
| 7531 | + | |
| 7532 | + | |
| 7533 | + | |
| 7534 | + | |
| 7535 | + | |
| 7536 | + | |
| 7537 | + | |
| 7538 | + | |
| 7539 | + | |
| 7540 | + | |
| 7541 | + | |
| 7542 | + | |
| 7543 | + | |
| 7544 | + | |
| 7545 | + | |
| 7546 | + | |
| 7547 | + | |
| 7548 | + | |
| 7549 | + | |
| 7550 | + | |
| 7551 | + | |
| 7552 | + | |
| 7553 | + | |
| 7554 | + | |
| 7555 | + | |
| 7556 | + | |
| 7557 | + | |
| 7558 | + | |
| 7559 | + | |
| 7560 | + | |
| 7561 | + | |
| 7562 | + | |
| 7563 | + | |
| 7564 | + | |
| 7565 | + | |
| 7566 | + | |
| 7567 | + | |
| 7568 | + | |
7516 | 7569 | | |
7517 | 7570 | | |
7518 | 7571 | | |
| |||
0 commit comments