agensgraph icon indicating copy to clipboard operation
agensgraph copied to clipboard

AgensGraph Error with Complex Cypher Query

Open stupalpa opened this issue 7 months ago • 2 comments

Environment

Agensgraph commit version: a706a3966f676cc04bd285af1d2c44e4e23736cf Operating System: Ubuntu22.04 Installation Method: source code compilation

Step to reproduce:

  1. Create the graph database: log33.txt

  2. Execute the following query:

MATCH (n0 :L2)-[r0 :T1]->(n1 :L2)-[r1 :T3]->(n2 :L4),(n3 :L1)-[r2 :T0]->(n4 :L0)<-[r3 :T1]-(n5) 
UNWIND [ -1864444377 , ( n2 . k28 ) ] AS a0 
OPTIONAL MATCH (n0)-[m0*1..2]->(n1)-[m1*1..1]->(n2),(n1)-[r4 :T0]->(n4)<-[r5 :T3]-(n6 :L2) WHERE length(m0)=1 AND length(m1)=1 AND (((r1.k59) CONTAINS 'nCztB6') AND ((r4.id) <> (r5.id))) WITH n0, n1, r0, n2, r1, n3, n4, r2, n5, r3, a0, r4, n6, r5 
OPTIONAL MATCH (n3)-[]->(n4)<-[]-(n5) 
WITH r4 , a0 
OPTIONAL MATCH (n0 :L2)-[ *..3]->(n2),(n7)<-[r6 :T2]-(n0 :L2) WHERE ((r4.k39) OR (n0.k13))
OPTIONAL MATCH (n7)<-[m4*1..1]-(n0:L2) WHERE length(m4)=1 WITH r4, a0, n0, n2, n7, r6 
RETURN a0

It results in the following error:

ERROR:  could not open relation with OID 0

But when I execute a simple version as below:

MATCH (n0 :L2)-[r0 :T1]->(n1 :L2)-[r1 :T3]->(n2 :L4), (n3 :L1)-[r2 :T0]->(n4 :L0)<-[r3 :T1]-(n5) 
UNWIND [-1864444377, (n2.k28)] AS a0 
OPTIONAL MATCH (n0)-[]->(n1)-[]->(n2), (n1)-[r4 :T0]->(n4)<-[r5 :T3]-(n6 :L2) WHERE (((r1.k59) CONTAINS 'nCztB6') AND ((r4.id) <> (r5.id))) 
OPTIONAL MATCH (n3)-[]->(n4)<-[]-(n5)  
WITH r4, a0 
OPTIONAL MATCH (n0 :L2)-[ *..3]->(n2), (n7)<-[r6 :T2]-(n0 :L2) WHERE ((r4.k39) OR (n0.k13)) 
OPTIONAL MATCH (n7)<-[]-(n0 :L2) 
RETURN a0

It returns:

     a0      
-------------
 -1864444377
 1841232600
(2 rows)

Analysis

When both queries are tested in Neo4j (after replacing length() with size()), they execute without errors and return identical results:

     a0      
-------------
 -1864444377
 1841232600
(2 rows)

stupalpa avatar Jun 13 '25 07:06 stupalpa

​​The detailed steps to reproduce the error are outlined below. I hope this helpful:​​

Step to reproduce

First we create a fresh database server

  1. mkdir data4
  2. ./bin/initdb -D ./data4
  3. ./bin/ag_ctl start -D ./data4 -l log4 -o "-p 5436"
  4. ./bin/agens -p 5436 postgres

Now we are in the database server, and execute the following cmd:

  1. CREATE GRAPH agens
  2. SET graph_path = agens
  3. Create the graph database use the log33.txt file.
  4. Execute the following query:
MATCH (n0 :L2)-[r0 :T1]->(n1 :L2)-[r1 :T3]->(n2 :L4),(n3 :L1)-[r2 :T0]->(n4 :L0)<-[r3 :T1]-(n5) 
UNWIND [ -1864444377 , ( n2 . k28 ) ] AS a0 
OPTIONAL MATCH (n0)-[m0*1..2]->(n1)-[m1*1..1]->(n2),(n1)-[r4 :T0]->(n4)<-[r5 :T3]-(n6 :L2) WHERE length(m0)=1 AND length(m1)=1 AND (((r1.k59) CONTAINS 'nCztB6') AND ((r4.id) <> (r5.id))) WITH n0, n1, r0, n2, r1, n3, n4, r2, n5, r3, a0, r4, n6, r5 
OPTIONAL MATCH (n3)-[]->(n4)<-[]-(n5) 
WITH r4 , a0 
OPTIONAL MATCH (n0 :L2)-[ *..3]->(n2),(n7)<-[r6 :T2]-(n0 :L2) WHERE ((r4.k39) OR (n0.k13))
OPTIONAL MATCH (n7)<-[m4*1..1]-(n0:L2) WHERE length(m4)=1 WITH r4, a0, n0, n2, n7, r6 
RETURN a0
  1. It results in the following error:

    ERROR: could not open relation with OID 0

The log in log4 file is:

2025-06-13 16:07:00.023 CST [625665] LOG:  starting PostgreSQL 15beta2 (AgensGraph 2.13-devel) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 64-bit
2025-06-13 16:07:00.023 CST [625665] LOG:  listening on IPv4 address "127.0.0.1", port 5436
2025-06-13 16:07:00.035 CST [625665] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5436"
2025-06-13 16:07:00.049 CST [625670] LOG:  database system was shut down at 2025-06-13 16:06:19 CST
2025-06-13 16:07:00.059 CST [625665] LOG:  database system is ready to accept connections
2025-06-13 16:09:25.869 CST [625836] ERROR:  could not open relation with OID 0
2025-06-13 16:09:25.869 CST [625836] STATEMENT:  MATCH (n0 :L2)-[r0 :T1]->(n1 :L2)-[r1 :T3]->(n2 :L4),(n3 :L1)-[r2 :T0]->(n4 :L0)<-[r3 :T1]-(n5) 
	UNWIND [ -1864444377 , ( n2 . k28 ) ] AS a0 
	OPTIONAL MATCH (n0)-[m0*1..2]->(n1)-[m1*1..1]->(n2),(n1)-[r4 :T0]->(n4)<-[r5 :T3]-(n6 :L2) WHERE length(m0)=1 AND length(m1)=1 AND (((r1.k59) CONTAINS 'nCztB6') AND ((r4.id) <> (r5.id))) WITH n0, n1, r0, n2, r1, n3, n4, r2, n5, r3, a0, r4, n6, r5 
	OPTIONAL MATCH (n3)-[]->(n4)<-[]-(n5) 
	WITH r4 , a0 
	OPTIONAL MATCH (n0 :L2)-[ *..3]->(n2),(n7)<-[r6 :T2]-(n0 :L2) WHERE ((r4.k39) OR (n0.k13))
	OPTIONAL MATCH (n7)<-[m4*1..1]-(n0:L2) WHERE length(m4)=1 WITH r4, a0, n0, n2, n7, r6 
	RETURN a0;
2025-06-13 16:12:00.148 CST [625668] LOG:  checkpoint starting: time
2025-06-13 16:12:28.041 CST [625668] LOG:  checkpoint complete: wrote 280 buffers (1.7%); 0 WAL file(s) added, 0 removed, 0 recycled; write=27.802 s, sync=0.068 s, total=27.893 s; sync files=143, longest=0.006 s, average=0.001 s; distance=959 kB, estimate=959 kB

stupalpa avatar Jun 13 '25 08:06 stupalpa

Oh sorry, I was on the different commit. After the pulling, I was able to reproduce your error.

That's why I deleted my post to prevent confusion. But I ended up making you post twice. Sorry about that.

Anyway, I'll try to fix it.

seo-kw avatar Jun 13 '25 08:06 seo-kw