brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: an IGNORED index lets you test dropping a database index without dropping it

Database
~/tips/tip-database-mariadb-ignored-index

ALTER TABLE orders ALTER INDEX idx_customer IGNORED;

Hides an index from the optimizer so you can see what breaks before you drop it.

Unused indexes slow down every write, but dropping one on a big table and finding out it was needed means a long rebuild. MariaDB 10.6 and later let you switch an index off first.

ALTER TABLE orders ALTER INDEX idx_customer IGNORED;
EXPLAIN SELECT * FROM orders WHERE customer = 'ann';

The optimizer now acts as if the index is not there. The plan can go from key: idx_customer to a full scan with type: ALL, which is exactly the kind of change you want to spot. The index itself stays and is still updated on every write, so switching it back is instant:

ALTER TABLE orders ALTER INDEX idx_customer NOT IGNORED;

SHOW INDEX FROM orders has an Ignored column that shows the current state.

I’d leave it ignored for a few days of normal traffic and watch the slow query log. If nothing gets worse, drop it for real.

A primary key cannot be ignored, and neither can a unique index that the table uses as its implicit primary key. MySQL 8 has the same idea under the name INVISIBLE, with ALTER INDEX ... INVISIBLE, so the syntax differs if you move between the two. Because ignored indexes still cost write time, do not leave them in that state forever.

Further reading: Ignored indexes

More Database tips mariadb -e 'CREATE DATABASE IF NOT EXISTS blog' mariadb-dump --no-create-info --insert-ignore shop orders > orders-rows.sql SELECT table_schema, table_name, CHECKSUM TABLE shop.orders; services: All Database tips (53) All topics

Link