I have inherited the task of maintaining a very poorly coded e-commerce site, and I am working on refactoring a lot of code and trying to fix current errors.
Each database insert (adding an item to the cart, etc.) starts with the grab_new_id function, which counts the number of rows in the table, and then, starting from this number, queries the database to find the unused index number. In addition to being horrible in performance (there are already 40,000+ rows and indexes are regularly deleted, so it sometimes takes a few seconds to find a new identifier), this is interrupted regularly when two operations are performed at the same time, as two records are added with duplicate identifier numbers.
It seems idiotic to me - why not just use auto-increment in the index field? I tested it in both directions and added rows to the table without specifying an index identifier (obviously) many times faster. My question is: can anyone think of any reason that the original programmer could do? Is there some kind of school of thought where auto_increment is somehow considered a bad form? Are there databases that do not have the ability to grow automatically?
mysql auto-increment
goldenapples
source share