Re: JOIN work somehow strange on simple query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux