PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > mysql.general > PRIMARY KEY and CreationTime columns
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
PRIMARY KEY and CreationTime columns

Réponse
 
LinkBack Outils de la discussion
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
Vieux 16/03/2008, 17h12   #2
Rob Wultsch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: PRIMARY KEY and CreationTime columns

On Sun, Mar 16, 2008 at 5:48 AM, Waynn Lue <waynnlue@gmail.com> wrote:
> 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


First off you have not specified a data type for CreationTime . You
probably meant timestamp.

You need a second index on CreationTime.

--
Rob Wultsch
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h51.


Édité par : vBulletin® version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,07294 seconds with 10 queries