Re: Error on pgbench logs - Mailing list pgsql-hackers

From Tatsuo Ishii
Subject Re: Error on pgbench logs
Date
Msg-id 20210614.094256.2022492290660299122.t-ishii@gmail.com
Whole thread Raw
In response to Re: Error on pgbench logs  (Fabien COELHO <coelho@cri.ensmp.fr>)
List pgsql-hackers
>> + while ((next = agg->start_time + agg_interval * INT64CONST(1000000))
>> <= now)
>>
>> I can find the similar code to convert "seconds" to "us" using casting
>> like
>>
>> end_time = threads[0].create_time + (int64) 1000000 * duration;
>>
>> or
>>
>> next_report = last_report + (int64) 1000000 * progress;
>>
>> Is there a reason use INT64CONST instead of (int64)? Do these imply
>> the same effect?
> 
> I guess that the macros does 1000000LL or something similar to
> directly create an int64 constant. It is necessary if the constant
> would overflow a usual 32 bits C integer, whereas the cast is
> sufficient if there is no overflow. Maybe I c/should have used the
> previous approach.

I think using INT64CONST to create a 64-bit constant is the standard
practice in PostgreSQL.

commit 9d6b160d7db76809f0c696d9073f6955dd5a973a
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date:   Fri Sep 1 15:14:18 2017 -0400

    Make [U]INT64CONST safe for use in #if conditions.
    
    Instead of using a cast to force the constant to be the right width,
    assume we can plaster on an L, UL, LL, or ULL suffix as appropriate.
    The old approach to this is very hoary, dating from before we were
    willing to require compilers to have working int64 types.
    
    This fix makes the PG_INT64_MIN, PG_INT64_MAX, and PG_UINT64_MAX
    constants safe to use in preprocessor conditions, where a cast
    doesn't work.  Other symbolic constants that might be defined using
    [U]INT64CONST are likewise safer than before.
    
    Also fix the SIZE_MAX macro to be similarly safe, if we are forced
    to provide a definition for that.  The test added in commit 2e70d6b5e
    happens to do what we want even with the hack "(size_t) -1" definition,
    but we could easily get burnt on other tests in future.
    
    Back-patch to all supported branches, like the previous commits.
    
    Discussion: https://postgr.es/m/15883.1504278595@sss.pgh.pa.us


Best regards,
--
Tatsuo Ishii
SRA OSS, Inc. Japan
English: http://www.sraoss.co.jp/index_en.php
Japanese:http://www.sraoss.co.jp



pgsql-hackers by date:

Previous
From: "kuroda.hayato@fujitsu.com"
Date:
Subject: RE: pgbench bug candidate: negative "initial connection time"
Next
From: Ranier Vilela
Date:
Subject: Re: Signed vs Unsigned (take 2) (src/backend/storage/ipc/procarray.c)