Sequences in MariaDB, and where AUTO_INCREMENT falls short

AUTO_INCREMENT belongs to a table and produces a value only on insert, so two tables cannot share a numbering space and nothing can reserve a block of ids in advance.

CREATE SEQUENCE order_ref START WITH 100000 INCREMENT BY 1 CACHE 20;

SELECT NEXTVAL(order_ref);      -- 100000
SELECT NEXTVAL(order_ref);      -- 100001

INSERT INTO orders (ref, total) VALUES (NEXTVAL(order_ref), 4900);
INSERT INTO quotes (ref, total) VALUES (NEXTVAL(order_ref), 4900);

The practical use is a reference number shared across several document types, or reserving a block of ids for a bulk import so the application can build the rows before writing them. CACHE pre-allocates and makes it faster at the cost of gaps after a restart, which is fine for an identifier and not for anything that must be gapless — an invoice number sequence with legal requirements needs NOCACHE and the contention that comes with it. MySQL has no equivalent.