I already answered a question like this
Of the three methods to insert data you mentioned, I would easily choose method #3 : Random insert id: 1-10000. Why ?
Ascending or Descending Ordered Insertion into an index structure will generate root and node splits 45% of the time as I mentioned in my two earlier posts.
In contrast, the ordering does not matter when it comes to reloading of a table from a mysqldump
or upon the execution of a LOAD DATA INFILE
command. That's because of the use of sorting mechanisms after the completion of the data load of the table and the index creation can be performed.
For example, look at how a MyISAM table is reloaded.
- Data Pages for .MYD are populated
- Index Pages for .MYI are populated with unique keys in parallel with Data Page Reload
- Secondary Indexes are built by the internal execution of
Repair by sorting
In that instance, order does not matter.
Switching gears to SELECT ORDER BY
, performance could be nominally affected if needed keys from indexes are so split apart that multiple index pages must be accessed for ranges of data, this again leads me to choose method #3
. The lower the frequency of index page splits, the fewer pages need to be read by an ORDER BY
request.