Skip to content

Commit 7335563

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 6a9b5a2 commit 7335563

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

46384638
case DTK_DOW:
46394639
case DTK_ISODOW:
4640-
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
4641-
ereport(ERROR,
4642-
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4643-
errmsg("timestamp out of range")));
46444640
result = j2day(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday));
46454641
if (val == DTK_ISODOW && result == 0)
46464642
result = 7;
46474643
break;
46484644

46494645
case DTK_DOY:
4650-
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
4651-
ereport(ERROR,
4652-
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4653-
errmsg("timestamp out of range")));
46544646
result = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday)
46554647
- date2j(tm->tm_year, 1, 1) + 1);
46564648
break;
@@ -4841,20 +4833,12 @@ timestamptz_part(PG_FUNCTION_ARGS)
48414833

48424834
case DTK_DOW:
48434835
case DTK_ISODOW:
4844-
if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
4845-
ereport(ERROR,
4846-
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4847-
errmsg("timestamp out of range")));
48484836
result = j2day(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday));
48494837
if (val == DTK_ISODOW && result == 0)
48504838
result = 7;
48514839
break;
48524840

48534841
case DTK_DOY:
4854-
if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
4855-
ereport(ERROR,
4856-
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4857-
errmsg("timestamp out of range")));
48584842
result = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday)
48594843
- date2j(tm->tm_year, 1, 1) + 1);
48604844
break;

0 commit comments

Comments
 (0)