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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]