views:

26

answers:

1

Do you know which table srtucture is better :

table user  
id  INT pk autoincrement  
name VARCHAR(255)  
email VARCHAR(255)  
statut TINYINT(4) 

The statut can only hold 2 states : 1/2

OR

table user  
id  INT pk autoincrement  
name VARCHAR(255)  
email VARCHAR(255)   
statut VARCHAR(45) 

The statut can only hold 2 states : active/inactive

I'm looking for the fastest way to do select statements such as

SELECT id, name, email   
FROM user  
WHERE statut=:statut

I read somewhere that "integer" types are generally processed faster than "text" types but for some other reasons I would prefer to store the statut with the VARCHAR type.
Is there a way to use statut with VARCHAR type AND that it runs faster ?
Or is the first structure definitively the fastest ?

+2  A: 

You could use ENUM if you're absolutely sure that you'll only ever need to store 2 values in that column. Combines the user-friendliness of text with the performance and space-efficiency of integers.

kijin
thank you, exactly what I was looking for !
ling
You'd also be damn sure you never migrate to another DBMS as ENUM isn't standard SQL AFAIK. Of course there's always some changes required when migrating, but I'd rather minimize the amount of needed work than maximize it.
pkauko
oops. Well thank you for this precision.
ling
@pkauko Haha yeah, I was assuming MySQL. If it were something like Postgres, I would have suggested `bool` for only two possible values!
kijin