Re: CommandCounterIncrement - Mailing list pgsql-hackers

From Tom Lane
Subject Re: CommandCounterIncrement
Date
Msg-id 25579.973183436@sss.pgh.pa.us
Whole thread Raw
In response to CommandCounterIncrement  (Denis Perchine <dyp@perchine.com>)
Responses Re: CommandCounterIncrement  (Denis Perchine <dyp@perchine.com>)
Re: CommandCounterIncrement  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-hackers
Denis Perchine <dyp@perchine.com> writes:
> Small technical question: what exactly CommandCounterIncrement do?

It increments the command counter ;-)

> And what exactly it should be used for?

You need it if, within a chunk of backend code, you want subsequent
queries to see the results of earlier queries.  Ordinarily a query
cannot see its own output --- else a command likeUPDATE foo SET x = x + 1
for example, would be an infinite loop, since as it scans the table
it would find the tuples it inserted, update them, insert the updated
copies, ...

Postgres' solution is that tuples inserted by the current transaction
AND current command ID are not visible.  So, to make them visible
without starting a new transaction, increment the command counter.

> I ask this question because I found out that when I run postgres with 
> verbose=4 I see lot's of StartTransactionCommand & CommitTransactionCommand
> pair in the place where BLOB is written. And I have a feeling that something 
> is wrong. Looks like explicitly commit all changes. That's really bad...

These do not commit anything, assuming you are inside a transaction
block.  Offhand I don't think they will amount to much more than a
CommandCounterIncrement() call in that case, but read xact.c if you want
to learn more.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Transaction costs?
Next
From: Denis Perchine
Date:
Subject: Re: CommandCounterIncrement