| Based on my understanding of DB storage (which is decades old and as I write the comment my explanation seems stupid but it’s what I was taught. Please someone correct me). Image a table with the following: id (int), title (varchar), created_date (date) That data is stored in a similar order on disk (is this still true?). So, if the initial insert has a title of 10 characters, then the date will get placed after those 10 characters on disk: Int, 10 characters, date Later, the row is updated with a longer title of 500 characters. Because it’s longer, you now have to get more space for the title on another part of the disk. Since there are columns after the title, it’ll either leave dead space where the old 10 character title was or it’ll need to move those other columns too. I can’t remember which I was taught. I just remember that columns after variable columns get impacted when the data in a preceding variable column changes. If the title were at the end of the row, the db could expand the data without needing to move other columns over (if there happened to be available space right there). If you were updating with a shorter value, it could shorten the row by moving the terminating character to the new shorter location, freeing up the space the longer title was using. Bottom line is you want to keep variable columns which get updated most frequently towards the end of your table structure. Knowing which column that would be isn’t always clear when creating the table. Again, this understanding was taught to me over 20 years ago. I’m probably remembering parts of it wrong and DB storage has likely (hopefully) advanced since then. |
There should be no requirement for this. Columns in relations are not conceptually ordered, so it shouldn't matter for the things you're doing with the data anyway, and the database should be able to reorder the data in whatever way it likes, since desire to isolate the user from physical data structures was one of the main reasons for the rise of RDBMS.