sql - How do I make my ORDER BY DESC queries efficient in MySQL if descending indexes are ignored? -
select * table from_user=? , to_user=? order created_at desc
created_at
datetime column.
according previous question (here), learned don't need create descending index.
is index ok if have billions of records? (notice i'm not specifying desc index created_at)
>> from_user_id, to_user_id, created_at
imo having index on from_user_id, to_user_id, created_at
not help much. don't think have many records same from_user_id, to_user_id, created_at
values. (date time millisecond!) if assumption correct, in index such low cardinality effectiveness reduced linear search plus wasting storage. suggest having index on from_user_id, to_user_id
, matching criteria, index applied before ordering. in case can see query execution plan see query cost, when having these indexes. (indexing mechanism overview interesting)
mysql sql database indexing
No comments:
Post a Comment