Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Should be 'date' be normalised?
Old 04-29-2008, 11:47 AM Should be 'date' be normalised?
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
Hi guys,

I am creating a database for a university project and have a query about one aspect of normalisation.

I have a few tables that have a date as a field (news, guestbook entries etc). Is it good practice to separate this date into a new table called 'Date' and therefore have only have one instance of each date and a reference through foreign key to the relevant one?

I have never bothered in previous databases but now that i'm thinking through the normalisation process more rigidly ive come to think it may be the correct thing to do - at least theoretically.

Any thoughts are appreciated!

Cheers
Stoot
stoot98 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-29-2008, 12:09 PM Re: Should be 'date' be normalised?
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
I haven't been creating databases for a real long time, so take what I have to say with a grain of salt. Personally, I don't think I would normalize a date field, especially when you have the date applied to completely different types of data like news and guestbook entries. If you're using any sort of time stamp, it wouldn't make sense because no two entries would share the same date. As I understand normalization, the whole purpose is to optimize the database by cutting down on duplication. If no duplication occurs, however, you're just creating extra work for yourself.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 04-29-2008, 12:28 PM Re: Should be 'date' be normalised?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
If you're using any sort of time stamp, it wouldn't make sense because no two entries would share the same date.
Exactly. Usually, a timestamp store the time with a millisecond precision.
Putting those in a separate table with FK referencing them will add nothing but overhead.
Your "time" table will grow, and each time you will need to look up for that time, you will have to scan the indexes.

And a simple reminder: the more datas a table contains, the more time the indexes needs to be parsed. It can reache a state where a sequential read is faster than an index scan.
http://www.mysqlperformanceblog.com/...-where-column/
Quote:
The reason why index scan is slower than table scan is that in case of the index scan the MySQL needs to perform more operations like :
read index, get pointer to row, get data from row,
that adds overhead to the operations.
In case of table scan MySQL just goes trough the table and read all rows in continuous mode.
When count of scanned rows more than 20% (in our example) the overhead of index scan makes it non-effective.
In real queries the right percent of rows depends on many factors, but for random uniformly distributed values I would say it is in 20-30% interval.
It should not be the case if you normlalize your dates, because no entries would be similar, but still, many peoples don't realize that.
I learned it not so long ago myself.

In the case of a timestamp, I almost always find it to be relative to the information I write in my table, so I keep them together.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 04-29-2008 at 12:40 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 04-29-2008, 01:00 PM Re: Should be 'date' be normalised?
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
Thanks for the replies!

I agree with you both about the timestamping. I wasn't thinking of them in terms of timestamps when i made the post but just as simple dates (e.g. 01/01/2008) however, i think it would probably be beneficial to have them store a time and a date, so ill just leave them together.

Anyway, that saves me writing a bit about how i normalised the dates!

Cheers
Stoot
stoot98 is offline
Reply With Quote
View Public Profile
 
Old 04-29-2008, 06:00 PM Re: Should be 'date' be normalised?
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
I would normalize events, but not dates. If lots of things correspond to the same point in time, something important enough to earn a name, that makes sense to describe in terms of PK and FK relationships. Say an election, or a software release.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 04-29-2008, 06:14 PM Re: Should be 'date' be normalised?
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Quote:
Originally Posted by tripy View Post
Your "time" table will grow, and each time you will need to look up for that time, you will have to scan the indexes.
If you're seeing a lot of index scans in your query plans, something is wrong in the design. You should see mostly index seeks, otherwise your system isn't performing as well as it could, and needs more expensive hardware to support it than absolutely necessary.

Quote:
Originally Posted by tripy View Post
And a simple reminder: the more datas a table contains, the more time the indexes needs to be parsed. It can reache a state where a sequential read is faster than an index scan.
This is true. It isn't just tables growing to hold more data over time that causes this. Any time the cost of traversing the index is more than the benefit of using it, you have this sorry state of affairs.

Plus, every time you change data on a keyed field, the index(es) that reference it are updated as part of that transaction. So delete, insert, and update commands all slow down for the presence of an index. Unless, of course, the update benefits from being able to find the row(s) to change.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Should be 'date' be normalised?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.30952 seconds with 12 queries