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

Posts: 325
Name: Stuart
Location: Glasgow, Scotland
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
 
Sponsored Links (We share ad revenue):
 
Old 04-29-2008, 11:09 AM Re: Should be 'date' be normalised?
VirtuosiMedia's Avatar
Ultra Talker

Latest Blog Post:
Web Development Business Tips
Posts: 390
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, 11:28 AM Re: Should be 'date' be normalised?
tripy's Avatar
Fetchez la vache!

Latest Blog Post:
Pretty pretty please….
Posts: 1,689
Name: Thierry
Location: In the void
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.
__________________
Listen to the ducky: "This is awesome!!!"


Last edited by tripy : 04-29-2008 at 11:40 AM.
tripy is online now
Reply With Quote
View Public Profile
 
Old 04-29-2008, 12:00 PM Re: Should be 'date' be normalised?
stoot98's Avatar
Ultra Talker

Posts: 325
Name: Stuart
Location: Glasgow, Scotland
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, 05:00 PM Re: Should be 'date' be normalised?
Learning Newbie's Avatar
Moderator

Latest Blog Post:
My Favorite Isaac Asimov Story
Posts: 4,068
Name: John Alexander
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.
__________________
HungarianNotation is the last resort of scoundrels. Why not the first resort? That's where it counts!
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 04-29-2008, 05:14 PM Re: Should be 'date' be normalised?
Learning Newbie's Avatar
Moderator

Latest Blog Post:
My Favorite Isaac Asimov Story
Posts: 4,068
Name: John Alexander
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.
__________________
HungarianNotation is the last resort of scoundrels. Why not the first resort? That's where it counts!
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Sponsored Links (We share ad revenue):
 
Reply     « Reply to Should be 'date' be normalised?
 

Thread Tools

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

vB 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.17806 seconds with 14 queries