Re: efficient math vector operations on arrays

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
Cc: Jony Cohen <jony(dot)cohenjo(at)gmail(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Marcus Engene <mengpg2(at)engene(dot)se>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: efficient math vector operations on arrays
Date: 2015-12-30 00:50:04
Message-ID: 17134.1451436604@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com> writes:
> BTW, if you want to simply apply a function to all elements in an array
> there is an internal C function array_map that can do it. There's no SQL
> interface to it, but it shouldn't be hard to add one.

That wouldn't be useful for the example given originally, since it
iterates over just one array not two arrays in parallel. But you could
imagine writing something similar that would iterate over two arrays and
call a two-argument function.

Whether it's worth a SQL interface is debatable though. Whatever
efficiency you might gain from using this would probably be eaten by the
overhead of calling a SQL or PL function for each pair of array elements.
You'd probably end up in the same ballpark performance-wise as the UNNEST
solution given earlier.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Hiroyuki Sato 2015-12-30 00:56:18 Re: grep -f keyword data query
Previous Message Tom Lane 2015-12-30 00:35:13 Re: cannot get stable function to use index