mariadb-create-index

Generates MariaDB-specific CREATE INDEX and DROP INDEX statements with correct syntax and behavior.

28|115|Updated Jan 28, 2025
One-click install
npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-create-index-mariadb-corporation
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: mariadb-create-index
Source: https://github.com/mariadb-corporation/mariadb-docs/tree/main/agent-skills/granular/statements/mariadb-create-index
Command: npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-create-index-mariadb-corporation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Standard SQL knowledge often produces incorrect or inefficient index statements on MariaDB, such as attempting expression indexes, omitting mandatory prefix lengths on TEXT/BLOB columns, or issuing multiple CREATE INDEX statements that each trigger a separate table rebuild. ## Core Features & Use Cases - MariaDB syntax deltas: Covers what CREATE INDEX cannot do (no PRIMARY KEY creation, no expression/functional indexes) and the correct workarounds like indexing generated columns. - Index kinds and options: Documents UNIQUE, FULLTEXT, SPATIAL, and VECTOR indexes, USING BTREE/HASH/RTREE, real descending indexes since 10.8, IGNORED indexes for optimizer testing, and CREATE OR REPLACE / IF NOT EXISTS. - Use Case: When adding three indexes to an existing orders table, batch them into a single ALTER TABLE with multiple ADD INDEX clauses instead of three CREATE INDEX statements, avoiding repeated table operations. ## Quick Start Ask the AI to write a MariaDB CREATE INDEX statement for a TEXT column with the required prefix length and descending order.

Frequently Asked Questions about mariadb-create-index

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create an index on a TEXT or BLOB column in MariaDB?▼

MariaDB requires a mandatory prefix length when indexing TEXT or BLOB columns, otherwise it raises ER_BLOB_KEY_WITHOUT_LENGTH. Use syntax like CREATE INDEX i ON t (body(255)) to index the first 255 characters.

How to create a functional or expression index in MariaDB?▼

MariaDB does not support expression or functional indexes in CREATE INDEX; index columns must be plain column names. Instead, add a generated column holding the expression and index that column, for example ALTER TABLE t ADD c INT AS (col1 + col2) PERSISTENT, ADD INDEX (c).

Can CREATE INDEX add a primary key in MariaDB?▼

No, CREATE INDEX cannot create a primary key in MariaDB. Use ALTER TABLE t ADD PRIMARY KEY or define it in CREATE TABLE, which is preferable for InnoDB since it clusters on the primary key and would otherwise rebuild the table.

Does MariaDB support descending indexes?▼

Yes, descending index parts are physically real since MariaDB 10.8. CREATE INDEX i ON t (a ASC, b DESC) stores b in reverse order, which can serve mixed-direction ORDER BY queries without a filesort.

How do I drop a primary key with DROP INDEX in MariaDB?▼

Drop a primary key using the reserved name PRIMARY with required backtick quoting: DROP INDEX `PRIMARY` ON t. DROP INDEX maps to ALTER TABLE DROP INDEX, and IF EXISTS downgrades a missing index to a warning.

Why is my MariaDB index not used when filtering with a function?▼

Wrapping an indexed column in a function like DATE(ts) or LOWER(email) defeats the index. Rewrite the predicate as a range condition, or index a generated column holding the expression so the optimizer can use it.