ranking entries in mysql table

后端 未结 5 1375
清歌不尽
清歌不尽 2021-02-06 12:44

I have a MySQL table with many rows. The table has a popularity column. If I sort by popularity, I can get the rank of each item. Is it possible to retrieve the rank of a partic

5条回答
  •  眼角桃花
    2021-02-06 13:16

    You are right that the second approach is inefficent, if the rank column is updated on every table read. However, depending on how many updates there are to the database, you could calculate the rank on every update, and store that - it is a form of caching. You are then turning a calculated field into a fixed value field.

    This video covers caching in mysql, and although it is rails specific, and is a slightly different form of caching, is a very similar caching strategy.

提交回复
热议问题