Thread: [BUGS] BUG #14838: clock_timestamp() returns same values for each row

[BUGS] BUG #14838: clock_timestamp() returns same values for each row

From
zam6ak@gmail.com
Date:
The following bug has been logged on the website:

Bug reference:      14838
Logged by:          zam zam
Email address:      zam6ak@gmail.com
PostgreSQL version: 10rc1
Operating system:   Windows 10
Description:

Hello

We use clock_timestamp() function in our code and I have noticed that in PG
10 RC1 it returns same values across rows...

Here is the output from 9.6 compare to 10rc1

select version();
-- "PostgreSQL 9.6.3, compiled by Visual C++ build 1800, 64-bit"

select clock_timestamp() from generate_series(1,10)
-- "clock_timestamp"
-- "2017-09-29 09:39:34.820954-04"
-- "2017-09-29 09:39:34.820977-04"
-- "2017-09-29 09:39:34.820979-04"
-- "2017-09-29 09:39:34.820981-04"
-- "2017-09-29 09:39:34.820982-04"
-- "2017-09-29 09:39:34.820983-04"
-- "2017-09-29 09:39:34.820984-04"
-- "2017-09-29 09:39:34.820986-04"
-- "2017-09-29 09:39:34.820987-04"
-- "2017-09-29 09:39:34.820988-04"



select version();
-- "PostgreSQL 10rc1 on x86_64-pc-mingw64, compiled by gcc.exe (Rev5, Built
by MSYS2 project) 4.9.2, 64-bit"

select clock_timestamp() from generate_series(1,10)
-- "clock_timestamp"
-- "2017-09-29 09:38:45.779869-04"
-- "2017-09-29 09:38:45.779869-04"
-- "2017-09-29 09:38:45.779869-04"
-- "2017-09-29 09:38:45.779869-04"
-- "2017-09-29 09:38:45.779869-04"
-- "2017-09-29 09:38:45.779869-04"
-- "2017-09-29 09:38:45.779869-04"
-- "2017-09-29 09:38:45.779869-04"
-- "2017-09-29 09:38:45.779869-04"
-- "2017-09-29 09:38:45.779869-04"






--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Re: [BUGS] BUG #14838: clock_timestamp() returns same values for each row

From
Jeff Janes
Date:
On Fri, Sep 29, 2017 at 6:43 AM, <zam6ak@gmail.com> wrote:
The following bug has been logged on the website:

Bug reference:      14838
Logged by:          zam zam
Email address:      zam6ak@gmail.com
PostgreSQL version: 10rc1
Operating system:   Windows 10
Description:

Hello

We use clock_timestamp() function in our code and I have noticed that in PG
10 RC1 it returns same values across rows...

Here is the output from 9.6 compare to 10rc1

select version();
-- "PostgreSQL 9.6.3, compiled by Visual C++ build 1800, 64-bit"

-- "PostgreSQL 10rc1 on x86_64-pc-mingw64, compiled by gcc.exe (Rev5, Built
by MSYS2 project) 4.9.2, 64-bit"


Probably not an issue of the different versions, but rather different compilers (or maybe different hardware?).

I get the same behavior on these two versions:

PostgreSQL 9.6.5, compiled by Visual C++ build 1800, 64-bit
PostgreSQL 10rc1, compiled by Visual C++ build 1800, 64-bit

and that behavior is that the timestamp jumps 500 usec at a time, despite looking as if it might have usec granularity:



 2017-09-29 10:34:50.881312-07
 2017-09-29 10:34:50.881312-07
 2017-09-29 10:34:50.881312-07
 2017-09-29 10:34:50.881312-07
 2017-09-29 10:34:50.881312-07
 2017-09-29 10:34:50.881812-07  <-- see here and above
 2017-09-29 10:34:50.881812-07
 2017-09-29 10:34:50.881812-07
 2017-09-29 10:34:50.881812-07

You probably don't see the jump in your 2nd example because you didn't run enough rows to cross a 500 usec boundary.

Cheers,

Jeff

Re: [BUGS] BUG #14838: clock_timestamp() returns same values for each row

From
Tom Lane
Date:
Jeff Janes <jeff.janes@gmail.com> writes:
> On Fri, Sep 29, 2017 at 6:43 AM, <zam6ak@gmail.com> wrote:
>> We use clock_timestamp() function in our code and I have noticed that in PG
>> 10 RC1 it returns same values across rows...

> Probably not an issue of the different versions, but rather different
> compilers (or maybe different hardware?).

AFAICS, our code in this area (see src/port/gettimeofday.c) has not
changed since 9.5.  I'm suspicious of a platform change.

> I get the same behavior on these two versions:
> ...
> and that behavior is that the timestamp jumps 500 usec at a time, despite
> looking as if it might have usec granularity:

What gettimeofday.c does is to use GetSystemTimePreciseAsFileTime()
if it can get hold of that, otherwise fall back to
GetSystemTimeAsFileTime().  I don't see anything very specific in
Windows' documentation about the resolution to be expected from either
one, but I wonder if the OP's 9.6 installation is using the former
while for some reason his 10rc1 installation is using the latter.
        regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Re: [BUGS] BUG #14838: clock_timestamp() returns same values for each row

From
zambak zambak
Date:

On Fri, Sep 29, 2017 at 2:03 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Jeff Janes <jeff.janes@gmail.com> writes:
> On Fri, Sep 29, 2017 at 6:43 AM, <zam6ak@gmail.com> wrote:
>> We use clock_timestamp() function in our code and I have noticed that in PG
>> 10 RC1 it returns same values across rows...

> Probably not an issue of the different versions, but rather different
> compilers (or maybe different hardware?).

AFAICS, our code in this area (see src/port/gettimeofday.c) has not
changed since 9.5.  I'm suspicious of a platform change.

> I get the same behavior on these two versions:
> ...
> and that behavior is that the timestamp jumps 500 usec at a time, despite
> looking as if it might have usec granularity:

What gettimeofday.c does is to use GetSystemTimePreciseAsFileTime()
if it can get hold of that, otherwise fall back to
GetSystemTimeAsFileTime().  I don't see anything very specific in
Windows' documentation about the resolution to be expected from either
one, but I wonder if the OP's 9.6 installation is using the former
while for some reason his 10rc1 installation is using the latter.


Just for the record, both PG instances I tested this on are running on the same OS system in same VM, just different ports.
I also tried Windows Server 2012 (in VM) and am getting same issue.

 

                        regards, tom lane

Re: [BUGS] BUG #14838: clock_timestamp() returns same values for each row

From
Magnus Hagander
Date:


On Fri, Sep 29, 2017 at 8:03 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Jeff Janes <jeff.janes@gmail.com> writes:
> On Fri, Sep 29, 2017 at 6:43 AM, <zam6ak@gmail.com> wrote:
>> We use clock_timestamp() function in our code and I have noticed that in PG
>> 10 RC1 it returns same values across rows...

> Probably not an issue of the different versions, but rather different
> compilers (or maybe different hardware?).

AFAICS, our code in this area (see src/port/gettimeofday.c) has not
changed since 9.5.  I'm suspicious of a platform change.

> I get the same behavior on these two versions:
> ...
> and that behavior is that the timestamp jumps 500 usec at a time, despite
> looking as if it might have usec granularity:

What gettimeofday.c does is to use GetSystemTimePreciseAsFileTime()
if it can get hold of that, otherwise fall back to
GetSystemTimeAsFileTime().  I don't see anything very specific in
Windows' documentation about the resolution to be expected from either
one, but I wonder if the OP's 9.6 installation is using the former
while for some reason his 10rc1 installation is using the latter.

The documentatino for  GetSystemTimePreciseAsFileTime() specifically says "the current system date and time with the highest possible level of precision (<1us)". Which is not super specific, but certainly a lot lower than the 500us observed.

GetSystemTime() is AFAIK at millisecond level, I recall reading about 10ms.

--