MySQL Forums
Forum List  »  InnoDB

Re: mysql online ddl still lock
Posted by: Rick James
Date: May 24, 2016 09:53AM

Tables and INDEXes in InnoDB are stored in BTree structures.

INSERTs... When a block in a BTree must be split, 1 full block becomes 2 half-full blocks. Those blocks then fill up as you insert more rows. This gradually leads to the BTree being about 69% full.

DELETEs... InnoDB combines adjacent blocks that are less than half full.

A "point query" (SELECT ... WHERE primary_key = constant) is very efficient -- For a million-row table the BTree will be about 3 levels deep. The query will drill down those three blocks in the BTree. For a trillion-row table, it is about 6 levels. The number of levels rarely changes. That is, whether the table is fully defragmented or only 69% full, the number of levels is likely to be the same.

A "range query" (SELECT ... WHERE primary_key BETWEEN 123 AND 456) will do a point query to 123, then scan forward through the block(s) until the 456. True, if it is 100% full, it will need fewer blocks than if it is 69% full. But this has zero impact all the necessary blocks are cached.

MVCC -- "Multi version concurrency control" -- If you have two connections doing transactions that touch the same rows, InnoDB will (in certain circumstances) hang onto old records until a transaction finishes. That is, there can be "multiple versions" of a single row for a brief period of time. That can cause block splits that you don't expect.

But what about "Data_free" (from SHOW TABLE STATUS and `information_schema`)? It shows one of several types of "free" space. It does not show the "69%". There is not good way to measure the free space.

Do you want to defragment after every query? The cost of that is quite unreasonable. Don't bother doing OPTIMIZE -- ever.

Options: ReplyQuote


Subject
Views
Written By
Posted
2394
February 19, 2016 02:35AM
1515
February 19, 2016 03:09AM
1418
February 19, 2016 06:53AM
1420
February 20, 2016 01:38AM
1139
August 24, 2016 03:48AM
1015
August 25, 2016 07:40PM
1165
August 30, 2016 09:33PM
1130
September 01, 2016 04:55PM
1073
September 01, 2016 11:40PM
1077
September 03, 2016 05:05PM
1068
September 05, 2016 01:20AM
1080
September 05, 2016 03:54PM
952
September 08, 2016 04:04AM
1028
September 10, 2016 12:19AM
1321
February 23, 2016 11:29PM
1673
February 29, 2016 11:32PM
1524
March 05, 2016 12:19AM
1438
March 07, 2016 03:34AM
1413
March 31, 2016 02:32AM
1374
April 02, 2016 12:39AM
1383
May 13, 2016 02:44AM
Re: mysql online ddl still lock
1299
May 24, 2016 09:53AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.