There's already a unique index. This hoop jumping prevents duplicates.

In order to get a duplicate 0 the smallest existing index would need to be 0 or lower and the number of attachments would have to be less than that, so that shouldn't be possible.