You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@age.apache.org by "gregfelice (via GitHub)" <gi...@apache.org> on 2026/06/22 20:13:37 UTC
[I] Single-node labeled pattern (a:Label) does not filter by label (vertex-only EXISTS skips label quals) [age]
gregfelice opened a new issue, #2443:
URL: https://github.com/apache/age/issues/2443
### Summary
Single-node labeled pattern expressions `(a:Label)` are accepted as boolean expressions but do **not** filter by label — they evaluate as trivially true. This is a pre-existing limitation in the vertex-only pattern transform, surfaced by #2360 (which lets a bare pattern appear anywhere an expression is valid).
### Reproduction
```sql
SELECT * FROM cypher('g', $$ CREATE (:Person {name:'Alice'}), (:Animal {name:'Rex'}) $$) AS (r agtype);
-- expected: only "Alice"; actual: "Alice" AND "Rex"
SELECT * FROM cypher('g', $$ MATCH (a) WHERE (a:Person) RETURN a.name $$) AS (n agtype);
-- expected: a boolean reflecting whether a has label Person; actual: always true
SELECT * FROM cypher('g', $$ MATCH (a:Person) RETURN (a:Person) $$) AS (b agtype);
```
### Root cause
`make_path_join_quals()` in `src/backend/parser/cypher_clause.c:5454` early-returns for vertex-only patterns:
```c
/* for vertex only queries, there is no work to do */
if (list_length(entities) < 3)
{
return NIL;
}
```
The label-filter quals (`_extract_label_id(id) = label_id`) are only emitted inside `make_join_condition_for_edge()`, which is never reached without a relationship. So a single-vertex pattern desugars to an `EXISTS` subquery with no label constraint → trivially true.
### Scope
- Relationship patterns (`(a)-[:R]->(b)`) correlate and filter correctly — the path goes through the ≥3-entity branch. This is the feature #2360 targets and it is unaffected.
- The buggy early-return is byte-identical on `master`; #2360 touches no transform code. It only makes the limitation reachable via the new `(a:Label)` expression surface.
### Suggested fix
Emit the label-filter qual for single bound vertices before the early return in `make_path_join_quals` (or hoist the label-filter logic out of `make_join_condition_for_edge` so it applies to vertex-only patterns), plus a regression test asserting `WHERE (a:Person)` filters and `RETURN (a:Label)` reflects the label.
Found during review of #2360.
--
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: dev-unsubscribe@age.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Single-node labeled pattern (a:Label) does not filter by label (vertex-only EXISTS skips label quals) [age]
Posted by "gregfelice (via GitHub)" <gi...@apache.org>.
gregfelice commented on issue #2443:
URL: https://github.com/apache/age/issues/2443#issuecomment-4773209734
Fix is up and ready for review: #2444. It makes single-node labeled patterns a correlated label predicate (WHERE / EXISTS), verified against a clean PG18 build with the full regression suite green (41/41). Merging #2444 will close this.
--
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: dev-unsubscribe@age.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Single-node labeled pattern (a:Label) does not filter by label (vertex-only EXISTS skips label quals) [age]
Posted by "gregfelice (via GitHub)" <gi...@apache.org>.
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: dev-unsubscribe@age.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Single-node labeled pattern (a:Label) does not filter by label (vertex-only EXISTS skips label quals) [age]
Posted by "jrgemignani (via GitHub)" <gi...@apache.org>.
jrgemignani closed issue #2443: Single-node labeled pattern (a:Label) does not filter by label (vertex-only EXISTS skips label quals)
URL: https://github.com/apache/age/issues/2443
--
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: dev-unsubscribe@age.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org