Re: First Aggregate Funtion?
От
Merlin Moncure
Тема
Re: First Aggregate Funtion?
Дата
Msg-id
CAHyXU0zWC7BNi4WouFwSVdp=jyj9EzthoWv+rb3QSsw2_f-bFg@mail.gmail.com
Ответ на
Re: First Aggregate Funtion? (sudalai)
Список
Дерево обсуждения
First Aggregate Funtion? Tony Caduto <tony_caduto@amsoftwaredesign.com>
Re: First Aggregate Funtion? Martijn van Oosterhout <kleptog@svana.org>
Re: First Aggregate Funtion? "Mike Rylander" <mrylander@gmail.com>
Re: First Aggregate Funtion? sudalai <sudalait2@gmail.com>
Re: First Aggregate Funtion? Robert Haas <robertmhaas@gmail.com>
Re: First Aggregate Funtion? sudalai <sudalait2@gmail.com>
Re: First Aggregate Funtion? Merlin Moncure <mmoncure@gmail.com>
Re: First Aggregate Funtion? Paul A Jungwirth <pj@illuminatedcomputing.com>
Re: First Aggregate Funtion? Corey Huinker <corey.huinker@gmail.com>
Re: First Aggregate Funtion? Marko Tiikkaja <marko@joh.to>
Re: First Aggregate Funtion? Jim Nasby <Jim.Nasby@BlueTreble.com>
Re: First Aggregate Funtion? Merlin Moncure <mmoncure@gmail.com>
Re: First Aggregate Funtion? Bruno Wolff III <bruno@wolff.to>
On Mon, Jul 20, 2015 at 8:40 AM, sudalai wrote:
>
>>I don't think so, because arrays can contain duplicates.
>
> I just add two element to the array. One for INITCOND value NULL, second
> for first row value.
> So Array size is always 2. So no duplicates.
>
>>rhaas=# select coalesce(first(x.column1), 'wrong') from (values
>>(null), ('correct')) x;
> >coalesce
>>----------
>> wrong
>>(1 row)
> It works correct..
> I didn't said it returns, first non-null value for a column from aggregate
> window.
> I said my implementation returns first row value for a column.
> Here first row element is "null ", hence it returns null.
>
>
> check this....
> db=# select
> db-# coalesce(first(x.column1),'null') as col1 ,
> db-# coalesce(first(x.column2),'null') as col2,
> db-# coalesce(first(x.column3),'null') as col3
> db-# from (values (null,'abc',null), ('correct','wrong','notsure'),
> ('second','second1','second3')) x
> db-# ;
> col1 | col2 | col3
> ------+------+------
> null | abc | null
> (1 row)
>
> Its work correct. It returns first row value for a column.
I was able to get ~45% runtime reduction by simply converting
"two_value_holder" from sql to plpgsql. SQL functions (unlike
pl/pgsql) are parsed and planned every time they are run unless they
are inlined. Our aggregation API unfortunately is a hard fence
against inlining; solving this is a major optimization target IMO.
merlin
В списке pgsql-hackers по дате отправления