Re: [HACKERS] Question about sorting internals

2013-12-11 Thread Tom Lane
hubert depesz lubaczewski writes: > There are two simple queries: ... > They differ only in order of queries in union all part. > The thing is that they return the same result. Why isn't one of them returning > "2005" for 6th "miesiac"? With such a small amount of data, you're getting an in-memor

Re: [HACKERS] Question about sorting internals

2013-12-11 Thread Robert Haas
On Wed, Dec 11, 2013 at 4:56 AM, hubert depesz lubaczewski wrote: > before I'll go any further - this is only thought-experiment. I do not > plan to use such queries in real-life applications. I was just presented > with a question that I can't answer in any logical way. > > There are two simple q

Re: [HACKERS] Question about sorting internals

2013-12-11 Thread hubert depesz lubaczewski
On Wed, Dec 11, 2013 at 03:34:38PM +0530, Ashutosh Bapat wrote: > Hi deepesz, > You might want to see their EXPLAIN VERBOSE outputs. Having one of them > (2004 one) lesser number of rows, might be getting picked up as first > relation being union and thus ends up having it's rows before the second

Re: [HACKERS] Question about sorting internals

2013-12-11 Thread Ashutosh Bapat
Hi deepesz, You might want to see their EXPLAIN VERBOSE outputs. Having one of them (2004 one) lesser number of rows, might be getting picked up as first relation being union and thus ends up having it's rows before the second one. Explain output would make it more clear. Also, try having same numb

[HACKERS] Question about sorting internals

2013-12-11 Thread hubert depesz lubaczewski
Hi, before I'll go any further - this is only thought-experiment. I do not plan to use such queries in real-life applications. I was just presented with a question that I can't answer in any logical way. There are two simple queries: #v+ with rok2005 (miesiac,wynik) as (VALUES (1,1),(2,2) ,