Skip to content

Commit f3cf330

Browse files
committed
Remove redundant function calls in timestamp[tz]_part().
The DTK_DOW/DTK_ISODOW and DTK_DOY switch cases in timestamp_part() and timestamptz_part() contained calls of timestamp2tm() that were fully redundant with the ones done just above the switch. This evidently crept in during commit 258ee1b, which relocated that code from another place where the calls were indeed needed. Just delete the redundant calls. I (tgl) noted that our test coverage of these functions left quite a bit to be desired, so extend timestamp.sql and timestamptz.sql to cover all the branches. Back-patch to all supported branches, as the previous commit was. There's no real issue here other than some wasted cycles in some not-too-heavily-used code paths, but the test coverage seems valuable. Report and patch by Li Japin; test case adjustments by me. Discussion: https://postgr.es/m/SG2PR06MB37762CAE45DB0F6CA7001EA9B6550@SG2PR06MB3776.apcprd06.prod.outlook.com
1 parent eecc150 commit f3cf330

File tree

5 files changed

+693
-395
lines changed

5 files changed

+693
-395
lines changed

src/backend/utils/adt/timestamp.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4403,20 +4403,12 @@ timestamp_part(PG_FUNCTION_ARGS)
44034403

44044404
case DTK_DOW:
44054405
case DTK_ISODOW:
4406-
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
4407-
ereport(ERROR,
4408-
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4409-
errmsg("timestamp out of range")));
44104406
result = j2day(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday));
44114407
if (val == DTK_ISODOW && result == 0)
44124408
result = 7;
44134409
break;
44144410

44154411
case DTK_DOY:
4416-
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
4417-
ereport(ERROR,
4418-
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4419-
errmsg("timestamp out of range")));
44204412
result = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday)
44214413
- date2j(tm->tm_year, 1, 1) + 1);
44224414
break;
@@ -4607,20 +4599,12 @@ timestamptz_part(PG_FUNCTION_ARGS)
46074599

46084600
case DTK_DOW:
46094601
case DTK_ISODOW:
4610-
if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
4611-
ereport(ERROR,
4612-
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4613-
errmsg("timestamp out of range")));
46144602
result = j2day(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday));
46154603
if (val == DTK_ISODOW && result == 0)
46164604
result = 7;
46174605
break;
46184606

46194607
case DTK_DOY:
4620-
if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
4621-
ereport(ERROR,
4622-
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4623-
errmsg("timestamp out of range")));
46244608
result = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday)
46254609
- date2j(tm->tm_year, 1, 1) + 1);
46264610
break;

0 commit comments

Comments
 (0)