Skip to content

Commit 8b0fd6d

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 3ddd8ee commit 8b0fd6d

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
@@ -4560,20 +4560,12 @@ timestamp_part(PG_FUNCTION_ARGS)
45604560

45614561
case DTK_DOW:
45624562
case DTK_ISODOW:
4563-
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
4564-
ereport(ERROR,
4565-
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4566-
errmsg("timestamp out of range")));
45674563
result = j2day(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday));
45684564
if (val == DTK_ISODOW && result == 0)
45694565
result = 7;
45704566
break;
45714567

45724568
case DTK_DOY:
4573-
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
4574-
ereport(ERROR,
4575-
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4576-
errmsg("timestamp out of range")));
45774569
result = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday)
45784570
- date2j(tm->tm_year, 1, 1) + 1);
45794571
break;
@@ -4774,20 +4766,12 @@ timestamptz_part(PG_FUNCTION_ARGS)
47744766

47754767
case DTK_DOW:
47764768
case DTK_ISODOW:
4777-
if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
4778-
ereport(ERROR,
4779-
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4780-
errmsg("timestamp out of range")));
47814769
result = j2day(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday));
47824770
if (val == DTK_ISODOW && result == 0)
47834771
result = 7;
47844772
break;
47854773

47864774
case DTK_DOY:
4787-
if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
4788-
ereport(ERROR,
4789-
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4790-
errmsg("timestamp out of range")));
47914775
result = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday)
47924776
- date2j(tm->tm_year, 1, 1) + 1);
47934777
break;

0 commit comments

Comments
 (0)