0

MySQL creates a clustered index automatically when I create a primary key.

But is there a situation where MySQL creates a nonclustered index automatically?

2
  • MySQL creates a clustered index automatically when I create a primary key. No, it creates clustered index always. If there is no PRIMARY index, first UNIQUE is used. If it abcent too, internal hidden record number is used. is there a situation where MySQL creates a nonclustered index automatically? No when you mean table index.
    – Akina
    Commented Dec 3, 2018 at 18:51
  • ^ looks good enough for an answer.
    – danblack
    Commented Dec 3, 2018 at 21:59

1 Answer 1

1
  • The PRIMARY KEY is a UNIQUE key; it is also "clustered". (Note: Clustered)
  • In the absence of an explicit PK, the 'first' UNIQUE key containing only non-NULL column(s) is effectively promoted to be the PK.
  • If that fails, a hidden 6-byte number is used for the PK.

  • A UNIQUE key is an INDEX, plus a uniqueness constraint. (Note: may be clustered)

  • An INDEX is a BTree that is used for efficient access.
  • A FOREIGN key creates an INDEX if there is not already a suitable index. (Note: Non-clustered)

The 3 "Notes" are implicitly-created indexes, but not necessarily non-clustered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.