October 31, 2006 at 2:26 pm
October 31, 2006 at 4:05 pm
I wouldn't consider doing this unless you have identified that your queries using these date functions have perf problems.
I have found that it's not a good idea to make assumptions about where perf problems lie - even the most experienced devs are almost always wrong about where the most time is spent in their code. the only way to find out is to measure, and for sql that means using profiler and showplan.
I would suggest testing your system under heavy load and finding the bottlenecks explicitly, rather than making changes in an a part of the code that's not known to have perf problems.
---------------------------------------
elsasoft.org
November 1, 2006 at 8:12 am
DATEADD and DATEDIFF functions have very good performance, as long as you stick to this way, you should be OK. Performance problems can be sometimes caused by excessive use of conversions (e.g. to varchar and back to datetime), especially if they are used in a way that forces scans instead of index seek.
For a range from-to, datetime data are very efficient (or "clean", as you said) and I don't see any reason to replace them with INT columns. On the contrary, I see so often on these forums questions of the type "how to do this if my date column is varchar/int instead of datetime" that I suppose doing what you said would only cause more problems. More often than not they end in "change the datatype to datetime or create another column with this datatype, then it will be easy". Stick to DATETIME datatype for all date and time entries.
If you are not thinking about performance, but about how simple the queries are for someone reading the code, then yes - "WHERE mytable.month = 3" is shorter than "WHERE mytable.date >= '20060301' AND mytable.date < '20060401' .." - but I don't think it will influence the performance. And maybe this particular query will be by 5% quicker, but some other will be by 20% slower. Everything depends on what you need to do with the data and how often, and how many rows are in the tables etc... But my opinion remains the same : don't do that, stick to datetime.
Think more about proper indexing than about nonstandard solutions. With a good index, queries are very fast with conditions on datetime columns. Choose the right column for clustered index, index all columns that need it, and you should be OK.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply