Re: Weird index or sort behaviour

От: Matthew Wakeling
Тема: Re: Weird index or sort behaviour
Дата: ,
Msg-id: alpine.DEB.2.00.0908181721320.19472@aragorn.flymine.org
(см: обсуждение, исходный текст)
Ответ на: Re: Weird index or sort behaviour  (Tom Lane)
Ответы: Re: Weird index or sort behaviour  (Tom Lane)
Список: pgsql-performance

Скрыть дерево обсуждения

Weird index or sort behaviour  (Matthew Wakeling, )
 Re: Weird index or sort behaviour  (Tom Lane, )
  Re: Weird index or sort behaviour  (Matthew Wakeling, )
   Re: Weird index or sort behaviour  (Tom Lane, )
    Re: Weird index or sort behaviour  (Tom Lane, )
     Re: Weird index or sort behaviour  (Greg Stark, )
      Re: Weird index or sort behaviour  (Tom Lane, )
       Re: Weird index or sort behaviour  (Matthew Wakeling, )
        Re: Weird index or sort behaviour  (Tom Lane, )
         Re: Weird index or sort behaviour  (Matthew Wakeling, )
          Re: Weird index or sort behaviour  (Tom Lane, )
           Re: Weird index or sort behaviour  (Matthew Wakeling, )

On Tue, 18 Aug 2009, Tom Lane wrote:
> Matthew Wakeling <> writes:
>> I'm seeing some interesting behaviour. I'm executing a query where I
>> perform a merge join between two copies of the same table, completely
>> symmetrically, and the two sides of the merge are sourced differently.
>
> This is not as surprising as you think.  A mergejoin is *not*
> symmetrical between its two inputs: the inner side is subject to being
> partially rewound and rescanned when the outer side is advanced to a new
> row with the same merge key.  This means there is a premium on cheap
> rescan for the inner side that doesn't exist for the outer ... and a
> sort node is cheaper to rescan than a generic indexscan.

Very clever. Yes, that is what is happening. I'm surprised that the system
doesn't buffer the inner side to avoid having to rescan each time, but
then I guess you would have problems if the buffer grew larger than
memory.

> It's impossible to tell from the data you provided whether the planner
> was correct to pick a sort over an indexscan for the inner side, but the
> fact that it did so is not prima facie evidence of a bug.  You could
> force choice of the other plan via enable_sort = off and then compare
> estimated and actual runtimes to see if the planner got it right.

Yes, it does get an almost unmeasureable amount slower if I force sorts
off and nested loop (its next choice) off.

Matthew

--
 $ rm core
 Segmentation Fault (core dumped)


В списке pgsql-performance по дате сообщения:

От: Scott Marlowe
Дата:
Сообщение: Re: number of rows estimation for bit-AND operation
От: Slava Moudry
Дата:
Сообщение: Re: number of rows estimation for bit-AND operation