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

   ### Summary
   
   This report highlights significant performance discrepancies between 
logically equivalent Cypher queries that should all return empty results. 
Although every query correctly returns 0 rows, some take way much longer to 
execute despite having the same semantic meaning.
   
   
   ### Configuration
   AGE Version: `apache/age:latest` (pulled 2025-12-26)
   
   Operating System: WSL2 – Ubuntu 24.04.1 LTS
   
   Installation Method: Docker
   
   
   ---
   
   ### Steps to reproduce
   
   1. Start AGE via Docker
   ```
   docker run \
     --name age \
     -p 5455:5432 \
     -e POSTGRES_USER=postgresUser \
     -e POSTGRES_PASSWORD=postgresPW \
     -e POSTGRES_DB=postgresDB \
     -d \
     apache/age:latest
   ```
   
   2. Connect with psql
   ```
   PGPASSWORD='postgresPW' psql -h localhost -p 5455 -U postgresUser -d 
postgresDB
   ```
   
   3. Run the following query
   
   Set up:
   ```
   \timing on
   
   CREATE EXTENSION IF NOT EXISTS age;
   LOAD 'age';
   SET search_path = ag_catalog, "$user", public;
   
   SELECT create_graph('test');
   
   SELECT *
   FROM cypher('test', $$
     WITH range(1, 500000) AS ids
     UNWIND ids AS id
     CREATE (:Person {age: (id % 50) + 18, score: (id % 100)})
     RETURN 1
   $$) AS (ok agtype);
   ```
   
   Positive case (finish immediately; All the negative cases below can be 
simplified to this one):
   ```
   postgresDB=# SELECT count(*)
   FROM cypher('test', $$
     MATCH (p:Person)
     WITH p LIMIT 1000
     MATCH (q:Person)
     WHERE false
     RETURN p
   $$) AS (p agtype);
    count
   -------
        0
   (1 row)
   
   Time: 0.347 ms
   ```
   
   Negative cases (take much longer):
   
   
   Some of the buggy queries may share the same root cause; I reported all of 
them anyway in case they turn out to be different issues.
   
   ```
   postgresDB=# SELECT count(*)
   FROM cypher('test', $$
     MATCH (p:Person)
     WITH p LIMIT 1000
     MATCH (q:Person)
     WHERE id(q) <> id(q)
     RETURN p
   $$) AS (p agtype);
    count
   -------
        0
   (1 row)
   
   Time: 565.713 ms
   ```
   
   ```
   postgresDB=# SELECT count(*)
   FROM cypher('test', $$
     MATCH (p:Person)
     WITH p LIMIT 1000
     MATCH (q:Person)
     WITH p, count(q) AS c
     WHERE c < 0
     RETURN p
   $$) AS (p agtype);
    count
   -------
        0
   (1 row)
   
   Time: 307900.914 ms (05:07.901)
   ```
   
   ```
   postgresDB=# SELECT count(*)
   FROM cypher('test', $$
     MATCH (p:Person)
     WITH p LIMIT 1000
     MATCH (q:Person)
     WITH p, {n:q} AS m
     WHERE m.n IS NULL
     RETURN p
   $$) AS (p agtype);
    count
   -------
        0
   (1 row)
   
   Time: 254.241 ms
   ```
   
   The following queries are not taking much longer, I am not sure are they 
really bugs:
   
   ```
   postgresDB=# SELECT count(*)
   FROM cypher('test', $$
     MATCH (p:Person)
     WITH p LIMIT 1000
     MATCH (q:Person)
     WHERE q.age = 1 AND q.age = 2
     RETURN p
   $$) AS (p agtype);
    count
   -------
        0
   (1 row)
   
   Time: 73.505 ms
   ```
   
   ```
   postgresDB=# SELECT count(*)
   FROM cypher('test', $$
     MATCH (p:Person)
     WITH p LIMIT 1000
     MATCH (q:Person)
     WHERE q.score > 50 AND q.score <= 50
     RETURN p
   $$) AS (p agtype);
    count
   -------
        0
   (1 row)
   
   Time: 94.082 ms
   ```
   ---
   
   ### Expected behaviour
   
   All queries should have comparable execution times, since each `WHERE 
predicate` is a constant condition that cannot evaluate to true for any row.
   
   ### Actual behaviour
   
   The positive case complete almost immediately. The negative cases take much 
longer.


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