proposal: searching in array function - array_position

Started by Pavel Stehuleabout 11 years ago62 messageshackers
Jump to latest
#1Pavel Stehule
pavel.stehule@gmail.com

Hi

I am proposing a simple function, that returns a position of element in
array.

FUNCTION array_position(anyarray, anyelement) RETURNS int

Implementation is simple (plpgsql code)

CREATE OR REPLACE FUNCTION array_position(anyarray, anyelement)
RETURNS int AS $$
DECLARE i int := 0;
BEGIN
FOREACH a IN ARRAY $1
LOOP
IF a = $1 THEN
RETURN i;
END IF;
i := i + 1;
END LOOP;
RETURN NULL;
END;
$$ LANGUAGE plpgsql IMMUTABLE STRICT;

A possible benefits:

1. speed in plpgsql applications
2. reduced length of SQL functions

Ideas, comments, notices?

Regards

Pavel

#2Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Pavel Stehule (#1)
Re: proposal: searching in array function - array_position

On 1/16/15 3:39 AM, Pavel Stehule wrote:

I am proposing a simple function, that returns a position of element in array.

Yes please!

FUNCTION array_position(anyarray, anyelement) RETURNS int

That won't work on a multi-dimensional array. Ideally it needs to accept a slice or an element and return the specifier for the slice.

This wouldn't be so bad if we had an easier way to extract subsets of an array, but even that is really ugly because whatever you extract keeps the original number of dimensions.

Implementation is simple (plpgsql code)

This would actually be written in C though, yes? Otherwise it's not really any better than just doing an extension...
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Pavel Stehule
pavel.stehule@gmail.com
In reply to: Jim Nasby (#2)
Re: proposal: searching in array function - array_position

2015-01-16 17:57 GMT+01:00 Jim Nasby <Jim.Nasby@bluetreble.com>:

On 1/16/15 3:39 AM, Pavel Stehule wrote:

I am proposing a simple function, that returns a position of element in
array.

Yes please!

FUNCTION array_position(anyarray, anyelement) RETURNS int

That won't work on a multi-dimensional array. Ideally it needs to accept a
slice or an element and return the specifier for the slice.

It is question, what is a result - probably, there can be a
multidimensional variant, where result will be a array

array_position([1,2,3],2) --> 2
array_position([[1,2],[2,3],[3,4]], [2,3]) --> 2 /* 2nd parameter should to
have N-1 dimension of first parameter */
array_position_md([1,2,3],2) --> [2]
array_position_md([[1,2],[2,3],[3,4]], 2) --> [2,1]

another question is how to solve more than one occurrence on one value -
probably two sets of functions - first returns first occurrence of value,
second returns set of occurrence

This wouldn't be so bad if we had an easier way to extract subsets of an
array, but even that is really ugly because whatever you extract keeps the
original number of dimensions.

Implementation is simple (plpgsql code)

This would actually be written in C though, yes? Otherwise it's not really
any better than just doing an extension...

Sure, I expect a C implementation

Pavel

Show quoted text

--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

#4Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Pavel Stehule (#3)
Re: proposal: searching in array function - array_position

On 1/16/15 11:16 AM, Pavel Stehule wrote:

2015-01-16 17:57 GMT+01:00 Jim Nasby <Jim.Nasby@bluetreble.com <mailto:Jim.Nasby@bluetreble.com>>:

On 1/16/15 3:39 AM, Pavel Stehule wrote:

I am proposing a simple function, that returns a position of element in array.

Yes please!

FUNCTION array_position(anyarray, anyelement) RETURNS int

That won't work on a multi-dimensional array. Ideally it needs to accept a slice or an element and return the specifier for the slice.

It is question, what is a result - probably, there can be a multidimensional variant, where result will be a array

array_position([1,2,3],2) --> 2
array_position([[1,2],[2,3],[3,4]], [2,3]) --> 2 /* 2nd parameter should to have N-1 dimension of first parameter */

The problem with that is you can't actually use '2' to get [2,3] back:

select (array[[1,2,3],[4,5,6],[7,8,9]])[1] IS NULL;
?column?
----------
t
(1 row)

I think the bigger problem here is we need something better than slices for handling subsets of arrays. Even if the function returned [2:2] it's still going to behave differently than it will in the non-array case because you won't be getting the expected number of dimensions back. :(

array_position_md([1,2,3],2) --> [2]
array_position_md([[1,2],[2,3],[3,4]], 2) --> [2,1]

another question is how to solve more than one occurrence on one value - probably two sets of functions - first returns first occurrence of value, second returns set of occurrence

Gee, if only way had some way to return multiple elements of something... ;P

In other words, I think all of these should actually return an array of positions. I think it's OK for someone that only cares about the first instance to just do [1].
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Pavel Stehule
pavel.stehule@gmail.com
In reply to: Jim Nasby (#4)
Re: proposal: searching in array function - array_position

2015-01-16 18:37 GMT+01:00 Jim Nasby <Jim.Nasby@bluetreble.com>:

On 1/16/15 11:16 AM, Pavel Stehule wrote:

2015-01-16 17:57 GMT+01:00 Jim Nasby <Jim.Nasby@bluetreble.com <mailto:
Jim.Nasby@bluetreble.com>>:

On 1/16/15 3:39 AM, Pavel Stehule wrote:

I am proposing a simple function, that returns a position of
element in array.

Yes please!

FUNCTION array_position(anyarray, anyelement) RETURNS int

That won't work on a multi-dimensional array. Ideally it needs to
accept a slice or an element and return the specifier for the slice.

It is question, what is a result - probably, there can be a
multidimensional variant, where result will be a array

array_position([1,2,3],2) --> 2
array_position([[1,2],[2,3],[3,4]], [2,3]) --> 2 /* 2nd parameter should
to have N-1 dimension of first parameter */

The problem with that is you can't actually use '2' to get [2,3] back:

select (array[[1,2,3],[4,5,6],[7,8,9]])[1] IS NULL;
?column?
----------
t
(1 row)

yes, but when you are searching a array in array you can use a full slice
selection:

postgres=# select (ARRAY[[1,2],[4,5]])[1][1:2]; -- [1:2] should be a
constant every time in this case -- so it should not be returned
array
---------
{{1,2}}
(1 row)

I think the bigger problem here is we need something better than slices
for handling subsets of arrays. Even if the function returned [2:2] it's
still going to behave differently than it will in the non-array case
because you won't be getting the expected number of dimensions back. :(

you cannot to return a slice and I don't propose it, although we can return
a range type or array of range type - but still we cannot to use range for
a arrays.

array_position_md([1,2,3],2) --> [2]

array_position_md([[1,2],[2,3],[3,4]], 2) --> [2,1]

another question is how to solve more than one occurrence on one value -
probably two sets of functions - first returns first occurrence of value,
second returns set of occurrence

Gee, if only way had some way to return multiple elements of something...
;P

In other words, I think all of these should actually return an array of
positions. I think it's OK for someone that only cares about the first
instance to just do [1].

there can be two functions - "position" - returns first and "positions"
returns all as a array

Show quoted text

--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

#6Pavel Stehule
pavel.stehule@gmail.com
In reply to: Jim Nasby (#2)
Re: proposal: searching in array function - array_position

2015-01-16 17:57 GMT+01:00 Jim Nasby <Jim.Nasby@bluetreble.com>:

On 1/16/15 3:39 AM, Pavel Stehule wrote:

I am proposing a simple function, that returns a position of element in
array.

Yes please!

FUNCTION array_position(anyarray, anyelement) RETURNS int

That won't work on a multi-dimensional array. Ideally it needs to accept a
slice or an element and return the specifier for the slice.

theoretically you can use this function for md arrays too. This function
returns offset, and you can calculate a Nd possition

so maybe better name -- array_offset or some similar

Regards

Pavel

Show quoted text

This wouldn't be so bad if we had an easier way to extract subsets of an
array, but even that is really ugly because whatever you extract keeps the
original number of dimensions.

Implementation is simple (plpgsql code)

This would actually be written in C though, yes? Otherwise it's not really
any better than just doing an extension...
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

#7Pavel Stehule
pavel.stehule@gmail.com
In reply to: Pavel Stehule (#5)
Re: proposal: searching in array function - array_position

Hi

here is a proof concept of array_offset function

possible question:

* used comparation "=" or "IS NOT DISTINCT FROM"

In this initial proof concept I used "IS NOT DISTINCT FROM" operator - but
my opinion is not strong in this question. Both has some advantages and
disadvantages.

Regards

Pavel

2015-01-16 19:12 GMT+01:00 Pavel Stehule <pavel.stehule@gmail.com>:

Show quoted text

2015-01-16 18:37 GMT+01:00 Jim Nasby <Jim.Nasby@bluetreble.com>:

On 1/16/15 11:16 AM, Pavel Stehule wrote:

2015-01-16 17:57 GMT+01:00 Jim Nasby <Jim.Nasby@bluetreble.com <mailto:
Jim.Nasby@bluetreble.com>>:

On 1/16/15 3:39 AM, Pavel Stehule wrote:

I am proposing a simple function, that returns a position of
element in array.

Yes please!

FUNCTION array_position(anyarray, anyelement) RETURNS int

That won't work on a multi-dimensional array. Ideally it needs to
accept a slice or an element and return the specifier for the slice.

It is question, what is a result - probably, there can be a
multidimensional variant, where result will be a array

array_position([1,2,3],2) --> 2
array_position([[1,2],[2,3],[3,4]], [2,3]) --> 2 /* 2nd parameter
should to have N-1 dimension of first parameter */

The problem with that is you can't actually use '2' to get [2,3] back:

select (array[[1,2,3],[4,5,6],[7,8,9]])[1] IS NULL;
?column?
----------
t
(1 row)

yes, but when you are searching a array in array you can use a full slice
selection:

postgres=# select (ARRAY[[1,2],[4,5]])[1][1:2]; -- [1:2] should be a
constant every time in this case -- so it should not be returned
array
---------
{{1,2}}
(1 row)

I think the bigger problem here is we need something better than slices
for handling subsets of arrays. Even if the function returned [2:2] it's
still going to behave differently than it will in the non-array case
because you won't be getting the expected number of dimensions back. :(

you cannot to return a slice and I don't propose it, although we can
return a range type or array of range type - but still we cannot to use
range for a arrays.

array_position_md([1,2,3],2) --> [2]

array_position_md([[1,2],[2,3],[3,4]], 2) --> [2,1]

another question is how to solve more than one occurrence on one value -
probably two sets of functions - first returns first occurrence of value,
second returns set of occurrence

Gee, if only way had some way to return multiple elements of something...
;P

In other words, I think all of these should actually return an array of
positions. I think it's OK for someone that only cares about the first
instance to just do [1].

there can be two functions - "position" - returns first and "positions"
returns all as a array

--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

Attachments:

array_offset-01.patchtext/x-patch; charset=US-ASCII; name=array_offset-01.patchDownload+222-7
#8Pavel Stehule
pavel.stehule@gmail.com
In reply to: Pavel Stehule (#7)
Re: proposal: searching in array function - array_position

Hi

I am sending updated version - it allow third optional argument that
specify where searching should to start. With it is possible repeatably
call this function.

Regards

Pavel

2015-01-17 23:43 GMT+01:00 Pavel Stehule <pavel.stehule@gmail.com>:

Show quoted text

Hi

here is a proof concept of array_offset function

possible question:

* used comparation "=" or "IS NOT DISTINCT FROM"

In this initial proof concept I used "IS NOT DISTINCT FROM" operator - but
my opinion is not strong in this question. Both has some advantages and
disadvantages.

Regards

Pavel

2015-01-16 19:12 GMT+01:00 Pavel Stehule <pavel.stehule@gmail.com>:

2015-01-16 18:37 GMT+01:00 Jim Nasby <Jim.Nasby@bluetreble.com>:

On 1/16/15 11:16 AM, Pavel Stehule wrote:

2015-01-16 17:57 GMT+01:00 Jim Nasby <Jim.Nasby@bluetreble.com <mailto:
Jim.Nasby@bluetreble.com>>:

On 1/16/15 3:39 AM, Pavel Stehule wrote:

I am proposing a simple function, that returns a position of
element in array.

Yes please!

FUNCTION array_position(anyarray, anyelement) RETURNS int

That won't work on a multi-dimensional array. Ideally it needs to
accept a slice or an element and return the specifier for the slice.

It is question, what is a result - probably, there can be a
multidimensional variant, where result will be a array

array_position([1,2,3],2) --> 2
array_position([[1,2],[2,3],[3,4]], [2,3]) --> 2 /* 2nd parameter
should to have N-1 dimension of first parameter */

The problem with that is you can't actually use '2' to get [2,3] back:

select (array[[1,2,3],[4,5,6],[7,8,9]])[1] IS NULL;
?column?
----------
t
(1 row)

yes, but when you are searching a array in array you can use a full slice
selection:

postgres=# select (ARRAY[[1,2],[4,5]])[1][1:2]; -- [1:2] should be a
constant every time in this case -- so it should not be returned
array
---------
{{1,2}}
(1 row)

I think the bigger problem here is we need something better than slices
for handling subsets of arrays. Even if the function returned [2:2] it's
still going to behave differently than it will in the non-array case
because you won't be getting the expected number of dimensions back. :(

you cannot to return a slice and I don't propose it, although we can
return a range type or array of range type - but still we cannot to use
range for a arrays.

array_position_md([1,2,3],2) --> [2]

array_position_md([[1,2],[2,3],[3,4]], 2) --> [2,1]

another question is how to solve more than one occurrence on one value
- probably two sets of functions - first returns first occurrence of value,
second returns set of occurrence

Gee, if only way had some way to return multiple elements of
something... ;P

In other words, I think all of these should actually return an array of
positions. I think it's OK for someone that only cares about the first
instance to just do [1].

there can be two functions - "position" - returns first and "positions"
returns all as a array

--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

Attachments:

array_offset-02.patchtext/x-patch; charset=US-ASCII; name=array_offset-02.patchDownload+295-24
#9Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Pavel Stehule (#8)
Re: proposal: searching in array function - array_position

On 1/20/15 11:12 AM, Pavel Stehule wrote:

I am sending updated version - it allow third optional argument that specify where searching should to start. With it is possible repeatably call this function.

What happened to returning an array of offsets? I think that would be both easier to use than this version as well as performing better.

I see you dropped multi-dimension support, but I think that's fine.
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#10Pavel Stehule
pavel.stehule@gmail.com
In reply to: Jim Nasby (#9)
Re: proposal: searching in array function - array_position

2015-01-20 21:32 GMT+01:00 Jim Nasby <Jim.Nasby@bluetreble.com>:

On 1/20/15 11:12 AM, Pavel Stehule wrote:

I am sending updated version - it allow third optional argument that
specify where searching should to start. With it is possible repeatably
call this function.

What happened to returning an array of offsets? I think that would be both
easier to use than this version as well as performing better.

I have still thinking about this idea. It needs a different function and I
didn't start with this.

Implementation a optional start parameter to array_offset is cheap - and I
am thinking so it can be useful for some use cases.

I see you dropped multi-dimension support, but I think that's fine.

It can be implemented later. There is no any barriers to later
implementation.

Show quoted text

--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

#11Pavel Stehule
pavel.stehule@gmail.com
In reply to: Jim Nasby (#9)
Re: proposal: searching in array function - array_position

Hi

with array_offsets - returns a array of offsets

Regards

Pavel

2015-01-20 21:32 GMT+01:00 Jim Nasby <Jim.Nasby@bluetreble.com>:

Show quoted text

On 1/20/15 11:12 AM, Pavel Stehule wrote:

I am sending updated version - it allow third optional argument that
specify where searching should to start. With it is possible repeatably
call this function.

What happened to returning an array of offsets? I think that would be both
easier to use than this version as well as performing better.

I see you dropped multi-dimension support, but I think that's fine.

--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

Attachments:

array_offset-03.patchtext/x-patch; charset=US-ASCII; name=array_offset-03.patchDownload+476-24
#12Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Pavel Stehule (#11)
Re: proposal: searching in array function - array_position

On 1/24/15 2:48 AM, Pavel Stehule wrote:

with array_offsets - returns a array of offsets

+         <entry>returns a offset of first occurrence of some element in a array. It uses
should be
+         <entry>returns the offset of the first occurrence of some element in an array. It uses
+         <entry>returns a array of offset of all occurrences some element in a array. It uses
should be
+         <entry>returns an array of the offsets of all occurrences of some element in an array. It uses

Any way to reduce the code duplication between the array and non-array versions? Maybe factor out the operator caching code?

You should remove the array_length() from the last array_offsets test; I don't see that it buys anything.

I think there should be tests for what happens when you feed these functions a multi-dimensional array.

Other than that, looks good.
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#13Pavel Stehule
pavel.stehule@gmail.com
In reply to: Jim Nasby (#12)
Re: proposal: searching in array function - array_position

2015-01-26 23:01 GMT+01:00 Jim Nasby <Jim.Nasby@bluetreble.com>:

On 1/24/15 2:48 AM, Pavel Stehule wrote:

with array_offsets - returns a array of offsets

+         <entry>returns a offset of first occurrence of some element in a
array. It uses
should be
+         <entry>returns the offset of the first occurrence of some
element in an array. It uses
+         <entry>returns a array of offset of all occurrences some element
in a array. It uses
should be
+         <entry>returns an array of the offsets of all occurrences of
some element in an array. It uses

Any way to reduce the code duplication between the array and non-array
versions? Maybe factor out the operator caching code?

I though about it - but there is different checks, different result
processing, different result type.

I didn't find any readable and reduced form :(

You should remove the array_length() from the last array_offsets test; I
don't see that it buys anything.

ok

I think there should be tests for what happens when you feed these
functions a multi-dimensional array.

I can do it. Result should be expected - it searching row by row due MD
format

Other than that, looks good.

Thank you

Pavel

Show quoted text

--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

#14Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Pavel Stehule (#13)
Re: proposal: searching in array function - array_position

On 1/26/15 4:17 PM, Pavel Stehule wrote:

Any way to reduce the code duplication between the array and non-array versions? Maybe factor out the operator caching code?

I though about it - but there is different checks, different result processing, different result type.

I didn't find any readable and reduced form :(

Yeah, that's why I was thinking specifically of the operator caching code... isn't that identical? That would at least remove a dozen lines...
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#15Pavel Stehule
pavel.stehule@gmail.com
In reply to: Jim Nasby (#14)
Re: proposal: searching in array function - array_position

2015-01-26 23:29 GMT+01:00 Jim Nasby <Jim.Nasby@bluetreble.com>:

On 1/26/15 4:17 PM, Pavel Stehule wrote:

Any way to reduce the code duplication between the array and
non-array versions? Maybe factor out the operator caching code?

I though about it - but there is different checks, different result
processing, different result type.

I didn't find any readable and reduced form :(

Yeah, that's why I was thinking specifically of the operator caching
code... isn't that identical? That would at least remove a dozen lines...

It is only partially identical - I would to use cache for array_offset, but
it is not necessary for array_offsets .. depends how we would to modify
current API to support externally cached data.

Regards

Pavel

Show quoted text

--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

#16Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Pavel Stehule (#15)
Re: proposal: searching in array function - array_position

On 1/27/15 4:36 AM, Pavel Stehule wrote:

2015-01-26 23:29 GMT+01:00 Jim Nasby <Jim.Nasby@bluetreble.com <mailto:Jim.Nasby@bluetreble.com>>:

On 1/26/15 4:17 PM, Pavel Stehule wrote:

Any way to reduce the code duplication between the array and non-array versions? Maybe factor out the operator caching code?

I though about it - but there is different checks, different result processing, different result type.

I didn't find any readable and reduced form :(

Yeah, that's why I was thinking specifically of the operator caching code... isn't that identical? That would at least remove a dozen lines...

It is only partially identical - I would to use cache for array_offset, but it is not necessary for array_offsets .. depends how we would to modify current API to support externally cached data.

Externally cached data?
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#17Pavel Stehule
pavel.stehule@gmail.com
In reply to: Jim Nasby (#16)
Re: proposal: searching in array function - array_position

2015-01-28 0:01 GMT+01:00 Jim Nasby <Jim.Nasby@bluetreble.com>:

On 1/27/15 4:36 AM, Pavel Stehule wrote:

2015-01-26 23:29 GMT+01:00 Jim Nasby <Jim.Nasby@bluetreble.com <mailto:
Jim.Nasby@bluetreble.com>>:

On 1/26/15 4:17 PM, Pavel Stehule wrote:

Any way to reduce the code duplication between the array and
non-array versions? Maybe factor out the operator caching code?

I though about it - but there is different checks, different
result processing, different result type.

I didn't find any readable and reduced form :(

Yeah, that's why I was thinking specifically of the operator caching
code... isn't that identical? That would at least remove a dozen lines...

It is only partially identical - I would to use cache for array_offset,
but it is not necessary for array_offsets .. depends how we would to modify
current API to support externally cached data.

Externally cached data?

Some from these functions has own caches for minimize access to typcache
(array_map, array_cmp is example). And in first case, I am trying to push
these information from fn_extra, in second case I don't do it, because I
don't expect a repeated call (and I am expecting so type cache will be
enough).

I plan to do some benchmark to calculate if we have to do, or we can use
type cache only.

Pavel

Show quoted text

--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

#18Petr Jelinek
petr@2ndquadrant.com
In reply to: Pavel Stehule (#17)
Re: proposal: searching in array function - array_position

On 28/01/15 08:15, Pavel Stehule wrote:

2015-01-28 0:01 GMT+01:00 Jim Nasby <Jim.Nasby@bluetreble.com
<mailto:Jim.Nasby@bluetreble.com>>:

On 1/27/15 4:36 AM, Pavel Stehule wrote:

It is only partially identical - I would to use cache for
array_offset, but it is not necessary for array_offsets ..
depends how we would to modify current API to support externally
cached data.

Externally cached data?

Some from these functions has own caches for minimize access to typcache
(array_map, array_cmp is example). And in first case, I am trying to
push these information from fn_extra, in second case I don't do it,
because I don't expect a repeated call (and I am expecting so type cache
will be enough).

You actually do caching via fn_extra in both case and I think that's the
correct way, and yes that part can be moved common function.

I also see that the documentation does not say what is returned by
array_offset if nothing is found (it's documented in code but not in sgml).

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#19Pavel Stehule
pavel.stehule@gmail.com
In reply to: Petr Jelinek (#18)
Re: proposal: searching in array function - array_position

2015-02-22 3:00 GMT+01:00 Petr Jelinek <petr@2ndquadrant.com>:

On 28/01/15 08:15, Pavel Stehule wrote:

2015-01-28 0:01 GMT+01:00 Jim Nasby <Jim.Nasby@bluetreble.com
<mailto:Jim.Nasby@bluetreble.com>>:

On 1/27/15 4:36 AM, Pavel Stehule wrote:

It is only partially identical - I would to use cache for
array_offset, but it is not necessary for array_offsets ..
depends how we would to modify current API to support externally
cached data.

Externally cached data?

Some from these functions has own caches for minimize access to typcache
(array_map, array_cmp is example). And in first case, I am trying to
push these information from fn_extra, in second case I don't do it,
because I don't expect a repeated call (and I am expecting so type cache
will be enough).

You actually do caching via fn_extra in both case and I think that's the
correct way, and yes that part can be moved common function.

I also see that the documentation does not say what is returned by
array_offset if nothing is found (it's documented in code but not in sgml).

rebased + fixed docs

Regards

Pavel

Show quoted text

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachments:

array_offset-04.patchtext/x-patch; charset=US-ASCII; name=array_offset-04.patchDownload+477-24
#20Petr Jelinek
petr@2ndquadrant.com
In reply to: Pavel Stehule (#19)
Re: proposal: searching in array function - array_position

On 22/02/15 12:19, Pavel Stehule wrote:

2015-02-22 3:00 GMT+01:00 Petr Jelinek <petr@2ndquadrant.com
<mailto:petr@2ndquadrant.com>>:

On 28/01/15 08:15, Pavel Stehule wrote:

2015-01-28 0:01 GMT+01:00 Jim Nasby <Jim.Nasby@bluetreble.com
<mailto:Jim.Nasby@bluetreble.com>>>:

On 1/27/15 4:36 AM, Pavel Stehule wrote:

It is only partially identical - I would to use cache for
array_offset, but it is not necessary for array_offsets ..
depends how we would to modify current API to support
externally
cached data.

Externally cached data?

Some from these functions has own caches for minimize access to
typcache
(array_map, array_cmp is example). And in first case, I am trying to
push these information from fn_extra, in second case I don't do it,
because I don't expect a repeated call (and I am expecting so
type cache
will be enough).

You actually do caching via fn_extra in both case and I think that's
the correct way, and yes that part can be moved common function.

I also see that the documentation does not say what is returned by
array_offset if nothing is found (it's documented in code but not in
sgml).

rebased + fixed docs

You still duplicate the type cache code, but many other array functions
do that too so I will not hold that against you. (Maybe somebody should
write separate patch that would put all that duplicate code into common
function?)

I think this patch is ready for committer so I am going to mark it as such.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#21Robert Haas
robertmhaas@gmail.com
In reply to: Petr Jelinek (#20)
#22Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Robert Haas (#21)
#23Pavel Stehule
pavel.stehule@gmail.com
In reply to: Jim Nasby (#22)
#24Pavel Stehule
pavel.stehule@gmail.com
In reply to: Robert Haas (#21)
#25Tom Lane
tgl@sss.pgh.pa.us
In reply to: Pavel Stehule (#24)
#26Pavel Stehule
pavel.stehule@gmail.com
In reply to: Tom Lane (#25)
#27Robert Haas
robertmhaas@gmail.com
In reply to: Pavel Stehule (#26)
#28Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Jim Nasby (#22)
#29Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Pavel Stehule (#19)
#30Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Pavel Stehule (#26)
#31Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jim Nasby (#30)
#32Robert Haas
robertmhaas@gmail.com
In reply to: Jim Nasby (#29)
#33Pavel Stehule
pavel.stehule@gmail.com
In reply to: Robert Haas (#32)
#34Pavel Stehule
pavel.stehule@gmail.com
In reply to: Jim Nasby (#29)
#35Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Pavel Stehule (#33)
#36Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Tom Lane (#31)
#37Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Pavel Stehule (#34)
#38Pavel Stehule
pavel.stehule@gmail.com
In reply to: Jim Nasby (#37)
#39Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Pavel Stehule (#38)
#40Pavel Stehule
pavel.stehule@gmail.com
In reply to: Jim Nasby (#39)
#41Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Pavel Stehule (#40)
#42Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Alvaro Herrera (#41)
#43Pavel Stehule
pavel.stehule@gmail.com
In reply to: Jim Nasby (#42)
#44Marko Tiikkaja
marko@joh.to
In reply to: Pavel Stehule (#43)
#45Pavel Stehule
pavel.stehule@gmail.com
In reply to: Marko Tiikkaja (#44)
#46Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Pavel Stehule (#45)
#47Pavel Stehule
pavel.stehule@gmail.com
In reply to: Alvaro Herrera (#46)
#48Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Pavel Stehule (#47)
#49Dean Rasheed
dean.a.rasheed@gmail.com
In reply to: Alvaro Herrera (#46)
#50Pavel Stehule
pavel.stehule@gmail.com
In reply to: Dean Rasheed (#49)
#51Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Pavel Stehule (#50)
#52Pavel Stehule
pavel.stehule@gmail.com
In reply to: Alvaro Herrera (#51)
#53Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#51)
#54Pavel Stehule
pavel.stehule@gmail.com
In reply to: Tom Lane (#53)
#55Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Pavel Stehule (#54)
#56Pavel Stehule
pavel.stehule@gmail.com
In reply to: Jim Nasby (#55)
#57Dean Rasheed
dean.a.rasheed@gmail.com
In reply to: Pavel Stehule (#56)
#58Pavel Stehule
pavel.stehule@gmail.com
In reply to: Alvaro Herrera (#51)
#59Dean Rasheed
dean.a.rasheed@gmail.com
In reply to: Pavel Stehule (#58)
#60Pavel Stehule
pavel.stehule@gmail.com
In reply to: Dean Rasheed (#59)
#61Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Pavel Stehule (#60)
#62Pavel Stehule
pavel.stehule@gmail.com
In reply to: Alvaro Herrera (#61)