From: | bricklen <bricklen(at)gmail(dot)com> |
---|---|
To: | Vitalii Tymchyshyn <tivv00(at)gmail(dot)com> |
Cc: | Merlin Moncure <mmoncure(at)gmail(dot)com>, "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org> |
Subject: | Re: array_except -- Find elements that are not common to both arrays |
Date: | 2011-09-30 14:28:36 |
Message-ID: | CAGrpgQ9bno_zT=N6eeCVH4pzeTsW7LfGOZt8LkbXX-YBLsmfcA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
On Fri, Sep 30, 2011 at 5:23 AM, Vitalii Tymchyshyn <tivv00(at)gmail(dot)com> wrote:
> Since you are using except and not except all, you are not looking at arrays
> with duplicates.
> For this case next function what the fastest for me:
>
> create or replace function array_except2(anyarray,anyarray) returns
> anyarray as $$
> select ARRAY(
> (
> select r.elements
> from (
> (select 1,unnest($1))
> union all
> (select 2,unnest($2))
> ) as r (arr, elements)
> group by 1
> having min(arr)=max(arr)
> ))
> $$ language sql strict immutable;
Nice! Your version shaved almost a full second off, now 2.5s from 3.4s
it was earlier.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2011-09-30 14:36:50 | Re: Shortcutting too-large offsets? |
Previous Message | Vitalii Tymchyshyn | 2011-09-30 12:23:11 | Re: array_except -- Find elements that are not common to both arrays |