If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Date index help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-06-08, 04:06
Ed_N Ed_N is offline
Registered User
 
Join Date: Feb 2008
Posts: 3
Date index help

Hi

I have a table with just 3 values: datetime_rx, datum_id, datum_value (for example). The datetime is a time stamp of the time when data is inserted and datum_id the identifier for the datum_value.

The searches are mainly done by date and later by datum_id within the selected days.

The DB works well but when reaching a few million rows, everythig strat to slow down a bit. I then added an index on datetime_rx as most of the date is first filtered by dates. This increased the speed considerably but with 7 million data entries, it takes a while to load first time the index (not to mention index is larger in size than the table itself).

How could I improve the performance of the index without having such a massive size index? is there anyway that the index can be limited only to the date and ditch the time values? Or would it make more sense to do a new colum with "date" only as 20080502 and then filter using this and re-filtering the results to find the hours I'm looking for?

I know this sounds very simple but I cannot figure out how to improve this...

Thanks

Ed
Reply With Quote
  #2 (permalink)  
Old 02-06-08, 04:07
Ed_N Ed_N is offline
Registered User
 
Join Date: Feb 2008
Posts: 3
Forgot to mention, I use PHP
Reply With Quote
  #3 (permalink)  
Old 02-06-08, 04:35
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
are you, your techies or your ISP worried about space?
does it matter what size the index is, if its required for the process?
how have you defined the datetime_rx, what data type is it?

i doubt the tabnle type will make much of a difference, but if you can it may be wirth using MyIsam as the data engine, unless of course you need the relational integrity required, in which case INNODB is the only choice.

as to whether you can ditch the datetime value I don't know, that surely is up to your application needs. Unless you have a very very good reason I wouldn't store a date value in anything other than a date datatype
Reply With Quote
  #4 (permalink)  
Old 02-06-08, 06:29
by0nder by0nder is offline
Registered User
 
Join Date: Jan 2008
Location: Kingdom of Sweden
Posts: 11
You can create the index like this:

CREATE INDEX idx_name ON table_name(datetime_rx(8));

This will create the index using the first 8 charachters.
Reply With Quote
  #5 (permalink)  
Old 02-06-08, 07:43
Ed_N Ed_N is offline
Registered User
 
Join Date: Feb 2008
Posts: 3
Thanks a lot for the help!

by0nder:
- That reduced the size of the index. I was using phpmyadmin and it didn't let me set the size of the index, your sql worked! Thanks

healdem:
- Regarding space, yes we were worried because the index was aproaching 100MB size and the server shares resources with other programs. At the rate we are inserting entries, the total volume of data is doubled every month so I was worried about the server running out of memmory to load the index before the query. Correct me if I'm wrong here?

- datetime_rx is "datetime" data type

- Not sure I understood well your comment about the DB type, we are using MyIsam, is INNODB faster?

Thanks

Ed
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On