Re: GroupAggregate and Integer Arrays

From: Marc Mamin <M(dot)Mamin(at)intershop(dot)de>
To: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>, David Osborne <david(at)qcode(dot)co(dot)uk>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: GroupAggregate and Integer Arrays
Date: 2015-10-24 20:23:18
Message-ID: B6F6FD62F2624C4C9916AC0175D56D884209D6B8@jenmbs01.ad.intershop.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

> CREATE OR REPLACE FUNCTION array_add(int[],int[]) RETURNS int[] AS $$
> -- Add two arrays.
> select
> ARRAY (
> SELECT coalesce($1[i],0) + coalesce($2[i],0)
> FROM (
> select generate_series(least(array_lower($1, 1),array_lower($2,
> 1)), greatest(array_upper($1, 1),array_upper($2, 1)), 1) AS i
> ) sub
> GROUP BY i
> ORDER BY i
> );
> $$ LANGUAGE sql STRICT IMMUTABLE;

it seems that both the GROUP and ORDER BY are superfluous and adding some cycles.

regards,

Marc Mamin

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Merlin Moncure 2015-10-26 15:03:33 Re: Recursive query performance issue
Previous Message Jeff Janes 2015-10-24 19:27:05 Re: GroupAggregate and Integer Arrays