Use OS timestamp for computing if the current statement has taken more than
authorPavan Deolasee <[email protected]>
Tue, 18 Oct 2016 05:18:39 +0000 (10:48 +0530)
committerPavan Deolasee <[email protected]>
Tue, 18 Oct 2016 05:18:39 +0000 (10:48 +0530)
log_min_statement_duration for execution

Since we compare the statement start time with the one obtained by
GetCurrentTimestamp(), which returns OS time without any adjustments for clock
skew, it seems fair to use statement start time obtained by the same clock.

src/backend/access/transam/xact.c
src/backend/tcop/postgres.c
src/include/access/xact.h

index 2a14c3cc1b0ebe9f17989ba6e83e2a4a3aa51bc6..d2e9aea110636adcddccafe112f583b3ec28f324 100644 (file)
@@ -929,6 +929,16 @@ GetCurrentStatementStartTimestamp(void)
 #endif
 }
 
+#ifdef XCP
+/*
+ *     GetCurrentLocalStatementStartTimestamp
+ */
+TimestampTz
+GetCurrentLocalStatementStartTimestamp(void)
+{
+       return stmtStartTimestamp;
+}
+#endif
 /*
  *     GetCurrentTransactionStopTimestamp
  *
index 6e14fea97c4fd6c4e20d72c447e34d431d008440..0d6685963ec5d585529695affc4975c2080b69e8 100644 (file)
@@ -2539,7 +2539,11 @@ check_log_duration(char *msec_str, bool was_logged)
                int                     msecs;
                bool            exceeded;
 
-               TimestampDifference(GetCurrentStatementStartTimestamp(),
+               /*
+                * Since GetCurrentTimestamp() returns OS time, use local time for
+                * statement-start for accurate comparison
+                */
+               TimestampDifference(GetCurrentLocalStatementStartTimestamp(),
                                                        GetCurrentTimestamp(),
                                                        &secs, &usecs);
                msecs = usecs / 1000;
index 5181082f263d4940381e1174a6e5439103180148..a8133c73f7d69c18d9d8c8aa6c9858215c8245c4 100644 (file)
@@ -341,6 +341,9 @@ extern bool SubTransactionIsActive(SubTransactionId subxid);
 extern CommandId GetCurrentCommandId(bool used);
 extern TimestampTz GetCurrentTransactionStartTimestamp(void);
 extern TimestampTz GetCurrentStatementStartTimestamp(void);
+#ifdef XCP
+extern TimestampTz GetCurrentLocalStatementStartTimestamp(void);
+#endif
 extern TimestampTz GetCurrentTransactionStopTimestamp(void);
 extern void SetCurrentStatementStartTimestamp(void);
 #ifdef PGXC