Afficher un message
Vieux 16/03/2008, 14h48   #1
Waynn Lue
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut PRIMARY KEY and CreationTime columns

Say I have this schema

CREATE TABLE temp (
EntityId BIGINT AUTO_INCREMENT PRIMARY KEY,
CreationTime DEFAULT NOW()
);

Now let's say I want to find all rows created within the last 24 hours. If I do

select * from temp where CreationTime > DATE_SUB(NOW(), INTERVAL 24 HOUR)

that's going to do a full table scan to find out, even though there's
already an implicit ordering in EntityId (this is of course assuming I
don't manually set CreationTime to something else). Is there any way
to take advantage of the fact that there's a primary key index on
entityId, or do I have to put a secondary index on CreationTime?

Thanks,
Waynn
  Réponse avec citation
 
Page generated in 0,04363 seconds with 9 queries