bitnine-oss / agensgraph

AgensGraph, a transactional graph database based on PostgreSQL
http://www.agensgraph.org
Other
1.32k stars 146 forks source link

Why can't I use the attribute index with the match syntax #615

Open YouthGoblin opened 1 year ago

YouthGoblin commented 1 year ago

I created a graph which nodes are composed of geometry in JSON format, and I created an attribute index for it, and the SQL statement is as follows: create INDEX idxgeom ON gisgraph.province USING GiST (ST_GeomFromGeoJSON(province.properties -> 'geom'));

geom represents geometry data in json format I use a regular query and it shows that the index is used: explain select count(*) from gisgraph.province where ST_GeomFromGeoJSON(province.properties -> 'geom') && st_geomfromtext('point(1 1)'); But when I use the match method, it uses a sequential scan: match (c0:province ) where ST_GeomFromGeoJSON(c0.properties->'geom') && 'point(1 1)'::geometry return (c0.geom); I debugged and it does the final judgment at the position of 'if (equal(indexkey, operand))' in the code, but I can't see the memory difference between index and sequential scan here

samoscyberallenh commented 6 months ago

Can you post a script with all the necessary parts (e.g., create vlabel, creation of test data, create function, etc.)? That might help people help you with this somewhat tricky question.

My initial read of the situation is that this isn't right in your MATCH clause:

where ST_GeomFromGeoJSON(c0.properties->'geom')

Specifically, I think you want c0.geom and not c0.properties->'geom'. Minimally, you need to drop the "properties" part there because that is probably getting translated to c0->'properties'->'properties'->'geom' in the PostgreSQL context (which would explain why it doesn't match your index). The actual EXPLAIN output would probably show that.