gregfelice commented on issue #2443:
URL: https://github.com/apache/age/issues/2443#issuecomment-4773020845

   **Correction — the root cause above is incomplete.** Verified by 
instrumenting the transform and inspecting the generated plans; the real cause 
is a missing correlation, not the `make_path_join_quals` early-return on its 
own.
   
   **What actually happens:** a single-node labeled pattern desugars to an 
`EXISTS` sub-pattern. The inner vertex is *not* correlated to the outer 
variable — it is handled like any vertex, and with no edge to carry a 
correlation qual, the sub-pattern references nothing from the enclosing query. 
The planner therefore produces an **uncorrelated one-time `InitPlan`** that is 
true whenever any vertex of that label exists, independent of the outer row:
   
   ```
   InitPlan 1
     ->  Result
   One-Time Filter: ((InitPlan 1).col1)::agtype
   ```
   
   Relationship patterns work precisely because the edge-driven join (`start_id 
= a.id`) correlates them to the outer variable — confirmed by identical 
node-level state in both cases but a correlated `SubPlan` only for the 
relationship form.
   
   So `make_path_join_quals` *is* the right place to fix, but the fix is to 
**emit a correlated label filter**, not merely "add the label qual": for a 
vertex-only pattern whose vertex has a non-default label and whose variable is 
bound in an ancestor parse state, emit `_extract_label_id(<id>) = <label_id>` 
via `make_qual` — whose name-based id reference resolves to the outer variable, 
which both correlates the sub-pattern and enforces the label. After the fix the 
plan is a correlated `SubPlan`:
   
   ```
   SubPlan 1
     ->  Result
           One-Time Filter: ((_extract_label_id(a_1.id))::integer = 3)
   ```
   
   Fix + regression coverage in #2444. Note: `RETURN (a:Label)` in a 
*projection* on an unlabeled bound variable is a separate, pre-existing 
"multiple labels" guard, orthogonal to this issue and left unchanged.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to