[PATCH] Slight improvement of worker_spi.c example

From: Aleksander Alekseev <aleksander(at)timescale(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: [PATCH] Slight improvement of worker_spi.c example
Date: 2023-05-12 15:39:04
Message-ID: CAJ7c6TMOhWmP92_fFss-cvNnsxdj5_TSdtmiE3AJOv6yGotoFQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Currently the example uses the following order of calls:

StartTransactionCommand();
SPI_connect();
PushActiveSnapshot(...);

...

SPI_finish();
PopActiveSnapshot();
CommitTransactionCommand();

This could be somewhat misleading. Typically one expects something to be freed
in a reverse order compared to initialization. This creates a false impression
that PushActiveSnapshot(...) _should_ be called after SPI_connect().

The patch changes the order to:

StartTransactionCommand();
PushActiveSnapshot(...);
SPI_connect();

...

SPI_finish();
PopActiveSnapshot();
CommitTransactionCommand();

... and also clarifies that the order of PushActiveSnapshot(...) and
SPI_connect() is not important.

--
Best regards,
Aleksander Alekseev

Attachment Content-Type Size
v1-0001-Slight-improvement-of-worker_spi.c-example.patch application/x-patch 2.6 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2023-05-12 15:50:53 Re: psql tests hangs
Previous Message Thorsten Glaser 2023-05-12 15:35:45 Re: Adding SHOW CREATE TABLE