Open
Bug 296668
Opened 19 years ago
Updated 14 years ago
[PostgreSQL] Comparisons of times to interval math can cause a table scan (NOW should be LOCALTIMESTAMP)
Categories
(Bugzilla :: Database, defect, P2)
Tracking
()
NEW
People
(Reporter: mkanat, Unassigned)
References
(Depends on 1 open bug)
Details
(Keywords: perf, Whiteboard: [blocker will fix])
At least in PostgreSQL 7.4, if you do something like this: WHERE delta_ts > (NOW() - INTERVAL '2 HOURS') You'll get a table scan on the bugs table, even though there's an index on delta_ts. This is because delta_ts is a TIMESTAMP WITHOUT TIME ZONE (the PostgreSQL default) and (NOW() - INTERVAL '2 HOURS') is automatically CAST'ed to TIMESTAMP WITH TIME ZONE.
Reporter | ||
Comment 1•19 years ago
|
||
In Pg, at least, the problem is that NOW() is a TIMESTAMP WITH TIME ZONE. Apparently the ANSI-standard way to solve this is to use LOCALTIMESTAMP instead of NOW(), but that doesn't seem to exist in MySQL, at least in the MySQL 3 installation that I tested.
Reporter | ||
Comment 2•19 years ago
|
||
The actual solution to this is to use "LOCALTIMESTAMP" instead of "NOW()" everywhere. In actual fact, "LOCALTIMESTAMP" is ANSI-standard where NOW() is DB-specific (even though almost every DB supports "NOW().") MySQL 4 supports LOCALTIMESTAMP starting from 4.0.6.
Depends on: 204217
Comment 3•19 years ago
|
||
I think we had also agreed to drop support for mysql3 after 2.22 ISTM 2.22 should still support mysql3/4 and contain experimental support for Pg 2.24 should require mysql4 (probably 4.0.something) and support mysql5 and Pg
Reporter | ||
Comment 4•19 years ago
|
||
(In reply to comment #3) > I think we had also agreed to drop support for mysql3 after 2.22 > ISTM 2.22 should still support mysql3/4 and contain experimental support for Pg > 2.24 should require mysql4 (probably 4.0.something) and support mysql5 and Pg No, 2.22 requires MySQL 4.
Summary: PostgreSQL: Comparisons of times to interval math can cause a table scan → [PostgreSQL] Comparisons of times to interval math can cause a table scan
Comment 5•19 years ago
|
||
Better still. Let's just make sure it is > 4.0.6
Comment 6•19 years ago
|
||
2.21 requires MySQL >= 4.0.14, see bug 204217. MySQL docs indeed say >= 4.0.6 is needed for localtimestamp.
Reporter | ||
Comment 7•19 years ago
|
||
Lance: Does LOCALTIMESTAMP also work in Oracle 9?
Comment 8•19 years ago
|
||
(In reply to comment #7) > Lance: Does LOCALTIMESTAMP also work in Oracle 9? Yes, LOCALTIMESTAMP is supported natively in Oracle 10g. (I'm not sure if it was in Oracle 9i, but Bugzilla requires Oracle 10g anyway since 9i didn't have native support for regular expressions.) In fact, NOW() doesn't even normally exist in Oracle (it has SYSDATE instead), so I had written a private function in the Bugzilla schema which simply returned SYSDATE. If we stop using NOW(), I can drop that private function.
![]() |
||
Comment 9•16 years ago
|
||
Any traction on this bug?
Reporter | ||
Updated•16 years ago
|
Summary: [PostgreSQL] Comparisons of times to interval math can cause a table scan → [PostgreSQL] Comparisons of times to interval math can cause a table scan (NOW should be LOCALTIMESTAMP)
Comment 11•16 years ago
|
||
This can be viewed as a standardization thing, so maybe the PostgreSQL flag should be dropped.
Comment 12•15 years ago
|
||
LOCALTIMESTAMP does not exist as a function in MSSQL, so even if the other DBs support it, MSSQL will still need the ability to override it.
Comment 13•14 years ago
|
||
Max see bug 602926, essentially of a duplicate of this issue but suggests CURRENT_TIMESTAMP might be a better substitution.
![]() |
||
Comment 14•14 years ago
|
||
It's not a duplicate. The other bug doesn't worry about doing a table scan or not. But one bug may fix the other one.
You need to log in
before you can comment on or make changes to this bug.
Description
•