SlideShare a Scribd company logo
Instant ADD COLUMN for
InnoDB in MariaDB 10.3+
On the way to instant ALTER TABLE for failure-free record
format changes
Valerii Kravchuk, Principal Support Engineer, MariaDB
vkravchuk@gmail.com
1
www.percona.com
Who am I?
Valerii (aka Valeriy) Kravchuk:
● MySQL Support Engineer in MySQL AB, Sun and Oracle, 2005 - 2012
● Principal Support Engineer in Percona, 2012 - 2016
● Principal Support Engineer in MariaDB Corporation since March 2016
● http://mysqlentomologist.blogspot.com - my blog about MySQL (a lot about
MySQL bugs, but some HowTos as well)
● https://www.facebook.com/valerii.kravchuk - my Facebook page, a lot about
MySQL (mostly bugs, rants and links to blog posts…)
● http://bugs.mysql.com - it used to be my personal playground
● @mysqlbugs - #bugoftheday on Twitter
● I like FOSDEM, see slides from my previous talks:
○ http://www.slideshare.net/valeriikravchuk1/fosdem2015-gdb-tips-and-tricks-for-my-sql-db-as
○ http://www.slideshare.net/ValeriyKravchuk/more-on-gdb-for-my-sql-db-as-fosdem-2016
○ https://www.slideshare.net/ValeriyKravchuk/applying-profilers-to-my-sql-fosdem-2017
2
www.percona.com
What is this session about?
● History of ALTER TABLE improvements in MySQL
● Problems with current “online” table rebuilds
● How instant ADD COLUMN for InnoDB appeared in
MariaDB
● Basic usage of instant ADD COLUMN, limitations
● Page changes for instant ADD COLUMN
● Some “benchmarks” (not sure if I have enough time…)
● Next steps on the way to instant ALTER TABLE for
failure-free InnoDB record format changes that may
happen in MariaDB 10.4+ (or not :)
3
www.percona.com
History of ALTER TABLE in MySQL/MariaDB
● The old way (also known as ALGORITHM=COPY starting with MySQL 5.6)
○ CREATE TABLE ...; INSERT … SELECT; RENAME TABLE ...; DROP TABLE ...;
○ Lots of unnecessary undo and redo logging in InnoDB ("bulk insert" would help)
● "Fast index creation" in InnoDB Plugin for MySQL 5.1 (built-in 5.5 InnoDB)
○ Supports ADD INDEX, ADD UNIQUE INDEX, ADD PRIMARY KEY (?)
● ALGORITHM=INPLACE starting with MySQL 5.6
○ Misleading name; some operations may rebuild the table
■ ADD/DROP COLUMN, ADD PRIMARY KEY, CHANGE ...[NOT] NULL
○ Some operations are instant: rename column, change DEFAULT value, …
■ Should have ALGORITHM=(INSTANT|NOCOPY) to avoid surprises (MDEV-13134)
○ Somewhat wrongly called "online" DDL:
■ Changes to data in table are still prevented for some time in the process. Bug #84004!
■ It still causes slaves lag (Bug #73196)
■ We all know it should be “more online”, see Bug #77097, Bug #68498, Bug #72109,
Bug #83557 etc
○ Online (LOCK=NONE) is sometimes refused:
■ ALTER TABLE … ADD (FULLTEXT|SPATIAL) INDEX, ALGORITHM=INPLACE;
■ Any table rebuild operation when FULLTEXT or SPATIAL indexes are present (see
Bug #81819)
4
www.percona.com
Problems with Online Table Rebuild
● MySQL 5.6+ includes “online” ALTER TABLE
([ADD|DROP] COLUMN etc.), with LOCK=NONE. Why
are tools like gh-ost or pt-osc still used?
○ Replication ignores LOCK=NONE: Slaves will only continue after
commit → huge lag
○ The online log needs to be buffered (in memory or temporary files)
■ The size depends on the concurrent DML workload; hard to predict!
○ The whole table (including all indexes) will have to be copied
■ MySQL 5.7 included some performance improvements to this, but huge I/O remains
○ Theoretically, do we really have to rebuild?
■ Only when introducing stricter constraints (shorter columns, add NOT NULL)
■ Even that could be done by validating the table and editing metadata
■ Only ADD [UNIQUE|PRIMARY|SPATIAL|FULLTEXT] KEY really require writes
5
www.percona.com
History of Instant ADD COLUMN for InnoDB
● Both Alibaba and Tencent have instant ADD in their MySQL 5.6 forks
○ Does not work with old data files; requires a new ROW_FORMAT
● MariaDB wants it to work on old (possibly large) files
○ Vin Chen from Tencent Game DBA Team wrote a prototype that adds
an optional record header to identify "afterwards added columns"
○ The ADD … DEFAULT values are stored in one place
○ Data dictionary only reflects the latest table definition, including the
latest DEFAULT
● Marko Mäkelä rewrote the prototype for MariaDB 10.3.2 (see MDEV-11369)
○ Store a 'default row' at the start of the table (we want to remove SYS_*
tables one day)
○ Support all but ROW_FORMAT=COMPRESSED
○ Crash-safe DDL (a new undo record type); simpler DML rollback;
"compression"
○ ensured that online table rebuild (e.g. DROP COLUMN) still works
6
www.percona.com
Basic Usage of Instant ADD COLUMN
● By default, ALTER TABLE … ADD COLUMN is instantaneous
○ Limitation: No hidden FTS_DOC_ID column (for FULLTEXT INDEX)
must exist
● Use the FORCE keyword for the old-fashioned ADD COLUMN, with the
old-fashioned (additional) limitations:
○ ALGORITHM=INPLACE will not work if multiple FULLTEXT indexes
exist
○ LOCK=NONE will not work if FULLTEXT or SPATIAL index exist
● To monitor the number of avoided table rebuilds:
SELECT variable_value
FROM information_schema.global_status
WHERE variable_name = 'innodb_instant_alter_column';
● See also
https://mariadb.com/resources/blog/instant-add-column-innodb
7
● No limitations on data types for added columns or
DEFAULT expression complexity:
CREATE TABLE t(id INT PRIMARY KEY, u INT UNIQUE)
ENGINE=InnoDB;
INSERT INTO t(id,u) VALUES(1,1),(2,2),(3,3);
ALTER TABLE t ADD COLUMN
(d DATETIME DEFAULT current_timestamp(),
t TEXT CHARSET utf8 DEFAULT 'The quick brown fox',
p POINT NOT NULL DEFAULT ST_GeomFromText('POINT(0 0)'));
UPDATE t SET t=NULL WHERE id=3;
SELECT * FROM t;
● No backward compatibility until rebuilt with FORCE
(ToDo: check this). See MDEV-13562 also.
www.percona.com
Example of Instant ADD COLUMN
8
www.percona.com
Page Changes for Instant ADD COLUMN
● Clustered index root page changes:
○ FIL_PAGE_TYPE_INSTANT indicates that instant operation was used
○ PAGE_INSTANT stores the original (smaller) number of clustered index
fields
● Change the leftmost clustered index leaf page:
○ After the infimum, store a "default" record with REC_INFO_MIN_REC_FLAG:
■ Must have the optional "added fields" header
■ The number of fields must match the current table definition
■ Values of "added fields" are the values of "missing fields"
● Clustered index contents from the previous example:
○ (default,id,u,d=2017-11-10 12:14:00,t='The quick brown fox',p=POINT(0 0)),
○ (1,1), (2,2), (3,3,2017-11-10 12:14:00, NULL)
○ We omit trailing fields that are equal to the fields in the "default" record
9
www.percona.com
MariaDB 10.4+: ADD… [FIRST|AFTER], DROP...
● Keep the user record format unchanged
○ Physically, keep doing ADD COLUMN last in the
clustered index records
○ DROP COLUMN will leave garbage in the records
○ Changing column order physically becomes a no-op
○ ADD COLUMN will be possible even if hidden
FTS_DOC_ID exists
● In the "default" record, store a mapping of table columns to
index fields, pass it somehow when needed
10
www.percona.com
MariaDB 10.4+: Instant CHANGE COLUMN?
● MySQL 5.7/MariaDB 10.2: Extend VARCHAR maximum size
○ Only if the physical format allows; not VARCHAR(255) to VARCHAR(256)
● We need something in the user data records to indicate physical format
○ "Format version number" that points to something in the "default" record?
● Format changes can only be instantaneous if they relax constraints:
○ Example: CHAR(1) to CHAR(2), INT to BIGINT or NOT NULL to NULL
○ Less likely: Changing POINT to GEOMETRY, changing latin1 to utf8
● Failure is an option, if we perform table scan to validate the data:
○ Example: Changing BIGINT NULL to INT UNSIGNED NOT NULL
● Affected secondary indexes must be rebuilt if the physical format changes
○ Still much faster than rebuilding the entire table; can be done online
● Follow MDEV-11424, “Instant ALTER TABLE of failure-free record format
changes”, if interested...
11
www.percona.com
Set of Statements to Do Lame “Benchmark”
See test_instant_alter.sql for more details:
create table t(id int auto_increment primary key, c1 int);
insert into t(c1) values (0);
-- repeat 19 times
insert into t(c1) select rand()*1000 from t; -- 0
select count(*) from t; -- 1
...
alter table t add column c2 char(200) default 'a'; -- 2
...
update t set c2 = 'b'; -- 3
update t set c2 = 'c'; -- 4
update t set c2 = 'd'; -- !!!
...
alter table t force; -- 5
update t set c2 = 'e'; -- 6
update t set c2 = 'f'; -- 7
12
It may be interesting to compare
times to execute 2 and 5, as well
as 3 and 4 to 6 and 7, also for
different engines (like MyRocks)
and versions (PS 5.7, 10.2, 10.3,
and, surely MySQL 8.0.4)
www.percona.com
Example of Instant ADD COLUMN for Benchmark
create table t(id int auto_increment primary key, c1 int);
insert into t(c1) values (0);
insert into t(c1) select rand()*1000 from t;
… continue that way until it’s big enough
MariaDB [test]> insert into t(c1) select rand()*1000 from t;
Query OK, 262144 rows affected ( 4.141 sec)
Records: 262144 Duplicates: 0 Warnings: 0
MariaDB [test]> alter table t add column c2 char(200) default
repeat('a',200);
Query OK, 0 rows affected ( 0.039 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [test]> update t set c2 = 'b';
Query OK, 524288 rows affected ( 55.682 sec)
Rows matched: 524288 Changed: 524288 Warnings: 0
MariaDB [test]> update t set c2 = 'c';
Query OK, 524288 rows affected ( 31.649 sec)
Rows matched: 524288 Changed: 524288 Warnings: 0
13
www.percona.com
Time to Run ALTER … ADD COLUMN (2)
● On my QuadCore Fedora 27 box, --no-defaults:
14
www.percona.com
Time to Run First UPDATE After ALTER (3)
● On my QuadCore Fedora 27 box, --no-defaults:
15
www.percona.com
Time to Run Entire “Benchmark” Script
● On my QuadCore Fedora 27 box, --no-defaults:
16
www.percona.com
Thanks and Links
● Thanks to Marko Mäkelä for his work, hints and slides on
this topic
● Thanks to LeFred and Belcona team for this event!
● Check MDEV-11369 for the details of original task in
MariaDB
● Check original blog post about the feature
● Check MDEV-11424 for further plans in MariaDB 10.4+ and
progress on them
● My blog post on current state of online DDL in MySQL 5.7
● Some test and raw benchmark results are shared here 17
www.percona.com
Thank you!
Questions and Answers?
Please, report bugs at:
https://bugs.mysql.com
https://jira.mariadb.org
https://jira.percona.com
18

More Related Content

What's hot

MariaDB Server on macOS - FOSDEM 2022 MariaDB Devroom
MariaDB Server on macOS -  FOSDEM 2022 MariaDB DevroomMariaDB Server on macOS -  FOSDEM 2022 MariaDB Devroom
MariaDB Server on macOS - FOSDEM 2022 MariaDB Devroom
Valeriy Kravchuk
 
MySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossukMySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossukValeriy Kravchuk
 
Flame Graphs for MySQL DBAs - FOSDEM 2022 MySQL Devroom
Flame Graphs for MySQL DBAs - FOSDEM 2022 MySQL DevroomFlame Graphs for MySQL DBAs - FOSDEM 2022 MySQL Devroom
Flame Graphs for MySQL DBAs - FOSDEM 2022 MySQL Devroom
Valeriy Kravchuk
 
Linux /proc filesystem for MySQL DBAs - FOSDEM 2021
Linux  /proc filesystem for MySQL DBAs - FOSDEM 2021Linux  /proc filesystem for MySQL DBAs - FOSDEM 2021
Linux /proc filesystem for MySQL DBAs - FOSDEM 2021
Valeriy Kravchuk
 
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB DevroomMore on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
Valeriy Kravchuk
 
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
Valeriy Kravchuk
 
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
Valeriy Kravchuk
 
The New MariaDB Offering - MariaDB 10, MaxScale and more
The New MariaDB Offering - MariaDB 10, MaxScale and moreThe New MariaDB Offering - MariaDB 10, MaxScale and more
The New MariaDB Offering - MariaDB 10, MaxScale and more
MariaDB Corporation
 
MySQL Indexierung CeBIT 2014
MySQL Indexierung CeBIT 2014MySQL Indexierung CeBIT 2014
MySQL Indexierung CeBIT 2014
FromDual GmbH
 
WiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-TreeWiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-Tree
Sveta Smirnova
 
Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)Antony T Curtis
 
Preparse Query Rewrite Plugins
Preparse Query Rewrite PluginsPreparse Query Rewrite Plugins
Preparse Query Rewrite Plugins
Sveta Smirnova
 
Developers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sad
Developers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sadDevelopers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sad
Developers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sad
mCloud
 
HA with Galera
HA with GaleraHA with Galera
HA with Galera
FromDual GmbH
 
The Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialThe Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication Tutorial
Jean-François Gagné
 
MySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsMySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitations
Jean-François Gagné
 
MySQL/MariaDB Parallel Replication: inventory, use-case and limitations
MySQL/MariaDB Parallel Replication: inventory, use-case and limitationsMySQL/MariaDB Parallel Replication: inventory, use-case and limitations
MySQL/MariaDB Parallel Replication: inventory, use-case and limitations
Jean-François Gagné
 
External Language Stored Procedures for MySQL
External Language Stored Procedures for MySQLExternal Language Stored Procedures for MySQL
External Language Stored Procedures for MySQLAntony T Curtis
 
Riding the Binlog: an in Deep Dissection of the Replication Stream
Riding the Binlog: an in Deep Dissection of the Replication StreamRiding the Binlog: an in Deep Dissection of the Replication Stream
Riding the Binlog: an in Deep Dissection of the Replication Stream
Jean-François Gagné
 
Using Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDBUsing Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDB
Antony T Curtis
 

What's hot (20)

MariaDB Server on macOS - FOSDEM 2022 MariaDB Devroom
MariaDB Server on macOS -  FOSDEM 2022 MariaDB DevroomMariaDB Server on macOS -  FOSDEM 2022 MariaDB Devroom
MariaDB Server on macOS - FOSDEM 2022 MariaDB Devroom
 
MySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossukMySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossuk
 
Flame Graphs for MySQL DBAs - FOSDEM 2022 MySQL Devroom
Flame Graphs for MySQL DBAs - FOSDEM 2022 MySQL DevroomFlame Graphs for MySQL DBAs - FOSDEM 2022 MySQL Devroom
Flame Graphs for MySQL DBAs - FOSDEM 2022 MySQL Devroom
 
Linux /proc filesystem for MySQL DBAs - FOSDEM 2021
Linux  /proc filesystem for MySQL DBAs - FOSDEM 2021Linux  /proc filesystem for MySQL DBAs - FOSDEM 2021
Linux /proc filesystem for MySQL DBAs - FOSDEM 2021
 
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB DevroomMore on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
 
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
 
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
 
The New MariaDB Offering - MariaDB 10, MaxScale and more
The New MariaDB Offering - MariaDB 10, MaxScale and moreThe New MariaDB Offering - MariaDB 10, MaxScale and more
The New MariaDB Offering - MariaDB 10, MaxScale and more
 
MySQL Indexierung CeBIT 2014
MySQL Indexierung CeBIT 2014MySQL Indexierung CeBIT 2014
MySQL Indexierung CeBIT 2014
 
WiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-TreeWiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-Tree
 
Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)
 
Preparse Query Rewrite Plugins
Preparse Query Rewrite PluginsPreparse Query Rewrite Plugins
Preparse Query Rewrite Plugins
 
Developers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sad
Developers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sadDevelopers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sad
Developers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sad
 
HA with Galera
HA with GaleraHA with Galera
HA with Galera
 
The Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialThe Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication Tutorial
 
MySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsMySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitations
 
MySQL/MariaDB Parallel Replication: inventory, use-case and limitations
MySQL/MariaDB Parallel Replication: inventory, use-case and limitationsMySQL/MariaDB Parallel Replication: inventory, use-case and limitations
MySQL/MariaDB Parallel Replication: inventory, use-case and limitations
 
External Language Stored Procedures for MySQL
External Language Stored Procedures for MySQLExternal Language Stored Procedures for MySQL
External Language Stored Procedures for MySQL
 
Riding the Binlog: an in Deep Dissection of the Replication Stream
Riding the Binlog: an in Deep Dissection of the Replication StreamRiding the Binlog: an in Deep Dissection of the Replication Stream
Riding the Binlog: an in Deep Dissection of the Replication Stream
 
Using Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDBUsing Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDB
 

Similar to Instant add column for inno db in mariadb 10.3+ (fosdem 2018, second draft)

ALTER TABLE Improvements in MariaDB Server
ALTER TABLE Improvements in MariaDB ServerALTER TABLE Improvements in MariaDB Server
ALTER TABLE Improvements in MariaDB Server
MariaDB plc
 
Changing your huge table's data types in production
Changing your huge table's data types in productionChanging your huge table's data types in production
Changing your huge table's data types in production
Jimmy Angelakos
 
Playing with the CONNECT storage engine
Playing with the CONNECT storage enginePlaying with the CONNECT storage engine
Playing with the CONNECT storage engine
Federico Razzoli
 
How to leave the ORM at home and write SQL
How to leave the ORM at home and write SQLHow to leave the ORM at home and write SQL
How to leave the ORM at home and write SQL
MariaDB plc
 
How Database Convergence Impacts the Coming Decades of Data Management
How Database Convergence Impacts the Coming Decades of Data ManagementHow Database Convergence Impacts the Coming Decades of Data Management
How Database Convergence Impacts the Coming Decades of Data Management
SingleStore
 
Developers’ mDay 2019. - Bogdan Kecman, Oracle – MySQL 8.0 – why upgrade
Developers’ mDay 2019. - Bogdan Kecman, Oracle – MySQL 8.0 – why upgradeDevelopers’ mDay 2019. - Bogdan Kecman, Oracle – MySQL 8.0 – why upgrade
Developers’ mDay 2019. - Bogdan Kecman, Oracle – MySQL 8.0 – why upgrade
mCloud
 
Redefining tables online without surprises
Redefining tables online without surprisesRedefining tables online without surprises
Redefining tables online without surprises
Nelson Calero
 
Advanced MariaDB features that developers love.pdf
Advanced MariaDB features that developers love.pdfAdvanced MariaDB features that developers love.pdf
Advanced MariaDB features that developers love.pdf
Federico Razzoli
 
What's new in MariaDB TX 3.0
What's new in MariaDB TX 3.0What's new in MariaDB TX 3.0
What's new in MariaDB TX 3.0
MariaDB plc
 
Meet MariaDB 10.3 Debconf 2017
Meet MariaDB 10.3   Debconf 2017Meet MariaDB 10.3   Debconf 2017
Meet MariaDB 10.3 Debconf 2017
Vicentiu Ciorbaru
 
MariaDB Temporal Tables
MariaDB Temporal TablesMariaDB Temporal Tables
MariaDB Temporal Tables
Federico Razzoli
 
What's New in MariaDB Server 10.3
What's New in MariaDB Server 10.3What's New in MariaDB Server 10.3
What's New in MariaDB Server 10.3
MariaDB plc
 
When and Why to Use MariaDB: New Features in 10.0 to 10.5
When and Why to Use MariaDB: New Features in 10.0 to 10.5When and Why to Use MariaDB: New Features in 10.0 to 10.5
When and Why to Use MariaDB: New Features in 10.0 to 10.5
Ian Gilfillan
 
Performance improvements in PostgreSQL 9.5 and beyond
Performance improvements in PostgreSQL 9.5 and beyondPerformance improvements in PostgreSQL 9.5 and beyond
Performance improvements in PostgreSQL 9.5 and beyond
Tomas Vondra
 
Grokking TechTalk #20: PostgreSQL Internals 101
Grokking TechTalk #20: PostgreSQL Internals 101Grokking TechTalk #20: PostgreSQL Internals 101
Grokking TechTalk #20: PostgreSQL Internals 101
Grokking VN
 
MariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB Server 10.3 - Temporale Daten und neues zur DB-KompatibilitätMariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB plc
 
Introducing Spirit - Online Schema Change
Introducing Spirit - Online Schema ChangeIntroducing Spirit - Online Schema Change
Introducing Spirit - Online Schema Change
Morgan Tocker
 
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
Dave Stokes
 
MySQL Query Optimisation 101
MySQL Query Optimisation 101MySQL Query Optimisation 101
MySQL Query Optimisation 101
Federico Razzoli
 

Similar to Instant add column for inno db in mariadb 10.3+ (fosdem 2018, second draft) (20)

ALTER TABLE Improvements in MariaDB Server
ALTER TABLE Improvements in MariaDB ServerALTER TABLE Improvements in MariaDB Server
ALTER TABLE Improvements in MariaDB Server
 
Changing your huge table's data types in production
Changing your huge table's data types in productionChanging your huge table's data types in production
Changing your huge table's data types in production
 
Playing with the CONNECT storage engine
Playing with the CONNECT storage enginePlaying with the CONNECT storage engine
Playing with the CONNECT storage engine
 
How to leave the ORM at home and write SQL
How to leave the ORM at home and write SQLHow to leave the ORM at home and write SQL
How to leave the ORM at home and write SQL
 
How Database Convergence Impacts the Coming Decades of Data Management
How Database Convergence Impacts the Coming Decades of Data ManagementHow Database Convergence Impacts the Coming Decades of Data Management
How Database Convergence Impacts the Coming Decades of Data Management
 
Developers’ mDay 2019. - Bogdan Kecman, Oracle – MySQL 8.0 – why upgrade
Developers’ mDay 2019. - Bogdan Kecman, Oracle – MySQL 8.0 – why upgradeDevelopers’ mDay 2019. - Bogdan Kecman, Oracle – MySQL 8.0 – why upgrade
Developers’ mDay 2019. - Bogdan Kecman, Oracle – MySQL 8.0 – why upgrade
 
Redefining tables online without surprises
Redefining tables online without surprisesRedefining tables online without surprises
Redefining tables online without surprises
 
Advanced MariaDB features that developers love.pdf
Advanced MariaDB features that developers love.pdfAdvanced MariaDB features that developers love.pdf
Advanced MariaDB features that developers love.pdf
 
What's new in MariaDB TX 3.0
What's new in MariaDB TX 3.0What's new in MariaDB TX 3.0
What's new in MariaDB TX 3.0
 
Meet MariaDB 10.3 Debconf 2017
Meet MariaDB 10.3   Debconf 2017Meet MariaDB 10.3   Debconf 2017
Meet MariaDB 10.3 Debconf 2017
 
MariaDB Temporal Tables
MariaDB Temporal TablesMariaDB Temporal Tables
MariaDB Temporal Tables
 
What's New in MariaDB Server 10.3
What's New in MariaDB Server 10.3What's New in MariaDB Server 10.3
What's New in MariaDB Server 10.3
 
When and Why to Use MariaDB: New Features in 10.0 to 10.5
When and Why to Use MariaDB: New Features in 10.0 to 10.5When and Why to Use MariaDB: New Features in 10.0 to 10.5
When and Why to Use MariaDB: New Features in 10.0 to 10.5
 
Less08 Schema
Less08 SchemaLess08 Schema
Less08 Schema
 
Performance improvements in PostgreSQL 9.5 and beyond
Performance improvements in PostgreSQL 9.5 and beyondPerformance improvements in PostgreSQL 9.5 and beyond
Performance improvements in PostgreSQL 9.5 and beyond
 
Grokking TechTalk #20: PostgreSQL Internals 101
Grokking TechTalk #20: PostgreSQL Internals 101Grokking TechTalk #20: PostgreSQL Internals 101
Grokking TechTalk #20: PostgreSQL Internals 101
 
MariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB Server 10.3 - Temporale Daten und neues zur DB-KompatibilitätMariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
 
Introducing Spirit - Online Schema Change
Introducing Spirit - Online Schema ChangeIntroducing Spirit - Online Schema Change
Introducing Spirit - Online Schema Change
 
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
 
MySQL Query Optimisation 101
MySQL Query Optimisation 101MySQL Query Optimisation 101
MySQL Query Optimisation 101
 

Recently uploaded

Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
AI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website CreatorAI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website Creator
Google
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 

Recently uploaded (20)

Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
AI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website CreatorAI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website Creator
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 

Instant add column for inno db in mariadb 10.3+ (fosdem 2018, second draft)

  • 1. Instant ADD COLUMN for InnoDB in MariaDB 10.3+ On the way to instant ALTER TABLE for failure-free record format changes Valerii Kravchuk, Principal Support Engineer, MariaDB vkravchuk@gmail.com 1
  • 2. www.percona.com Who am I? Valerii (aka Valeriy) Kravchuk: ● MySQL Support Engineer in MySQL AB, Sun and Oracle, 2005 - 2012 ● Principal Support Engineer in Percona, 2012 - 2016 ● Principal Support Engineer in MariaDB Corporation since March 2016 ● http://mysqlentomologist.blogspot.com - my blog about MySQL (a lot about MySQL bugs, but some HowTos as well) ● https://www.facebook.com/valerii.kravchuk - my Facebook page, a lot about MySQL (mostly bugs, rants and links to blog posts…) ● http://bugs.mysql.com - it used to be my personal playground ● @mysqlbugs - #bugoftheday on Twitter ● I like FOSDEM, see slides from my previous talks: ○ http://www.slideshare.net/valeriikravchuk1/fosdem2015-gdb-tips-and-tricks-for-my-sql-db-as ○ http://www.slideshare.net/ValeriyKravchuk/more-on-gdb-for-my-sql-db-as-fosdem-2016 ○ https://www.slideshare.net/ValeriyKravchuk/applying-profilers-to-my-sql-fosdem-2017 2
  • 3. www.percona.com What is this session about? ● History of ALTER TABLE improvements in MySQL ● Problems with current “online” table rebuilds ● How instant ADD COLUMN for InnoDB appeared in MariaDB ● Basic usage of instant ADD COLUMN, limitations ● Page changes for instant ADD COLUMN ● Some “benchmarks” (not sure if I have enough time…) ● Next steps on the way to instant ALTER TABLE for failure-free InnoDB record format changes that may happen in MariaDB 10.4+ (or not :) 3
  • 4. www.percona.com History of ALTER TABLE in MySQL/MariaDB ● The old way (also known as ALGORITHM=COPY starting with MySQL 5.6) ○ CREATE TABLE ...; INSERT … SELECT; RENAME TABLE ...; DROP TABLE ...; ○ Lots of unnecessary undo and redo logging in InnoDB ("bulk insert" would help) ● "Fast index creation" in InnoDB Plugin for MySQL 5.1 (built-in 5.5 InnoDB) ○ Supports ADD INDEX, ADD UNIQUE INDEX, ADD PRIMARY KEY (?) ● ALGORITHM=INPLACE starting with MySQL 5.6 ○ Misleading name; some operations may rebuild the table ■ ADD/DROP COLUMN, ADD PRIMARY KEY, CHANGE ...[NOT] NULL ○ Some operations are instant: rename column, change DEFAULT value, … ■ Should have ALGORITHM=(INSTANT|NOCOPY) to avoid surprises (MDEV-13134) ○ Somewhat wrongly called "online" DDL: ■ Changes to data in table are still prevented for some time in the process. Bug #84004! ■ It still causes slaves lag (Bug #73196) ■ We all know it should be “more online”, see Bug #77097, Bug #68498, Bug #72109, Bug #83557 etc ○ Online (LOCK=NONE) is sometimes refused: ■ ALTER TABLE … ADD (FULLTEXT|SPATIAL) INDEX, ALGORITHM=INPLACE; ■ Any table rebuild operation when FULLTEXT or SPATIAL indexes are present (see Bug #81819) 4
  • 5. www.percona.com Problems with Online Table Rebuild ● MySQL 5.6+ includes “online” ALTER TABLE ([ADD|DROP] COLUMN etc.), with LOCK=NONE. Why are tools like gh-ost or pt-osc still used? ○ Replication ignores LOCK=NONE: Slaves will only continue after commit → huge lag ○ The online log needs to be buffered (in memory or temporary files) ■ The size depends on the concurrent DML workload; hard to predict! ○ The whole table (including all indexes) will have to be copied ■ MySQL 5.7 included some performance improvements to this, but huge I/O remains ○ Theoretically, do we really have to rebuild? ■ Only when introducing stricter constraints (shorter columns, add NOT NULL) ■ Even that could be done by validating the table and editing metadata ■ Only ADD [UNIQUE|PRIMARY|SPATIAL|FULLTEXT] KEY really require writes 5
  • 6. www.percona.com History of Instant ADD COLUMN for InnoDB ● Both Alibaba and Tencent have instant ADD in their MySQL 5.6 forks ○ Does not work with old data files; requires a new ROW_FORMAT ● MariaDB wants it to work on old (possibly large) files ○ Vin Chen from Tencent Game DBA Team wrote a prototype that adds an optional record header to identify "afterwards added columns" ○ The ADD … DEFAULT values are stored in one place ○ Data dictionary only reflects the latest table definition, including the latest DEFAULT ● Marko Mäkelä rewrote the prototype for MariaDB 10.3.2 (see MDEV-11369) ○ Store a 'default row' at the start of the table (we want to remove SYS_* tables one day) ○ Support all but ROW_FORMAT=COMPRESSED ○ Crash-safe DDL (a new undo record type); simpler DML rollback; "compression" ○ ensured that online table rebuild (e.g. DROP COLUMN) still works 6
  • 7. www.percona.com Basic Usage of Instant ADD COLUMN ● By default, ALTER TABLE … ADD COLUMN is instantaneous ○ Limitation: No hidden FTS_DOC_ID column (for FULLTEXT INDEX) must exist ● Use the FORCE keyword for the old-fashioned ADD COLUMN, with the old-fashioned (additional) limitations: ○ ALGORITHM=INPLACE will not work if multiple FULLTEXT indexes exist ○ LOCK=NONE will not work if FULLTEXT or SPATIAL index exist ● To monitor the number of avoided table rebuilds: SELECT variable_value FROM information_schema.global_status WHERE variable_name = 'innodb_instant_alter_column'; ● See also https://mariadb.com/resources/blog/instant-add-column-innodb 7
  • 8. ● No limitations on data types for added columns or DEFAULT expression complexity: CREATE TABLE t(id INT PRIMARY KEY, u INT UNIQUE) ENGINE=InnoDB; INSERT INTO t(id,u) VALUES(1,1),(2,2),(3,3); ALTER TABLE t ADD COLUMN (d DATETIME DEFAULT current_timestamp(), t TEXT CHARSET utf8 DEFAULT 'The quick brown fox', p POINT NOT NULL DEFAULT ST_GeomFromText('POINT(0 0)')); UPDATE t SET t=NULL WHERE id=3; SELECT * FROM t; ● No backward compatibility until rebuilt with FORCE (ToDo: check this). See MDEV-13562 also. www.percona.com Example of Instant ADD COLUMN 8
  • 9. www.percona.com Page Changes for Instant ADD COLUMN ● Clustered index root page changes: ○ FIL_PAGE_TYPE_INSTANT indicates that instant operation was used ○ PAGE_INSTANT stores the original (smaller) number of clustered index fields ● Change the leftmost clustered index leaf page: ○ After the infimum, store a "default" record with REC_INFO_MIN_REC_FLAG: ■ Must have the optional "added fields" header ■ The number of fields must match the current table definition ■ Values of "added fields" are the values of "missing fields" ● Clustered index contents from the previous example: ○ (default,id,u,d=2017-11-10 12:14:00,t='The quick brown fox',p=POINT(0 0)), ○ (1,1), (2,2), (3,3,2017-11-10 12:14:00, NULL) ○ We omit trailing fields that are equal to the fields in the "default" record 9
  • 10. www.percona.com MariaDB 10.4+: ADD… [FIRST|AFTER], DROP... ● Keep the user record format unchanged ○ Physically, keep doing ADD COLUMN last in the clustered index records ○ DROP COLUMN will leave garbage in the records ○ Changing column order physically becomes a no-op ○ ADD COLUMN will be possible even if hidden FTS_DOC_ID exists ● In the "default" record, store a mapping of table columns to index fields, pass it somehow when needed 10
  • 11. www.percona.com MariaDB 10.4+: Instant CHANGE COLUMN? ● MySQL 5.7/MariaDB 10.2: Extend VARCHAR maximum size ○ Only if the physical format allows; not VARCHAR(255) to VARCHAR(256) ● We need something in the user data records to indicate physical format ○ "Format version number" that points to something in the "default" record? ● Format changes can only be instantaneous if they relax constraints: ○ Example: CHAR(1) to CHAR(2), INT to BIGINT or NOT NULL to NULL ○ Less likely: Changing POINT to GEOMETRY, changing latin1 to utf8 ● Failure is an option, if we perform table scan to validate the data: ○ Example: Changing BIGINT NULL to INT UNSIGNED NOT NULL ● Affected secondary indexes must be rebuilt if the physical format changes ○ Still much faster than rebuilding the entire table; can be done online ● Follow MDEV-11424, “Instant ALTER TABLE of failure-free record format changes”, if interested... 11
  • 12. www.percona.com Set of Statements to Do Lame “Benchmark” See test_instant_alter.sql for more details: create table t(id int auto_increment primary key, c1 int); insert into t(c1) values (0); -- repeat 19 times insert into t(c1) select rand()*1000 from t; -- 0 select count(*) from t; -- 1 ... alter table t add column c2 char(200) default 'a'; -- 2 ... update t set c2 = 'b'; -- 3 update t set c2 = 'c'; -- 4 update t set c2 = 'd'; -- !!! ... alter table t force; -- 5 update t set c2 = 'e'; -- 6 update t set c2 = 'f'; -- 7 12 It may be interesting to compare times to execute 2 and 5, as well as 3 and 4 to 6 and 7, also for different engines (like MyRocks) and versions (PS 5.7, 10.2, 10.3, and, surely MySQL 8.0.4)
  • 13. www.percona.com Example of Instant ADD COLUMN for Benchmark create table t(id int auto_increment primary key, c1 int); insert into t(c1) values (0); insert into t(c1) select rand()*1000 from t; … continue that way until it’s big enough MariaDB [test]> insert into t(c1) select rand()*1000 from t; Query OK, 262144 rows affected ( 4.141 sec) Records: 262144 Duplicates: 0 Warnings: 0 MariaDB [test]> alter table t add column c2 char(200) default repeat('a',200); Query OK, 0 rows affected ( 0.039 sec) Records: 0 Duplicates: 0 Warnings: 0 MariaDB [test]> update t set c2 = 'b'; Query OK, 524288 rows affected ( 55.682 sec) Rows matched: 524288 Changed: 524288 Warnings: 0 MariaDB [test]> update t set c2 = 'c'; Query OK, 524288 rows affected ( 31.649 sec) Rows matched: 524288 Changed: 524288 Warnings: 0 13
  • 14. www.percona.com Time to Run ALTER … ADD COLUMN (2) ● On my QuadCore Fedora 27 box, --no-defaults: 14
  • 15. www.percona.com Time to Run First UPDATE After ALTER (3) ● On my QuadCore Fedora 27 box, --no-defaults: 15
  • 16. www.percona.com Time to Run Entire “Benchmark” Script ● On my QuadCore Fedora 27 box, --no-defaults: 16
  • 17. www.percona.com Thanks and Links ● Thanks to Marko Mäkelä for his work, hints and slides on this topic ● Thanks to LeFred and Belcona team for this event! ● Check MDEV-11369 for the details of original task in MariaDB ● Check original blog post about the feature ● Check MDEV-11424 for further plans in MariaDB 10.4+ and progress on them ● My blog post on current state of online DDL in MySQL 5.7 ● Some test and raw benchmark results are shared here 17
  • 18. www.percona.com Thank you! Questions and Answers? Please, report bugs at: https://bugs.mysql.com https://jira.mariadb.org https://jira.percona.com 18