Re: Add support for AT LOCAL
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: Michael Paquier <michael@paquier.xyz>,
Vik Fearing <vik@postgresfriends.org>,
cary huang <hcary328@gmail.com>,
pgsql-hackers@lists.postgresql.org
Date: 2023-10-15T21:57:51Z
Lists: pgsql-hackers
Thomas Munro <thomas.munro@gmail.com> writes:
> One of the AIX animals gave a strange result here:
> https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=hornet&dt=2023-10-15%2011%3A40%3A01
> If you ignore the diffs due to change in column width, the interesting
> change seems to be:
> - 23:59:00-07 | 06:59:00+00 | 06:59:00+00 | 06:59:00+00
> - 23:59:59.99-07 | 06:59:59.99+00 | 06:59:59.99+00 | 06:59:59.99+00
> + 23:59:00-07 | 4294966103:4294967295:00+00 |
> 4294966103:4294967295:00+00 | 4294966103:4294967295:00+00
> + 23:59:59.99-07 | 4294966103:00:00.01+00 |
> 4294966103:00:00.01+00 | 4294966103:00:00.01+00
> But the other AIX animal 'sungazer' was OK with it. They're both on
> the same AIX7.1 host IIRC, both 64 bit builds, but the former is using
> xlc and the latter gcc. I don't immediately see what would cause that
> underflow on that old compiler but not elsewhere. I have a shell
> there (cfarm111) if someone has an idea...
Hmm. Seems like the error has to be creeping in during this part
of timetz_zone():
result->time = t->time + (t->zone - tz) * USECS_PER_SEC;
while (result->time < INT64CONST(0))
result->time += USECS_PER_DAY;
while (result->time >= USECS_PER_DAY)
result->time -= USECS_PER_DAY;
According to my machine, the initial computation of result->time
(for the '23:59:59.99-07' input) yields 111599990000, and then we
iterate the second loop once to get 25199990000, which is the right
answer. If I force a second iteration to get -61200010000, I get
# select '23:59:59.99-07'::timetz at local;
timezone
------------------------
4294967279:00:00.01+00
(1 row)
which doesn't quite match hornet's result but it seems
suggestively close.
Another line of thought is that while the time fields are int64,
t->zone and tz are only int32. Multiplying by the INT64CONST
USECS_PER_SEC ought to be enough to make the compiler widen
the subtraction result to int64, but maybe that's screwing up?
I'm tempted to wonder if this helps:
- result->time = t->time + (t->zone - tz) * USECS_PER_SEC;
+ result->time = t->time + (int64) (t->zone - tz) * USECS_PER_SEC;
Forcing the wrong thing to happen there doesn't produce a match
to hornet's result either, so I don't have a lot of hope for that
theory, but it seems like the explanation has to be somewhere here.
regards, tom lane
Commits
-
Dodge a compiler bug affecting timetz_zone/timetz_izone.
- f4f55d5124a9 13.13 landed
- e98f47d570a2 11.22 landed
- d8c2877b9efa 12.17 landed
- 85c9dda81887 14.10 landed
- 5463319acd19 15.5 landed
- 1ad3a7bd396a 16.1 landed
- 19fa977311b9 17.0 landed
-
Back-patch test cases for timetz_zone/timetz_izone.
- fdf8b70a51cf 13.13 landed
- dc159b95d921 14.10 landed
- b18781c2df44 12.17 landed
- 4a427b82cf19 16.1 landed
- 29231dbd40cb 15.5 landed
- 05b4614decac 11.22 landed
-
Add regression test coverage for timetz_izone().
- 2f047203074c 17.0 landed
-
Add support for AT LOCAL
- 97957fdbaa42 17.0 landed
-
doc: Mention timezone(zone, time) in section for AT TIME ZONE
- 7e1f544827ec 17.0 landed
-
Use HASH_BLOBS for xidhash.
- a1b8aa1e4eec 14.0 cited