Search code examples
sqldatabaserelational-database

How do databases maintain results if another query edits those results


How do relational databases maintain your set of results if another query has edited those rows that you were working on?

For instance if I select 100k rows and while I am still fetching those another query does an update on a row that hasn't been read yet I will not see the update.


Solution

  • Please lookup Multi Version Concurrency Control. Different databases have different approaches to managing this. For MySQL, InnoDB, you can try http://dev.mysql.com/doc/refman/5.0/en/innodb-multi-versioning.html. PostgreSQL - https://wiki.postgresql.org/wiki/MVCC. A great presentation here - http://momjian.us/main/writings/pgsql/mvcc.pdf. It is explained in stackoverflow in this thread Database: What is Multiversion Concurrency Control (MVCC) and who supports it?