Re: Why is this query running slowly?

From: John R Pierce <pierce(at)hogranch(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Why is this query running slowly?
Date: 2011-09-15 08:14:36
Message-ID: 4E71B3EC.9080701@hogranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 09/15/11 12:53 AM, Yang Zhang wrote:
> mydb=# explain select user_id from den where user_id not in (select
> duid from user_mappings) and timestamp between '2009-04-01' and
> '2010-04-01';
>
> QUERY PLAN
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> Seq Scan on den (cost=711.58..66062724212.74 rows=22634720 width=4)
> Filter: (("timestamp">= '2009-04-01 00:00:00'::timestamp without
> time zone) AND ("timestamp"<= '2010-04-01 00:00:00'::timestamp
> without time zone) AND (NOT (SubPlan 1)))
> SubPlan 1
> -> Materialize (cost=711.58..1223.38 rows=36780 width=4)
> -> Seq Scan on user_mappings (cost=0.00..530.80 rows=36780 width=4)
>
> user_mappings is fairly small:

so you have to check if every one of the 22 million rows of 'den' in
that time range and is not one of the 36000 rows of user_mappings?

how many rows are in that time range?

are timestamp and duid indexed? have the tables been analyzed any time
recently?

--
john r pierce N 37, W 122
santa cruz ca mid-left coast

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2011-09-15 08:18:32 Re: Problem with the 9.1 one-click installer Windows7 64bit
Previous Message Yang Zhang 2011-09-15 08:07:11 Re: Why is this query running slowly?