Re: When are index scans used over seq scans?

From: Richard van den Berg <richard(dot)vandenberg(at)trust-factory(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-perform <pgsql-performance(at)postgresql(dot)org>
Subject: Re: When are index scans used over seq scans?
Date: 2005-04-21 08:15:40
Message-ID: 4267612C.10803@trust-factory.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Tom Lane wrote:
> The explain shows no such thing. What is the *actual* runtime of
> each plan per EXPLAIN ANALYZE, please?

Ok, it took 3.5 hours to complete. :-/

This is with the default cpu_tuple_cost = 0.01:

Nested Loop (cost=252.80..233010147.16 rows=1035480320 width=98)
(actual time=0.369..12672213.137 rows=6171334 loops=1)
Join Filter: (("outer".starttimetrunc <= "inner".ts) AND
("outer".finishtimetrunc >= "inner".ts))
-> Seq Scan on sessions us (cost=0.00..26822.36 rows=924536
width=106) (actual time=0.039..5447.349 rows=924536 loops=1)
-> Materialize (cost=252.80..353.60 rows=10080 width=8) (actual
time=0.000..2.770 rows=10080 loops=924536)
-> Seq Scan on duration du (cost=0.00..252.80 rows=10080
width=8) (actual time=0.019..13.397 rows=10080 loops=1)
Total runtime: 12674486.670 ms

Once again with cpu_tuple_cost = 0.1:

Nested Loop (cost=0.00..667684584.42 rows=1035480320 width=98) (actual
time=42.892..39877.928 rows=6171334 loops=1)
-> Seq Scan on sessions us (cost=0.00..110030.60 rows=924536
width=106) (actual time=0.020..917.803 rows=924536 loops=1)
-> Index Scan using ix_du_ts on duration du (cost=0.00..604.46
rows=1120 width=8) (actual time=0.004..0.011 rows=7 loops=924536)
Index Cond: (("outer".starttimetrunc <= du.ts) AND
("outer".finishtimetrunc >= du.ts))
Total runtime: 41635.468 ms
(5 rows)

--
Richard van den Berg, CISSP
-------------------------------------------
Trust Factory B.V. | www.dna-portal.net
Bazarstraat 44a | www.trust-factory.com
2518AK The Hague | Phone: +31 70 3620684
The Netherlands | Fax : +31 70 3603009
-------------------------------------------

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message David Roussel 2005-04-21 10:13:10 How can an index be larger than a table
Previous Message William Yu 2005-04-21 05:02:42 Re: How to improve db performance with $7K?