Thursday 15 August 2013

php - Will specifying a SUBTIME interval in MYSQL prevent the query from unnecessarily going through the entire table? -



php - Will specifying a SUBTIME interval in MYSQL prevent the query from unnecessarily going through the entire table? -

please tell me, if specify interval such: subtime(now(), interval 1 day) within mysql select query while having proper datetime column utilize reference - prevent query through entire table (over 100,000 records in case) each time runs rather through records made past 24 hours? desc order needed datetime table or such? also, if have sum(column) in query, run interval specified?

edit: if utilize above mentioned sum sum column there integers of value "1" - improve check how many rows select query returns mysql_num_rows - more efficient in combination time interval setting?

thank you!

it in fact prevent mysql go through whole table not if subtime() in select-part. instead have this:

select * mytable mydatecol between date_sub(now(), interval 1 day) , now()

the query select rows 1 day old. add together b-tree index on mydatecol speed things up:

alter table mytable add together index myidx using btree (mydatecol)

see mysql doc on topic

php mysql sql

No comments:

Post a Comment