6

Do we experience a noticeable difference in performance for these two queries?

INSERT INTO table (col1, col2, col3, col4, col5) ...

and

INSERT INTO table (col5, col3, col1, col2, col4) ...

Do we need to arrange INSERT columns according to the order of columns in the table?

  • 3
    Are you suffering from premature optimization syndrome? – Denis Valeev Mar 27 '12 at 17:25
  • 1
    :D something like that! I'm just curious to learn! – Googlebot Mar 27 '12 at 17:27
  • 1
    Obviously the order in which the columns are specified doesn't affect performance. Because if you were the compiler you could just rehash the whole thing to represent it in its proper order which the compiler obviously does by matching names with the proper places on the data page. Things are a bit complex on the lower level so do you really think mysql guys messed up with this triviality? – Denis Valeev Mar 27 '12 at 17:32
10

No, you don't need to gave the columns in the same order. Not least, table order may not reflect actual on-disk order (this is 100% true for SQL Server, and I'm sure MySQL is the same)

Unless your OCD itch needs scratched

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.