Re: hash join vs nested loop join

Поиск
Список
Период
Сортировка
От Kevin Grittner
Тема Re: hash join vs nested loop join
Дата
Msg-id 20121219131637.14740@gmx.com
обсуждение исходный текст
Ответ на hash join vs nested loop join  (Huan Ruan <leohuanruan@gmail.com>)
Ответы Re: hash join vs nested loop join  (Huan Ruan <huan.ruan.it@gmail.com>)
Список pgsql-performance
"Huan Ruan" <huan.ruan.it@gmail.com> wrote:

> explain (analyze, buffers)
> SELECT
>  *
> FROM IM_Match_Table smalltable
>  inner join invtran bigtable on bigtable.invtranref = smalltable.invtranref

Well, one table or the other will need to be read in full, and you
would normally want that one to be the small table. When there is
no ORDER BY clause, the fastest way to do that will normally be a
seqscan. So that part of the query is as it should be. The only
question is whether the access to the big table is using the
fastest technique.

If you want to see what the planner's second choice would have
been, you could run:

SET enable_indexscan = off;

on a connection and try the explain again. If you don't like that
one, you might be able to disable another node type and see what
you get. If one of the other alternatives is faster, that would
suggest that adjustments are needed to the costing factors;
otherwise, it just takes that long to read hundreds of thousands of
rows in one table and look for related data for each of them in
another table.

> "Nested Loop (cost=0.00..341698.92 rows=48261 width=171) (actual
> time=0.042..567.980 rows=48257 loops=1)"

Frankly, at 12 microseconds per matched pair of rows, I think
you're doing OK.

-Kevin


В списке pgsql-performance по дате отправления:

Предыдущее
От: Huan Ruan
Дата:
Сообщение: Re: hash join vs nested loop join
Следующее
От: Igor Neyman
Дата:
Сообщение: Re: How can i find out top high load sql queries in PostgreSQL.