Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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?

share|improve this question
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! –  All 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

1 Answer 1

up vote 7 down vote accepted

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

share|improve this answer
    
Thanks for explicit and informative answer! –  All Mar 27 '12 at 17:33
    
I mainly keep it in the same order for consistency. Copy/paste FTW! –  DForck42 Mar 28 '12 at 5:27
    
@DForck42: agree. Also see my tip here: stackoverflow.com/a/729221/27535 –  gbn Mar 28 '12 at 5:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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