From: | Yeb Havinga <yebhavinga(at)gmail(dot)com> |
---|---|
To: | AI Rumman <rummandba(at)gmail(dot)com> |
Cc: | pgsql-performance(at)postgresql(dot)org |
Subject: | Re: Why primary key index are not using in joining? |
Date: | 2010-02-15 11:11:23 |
Message-ID: | 4B792BDB.5090609@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
AI Rumman wrote:
>
> explain analyze
> select *
> from vtiger_crmentity
> inner JOIN vtiger_users
> ON vtiger_users.id <http://vtiger_users.id> =
> vtiger_crmentity.smownerid
> where vtiger_crmentity.deleted = 0 ;
>
> QUERY
> PLAN
>
> ------------------------------------------------------------------------------------------------------------------------------------------------------------
> Hash Join (cost=3665.17..40019.25 rows=640439 width=1603) (actual
> time=115.613..3288.436 rows=638081 loops=1)
> Hash Cond: ("outer".smownerid = "inner".id)
> -> Bitmap Heap Scan on vtiger_crmentity (cost=3646.54..30394.02
> rows=640439 width=258) (actual time=114.763..986.504 rows=638318 loops=1)
> Recheck Cond: (deleted = 0)
> -> Bitmap Index Scan on vtiger_crmentity_deleted_idx
> (cost=0.00..3646.54 rows=640439 width=0) (actual time=107.851..107.851
> rows=638318 loops=1)
> Index Cond: (deleted = 0)
> -> Hash (cost=18.11..18.11 rows=211 width=1345) (actual
> time=0.823..0.823 rows=211 loops=1)
> -> Seq Scan on vtiger_users (cost=0.00..18.11 rows=211
> width=1345) (actual time=0.005..0.496 rows=211 loops=1)
> Total runtime: 3869.022 ms
>
> Sequential index is occuring on vtiger_users table while it has
> primary key index on id.
> Could anyone please tell me why?
>
From the list of indexes you also supplied it seems to me you very much
want index scanning, the reason being that 4secs is too slow? The
seqscan is not the reason for that - the main reason is that you process
almost all rows of the crmentity table. I bet that if you add a LIMIT,
or adding a clause that selects only for a specific vtiger_user, the
plan looks different on the access to the crmentity table as well as the
kind of join, however if your application really needs to process the
600k rows, I'm not sure if it can get any faster than that. Perhaps it
would help a bit to shorten the SELECT * to only the attributes you
really need.
Regards,
Yeb Havinga
From | Date | Subject | |
---|---|---|---|
Next Message | Kevin Grittner | 2010-02-15 14:19:19 | Re: Almost infinite query -> Different Query Plan when changing where clause value |
Previous Message | lionel duboeuf | 2010-02-15 09:52:49 | Re: Almost infinite query -> Different Query Plan when changing where clause value |