Skip to main content
added [query-optimization] to 86 questions - Shog9 (Id=1924)
Link
Tweeted twitter.com/#!/StackDBAs/status/530049294925963264
added 835 characters in body
Source Link
kolistivra
  • 231
  • 3
  • 6

Update 2:

Tried creating an index on time column, and ran the second query, still no luck.

foodb=# CREATE INDEX ix_datapoints_time ON datapoints(time);
CREATE INDEX
foodb=# EXPLAIN ANALYZE SELECT tag, min(time) as minTime, max(time) as maxTime FROM datapoints GROUP BY tag;
                                                              QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------
 HashAggregate  (cost=5914895.96..5915147.35 rows=25139 width=114) (actual time=91870.389..91931.164 rows=218367 loops=1)
   ->  Seq Scan on datapoints  (cost=0.00..4694438.12 rows=162727712 width=114) (actual time=0.013..24101.108 rows=162727709 loops=1)
 Total runtime: 91944.348 ms
(3 rows)

Update 2:

Tried creating an index on time column, and ran the second query, still no luck.

foodb=# CREATE INDEX ix_datapoints_time ON datapoints(time);
CREATE INDEX
foodb=# EXPLAIN ANALYZE SELECT tag, min(time) as minTime, max(time) as maxTime FROM datapoints GROUP BY tag;
                                                              QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------
 HashAggregate  (cost=5914895.96..5915147.35 rows=25139 width=114) (actual time=91870.389..91931.164 rows=218367 loops=1)
   ->  Seq Scan on datapoints  (cost=0.00..4694438.12 rows=162727712 width=114) (actual time=0.013..24101.108 rows=162727709 loops=1)
 Total runtime: 91944.348 ms
(3 rows)
Tried turning of sequential scan
Source Link
kolistivra
  • 231
  • 3
  • 6

Update 1:

Turning off sequential scan doesn't seem to help much.

foodb=# set enable_seqscan = off;
SET
foodb=# EXPLAIN ANALYZE SELECT DISTINCT tag FROM datapoints;
                                                                              QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Unique  (cost=0.82..591769146.07 rows=25139 width=106) (actual time=0.037..81086.671 rows=218367 loops=1)
   ->  Index Only Scan using ix_datapoints_tag on datapoints  (cost=0.82..591375490.15 rows=157462368 width=106) (actual time=0.033..54393.956 rows=162727709 loops=1)
         Heap Fetches: 162727709
 Total runtime: 81104.455 ms
(4 rows)

Update 1:

Turning off sequential scan doesn't seem to help much.

foodb=# set enable_seqscan = off;
SET
foodb=# EXPLAIN ANALYZE SELECT DISTINCT tag FROM datapoints;
                                                                              QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Unique  (cost=0.82..591769146.07 rows=25139 width=106) (actual time=0.037..81086.671 rows=218367 loops=1)
   ->  Index Only Scan using ix_datapoints_tag on datapoints  (cost=0.82..591375490.15 rows=157462368 width=106) (actual time=0.033..54393.956 rows=162727709 loops=1)
         Heap Fetches: 162727709
 Total runtime: 81104.455 ms
(4 rows)
Source Link
kolistivra
  • 231
  • 3
  • 6
Loading