Paste this into a new question or an answer at dba.stackexchange.com:
<!-- --> > select version(); > > <pre> > | version() | > | :-------- | > | 8.0.20 | > </pre> <!-- --> > CREATE TABLE a (x INT, f char(255) default 'xxxxxxxxxxx', INDEX(x)); > > <pre> > ✓ > </pre> <!-- --> > INSERT INTO a (x) VALUES (4), (3), (1), (2), (0) ; > > <pre> > ✓ > </pre> <!-- --> > select x from a ; -- Field x is a key, so MySQL sorts by that key when a SELECT is done > -- on that field only! > > <pre> > | x | > | -: | > | 0 | > | 1 | > | 2 | > | 3 | > | 4 | > > ✓ > </pre> <!-- --> > SELECT * FROM a; -- Compare with this where the sort is by the implicit PK, > -- i.e. INSERT order if no ORDER BY is specified! > > <pre> > x | f > -: | :---------- > 4 | xxxxxxxxxxx > 3 | xxxxxxxxxxx > 1 | xxxxxxxxxxx > 2 | xxxxxxxxxxx > 0 | xxxxxxxxxxx > > ✓ > </pre> *db<>fiddle [here](https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=3ae03146c774c569ecfabff22cb00b61)*
back to fiddle