Is it possible to use a negative length for a MySQL index? If so, does it work the same way as using a negative value when calling PHP's substring function?
According to CREATE INDEX Syntax:
index entries consist of the first length characters of each column value for CHAR, VARCHAR, and TEXT columns, and the first length bytes of each column value for BINARY, VARBINARY, and BLOB columns.
No exception is mentioned for negative values. So my guess is, it is not defined how MySQL behaves when a negative length is given.
No. Indexes either cover the entire field, or the first N
characters of a field. If you want a reverse index, store the appropriate field(s) in a reserved state and index those.