Re: general purpose array_sort

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Junwang Zhao <zhjwpku(at)gmail(dot)com>, Aleksander Alekseev <aleksander(at)timescale(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Amit Langote <amitlangote09(at)gmail(dot)com>, "andreas(at)proxel(dot)se" <andreas(at)proxel(dot)se>, Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: Re: general purpose array_sort
Date: 2024-11-05 07:12:50
Message-ID: CACJufxGMCALTkLS0MR9SYHmMb3Y0xwGS8nvSQmSk6zTerO=aQA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Nov 4, 2024 at 7:34 PM Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> wrote:
>
> Testing this with an array with non-default lower bounds, it fails to
> preserve the array bounds, which I think it should (note:
> array_reverse() and array_shuffle() do preserve the bounds):
>
> SELECT array_reverse(a), array_shuffle(a), array_sort(a)
> FROM (VALUES ('[10:12][20:21]={{1,2},{10,20},{3,4}}'::int[])) v(a);
>
> -[ RECORD 1 ]-+-------------------------------------
> array_reverse | [10:12][20:21]={{3,4},{10,20},{1,2}}
> array_shuffle | [10:12][20:21]={{10,20},{3,4},{1,2}}
> array_sort | [1:3][20:21]={{1,2},{3,4},{10,20}}
>

if i understand it correctly,
array_create_iterator cannot cope with top dimension bound information.
since input array arguments already have dims, lbs information.
so at the end of array_sort directly copy
from the input array argument to astate.

tuplesort_performsort won't need array bounds, we should be safe?

v12-0001 same as v11-0001-general-purpose-array_sort.patch, only
resolve git conflict
v12-0002 preserve array bound information.
v12-0003 cache ArrayMetaState.

after v12-0003 now
typedef struct ArraySortCachedInfo
{
TypeCacheEntry *typentry;
TypeCacheEntry *array_typentry;
ArrayMetaState array_meta;
} ArraySortCachedInfo;

function array_create_iterator, get_typlenbyvalalign
will do cache search, we can cache ArrayMetaState.
so multiple array_create_iterator calls won't need to call get_typlenbyvalalign.
every time.

0002, I also have a 3 dimensional array test.
create table t(a int[]);
insert into t values ('[-1:-0]={7,1}'::int[]),
('[-2:-0][20:21]={{1,2},{10,20},{1,-4}}'),
('[-2:-0][20:22]={{-11,2,-1},{-11,2, 1},{-11,-4, 10}}'),
('[-13:-10][0:1][20:22]={
{{1,2,112},{1,2,-123}},
{{10,-20,1},{11,123,3}},
{{10,-20,1},{11,-123,-9}},
{{1,2,-11},{1,2,211}}}'::int[]);
SELECT array_sort(t.a) from t;
SELECT array_sort((t.a) [-13:-10][0:1][21:22]) from t where array_ndims(a) = 3;
SELECT array_sort((t.a) [-13:-11][0:1][21:22]) from t where array_ndims(a) = 3;
SELECT array_sort((t.a) [-13:-11][0:0][20:21]) from t where array_ndims(a) = 3;

The test output is ok to me.

Attachment Content-Type Size
v12-0003-array_sort-cache-ArrayMetaState.patch application/x-patch 2.2 KB
v12-0002-array_sort-preserve-array-dimenion-and-bound-inf.patch application/x-patch 7.4 KB
v12-0001-general-purpose-array_sort.patch application/x-patch 10.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Shlok Kyal 2024-11-05 07:22:45 Disallow UPDATE/DELETE on table with unpublished generated column as REPLICA IDENTITY
Previous Message Peter Smith 2024-11-05 07:02:24 Re: Pgoutput not capturing the generated columns