Re: JOIN work somehow strange on simple query

From: Anton <anton200(at)gmail(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: JOIN work somehow strange on simple query
Date: 2006-12-05 09:38:54
Message-ID: 8cac8dd0612050138t4920d8a8tb2de52da64e8abd9@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-performance

> Hi. I have a performance problem with this simple query:
>
> SELECT collect_time FROM n_traffic JOIN n_logins USING (login_id)
> WHERE n_logins.account_id = '1655' ORDER BY collect_time LIMIT 1;

I must add that is occurs when there is no rows in n_traffic for these
login_id's. Where there is at least one (example, login_id='411'
belongs to account_id='1655') query goes fast:

=# INSERT INTO n_traffic VALUES ('411', '1', '2006-09-23 12:23:05', '0', '0');

=# explain analyze SELECT collect_time FROM n_traffic JOIN n_logins
USING (login_id) WHERE n_logins.account_id= '1655' ORDER BY
collect_time LIMIT 1;
------------------------------------
Limit (cost=0.00..2025.76 rows=1 width=8) (actual time=0.070..0.072
rows=1 loops=1)
-> Nested Loop (cost=0.00..913617.15 rows=451 width=8) (actual
time=0.065..0.065 rows=1 loops=1)
-> Index Scan using n_traffic_collect_time_login_id on
n_traffic (cost=0.00..10418.19 rows=285290 width=12) (actual
time=0.026..0.026 rows=1 loops=1)
-> Index Scan using n_logins_pkey on n_logins
(cost=0.00..3.15 rows=1 width=4) (actual time=0.026..0.026 rows=1
loops=1)
Index Cond: ("outer".login_id = n_logins.login_id)
Filter: (account_id = 1655)
Total runtime: 0.322 ms
(7 rows)

--
engineer

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Goodenough 2006-12-05 10:18:21 How to speed up Exclusive Locking
Previous Message Alban Hertroys 2006-12-05 09:31:43 Re: PG Admin

Browse pgsql-performance by date

  From Date Subject
Next Message Sven Geisler 2006-12-05 09:57:11 Re: Hardware advice
Previous Message Anton 2006-12-05 09:05:35 JOIN work somehow strange on simple query