A little tweak to the code.
GetTopTransactionIdIfAny() != InvalidTransactionId
changed to
TransactionIdIsValid(GetTopTransactionIdIfAny()
On 2024/1/12 08:51, jian he wrote:
> Hi
...
> with patch:
> src3=# explain(analyze, costs off) select 1 from pg_sleep(10);
> 2024-01-12 08:43:14.750 CST [5739] jian(at)src3/psql XID:0 LOG:
> duration: 10010.167 ms plan:
> Query Text: explain(analyze, costs off) select 1 from pg_sleep(10);
> Function Scan on pg_sleep (cost=0.00..0.01 rows=1 width=4)
> (actual time=10010.155..10010.159 rows=1 loops=1)
> 2024-01-12 08:43:14.750 CST [5739] jian(at)src3/psql XID:0 LOG:
> statement: explain(analyze, costs off) select 1 from pg_sleep(10);
> QUERY PLAN
> -----------------------------------------------------------------------------
> Function Scan on pg_sleep (actual time=10010.155..10010.159 rows=1 loops=1)
> Planning Time: 0.115 ms
> Execution Time: 10010.227 ms
> (3 rows)
This problem does exist in a statement that takes a long time to run.
XID is applied only for the first change tuple. If the user want to see
it in a single statement log, they have to wait until the statement has
finished executing. And we don't know how long it will take until the
statement ends. It is not appropriate to output the log twice because of
xid. Besides, without parsing log_line_prefix we don't know if the user
wants to see xid.