[PATCH] Add min/max aggregate functions to BYTEA

Lists: pgsql-hackers
From: Marat Buharov <marat(dot)buharov(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: [PATCH] Add min/max aggregate functions to BYTEA
Date: 2024-07-03 13:03:38
Message-ID: CAPCEVGXiASjodos4P8pgyV7ixfVn-ZgG9YyiRZRbVqbGmfuDyg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello. BYTEA type has the ability to use comparison operations. But it
is absent of min/max aggregate functions. They are nice to have to
provide consistency with the TEXT type.

--

With best regards,
Marat Bukharov

Attachment Content-Type Size
v1-0001-add-bytea-agg-funcs.patch text/x-patch 6.9 KB

From: Marat Buharov <marat(dot)buharov(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Add min/max aggregate functions to BYTEA
Date: 2024-07-03 14:17:39
Message-ID: CAPCEVGUFFfbfUBzLmOBnSPFaCPOvOBjpTjZpN-cXUPgmKmwsPw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

V2 patch with fixed tests

--

With best regards,
Marat Bukharov

ср, 3 июл. 2024 г. в 16:03, Marat Buharov <marat(dot)buharov(at)gmail(dot)com>:
>
> Hello. BYTEA type has the ability to use comparison operations. But it
> is absent of min/max aggregate functions. They are nice to have to
> provide consistency with the TEXT type.
>
>
> --
>
> With best regards,
> Marat Bukharov

Attachment Content-Type Size
v2-0001-add-bytea-agg-funcs.patch text/x-patch 8.1 KB

From: Marat Bukharov <marat(dot)buharov(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Add min/max aggregate functions to BYTEA
Date: 2024-07-03 14:54:24
Message-ID: CAPCEVGVczn-btFeP_DvmJo5j631bB6jbgabZC0NM8HTy1bO9ZQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

V3 patch with fixed length comparison

--

With best regards,
Marat Bukharov

>
> V2 patch with fixed tests
>
> >
> > Hello. BYTEA type has the ability to use comparison operations. But it
> > is absent of min/max aggregate functions. They are nice to have to
> > provide consistency with the TEXT type.
> >


From: Marat Bukharov <marat(dot)buharov(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Add min/max aggregate functions to BYTEA
Date: 2024-07-03 14:55:54
Message-ID: CAPCEVGUAzYaFtB1dEXP1RmX5zU4_NRqzr7Dx-hzwn3q6CH-yvg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

V3 patch with fixed length comparison

--

With best regards,
Marat Bukharov

>
> V2 patch with fixed tests
>
> >
> > Hello. BYTEA type has the ability to use comparison operations. But it
> > is absent of min/max aggregate functions. They are nice to have to
> > provide consistency with the TEXT type.
> >

Attachment Content-Type Size
v3-0001-add-bytea-agg-funcs.patch text/x-patch 8.1 KB

From: Marat Bukharov <marat(dot)buharov(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Add min/max aggregate functions to BYTEA
Date: 2024-07-03 16:04:40
Message-ID: CAPCEVGXiD_VPqsjnUp2wGxqtv4ea4iKgKPJOdJJgTE5sxyi6gQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

V4 path with fixed usage PG_GETARG_BYTEA_PP instead of PG_GETARG_TEXT_PP

--

With best regards,
Marat Bukharov

>
> V3 patch with fixed length comparison
>
> >
> > V2 patch with fixed tests
> >
> > >
> > > Hello. BYTEA type has the ability to use comparison operations. But it
> > > is absent of min/max aggregate functions. They are nice to have to
> > > provide consistency with the TEXT type.
> > >

Attachment Content-Type Size
v4-0001-add-bytea-agg-funcs.patch text/x-patch 8.1 KB

From: Aleksander Alekseev <aleksander(at)timescale(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Marat Bukharov <marat(dot)buharov(at)gmail(dot)com>
Subject: Re: [PATCH] Add min/max aggregate functions to BYTEA
Date: 2024-07-04 12:29:09
Message-ID: CAJ7c6TMLcsisvnCLDyfhcbeVvJeNQABM12+gYjqh4m6cKinN+A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi Marat,

> V4 path with fixed usage PG_GETARG_BYTEA_PP instead of PG_GETARG_TEXT_PP

Thanks for the patch.

Please add it to the nearest open commitfest [1].

```
+select min(v) from bytea_test_table;
+ min
+------
+ \xaa
+(1 row)
+
+select max(v) from bytea_test_table;
+ max
+------
+ \xff
+(1 row)
```

If I understand correctly, all the v's are of the same size. If this
is the case you should add more test cases.

[1]: https://commitfest.postgresql.org/

--
Best regards,
Aleksander Alekseev


From: Marat Bukharov <marat(dot)buharov(at)gmail(dot)com>
To: Aleksander Alekseev <aleksander(at)timescale(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Add min/max aggregate functions to BYTEA
Date: 2024-07-05 19:43:56
Message-ID: CAPCEVGXahAzUWq875T2ZnDYP=dkf+sKo7Ph74F03ZpNZvv-EiA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

What part of commitfest should I put the current patch to: "SQL
Commands", "Miscellaneous" or something else? I can't figure it out.

--

With best regards,
Marat Bukharov

> Hi Marat,
>
> > V4 path with fixed usage PG_GETARG_BYTEA_PP instead of PG_GETARG_TEXT_PP
>
> Thanks for the patch.
>
> Please add it to the nearest open commitfest [1].
>
> ```
> +select min(v) from bytea_test_table;
> + min
> +------
> + \xaa
> +(1 row)
> +
> +select max(v) from bytea_test_table;
> + max
> +------
> + \xff
> +(1 row)
> ```
>
> If I understand correctly, all the v's are of the same size. If this
> is the case you should add more test cases.
>
> [1]: https://commitfest.postgresql.org/
>
> --
> Best regards,
> Aleksander Alekseev


From: Aleksander Alekseev <aleksander(at)timescale(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Marat Bukharov <marat(dot)buharov(at)gmail(dot)com>
Subject: Re: [PATCH] Add min/max aggregate functions to BYTEA
Date: 2024-07-08 09:06:29
Message-ID: CAJ7c6TMh4JQ_eiYdztRGBozVyjn3GoiteNshZ9BkMCA_ggTg6A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

> What part of commitfest should I put the current patch to: "SQL
> Commands", "Miscellaneous" or something else? I can't figure it out.

Personally I qualified a similar patch [1] as "Server Features",
although I'm not 100% sure if this was the best choice.

[1]: https://commitfest.postgresql.org/48/4905/

--
Best regards,
Aleksander Alekseev


From: Marat Bukharov <marat(dot)buharov(at)gmail(dot)com>
To: Aleksander Alekseev <aleksander(at)timescale(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Add min/max aggregate functions to BYTEA
Date: 2024-07-24 14:42:11
Message-ID: CAPCEVGVi5A65V5chbdwyh9jtsFWuz1eUR__mkPbkHL3MJtpTzA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

V5 patch. I've added more tests with different bytea sizes

--

With best regards,
Marat Bukharov

чт, 4 июл. 2024 г. в 15:29, Aleksander Alekseev <aleksander(at)timescale(dot)com>:
>
> Hi Marat,
>
> > V4 path with fixed usage PG_GETARG_BYTEA_PP instead of PG_GETARG_TEXT_PP
>
> Thanks for the patch.
>
> Please add it to the nearest open commitfest [1].
>
> ```
> +select min(v) from bytea_test_table;
> + min
> +------
> + \xaa
> +(1 row)
> +
> +select max(v) from bytea_test_table;
> + max
> +------
> + \xff
> +(1 row)
> ```
>
> If I understand correctly, all the v's are of the same size. If this
> is the case you should add more test cases.
>
> [1]: https://commitfest.postgresql.org/
>
> --
> Best regards,
> Aleksander Alekseev

Attachment Content-Type Size
v5-0001-add-bytea-agg-funcs.patch text/x-patch 8.6 KB

From: Marat Bukharov <marat(dot)buharov(at)gmail(dot)com>
To: Aleksander Alekseev <aleksander(at)timescale(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Add min/max aggregate functions to BYTEA
Date: 2024-07-24 14:47:01
Message-ID: CAPCEVGXfhP-Mj-pDkw8z9-WNjBD1S+EVA_R1+b1gR-ujhGyOiw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Added patch to commitfest https://commitfest.postgresql.org/49/5138/

--

With best regards,
Marat Bukharov

>
> Hi,
>
> > What part of commitfest should I put the current patch to: "SQL
> > Commands", "Miscellaneous" or something else? I can't figure it out.
>
> Personally I qualified a similar patch [1] as "Server Features",
> although I'm not 100% sure if this was the best choice.
>
> [1]: https://commitfest.postgresql.org/48/4905/
>
> --
> Best regards,
> Aleksander Alekseev


From: "Andrey M(dot) Borodin" <x4mmm(at)yandex-team(dot)ru>
To: Marat Bukharov <marat(dot)buharov(at)gmail(dot)com>
Cc: Aleksander Alekseev <aleksander(at)timescale(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Add min/max aggregate functions to BYTEA
Date: 2024-08-02 09:20:04
Message-ID: [email protected]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> On 24 Jul 2024, at 17:42, Marat Bukharov <marat(dot)buharov(at)gmail(dot)com> wrote:
>
> V5 patch. I've added more tests with different bytea sizes

Hi Marat!

This looks like a nice feature to have.

I’ve took a look into the patch and have few suggestions:
0. Please write more descriptive commit message akin to [0]
1. Use oids from development range 8000-9999
2. Replace VARDATA_ANY\memcmp dance with a call to varstrfastcmp_c().

Thank you!

Best regards, Andrey Borodin.

[0] https://github.com/postgres/postgres/commit/a0f1fce80c03


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Andrey M(dot) Borodin" <x4mmm(at)yandex-team(dot)ru>
Cc: Marat Bukharov <marat(dot)buharov(at)gmail(dot)com>, Aleksander Alekseev <aleksander(at)timescale(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Add min/max aggregate functions to BYTEA
Date: 2024-09-03 21:19:14
Message-ID: [email protected]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Andrey M. Borodin" <x4mmm(at)yandex-team(dot)ru> writes:
> 0. Please write more descriptive commit message akin to [0]
> 1. Use oids from development range 8000-9999

Yeah, we don't try anymore to manually select permanent oids [1].

> 2. Replace VARDATA_ANY\memcmp dance with a call to varstrfastcmp_c().

I don't agree with that recommendation in the slightest: it's a
fundamental type pun for bytea to piggyback on text/varchar functions.
It risks bugs in bytea due to somebody inserting collation dependencies
into those functions. It also creates special cases that those
functions shouldn't have to cope with, see e.g. comment for
varstr_sortsupport about how we have to allow NUL bytes there but
only if it's C locale. That's a laughably rickety bit of coding.

I see that somebody already made such a pun in bytea_sortsupport,
but that was a bad idea that we should undo not double down on.

I wonder if we shouldn't pull all the bytea support functions out
of varlena.c (say into a new file bytea.c), to discourage such
gamesmanship in the future.

regards, tom lane

[1] https://www.postgresql.org/docs/devel/system-catalog-initial-data.html#SYSTEM-CATALOG-OID-ASSIGNMENT


From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Marat Bukharov <marat(dot)buharov(at)gmail(dot)com>
Cc: Aleksander Alekseev <aleksander(at)timescale(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Add min/max aggregate functions to BYTEA
Date: 2024-09-23 01:05:37
Message-ID: CAApHDvq-PaDK+NWcG4yhCFcQtvD8WzjzGO3WzJjM7GQREA5tYQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 25 Jul 2024 at 02:42, Marat Bukharov <marat(dot)buharov(at)gmail(dot)com> wrote:
> V5 patch. I've added more tests with different bytea sizes

I just glanced over this patch. Are you still planning on working on
it? There's been no adjustments made since the last feedback you got
in early August.

Can you address Andrey's feedback on point #1?

Also, for bytea_larger() and bytea_smaller(), I suggest copying what's
been done in record_larger() and record_smaller() except use
byteacmp(). That'll remove all the duplicated code.

If you fix those up, I see no reason not to commit the patch.

David


From: Aleksander Alekseev <aleksander(at)timescale(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Marat Bukharov <marat(dot)buharov(at)gmail(dot)com>, David Rowley <dgrowleyml(at)gmail(dot)com>, Andrey Borodin <x4mmm(at)yandex-team(dot)ru>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: [PATCH] Add min/max aggregate functions to BYTEA
Date: 2024-10-08 14:23:54
Message-ID: CAJ7c6TMQWB92tJ0YgAVuihXsJjtuK-b3oSz-ZDKjz5chv-TvLA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

> I just glanced over this patch. Are you still planning on working on
> it? There's been no adjustments made since the last feedback you got
> in early August.
>
> Can you address Andrey's feedback on point #1?
>
> Also, for bytea_larger() and bytea_smaller(), I suggest copying what's
> been done in record_larger() and record_smaller() except use
> byteacmp(). That'll remove all the duplicated code.
>
> If you fix those up, I see no reason not to commit the patch.

Since we haven't heard from Marat since July I decided to rebase the
patch and address the feedback received so far. PFA patch v6.

--
Best regards,
Aleksander Alekseev

Attachment Content-Type Size
v6-0001-Add-min-and-max-aggregates-for-bytea-type.patch application/octet-stream 9.0 KB

From: "Andrey M(dot) Borodin" <x4mmm(at)yandex-team(dot)ru>
To: Aleksander Alekseev <aleksander(at)timescale(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Marat Bukharov <marat(dot)buharov(at)gmail(dot)com>, David Rowley <dgrowleyml(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: [PATCH] Add min/max aggregate functions to BYTEA
Date: 2024-10-08 14:33:03
Message-ID: [email protected]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> On 8 Oct 2024, at 19:23, Aleksander Alekseev <aleksander(at)timescale(dot)com> wrote:
>
> PFA patch v6.

IMO the patch looks RfC.

Best regards, Andrey Borodin.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Andrey M(dot) Borodin" <x4mmm(at)yandex-team(dot)ru>
Cc: Aleksander Alekseev <aleksander(at)timescale(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Marat Bukharov <marat(dot)buharov(at)gmail(dot)com>, David Rowley <dgrowleyml(at)gmail(dot)com>
Subject: Re: [PATCH] Add min/max aggregate functions to BYTEA
Date: 2024-10-08 17:52:49
Message-ID: [email protected]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Andrey M. Borodin" <x4mmm(at)yandex-team(dot)ru> writes:
> IMO the patch looks RfC.

LGTM too. Pushed.

regards, tom lane


From: Marat Bukharov <marat(dot)buharov(at)gmail(dot)com>
To: Aleksander Alekseev <aleksander(at)timescale(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, David Rowley <dgrowleyml(at)gmail(dot)com>, Andrey Borodin <x4mmm(at)yandex-team(dot)ru>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: [PATCH] Add min/max aggregate functions to BYTEA
Date: 2024-10-08 18:12:22
Message-ID: CAPCEVGXeJQY-=wwbp=2WMiYEAGmqQMYUejDhizeaZa7xv80oXA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Thank you for the corrections. I was busy recently and did not follow
conversations in the mailing list. Sorry about that.

--

With best regards,
Marat Bukharov

вт, 8 окт. 2024 г. в 17:24, Aleksander Alekseev <aleksander(at)timescale(dot)com>:
>
> Hi,
>
> > I just glanced over this patch. Are you still planning on working on
> > it? There's been no adjustments made since the last feedback you got
> > in early August.
> >
> > Can you address Andrey's feedback on point #1?
> >
> > Also, for bytea_larger() and bytea_smaller(), I suggest copying what's
> > been done in record_larger() and record_smaller() except use
> > byteacmp(). That'll remove all the duplicated code.
> >
> > If you fix those up, I see no reason not to commit the patch.
>
> Since we haven't heard from Marat since July I decided to rebase the
> patch and address the feedback received so far. PFA patch v6.
>
> --
> Best regards,
> Aleksander Alekseev