I'm trying to make Postgis using an index scan only but instead it's performing a Bitmap index scan into a Bitmap heap scan.
I got the following table - containing 50k rows:
CREATE TABLE IF NOT EXISTS public.forme_iris
(
code_iris character varying(20) COLLATE pg_catalog."default" NOT NULL,
geometry geometry,
CONSTRAINT forme_iris_pkey PRIMARY KEY (code_iris)
)
I've created this index:
CREATE INDEX forme_iris_geometry_idx1
ON public.forme_iris USING gist
(geometry, code_iris)
TABLESPACE pg_default;
I couldn't use a proper covering index with INCLUDE
statement, Postgis tells me that's not supported.
Performed request:
SELECT geometry, code_iris
FROM forme_iris iris
WHERE ST_Intersects(iris.geometry, ST_SetSrid(ST_GeomFromGeoJson('<geojson>'), 4326))
It returns 821 rows, I've vacuumed + analyzed the table before performing the request.
PostgreSQL version: PostgreSQL 11.12 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-12), 64-bit
Postgis version: 2.5 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
EXPLAIN ANALYZE
output: https://explain.dalibo.com/plan/TJQt
Thanks !
PostGIS GiST indexes compress the values (they store a bounding box) and have no "fetch" method, so they cannot do index-only scans:
See the documentation:
The documentation doesn't cover what the method numbers for these are, you have to consult the source for that.