age
age copied to clipboard
how to optimise this sql, its execution is extremely slow.
SELECT * FROM ag_catalog.cypher ( 'chunk_entity_relation', $$ MATCH ( n ) OPTIONAL MATCH ( n ) -[ r ]- ( ) WITH n, COUNT ( r ) AS DEGREE RETURN n, DEGREE ORDER BY DEGREE DESC LIMIT 1000 $$ ) AS ( n agtype, DEGREE agtype );
psql-16.2-5432-psql=# SELECT * FROM cypher('my_graph_name', $$ match (u) return u, vertex_stats(u) $$) as (u agtype, degree agtype);
u | degree
----------------------------------------------------------------+-------------------------------------------------------------------
---------------------
{"id": 281474976710657, "label": "", "properties": {}}::vertex | {"id": 281474976710657, "label": "", "in_degree": 0, "out_degree":
0, "self_loops": 0}
{"id": 281474976710658, "label": "", "properties": {}}::vertex | {"id": 281474976710658, "label": "", "in_degree": 0, "out_degree":
1, "self_loops": 0}
{"id": 281474976710659, "label": "", "properties": {}}::vertex | {"id": 281474976710659, "label": "", "in_degree": 1, "out_degree":
0, "self_loops": 0}
(3 rows)
psql-16.2-5432-psql=# SELECT * FROM cypher('my_graph_name', $$ match (u) return u, (vertex_stats(u).in_degree+vertex_stats(u).out_degree+vertex_stats(u).self_loops) $$) as (u agtype, degree agtype);
u | degree
----------------------------------------------------------------+--------
{"id": 281474976710657, "label": "", "properties": {}}::vertex | 0
{"id": 281474976710658, "label": "", "properties": {}}::vertex | 1
{"id": 281474976710659, "label": "", "properties": {}}::vertex | 1
(3 rows)
psql-16.2-5432-psql=#