[PATCH] Slight improvement of worker_spi.c example - Mailing list pgsql-hackers

From Aleksander Alekseev
Subject [PATCH] Slight improvement of worker_spi.c example
Date
Msg-id CAJ7c6TMOhWmP92_fFss-cvNnsxdj5_TSdtmiE3AJOv6yGotoFQ@mail.gmail.com
Whole thread Raw
Responses Re: [PATCH] Slight improvement of worker_spi.c example
List 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

pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: psql tests hangs
Next
From: Tom Lane
Date:
Subject: Re: psql tests hangs