zihaozeng0021 opened a new issue, #2616:
URL: https://github.com/apache/age/issues/2616

   # Chained MATCH rebinding a variable bound to zero rows errors with 
"argument 1 must not be null"
   
   ### Configuration
   
   Docker Image: `apache/age:release_PG18_1.8.0`
   Image Digest: 
`sha256:47a0b054c3663a3e64a25fc0c5a982f1b58348019274b326a691cdf77f78eb58`
   PostgreSQL Version: `18.6`
   Apache AGE Extension Version: `1.8.0`
   Operating System: WSL2, Ubuntu 24.04.1 LTS
   Installation Method: Docker
   Query Interface: `psql` (`SELECT * FROM cypher('xgdb', $$ ... $$) AS (...)`)
   
   ---
   
   ### Description
   
   On an empty graph, a chained `MATCH` that rebinds a variable bound by the 
first `MATCH` to zero
   rows aborts with the assertion-style internal error `ERROR:  argument 1 must 
not be null`. The
   same query shape returns the correct result on a non-empty graph, so the 
failure is specific to
   the empty-binding case. The clause chain is accepted by the validator and 
then fails inside the
   transformation machinery, rather than being rejected up front.
   
   ---
   
   ### Steps to reproduce
   
   1. Start the AGE container and connect with `psql`.
   2. On a fresh empty graph, run:
   
   ```sql
   DO $ddl$ BEGIN
     IF NOT EXISTS (SELECT 1 FROM ag_catalog.ag_graph WHERE name = 'xgdb') THEN
       PERFORM ag_catalog.create_graph('xgdb');
     END IF;
   END $ddl$;
   SELECT * FROM cypher('xgdb', $$ MATCH (m1)-[:rt3]->(m2) MATCH q = (m2) 
RETURN count(q) $$) AS (b agtype);
   ```
   
   3. For contrast, seed 2 vertices and 1 edge and run the same query: it 
returns 1.
   
   ---
   
   ### Expected behaviour
   
   Rebinding an already-bound variable is documented Cypher semantics (Neo4j 
"Matching a variable
   that is already bound"). On an empty graph the first `MATCH` yields 0 rows, 
so the whole query is
   legal and must simply return `count = 0`.
   
   ---
   
   ### Actual behaviour
   
   The query aborts on both fresh-container runs:
   
   ```text
   ERROR:  argument 1 must not be null
   exit=3
   ```
   
   Cross-checks on the same server:
   
   - The same shape on a non-empty graph returns `b_count = 1`.
   - Replacing the rebound variable with a fresh one (`MATCH (zz)`) on the 
empty graph returns 0.
   - The `MATCH -> WITH m2 -> MATCH q = (m2)` shape triggers the same error.
   
   Backend stays alive (`RestartCount=0`) with no FATAL/PANIC in the server log.
   
   ---
   
   ### Minimal reproduction
   
   ```sql
   SELECT * FROM cypher('xgdb', $$ MATCH (m1)-[:rt3]->(m2) MATCH q = (m2) 
RETURN count(q) $$) AS (b agtype);
   ```
   
   Empty graph; no data required.
   
   ---
   
   ### Why this appears to be a bug
   
   A legal query that matches nothing terminates with an internal, 
assertion-style error instead of
   returning 0 rows. The error text is identical to upstream apache/age#882, 
which was triggered by a
   `MERGE () MERGE n0 = ()` shape in 2023 and closed in May 2024; the same 
failure class is still
   reachable on AGE 1.8.0 / PG18 through a chained-MATCH rebinding shape.
   
   ---
   
   ### References
   
   - Related upstream issue: 
[[apache/age#882](https://github.com/apache/age/issues/882)](https://github.com/apache/age/issues/882)
 (closed; same `argument 1 must not be null` message, different trigger shape)


-- 
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