I am using PostgreSQL 10 on windows 7 (64 bit) machine.I have a PostgreSQL table whose structure is given below.
CREATE TABLE public.linedata ( linedataid bigint NOT NULL, customerid integer NOT NULL, linelatlong geometry(LineString,4326), createdon date DEFAULT now() ) WITH ( OIDS = FALSE ) TABLESPACE pg_default; ALTER TABLE public.linedata OWNER to postgres; CREATE INDEX idx_linedata_customerid ON public.linedata USING btree (customerid) TABLESPACE pg_default; CREATE INDEX idx_linedata_linedataid ON public.linedata USING btree (linedataid) TABLESPACE pg_default; CREATE INDEX idx_linedata_geom ON public.linedata USING gist (linelatlong) TABLESPACE pg_default;
This table has 4333053 records. Geoserver call this table to get data and render layers. But the performance is very slow. Geoserver uses below given query.
Select pgis.linelatlong From public.linedata as pgis INNER JOIN public.tempLine as tdp ON tdp.templineid=pgis.linedataid where tdp.uniquedata=%drivepathid% AND pgis.linelatlong is not null
structure of templine table is given below.
CREATE TABLE public.tempLine ( templineid bigint, uniquedata bigint ) WITH ( OIDS = FALSE ) TABLESPACE pg_default; ALTER TABLE public.tempLine OWNER to postgres; CREATE INDEX idx_tempLine_uniquedata ON public.tempLine USING btree (uniquedata) TABLESPACE pg_default;
drivepathid is a viewparams. In the LineData table linedataid can be duplicate for a customer therefore did not set it as primary key.LineData table is populated from some external source. The above query returns 14652 records only and took 4-5 minutes. AutoVaccum and AutoAnalyze is set on this table.
Explain analyze and query is given below.
Select pgis.linelatlong From public.linedata as pgis INNER JOIN public.tempLine as tdp ON tdp.templineid=pgis.linedataid where tdp.uniquedata=1711058674182521921 AND pgis.linelatlong is not null
"Gather (cost=1000.43..226588.94 rows=50881 width=6588) (actual time=0.555..525.171 rows=14652 loops=1)" " Workers Planned: 2" " Workers Launched: 2" " -> Nested Loop (cost=0.43..220500.84 rows=21200 width=6588) (actual time=250.457..425.718 rows=4884 loops=3)" " -> Parallel Seq Scan on tempLine tdp (cost=0.00..121612.47 rows=6525 width=8) (actual time=250.411..415.384 rows=4884 loops=3)" " Filter: (uniquedata = '1711058674182521921'::bigint)" " Rows Removed by Filter: 3814396" " -> Index Scan using idx_linedata_linedataid on linedata pgis (cost=0.43..15.13 rows=3 width=6596) (actual time=0.002..0.002 rows=1 loops=14652)" " Index Cond: (drivepathid = tdp.drivepathid)" "Planning time: 0.256 ms" "Execution time: 530.261 ms"
Any Suggestion ?