HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Does MySQL do UPDATE in place on NOT NULL column?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
updatecolumnnullplacemysqldoesnot

Problem

Assume I have a table like this in MySQL:

CREATE TABLE Foo (
Key INT NOT NULL
, MyCol INT NOT NULL
PRIMARY KEY (Key))


And I execute a statement like this on:

UPDATE Foo 
SET MyCol = 13
WHERE Key = 42


Will MySQL do an INSERT followed by DELETE of this row behind the scenes (and thus, potentially cause a page split) or can the UPDATE happen in place on the row?

Under which conditions do each of these situations happen?

Solution

I can confirm that the comment by ypercube above is correct :) Here are some additional details:

  • Updates occur in place, with the older version of the columns relocated to UNDO space. The UNDO is used for providing MVCC, but also in the event of a rollback. As InnoDB pages are initially written they are only 15/16ths filled, so there is some free space to reduce page splits.



  • Indexes contain all 'versions' of a column. This is required to be able to perform index-only-scans while still offering MVCC.



  • Exception to this rule is overflow text/blob pages, which are always freshly written and not updated in place.

Context

StackExchange Database Administrators Q#56880, answer score: 3

Revisions (0)

No revisions yet.