Description\n-----------\n\nThis article explains the UPDATE statement's _Using Buffer_ algorithm.\n\nConsider the following table and query:\n\n| Name      | Salary |\n| --------- | ------ |\n| Babatunde | 1000   |\n| Jolana    | 1050   |\n| Pankaja   | 1300   |\n\n``sql\nUPDATE employees SET salary = salary+100 WHERE salary < 2000;\n`\n\nSuppose the _employees_ table has an index on the _salary_ column, and the optimizer decides to use a range scan on that index.\n\nThe optimizer starts a range scan on the _salary_ index. We find the first record _Babatunde, 1000_. If we do an on-the-fly update, we immediately instruct the storage engine to change this record to be _Babatunde, 1000+100=1100_.\n\nThen we proceed to search for the next record, and find _Jolana, 1050_. We instruct the storage engine to update it to be _Jolana, 1050+100=1150_.\n\nThen we proceed to search for the next record ... and what happens next depends on the storage engine. In some storage engines, data changes are visible immediately, so we will find the _Babatunde, 1100_ record that we wrote at the first step, modifying it again, giving Babatunde an undeserved raise. Then we will see Babatunde again and again, looping continually.\n\nIn order to prevent such situations, the optimizer checks whether the UPDATE statement is going to change key values for the keys it is using. In that case, it will use a different algorithm:\n\n1. Scan everyone with "salary<2000", remembering the rowids of the rows in a buffer.\n2. Read the buffer and apply the updates.\n\nThis way, each row will be updated only once.\n\nThe Using buffer` EXPLAIN output indicates that the buffer as described above will be used.\n\nURL: https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/analyze-and-explain-statements/using-buffer-update-algorithm