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
1500
February 19, 2016 02:35AM
948
February 19, 2016 03:09AM
880
February 19, 2016 06:53AM
917
February 20, 2016 01:38AM
642
August 24, 2016 03:48AM
510
August 25, 2016 07:40PM
562
August 30, 2016 09:33PM
583
September 01, 2016 04:55PM
528
September 01, 2016 11:40PM
507
September 03, 2016 05:05PM
580
September 05, 2016 01:20AM
518
September 05, 2016 03:54PM
449
September 08, 2016 04:04AM
500
September 10, 2016 12:19AM
808
February 23, 2016 11:29PM
939
February 29, 2016 11:32PM
1030
March 05, 2016 12:19AM
900
March 07, 2016 03:34AM
892
March 31, 2016 02:32AM
788
April 02, 2016 12:39AM
622
May 13, 2016 02:44AM
Re: mysql online ddl still lock
581
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.