Greg Sabino Mullane <htamfids@gmail.com> writes:
> All we can guarantee
> via pg_stat_activity is that if xact_start and query_start *are* identical,
> no snapshot has been granted yet,
Surely that's not true either. xact_start = query_start implies that
the current statement is the first in its transaction (assuming
sufficiently fine-grained clock timestamps, something I'm not sure is
an entirely safe assumption). But if that statement is not simply
a BEGIN, it's likely obtained its own transaction snapshot after a
few microseconds.
As long as "read the system clock" is a distinct operation from
"read a snapshot", there are going to be skew issues here. We
could maybe eliminate that by reading the clock while holding the
lock that prevents commits while reading a snapshot, but I doubt
that anybody is going to accept that on performance grounds.
Adding a not-guaranteed-cheap syscall inside that extremely hot
code path seems unsatisfactory.
Also, we currently do guarantee that xact_start matches query_start
for the first statement of the transaction (the converse of what
I said above). Removing that guarantee in order to add some other
one wouldn't necessarily please everybody.
regards, tom lane