I am trying to write a new column based on the intersection of two polygon features which have 50m rows in one table, I have created the "gist" index before running them but it takes forever and I cannot get the result in Postgresql. The gist index is not used in the computation. How can I use the index for the operation?
The model is attached in the fiddle below,
CREATE INDEX idx_operation_geom ON public."Operation" USING gist (geom);
CREATE INDEX idx_operation_buffer ON public."Operation" USING gist (buffer);
CREATE INDEX idx_residential_geom ON public."Residential" USING gist (geom);
SELECT
ST_Intersection(ST_MakeValid(r.geom),o.buffer) AS intersection,
ST_Area(ST_Intersection(ST_MakeValid(r.geom),o.buffer))/ST_Area(r.geom)*100
FROM public."Residential" r, public."Operation" o
WHERE ST_Intersects(o.buffer,ST_MakeValid(r.geom));
I have tried to check the index using "Explain" but I am not sure how it works,
ERROR: operator does not exist: geometry = integer LINE 1: EXPLAIN SELECT * FROM public."Operation" where buffer = 2;
Any input will be very helpful.
buffer geometry(polygon,4326),You can't do an integer comparison, this is why your explain is failing. Fix this then you will see correct Explain output and you can go from there.