explain analyze select count(*) as y0_ from RPI_SPONSER_REPORT this_ where this_.session_UID=1 and this_.ORIGIN_DATE_TIME between '2014-06-01 00:00:00'::timestamp without time zone and '2014-06-01 06:11:56.33'::timestamp without time zone and (ST_within (this_.SPONSER_LOCATION,'010300000001000000050000006787D1E89889F5BFFBA6BE01196EE53F1AF703F9588EF5BF6D9AC3A07D5FE53F0C2792E0B193F5BF6D9AC3A07D5FE53FC096C4F07198F5BFFBA6BE01196EE53F6787D1E89889F5BFFBA6BE01196EE53F') or ST_touches (this_.SPONSER_LOCATION,'010300000001000000050000006787D1E89889F5BFFBA6BE01196EE53F1AF703F9588EF5BF6D9AC3A07D5FE53F0C2792E0B193F5BF6D9AC3A07D5FE53FC096C4F07198F5BFFBA6BE01196EE53F6787D1E89889F5BFFBA6BE01196EE53F')); QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=9.79..9.82 rows=1 width=0) (actual time=63912.612..63912.613 rows=1 loops=1) -> Append (cost=0.00..9.78 rows=3 width=0) (actual time=63912.606..63912.606 rows=0 loops=1) -> Seq Scan on rpi_sponser_report this_ (cost=0.00..0.00 rows=1 width=0) (actual time=0.001..0.001 rows=0 loops=1) Filter: ((origin_date_time >= '2014-06-01 00:00:00'::timestamp without time zone) AND (origin_date_time <= '2014-06-01 06:11:56.33'::timestamp without time zone) AND (sponser_location && '010300000001000000050000006787D1E89889F5BFFBA6BE01196EE53F1AF703F9588EF5BF6D9AC3A07D5FE53F0C2792E0B193F5BF6D9AC3A07D5FE53FC096C4F07198F5BFFBA6BE01196EE53F6787D1E89889F5BFFBA6BE01196EE53F'::geometry) AND (session_uid = 1) AND (_st_contains('010300000001000000050000006787D1E89889F5BFFBA6BE01196EE53F1AF703F9588EF5BF6D9AC3A07D5FE53F0C2792E0B193F5BF6D9AC3A07D5FE53FC096C4F07198F5BFFBA6BE01196EE53F6787D1E89889F5BFFBA6BE01196EE53F'::geometry, sponser_location) OR _st_touches(sponser_location, '010300000001000000050000006787D1E89889F5BFFBA6BE01196EE53F1AF703F9588EF5BF6D9AC3A07D5FE53F0C2792E0B193F5BF6D9AC3A07D5FE53FC096C4F07198F5BFFBA6BE01196EE53F6787D1E89889F5BFFBA6BE01196EE53F'::geometry))) -> Seq Scan on rpi_sponser_report_overflow this__1 (cost=0.00..72.40 rows=1 width=0) (actual time=0.000..0.000 rows=0 loops=1) Filter: ((origin_date_time >= '2014-06-01 00:00:00'::timestamp without time zone) AND (origin_date_time <= '2014-06-01 06:11:56.33'::timestamp without time zone) AND (sponser_location && '010300000001000000050000006787D1E89889F5BFFBA6BE01196EE53F1AF703F9588EF5BF6D9AC3A07D5FE53F0C2792E0B193F5BF6D9AC3A07D5FE53FC096C4F07198F5BFFBA6BE01196EE53F6787D1E89889F5BFFBA6BE01196EE53F'::geometry) AND (session_uid = 1) AND (_st_contains('010300000001000000050000006787D1E89889F5BFFBA6BE01196EE53F1AF703F9588EF5BF6D9AC3A07D5FE53F0C2792E0B193F5BF6D9AC3A07D5FE53FC096C4F07198F5BFFBA6BE01196EE53F6787D1E89889F5BFFBA6BE01196EE53F'::geometry, sponser_location) OR _st_touches(sponser_location, '010300000001000000050000006787D1E89889F5BFFBA6BE01196EE53F1AF703F9588EF5BF6D9AC3A07D5FE53F0C2792E0B193F5BF6D9AC3A07D5FE53FC096C4F07198F5BFFBA6BE01196EE53F6787D1E89889F5BFFBA6BE01196EE53F'::geometry))) -> Index Scan using sidx_sponser_report_y2014m06 on rpi_sponser_report_y2014m06 this__2 (cost=0.55..5.09 rows=1 width=0) (actual time=63912.525..63912.525 rows=0 loops=1) Index Cond: (sponser_location && '010300000001000000050000006787D1E89889F5BFFBA6BE01196EE53F1AF703F9588EF5BF6D9AC3A07D5FE53F0C2792E0B193F5BF6D9AC3A07D5FE53FC096C4F07198F5BFFBA6BE01196EE53F6787D1E89889F5BFFBA6BE01196EE53F'::geometry) Filter: ((origin_date_time >= '2014-06-01 00:00:00'::timestamp without time zone) AND (origin_date_time <= '2014-06-01 06:11:56.33'::timestamp without time zone) AND (session_uid = 1) AND (_st_contains('010300000001000000050000006787D1E89889F5BFFBA6BE01196EE53F1AF703F9588EF5BF6D9AC3A07D5FE53F0C2792E0B193F5BF6D9AC3A07D5FE53FC096C4F07198F5BFFBA6BE01196EE53F6787D1E89889F5BFFBA6BE01196EE53F'::geometry, sponser_location) OR _st_touches (sponser_location, '010300000001000000050000006787D1E89889F5BFFBA6BE01196EE53F1AF703F9588EF5BF6D9AC3A07D5FE53F0C2792E0B193F5BF6D9AC3A07D5FE53FC096C4F07198F5BFFBA6BE01196EE53F6787D1E89889F5BFFBA6BE01196EE53F'::geometry))) Rows Removed by Filter: 3849011 Total runtime: 63913.610 ms (12 rows) Time: 73490.262 ms -- Then I disable the spatial index update pg_index set indisvalid = false where indexrelid = 'sidx_sponser_report_y2014m06'::regclass; Indexes: "rpi_sponser_report_y2014m06_pkey" PRIMARY KEY, btree (sponser_report_uid), tablespace "sponser_data_y2014" "idx_sessiondatetime_rpi_sponser_report_y2014m06" btree (session_uid, origin_date_time), tablespace "sponser_data_y2014" "idx_uuid_rpi_sponser_report_y2014m06" btree (sponser_report_uuid), tablespace "sponser_data_y2014" "sidx_sponser_report_y2014m06" gist (sponser_location) INVALID, tablespace "sponser_data_y2014" QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=33612.11..33612.14 rows=1 width=0) (actual time=1124.165..1124.165 rows=1 loops=1) -> Append (cost=0.00..33612.10 rows=3 width=0) (actual time=1124.161..1124.161 rows=0 loops=1) -> Seq Scan on rpi_sponser_report this_ (cost=0.00..0.00 rows=1 width=0) (actual time=0.002..0.002 rows=0 loops=1) Filter: ((origin_date_time >= '2014-06-01 00:00:00'::timestamp without time zone) AND (origin_date_time <= '2014-06-01 06:11:56.33'::timestamp without time zone) AND (sponser_location && '010300000001000000050000006787D1E89889F5BFFBA6BE01196EE53F1AF703F9588EF5BF6D9AC3A07D5FE53F0C2792E0B193F5BF6D9AC3A07D5FE53FC096C4F07198F5BFFBA6BE01196EE53F6787D1E89889F5BFFBA6BE01196EE53F'::geometry) AND (session_uid = 1) AND (_st_contains('010300000001000000050000006787D1E89889F5BFFBA6BE01196EE53F1AF703F9588EF5BF6D9AC3A07D5FE53F0C2792E0B193F5BF6D9AC3A07D5FE53FC096C4F07198F5BFFBA6BE01196EE53F6787D1E89889F5BFFBA6BE01196EE53F'::geometry, sponser_location) OR _st_touches(sponser_location, '010300000001000000050000006787D1E89889F5BFFBA6BE01196EE53F1AF703F9588EF5BF6D9AC3A07D5FE53F0C2792E0B193F5BF6D9AC3A07D5FE53FC096C4F07198F5BFFBA6BE01196EE53F6787D1E89889F5BFFBA6BE01196EE53F'::geometry))) -> Seq Scan on rpi_sponser_report_overflow this__1 (cost=0.00..72.40 rows=1 width=0) (actual time=0.000..0.000 rows=0 loops=1) Filter: ((origin_date_time >= '2014-06-01 00:00:00'::timestamp without time zone) AND (origin_date_time <= '2014-06-01 06:11:56.33'::timestamp without time zone) AND (sponser_location && '010300000001000000050000006787D1E89889F5BFFBA6BE01196EE53F1AF703F9588EF5BF6D9AC3A07D5FE53F0C2792E0B193F5BF6D9AC3A07D5FE53FC096C4F07198F5BFFBA6BE01196EE53F6787D1E89889F5BFFBA6BE01196EE53F'::geometry) AND (session_uid = 1) AND (_st_contains('010300000001000000050000006787D1E89889F5BFFBA6BE01196EE53F1AF703F9588EF5BF6D9AC3A07D5FE53F0C2792E0B193F5BF6D9AC3A07D5FE53FC096C4F07198F5BFFBA6BE01196EE53F6787D1E89889F5BFFBA6BE01196EE53F'::geometry, sponser_location) OR _st_touches(sponser_location, '010300000001000000050000006787D1E89889F5BFFBA6BE01196EE53F1AF703F9588EF5BF6D9AC3A07D5FE53F0C2792E0B193F5BF6D9AC3A07D5FE53FC096C4F07198F5BFFBA6BE01196EE53F6787D1E89889F5BFFBA6BE01196EE53F'::geometry))) -> Index Scan using idx_sessiondatetime_rpi_sponser_report_y2014m06 on rpi_sponser_report_y2014m06 this__2 (cost=0.57..33607.41 rows=1 width=0) (actual time=1124.144..1124.144 rows=0 loops=1) Index Cond: ((session_uid = 1) AND (origin_date_time >= '2014-06-01 00:00:00'::timestamp without time zone) AND (origin_date_time <= '2014-06-01 06:11:56.33'::timestamp without time zone)) Filter: ((sponser_location && '010300000001000000050000006787D1E89889F5BFFBA6BE01196EE53F1AF703F9588EF5BF6D9AC3A07D5FE53F0C2792E0B193F5BF6D9AC3A07D5FE53FC096C4F07198F5BFFBA6BE01196EE53F6787D1E89889F5BFFBA6BE01196EE53F'::geometry) AND (_st_contains('010300000001000000050000006787D1E89889F5BFFBA6BE01196EE53F1AF703F9588EF5BF6D9AC3A07D5FE53F0C2792E0B193F5BF6D9AC3A07D5FE53FC096C4F07198F5BFFBA6BE01196EE53F6787D1E89889F5BFFBA6BE01196EE53F'::geometry, sponser_location) OR _st_touches(sponser_location, '010300000001000000050000006787D1E89889F5BFFBA6BE01196EE53F1AF703F9588EF5BF6D9AC3A07D5FE53F0C2792E0B193F5BF6D9AC3A07D5FE53FC096C4F07198F5BFFBA6BE01196EE53F6787D1E89889F5BFFBA6BE01196EE53F'::geometry))) Rows Removed by Filter: 1128161 Total runtime: 1124.355 ms (11 rows)