News feed database design as in Facebook

后端 未结 3 2036
难免孤独
难免孤独 2021-02-04 13:20

How would make a news feed \"friendly\" database design, so that it wouldn\'t be extremely expensive to get all of the items (query) to put in the news feed? The only way I can

3条回答
  •  囚心锁ツ
    2021-02-04 13:54

    UNION = expensive, because the complete result set is subject to a DISTINCT operation. UNION ALL = cheaper, because it is effectively multiple queries for which the results of each are appended together.

    It depends on the data volume, or course.

    The main driver of efficiency would be the individual queries that are unioned together, but there's no reason why selecting the most recent (say) 10 records from each of 10 tables should take more than a small fraction of a second.

提交回复
热议问题