Hello everybody!
I am not an expert of MySQL, and I have search a lot about the following problem without finding the solution.
So, I'm using a MySQL table with this structure:
CREATE TABLE photos (
file varchar(30) NOT NULL default "",
place tinytext NOT NULL default "",
description tinytext NOT NULL default "",
type char(1) NOT NULL default "",
taken year NOT NULL default "0000",
modified tinyint NOT NULL default 0,
PRIMARY KEY (file)
);
The first parameter is the relative path to a file. It is used as a primary key.
Currently, the rows are not sorted (which means that the order I observe in phpMyAdmin, by default, is the order in which the items were inserted in the table).
As 99% of the accesses to that table are SELECT (INSERT and UPDATE are rare in my program), I suppose that I should add an INDEX to the column 'file' (almost all the SELECT use only this column).
However, my question is "wouldn't it be more efficient to always store the rows by alphabetical order of 'file', instead of creating an index?" and so, "is it possible to inform MySQL that the data is sorted in that order and force it to keep that order when inserting elements in the table?".
I'm not sure my questions really make sense, because maybe this is just a particular case in which there is already a kind of index in the table... But I would really like to have an answer...
Thanks in advance!