Обсуждение: confusing comment in tqual.c

Поиск
Список
Период
Сортировка

confusing comment in tqual.c

От
Gregory Stark
Дата:

I'm reading the code in tqual.c and find that this comment doesn't seem to
match the code. CommandId always seems to be compared with >= or <= rather
than equality as the comment says.

I'm not even sure I have these operators right as the expression as written
here is in a few places the converse case that the code actually tests. It's
also pretty confusing.

I'm not so much submitting this patch to try to correct it as to verify my
understanding of the code.


*** tqual.c    14 Sep 2006 13:54:45 +0100    1.96
--- tqual.c    15 Sep 2006 15:50:41 +0100    
***************
*** 254,269 ****  * The satisfaction of "now" requires the following:  *  * ((Xmin == my-transaction &&
changedby the current transaction
 
!  *     Cmin != my-command &&                    but not by this command, and  *        (Xmax is null ||
        the row has not been deleted, or  *            (Xmax == my-transaction &&            it was deleted by the
currenttransaction
 
!  *             Cmax != my-command)))                but not by this command,  * ||
   or  *  *    (Xmin is committed &&                    the row was modified by a committed transaction, and  *
(Xmaxis null ||                    the row has not been deleted, or  *            (Xmax == my-transaction &&
therow is being deleted by this command, or
 
!  *             Cmax == my-command) ||  *            (Xmax is not committed &&            the row was deleted by
anothertransaction  *             Xmax != my-transaction))))            that has not been committed  *
 
--- 254,269 ----  * The satisfaction of "now" requires the following:  *  * ((Xmin == my-transaction &&
changedby the current transaction
 
!  *     Cmin < my-command &&                    by an earlier command than this scan, and  *        (Xmax is null ||
                    the row has not been deleted, or  *            (Xmax == my-transaction &&            it was deleted
bythe current transaction
 
!  *             Cmax >= my-command)))                but not by a command before this scan  * ||
                or  *  *    (Xmin is committed &&                    the row was modified by a committed transaction,
and *        (Xmax is null ||                    the row has not been deleted, or  *            (Xmax == my-transaction
&&           the row is being deleted by an earlier command
 
!  *             Cmax >= my-command) ||  *            (Xmax is not committed &&            the row was deleted by
anothertransaction  *             Xmax != my-transaction))))            that has not been committed  *
 


--  Gregory Stark EnterpriseDB          http://www.enterprisedb.com


Re: confusing comment in tqual.c

От
Tom Lane
Дата:
Gregory Stark <stark@enterprisedb.com> writes:
> I'm reading the code in tqual.c and find that this comment doesn't seem to
> match the code. CommandId always seems to be compared with >= or <= rather
> than equality as the comment says.

Yeah, you're right, the comment seems to be written on the assumption
that it's not possible to see cmin or cmax > curcid ... but that is
possible given sufficiently bizarre programming (eg, query fires a
function or trigger that updates the table again while outer query is
still scanning).  The actual rule for "now" is that a change made in the
current transaction is considered to have taken effect if its cmin or
cmax is strictly less than the current command's CID.

(Hmm ... actually, given the limited ways in which SnapshotNow is used,
I guess it's possible that indeed this can never happen.  The code is
made to be parallel to similar tests in SatisfiesSnapshot, which
definitely can see the sort of scenario mentioned above.)
        regards, tom lane