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
2290
February 19, 2016 02:35AM
1472
February 19, 2016 03:09AM
1356
February 19, 2016 06:53AM
1382
February 20, 2016 01:38AM
1098
August 24, 2016 03:48AM
961
August 25, 2016 07:40PM
1114
August 30, 2016 09:33PM
1084
September 01, 2016 04:55PM
1036
September 01, 2016 11:40PM
1024
September 03, 2016 05:05PM
1032
September 05, 2016 01:20AM
1020
September 05, 2016 03:54PM
914
September 08, 2016 04:04AM
985
September 10, 2016 12:19AM
1283
February 23, 2016 11:29PM
1592
February 29, 2016 11:32PM
1491
March 05, 2016 12:19AM
1396
March 07, 2016 03:34AM
1380
March 31, 2016 02:32AM
1317
April 02, 2016 12:39AM
1327
May 13, 2016 02:44AM
Re: mysql online ddl still lock
1192
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.