Fixed patch for timestamp refactor effort

Поиск
Список
Период
Сортировка
Искать

Fixed patch for timestamp refactor effort

От:
Warren Turkal <turkal@google.com>
Дата:

Here is a fixed patch for the timestamp refactor. I apologize for sending the
wrong patch earlier.

I would like to get some comments on if this patch is heading in the right
direction. Here's the proposal for what I am doing:


Proposal for Refactoring of Timestamp Datatype


Goal:
The primary goal of this effort is to remove as many of the #ifdef tests for
HAVE_INT64_TIMESTAMP from timestamp.c[1] as possible. I have played with
PostgreSQL for many years and I look at this as an opportunity to give back to
the community.


Plan:
1. Replace datatypes selected by value of HAVE_INT64_TIMESTAMP with typedefs.  The typedefs will most likely be placed in timestamp.h[2].
2. Replace the places where the logic is determined by the value of  HAVE_INT64_TIMESTAMP with macros or function calls.


Further Investigation:
It may also be useful to investigate if PostgreSQL still needs two different
representations for timestamps (int64 or double).


[1]$(srcdir)/src/backend/utils/adt/timestamp.c
[2]$(srcdir)/src/include/utils/timestamp.h

Thanks,
wt

[PATCH] Add TimeOffset and DateOffset typedefs

От:
Warren Turkal <turkal@google.com>
Дата:
I added TimeOffset and DateOffset typedefs to get rid of the instances
using the HAVE_INT64_TIMESTAMP define being used to determine the
types of variables or functions in timestamp.c.
---src/backend/utils/adt/timestamp.c |   77 +++++++-----------------------------src/include/utils/timestamp.h     |    4 ++2 files changed, 19 insertions(+), 62 deletions(-)

diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index 2883caf..fcccf97 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -44,11 +44,7 @@TimestampTz PgStartTime;
-#ifdef HAVE_INT64_TIMESTAMP
-static int64 time2t(const int hour, const int min, const int sec, const fsec_t fsec);
-#else
-static double time2t(const int hour, const int min, const int sec, const fsec_t fsec);
-#endif
+static TimeOffset time2t(const int hour, const int min, const int sec, const fsec_t fsec);static int	EncodeSpecialTimestamp(Timestamp dt, char *str);static Timestamp dt2local(Timestamp dt, int timezone);static void AdjustTimestampForTypmod(Timestamp *time, int32 typmod);
@@ -977,11 +973,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)		}		else if (range == INTERVAL_MASK(MINUTE))		{
-#ifdef HAVE_INT64_TIMESTAMP
-			int64		hour;
-#else
-			double		hour;
-#endif
+			TimeOffset	hour;			interval->month = 0;			interval->day = 0;
@@ -998,11 +990,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)		}		else if (range == INTERVAL_MASK(SECOND))		{
-#ifdef HAVE_INT64_TIMESTAMP
-			int64		minute;
-#else
-			double		minute;
-#endif
+			TimeOffset	minute;			interval->month = 0;			interval->day = 0;
@@ -1076,11 +1064,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)		else if (range == (INTERVAL_MASK(MINUTE) |						   INTERVAL_MASK(SECOND)))		{
-#ifdef HAVE_INT64_TIMESTAMP
-			int64		hour;
-#else
-			double		hour;
-#endif
+			TimeOffset	hour;			interval->month = 0;			interval->day = 0;
@@ -1332,11 +1316,7 @@ timestamptz_to_str(TimestampTz t)voiddt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec){
-#ifdef HAVE_INT64_TIMESTAMP
-	int64		time;
-#else
-	double		time;
-#endif
+	TimeOffset	time;	time = jd;
@@ -1537,13 +1517,8 @@ recalc_t:inttm2timestamp(struct pg_tm * tm, fsec_t fsec, int *tzp, Timestamp *result){
-#ifdef HAVE_INT64_TIMESTAMP
-	int			date;
-	int64		time;
-#else
-	double		date,
-				time;
-#endif
+	DateOffset	date;
+	TimeOffset	time;	/* Julian day routines are not correct for negative Julian days */	if (!IS_VALID_JULIAN(tm->tm_year, tm->tm_mon, tm->tm_mday))
@@ -1586,13 +1561,8 @@ tm2timestamp(struct pg_tm * tm, fsec_t fsec, int *tzp, Timestamp *result)intinterval2tm(Interval span, struct pg_tm * tm, fsec_t *fsec){
-#ifdef HAVE_INT64_TIMESTAMP
-	int64		time;
-	int64		tfrac;
-#else
-	double		time;
-	double		tfrac;
-#endif
+	TimeOffset	time;
+	TimeOffset	tfrac;	tm->tm_year = span.month / MONTHS_PER_YEAR;	tm->tm_mon = span.month % MONTHS_PER_YEAR;
@@ -1648,19 +1618,15 @@ tm2interval(struct pg_tm * tm, fsec_t fsec, Interval *span)	return 0;}
-#ifdef HAVE_INT64_TIMESTAMP
-static int64
+static TimeOffsettime2t(const int hour, const int min, const int sec, const fsec_t fsec){
+#ifdef HAVE_INT64_TIMESTAMP	return (((((hour * MINS_PER_HOUR) + min) * SECS_PER_MINUTE) + sec) * USECS_PER_SEC) + fsec;
-}	/* time2t() */#else
-static double
-time2t(const int hour, const int min, const int sec, const fsec_t fsec)
-{	return (((hour * MINS_PER_HOUR) + min) * SECS_PER_MINUTE) + sec + fsec;
-}	/* time2t() */#endif
+}	/* time2t() */static Timestampdt2local(Timestamp dt, int tz)
@@ -2032,13 +1998,8 @@ timestamptz_cmp_timestamp(PG_FUNCTION_ARGS)static intinterval_cmp_internal(Interval *interval1, Interval *interval2){
-#ifdef HAVE_INT64_TIMESTAMP
-	int64		span1,
+	TimeOffset	span1,				span2;
-#else
-	double		span1,
-				span2;
-#endif	span1 = interval1->time;	span2 = interval2->time;
@@ -2378,11 +2339,7 @@ interval_justify_interval(PG_FUNCTION_ARGS)	Interval   *span = PG_GETARG_INTERVAL_P(0);	Interval   *result;
-#ifdef HAVE_INT64_TIMESTAMP
-	int64		wholeday;
-#else
-	double		wholeday;
-#endif
+	TimeOffset	wholeday;	int32		wholemonth;	result = (Interval *) palloc(sizeof(Interval));
@@ -2450,11 +2407,7 @@ interval_justify_hours(PG_FUNCTION_ARGS)	Interval   *span = PG_GETARG_INTERVAL_P(0);	Interval   *result;
-#ifdef HAVE_INT64_TIMESTAMP
-	int64		wholeday;
-#else
-	double		wholeday;
-#endif
+	TimeOffset	wholeday;	result = (Interval *) palloc(sizeof(Interval));	result->month = span->month;
diff --git a/src/include/utils/timestamp.h b/src/include/utils/timestamp.h
index 6eec76d..6a404a1 100644
--- a/src/include/utils/timestamp.h
+++ b/src/include/utils/timestamp.h
@@ -36,9 +36,13 @@#ifdef HAVE_INT64_TIMESTAMPtypedef int64 Timestamp;typedef int64 TimestampTz;
+typedef int64 TimeOffset;
+typedef int   DateOffset;#elsetypedef double Timestamp;typedef double TimestampTz;
+typedef double TimeOffset;
+typedef double DateOffset;#endiftypedef struct
-- 
1.5.2.5


FAQ