MY PLATFORM:
PHP & mySQL
MY SITUATION:
I came across a situation where I need to store a value for user selection in one of my columns of a table. Now my options would be to:
- Either declare the Column as char(1) and store the value as 'y' or 'n'
- Or declare the Column as tinyint(1) and store the value as 1 or 0
- This column so declared, may also be indexed for use within the application.
MY QUESTIONS:
So I wanted to know, which of the above two types:
Leads to faster query speed when that column is accessed (for the sake of simplicity, let's leave out mixing other queries or accessing other columns, please).
Is the most efficient way of storing and accessing data and why?
How does the access speed vary if the columns are indexed and when they are not?
My understanding is that since char(1) and tinyint(1) take up only 1 byte space, storage space will not be an issue in this case. Then what would remain is the access speed. As far as I know, numeric indexing is faster and more efficient than anything else. But the case here is tough one to decide, I think. Would definitely like to hear your experience on this one.
Thank you in advance.
enum('1','0')
(for example). – ExpeditionWHERE
clause and there's no index its going to have to do a full table scan regardless of the type. – Trichromatism