Search code examples
mysqlreliability

MySQL table read order reliability


Is it safe to assume when reading a MySQL table line by line from an application that the table will always read from top to bottom, one after the other in perfect sequential order.

E.G. If a table is ordered by a unique ID and I read it in via C++ one line at a time. Is it safe to assume I will get each line in exact unique ID order every time.

My gut feeling is that it is not a safe assumption but I have no technical reasoning for that.

My testing has always shown that it does provide table rows in order but it makes me nervous relying on it. As a result I write programs such that they do not depend on this assumption which makes them a little more complicated and a little less efficient.

Thanks C


Solution

  • If you are using the standard C++ MySQL connector, then according to the reference manual, "The preview version does buffer all result sets on the client to support cursors".

    It has also generally been my experience that your result sets are buffered, and therefore do not change when the underlying table changes.