Re: Query across a date range

From: David Jaquay <djaquay(at)gmail(dot)com>
To: josh(at)agliodbs(dot)com
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Query across a date range
Date: 2005-01-07 20:04:28
Message-ID: ad4aa5a805010712047409fce9@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

'explain analyze' output is below. I have done analyze recently, and
am using pg 7.4.2 on SuSE 9.1. I'd be curious to know how to "a
nestloop indexscan" to try it out.

Thanks,
Dave

mydb=> explain analyze select * from line_items t, sales_tickets s
where writtenDate >= '12/01/2002' and writtenDate <= '12/31/2002' and
t.ticketid = s.ticketId and s.storeId = 1;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------
Hash Join (cost=93865.46..114054.74 rows=19898 width=28) (actual
time=25419.088..32140.217 rows=23914 loops=1)
Hash Cond: ("outer".ticketid = "inner".ticketid)
-> Index Scan using line_items_written on line_items t
(cost=0.00..3823.11 rows=158757 width=16) (actual
time=100.621..3354.818 rows=169770 loops=1)
Index Cond: ((writtendate >= '2002-12-01'::date) AND
(writtendate <= '2002-12-31'::date))
-> Hash (cost=89543.50..89543.50 rows=626783 width=12) (actual
time=22844.146..22844.146 rows=0 loops=1)
-> Seq Scan on sales_tickets s (cost=0.00..89543.50
rows=626783 width=12) (actual time=38.017..19387.447 rows=713846
loops=1)
Filter: (storeid = 1)
Total runtime: 32164.948 ms
(8 rows)

On Fri, 7 Jan 2005 11:35:11 -0800, Josh Berkus <josh(at)agliodbs(dot)com> wrote:
> Can you run EXPLAIN ANALYZE instead of just EXPLAIN? That will show you the
> discrepancy between estimated and actual costs, and probably show you what
> needs fixing.

Also, Tom Lane wrote:
> Could we see EXPLAIN ANALYZE, not just EXPLAIN, results?
>
> Also, have you ANALYZEd lately? If the estimated row counts are at all
> accurate, I doubt that forcing a nestloop indexscan would improve the
> situation.
>
> Also, what PG version is this?

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Josh Berkus 2005-01-07 20:15:27 Re: Query across a date range
Previous Message Josh Berkus 2005-01-07 19:35:11 Re: Query across a date range