You've successfully subscribed to Nuvotex Blog
Great! Next, complete checkout for full access to Nuvotex Blog
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.

mysql - online index creation

This post shows how easy it is to alter tables (in this example index creation) online to keep your sql database uninterrupted and clients online.

Daniel Nachtrub
Daniel Nachtrub

Personally, i'm quite a huge fan of document databases, mostly because the mindset behind those is around a schemaless dataset and the operations are meant to scale horizontally. In addition, many if not all operations on the data are non-blocking.

Relational databases tend to be more complex, often relaed to the intrinsic demand to be ACID compliant. Luckily, sometimes there are options 😄

Online structural change - index creation

A simple (yet seemingly very often not utilized) option to alter a database is for example to create indices online (or possibly rebuild, reorganize, etc. them).

So, when you're in mysql / mariadb, how just use the ALGORITHM and LOCK flags and you can process large amounts of data without (b)locking your tables.

CREATE INDEX IF NOT EXISTS myOnlineCreateIndex ON MySuperBusyTable (Id, Transaction, Date) ALGORITHM=INPLACE LOCK=NONE;

online index creation

That's it - simple yet powerful.

Side node: IF NOT EXISTS is a part of mariadb's SQL features and not available on mysql as of today.

Database

Daniel Nachtrub

Kind of likes computers. Linux foundation certified: LFCS / CKA / CKAD / CKS. Microsoft certified: Cybersecurity Architect Expert & Azure Solutions Architect Expert.