Re: Question regarding Sync message and unnamed portal

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Tatsuo Ishii <ishii(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Question regarding Sync message and unnamed portal
Date: 2013-09-11 04:19:34
Message-ID: CAA4eK1JoLhrT8jAnN+JkWpuS1nn9L9AUYS=etuf9TX_-246LQA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Sep 11, 2013 at 2:06 AM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> On Sat, Jan 26, 2013 at 09:25:56AM +0900, Tatsuo Ishii wrote:
>> Sorry for confusion.
>>
>> I knew an unamed portal only lasts until current transaction ends. I
>> was confused in the case when no explicit transaction is used.
>>
>> At completion of each series of extended-query messages, the
>> frontend should issue a Sync message.
>>
>> This is not actually true because Sync is not actually mandatory as
>> Tom pointed out before. We could use a Flush message instead but it's
>> another story. And next sentence says:
>>
>> This parameterless message causes the backend to close the current
>> transaction if it's not inside a BEGIN/COMMIT transaction block
>> ("close" meaning to commit if no error, or roll back if error).
>>
>> I did not understand this at first because if we are not inside a
>> BEGIN/COMMIT transaction block, how does Sync close it? In my
>> understanding each extended query message(parse/bind/execute) starts
>> an internal transaction and does not close it until Sync issued(and
>> Sync is mandatory according to the manual). So if we are not in an
>> explicit transaction we cannot reuse unnamed portal because Sync
>> closes the transaction, which in turn destroys the unnamed portal.
>> This gave me a miss understanding that unnamed portal is destroyed
>> even transaction is not explicitly closed.
>>
>> It would be nice if something like "unnamed portal will be destroyed
>> by a Sync message if you are in an explicit transaction" is in our
>> manual.
>
> I am back to this issue and still confused. Perhaps if I give some
> specific examples it will help.
>
> Based on the current documentation, I assume that if you do an explicit
> transaction (BEGIN WORK), Sync will not close any portals. For an
> implicit transaction, I assume Sync will close all portals except FOR
> HOLD named portals. Is this not how it behaves?

This is right.
AFAIU, purpose of SYNC message as per code for explicit and implicit
transaction is as below:

For Implicit Transaction: It will commit or abort the current
transaction which will internally close all the portals except FOR
HOLD named portals.

For Explicit Transaction:
It will do CommandCounterIncrement() which is required as we have
finished executing a command someplace within a transaction block.

Now I am not able to see how below statement in one of above mails is correct
> It would be nice if something like "unnamed portal will be destroyed by a Sync message if you are in an explicit transaction" is in our manual.

I think portal will be destroyed by Close 'C' message.

With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tatsuo Ishii 2013-09-11 05:00:22 Re: Question regarding Sync message and unnamed portal
Previous Message Kohei KaiGai 2013-09-11 03:45:13 Re: Custom Plan node