I have a MySQL db running MYISAM. I am processing a large amount of data with another program…the problem is it will not output the it with the key in numerical order.
Two questions…are there any performance losses with:
- Using data infile to load data where the primary key is in random order (but still numerical and unique)?
- Query that primary key?
It always seemed the primary key look up were faster than index look ups…I wasnt sure if that was bc the primary key was in often in numerical order.
In most databases that I know of, the order you “see” may not have anything to do with how the data is actually stored by the database system, so no, having your primary keys “in order” won’t do anything for you. It is likely that your database is storing them in some kind of optimized order already.
Now, as to your comment about indexes, a primary key is often an index as well. An index can improve performance, but it depends on many factors, such as size of the database, how much the data has changed, and so on. I’m not a dba, so I can’t give you a perfect answer. A numeric primary key, without any specific order, will be faster than a character-based primary key, because numbers can always be searched faster.