Re: Add test module for Table Access Method

Lists: pgsql-hackers
From: Fabrízio de Royes Mello <fabriziomello(at)gmail(dot)com>
To: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Add test module for Table Access Method
Date: 2023-06-03 23:42:36
Message-ID: CAFcNs+pcU2ib=jvjNZNboD+M2tHO+vD77C_YZJ2rsGR0Tp35mg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Hi all,

During the PGCon Unconference session about Table Access Method one missing
item pointed out is that currently we lack documentation and examples of
TAM.

So in order to improve things a bit in this area I'm proposing to add a
test module for Table Access Method similar what we already have for Index
Access Method.

This code is based on the "blackhole_am" implemented by Michael Paquier:
https://github.com/michaelpq/pg_plugins/tree/main/blackhole_am

Regards,

--
Fabrízio de Royes Mello

Attachment Content-Type Size
0001-Add-test-module-for-Table-Access-Method.patch text/x-patch 25.4 KB

From: Fabrízio de Royes Mello <fabriziomello(at)gmail(dot)com>
To: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Add test module for Table Access Method
Date: 2023-06-05 16:24:38
Message-ID: CAFcNs+qPD5U3vUzHxr2DGPgV_E14OpSj-ypoLk84QKN=Jux1=A@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Jun 3, 2023 at 7:42 PM Fabrízio de Royes Mello <
fabriziomello(at)gmail(dot)com> wrote:
>
>
> Hi all,
>
> During the PGCon Unconference session about Table Access Method one
missing item pointed out is that currently we lack documentation and
examples of TAM.
>
> So in order to improve things a bit in this area I'm proposing to add a
test module for Table Access Method similar what we already have for Index
Access Method.
>
> This code is based on the "blackhole_am" implemented by Michael Paquier:
https://github.com/michaelpq/pg_plugins/tree/main/blackhole_am
>

Just added some more tests, ran pgindent and also organized a bit some
comments and README.txt.

Regards,

--
Fabrízio de Royes Mello

Attachment Content-Type Size
v2-0001-Add-test-module-for-Table-Access-Method.patch text/x-patch 26.9 KB

From: Fabrízio de Royes Mello <fabriziomello(at)gmail(dot)com>
To: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Add test module for Table Access Method
Date: 2023-09-26 13:00:08
Message-ID: CAFcNs+r8OGpa-qH44Kp6=12sch9C9sPKrbpO-gwCaasVfNKZtA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Jun 5, 2023 at 1:24 PM Fabrízio de Royes Mello <
fabriziomello(at)gmail(dot)com> wrote:
>
> On Sat, Jun 3, 2023 at 7:42 PM Fabrízio de Royes Mello <
fabriziomello(at)gmail(dot)com> wrote:
> >
> >
> > Hi all,
> >
> > During the PGCon Unconference session about Table Access Method one
missing item pointed out is that currently we lack documentation and
examples of TAM.
> >
> > So in order to improve things a bit in this area I'm proposing to add a
test module for Table Access Method similar what we already have for Index
Access Method.
> >
> > This code is based on the "blackhole_am" implemented by Michael
Paquier: https://github.com/michaelpq/pg_plugins/tree/main/blackhole_am
> >
>
> Just added some more tests, ran pgindent and also organized a bit some
comments and README.txt.
>

Rebased version.

--
Fabrízio de Royes Mello

Attachment Content-Type Size
v3-0001-Add-test-module-for-Table-Access-Method.patch text/x-patch 26.9 KB

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Fabrízio de Royes Mello <fabriziomello(at)gmail(dot)com>
Cc: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Add test module for Table Access Method
Date: 2023-09-28 01:08:24
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Jun 03, 2023 at 07:42:36PM -0400, Fabrízio de Royes Mello wrote:
> So in order to improve things a bit in this area I'm proposing to add a
> test module for Table Access Method similar what we already have for Index
> Access Method.
>
> This code is based on the "blackhole_am" implemented by Michael Paquier:
> https://github.com/michaelpq/pg_plugins/tree/main/blackhole_am

dummy_index_am has included from the start additional coverage for the
various internal add_*_reloption routines, that were never covered in
the core tree. Except if I am missing something, I am not seeing some
of the extra usefulness for the patch you've sent here.
--
Michael


From: vignesh C <vignesh21(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Fabrízio de Royes Mello <fabriziomello(at)gmail(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Add test module for Table Access Method
Date: 2024-01-14 11:09:18
Message-ID: CALDaNm2-QPfKe-rd-t7OT=Q++VTjpHJTPiG_htwL0m0Q--GD3w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 28 Sept 2023 at 10:23, Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>
> On Sat, Jun 03, 2023 at 07:42:36PM -0400, Fabrízio de Royes Mello wrote:
> > So in order to improve things a bit in this area I'm proposing to add a
> > test module for Table Access Method similar what we already have for Index
> > Access Method.
> >
> > This code is based on the "blackhole_am" implemented by Michael Paquier:
> > https://github.com/michaelpq/pg_plugins/tree/main/blackhole_am
>
> dummy_index_am has included from the start additional coverage for the
> various internal add_*_reloption routines, that were never covered in
> the core tree. Except if I am missing something, I am not seeing some
> of the extra usefulness for the patch you've sent here.

I have changed the status of commitfest entry to "Returned with
Feedback" as Michael's comments have not yet been resolved. Please
handle the comments and update the commitfest entry accordingly.

Regards,
Vignesh


From: Jelte Fennema-Nio <postgres(at)jeltef(dot)nl>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Fabrízio de Royes Mello <fabriziomello(at)gmail(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Add test module for Table Access Method
Date: 2024-01-15 09:36:49
Message-ID: CAGECzQR0OExsrx33nBkySPkDShSn-izcz+JhVrqTrJwRfAQm6w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 28 Sept 2023 at 03:08, Michael Paquier <michael(at)paquier(dot)xyz> wrote:
> dummy_index_am has included from the start additional coverage for the
> various internal add_*_reloption routines, that were never covered in
> the core tree. Except if I am missing something, I am not seeing some
> of the extra usefulness for the patch you've sent here.

When trying to implement a table access method in the past I remember
very well that I was having a really hard time finding an example of
one. I remember seeing the dummy_index_am module and being quite
disappointed that there wasn't a similar one for table access methods.
I believe that I eventually found blackhole_am, but it took me quite a
bit of mailing list spelunking to get there. So I think purely for
documentation purposes this addition would already be useful.


From: Aleksander Alekseev <aleksander(at)timescale(dot)com>
To: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: Jelte Fennema-Nio <postgres(at)jeltef(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Fabrízio de Royes Mello <fabriziomello(at)gmail(dot)com>
Subject: Re: Add test module for Table Access Method
Date: 2024-01-15 13:26:08
Message-ID: CAJ7c6TM3=tnDYAWyyvRB6UdeoafXaPPMq+XpafW+ZBcOnkg1gA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

> When trying to implement a table access method in the past I remember
> very well that I was having a really hard time finding an example of
> one.

To be fair, Postgres uses TAM internally, so there is at least one
complete and up-to-date real-life example. Learning curve for TAMs is
indeed steep, and I wonder if we could do a better job in this respect
e.g. by providing a simpler example. This being said, I know several
people who learned TAM successfully (so far only for R&D tasks) which
indicates that its difficulty is adequate.

--
Best regards,
Aleksander Alekseev


From: Jelte Fennema-Nio <postgres(at)jeltef(dot)nl>
To: Aleksander Alekseev <aleksander(at)timescale(dot)com>
Cc: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>, Michael Paquier <michael(at)paquier(dot)xyz>, Fabrízio de Royes Mello <fabriziomello(at)gmail(dot)com>
Subject: Re: Add test module for Table Access Method
Date: 2024-01-15 14:40:30
Message-ID: CAGECzQQwNZ2sKh+Qfx1X+=ODEfx+9V0ig6CsmBwOOs2CAy+kmQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, 15 Jan 2024 at 14:26, Aleksander Alekseev
<aleksander(at)timescale(dot)com> wrote:
> To be fair, Postgres uses TAM internally, so there is at least one
> complete and up-to-date real-life example.

Sure, but that one is quite hard to follow if you don't already know
lots of details of the heap storage. At least for me, having a minimal
example was extremely helpful and it made for a great code skeleton to
start from.


From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Jelte Fennema-Nio <postgres(at)jeltef(dot)nl>
Cc: Aleksander Alekseev <aleksander(at)timescale(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>, Fabrízio de Royes Mello <fabriziomello(at)gmail(dot)com>
Subject: Re: Add test module for Table Access Method
Date: 2024-01-16 04:58:10
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Jan 15, 2024 at 03:40:30PM +0100, Jelte Fennema-Nio wrote:
> On Mon, 15 Jan 2024 at 14:26, Aleksander Alekseev
> <aleksander(at)timescale(dot)com> wrote:
>> To be fair, Postgres uses TAM internally, so there is at least one
>> complete and up-to-date real-life example.
>
> Sure, but that one is quite hard to follow if you don't already know
> lots of details of the heap storage. At least for me, having a minimal
> example was extremely helpful and it made for a great code skeleton to
> start from.

Hmm. I'd rather have it do something useful in terms of test coverage
rather than being just an empty skull.

How about adding the same kind of coverage as dummy_index_am with a
couple of reloptions then? That can serve as a point of reference
when a table AM needs a few custom options. A second idea would be to
show how to use toast relations when implementing your new AM, where a
toast table could be created even in cases where we did not want one
with heap, when it comes to size limitations with char and/or varchar,
and that makes for a simpler needs_toast_table callback.
--
Michaxel


From: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Jelte Fennema-Nio <postgres(at)jeltef(dot)nl>, Aleksander Alekseev <aleksander(at)timescale(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>, Fabrízio de Royes Mello <fabriziomello(at)gmail(dot)com>
Subject: Re: Add test module for Table Access Method
Date: 2024-01-16 05:15:25
Message-ID: CALj2ACWYQbU4_6UA5p24Vc5UKnp11sFh0E7qefqcJX2RaE-Rnw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Jan 16, 2024 at 10:28 AM Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>
> Hmm. I'd rather have it do something useful in terms of test coverage
> rather than being just an empty skull.
>
> How about adding the same kind of coverage as dummy_index_am with a
> couple of reloptions then? That can serve as a point of reference
> when a table AM needs a few custom options. A second idea would be to
> show how to use toast relations when implementing your new AM, where a
> toast table could be created even in cases where we did not want one
> with heap, when it comes to size limitations with char and/or varchar,
> and that makes for a simpler needs_toast_table callback.

I think a test module for a table AM will really help developers. Just
to add to the above list - how about the table AM implementing a
simple in-memory (columnar if possible) database storing tables
in-memory and subsequently providing readers with the access to the
tables?

--
Bharath Rupireddy
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com


From: Japin Li <japinli(at)hotmail(dot)com>
To: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Jelte Fennema-Nio <postgres(at)jeltef(dot)nl>, Aleksander Alekseev <aleksander(at)timescale(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>, Fabrízio de Royes Mello <fabriziomello(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Add test module for Table Access Method
Date: 2024-01-16 06:15:21
Message-ID: ME3P282MB3166E4BA9602E4FFC977BE52B6732@ME3P282MB3166.AUSP282.PROD.OUTLOOK.COM
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers


On Tue, 16 Jan 2024 at 13:15, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com> wrote:
> On Tue, Jan 16, 2024 at 10:28 AM Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>>
>> Hmm. I'd rather have it do something useful in terms of test coverage
>> rather than being just an empty skull.
>>
>> How about adding the same kind of coverage as dummy_index_am with a
>> couple of reloptions then? That can serve as a point of reference
>> when a table AM needs a few custom options. A second idea would be to
>> show how to use toast relations when implementing your new AM, where a
>> toast table could be created even in cases where we did not want one
>> with heap, when it comes to size limitations with char and/or varchar,
>> and that makes for a simpler needs_toast_table callback.
>
> I think a test module for a table AM will really help developers. Just
> to add to the above list - how about the table AM implementing a
> simple in-memory (columnar if possible) database storing tables
> in-memory and subsequently providing readers with the access to the
> tables?

That's a good idea.


From: Aleksander Alekseev <aleksander(at)timescale(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: Japin Li <japinli(at)hotmail(dot)com>, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Jelte Fennema-Nio <postgres(at)jeltef(dot)nl>, Fabrízio de Royes Mello <fabriziomello(at)gmail(dot)com>
Subject: Re: Add test module for Table Access Method
Date: 2024-01-16 09:39:42
Message-ID: CAJ7c6TNHHUdQCcx98trOw+0BkDgMW+Zc1zFHy1aqqSJ=OLbMzw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

> > I think a test module for a table AM will really help developers. Just
> > to add to the above list - how about the table AM implementing a
> > simple in-memory (columnar if possible) database storing tables
> > in-memory and subsequently providing readers with the access to the
> > tables?
>
> That's a good idea.

Personally I would be careful with this idea.

Practice shows that when you show the first incomplete, limited and
buggy PoC it ends up being in the production environment the next day
:) In other words sooner or later there will be users demanding a full
in-memory columnar storage support from Postgres. I believe it would
be a problem. Last time I checked TAM was not extremely good for
implementing proper columnar storages, and there are lots of open
questions when it comes to in-memory tables (e.g. what to do with
foreign keys, inherited tables, etc).

All in all I don't think we should provide something that can look /
be interpreted as first-class alternative storage but in fact is not.

> How about adding the same kind of coverage as dummy_index_am with a
> couple of reloptions then? That can serve as a point of reference
> when a table AM needs a few custom options. A second idea would be to
> show how to use toast relations when implementing your new AM, where a
> toast table could be created even in cases where we did not want one
> with heap, when it comes to size limitations with char and/or varchar,
> and that makes for a simpler needs_toast_table callback.

Good ideas. Additionally we could provide a proxy TAM for a heap TAM
which does nothing but logging used TAM methods, its arguments and
return values. This would be a good example and also potentially can
be used as a debugging tool.

--
Best regards,
Aleksander Alekseev


From: Mats Kindahl <mats(at)timescale(dot)com>
To: Aleksander Alekseev <aleksander(at)timescale(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, Japin Li <japinli(at)hotmail(dot)com>, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Jelte Fennema-Nio <postgres(at)jeltef(dot)nl>, Fabrízio de Royes Mello <fabriziomello(at)gmail(dot)com>
Subject: Re: Add test module for Table Access Method
Date: 2024-01-16 12:12:52
Message-ID: CA+14424qbsh4yQuQdsi90xOhqzk+12CoJp6w=edd_jpwJoyLCQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Hi all,

On Tue, Jan 16, 2024 at 10:40 AM Aleksander Alekseev <
aleksander(at)timescale(dot)com> wrote:

> Hi,
>
> > > I think a test module for a table AM will really help developers. Just
> > > to add to the above list - how about the table AM implementing a
> > > simple in-memory (columnar if possible) database storing tables
> > > in-memory and subsequently providing readers with the access to the
> > > tables?
> >
> > That's a good idea.
>
> Personally I would be careful with this idea.
>
> Practice shows that when you show the first incomplete, limited and
> buggy PoC it ends up being in the production environment the next day
> :) In other words sooner or later there will be users demanding a full
> in-memory columnar storage support from Postgres. I believe it would
> be a problem. Last time I checked TAM was not extremely good for
> implementing proper columnar storages, and there are lots of open
> questions when it comes to in-memory tables (e.g. what to do with
> foreign keys, inherited tables, etc).
>
> All in all I don't think we should provide something that can look /
> be interpreted as first-class alternative storage but in fact is not.
>

I tossed together a table access method for in-memory storage in column
format for experimental purposes over the holidays (I actually have a
row-based one as well, but that is in no shape to share at this point).
It's available under https://github.com/mkindahl/pg_arrow. The intention
was mostly to have something simple to play and experiment with. It is
loosely based on the Apache Arrow Columnar format, but the normal data
structures are not suitable for storing in shared memory so I have tweaked
it a little.

> > How about adding the same kind of coverage as dummy_index_am with a
> > couple of reloptions then? That can serve as a point of reference
> > when a table AM needs a few custom options. A second idea would be to
> > show how to use toast relations when implementing your new AM, where a
> > toast table could be created even in cases where we did not want one
> > with heap, when it comes to size limitations with char and/or varchar,
> > and that makes for a simpler needs_toast_table callback.
>
> Good ideas. Additionally we could provide a proxy TAM for a heap TAM
> which does nothing but logging used TAM methods, its arguments and
> return values. This would be a good example and also potentially can
> be used as a debugging tool.
>

We wrote a table access method for experimenting with and to be able to
trace what happens while executing various statements. It is available
under https://github.com/timescale/pg_traceam for anybody who is interested.

Best wishes,
Mats Kindahl

>
> --
> Best regards,
> Aleksander Alekseev
>
>
>


From: Mats Kindahl <mats(at)timescale(dot)com>
To: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Jelte Fennema-Nio <postgres(at)jeltef(dot)nl>, Aleksander Alekseev <aleksander(at)timescale(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>, Fabrízio de Royes Mello <fabriziomello(at)gmail(dot)com>
Subject: Re: Add test module for Table Access Method
Date: 2024-01-16 12:16:27
Message-ID: CA+144260ce_BNuGGhVGHv+ooJsOsTYbTVtw=49c34TkMa6GG7g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Jan 16, 2024 at 6:15 AM Bharath Rupireddy <
bharath(dot)rupireddyforpostgres(at)gmail(dot)com> wrote:

> On Tue, Jan 16, 2024 at 10:28 AM Michael Paquier <michael(at)paquier(dot)xyz>
> wrote:
> >
> > Hmm. I'd rather have it do something useful in terms of test coverage
> > rather than being just an empty skull.
> >
> > How about adding the same kind of coverage as dummy_index_am with a
> > couple of reloptions then? That can serve as a point of reference
> > when a table AM needs a few custom options. A second idea would be to
> > show how to use toast relations when implementing your new AM, where a
> > toast table could be created even in cases where we did not want one
> > with heap, when it comes to size limitations with char and/or varchar,
> > and that makes for a simpler needs_toast_table callback.
>
> I think a test module for a table AM will really help developers. Just
> to add to the above list - how about the table AM implementing a
> simple in-memory (columnar if possible) database storing tables
> in-memory and subsequently providing readers with the access to the
> tables?
>

Hi,

One idea I wanted to implement is a table access method that you can use to
test the interface, something like a "mock TAM" where you can
programmatically decide on the responses to unit-test the API. I was
thinking that you could implement a framework that allows you to implement
the TAM in some scripting language like Perl, Python, or (horrors) Tcl for
easy prototyping.

Best wishes,
Mats Kindahl

> --
> Bharath Rupireddy
> PostgreSQL Contributors Team
> RDS Open Source Databases
> Amazon Web Services: https://aws.amazon.com
>
>
>