Search code examples
mysqlindexingmariadbinnodb

In mysql/mariadb is index stored database level or in table level?


I'm in the process of moving an sql server database to mariadb.

In that i'm now doing the index naming, and have to modify some names because they are longer than 64 chars.

That got me wondering, do in mariadb the indexes get stored on the table level or on the database level like on sql server?

To rephrase the question in another way, do index name need to be unique per database or per table?

The storage engine I'm using is innoDB


Solution

  • Index names (in MySQL) are almost useless. About the only use is for DROP INDEX, which is rarely done. So, I recommend spending very little time on naming indexes. The names only need to be unique within the table.

    The PRIMARY KEY (which has no other name than that) is "clustered" with the data. That is, the PK and the data are in the same BTree.

    Each secondary key is a separate BTree. The BTree is sorted according to the column(s) specified. The leaf node 'records' contain the columns of the PK, thereby providing a way to get to the actual record.

    FULLTEXT and SPATIAL indexes work differently.

    PARTITIONing... First of all, partitioning is rarely useful. But if you have any partitioned tables, then here are some details about indexes. A Partitioned table is essentially a collection of sub-tables, each identical (including index names). There is no "global index" across the table; each index for a sub-table refers only to the sub-table.

    Keys belong to a table, not a database.