Mysql VIEWS vs. PHP query

前端 未结 5 1007
温柔的废话
温柔的废话 2021-02-12 11:16

I am working on a web application which involves create list of Restaurants in various lists like \"Joe\'s must visit places\". Now for each Restaurant and list, I have display

5条回答
  •  [愿得一人]
    2021-02-12 12:12

    My complete answer would depend upon several things (from your application's perspective):

    • do you plan to allow users to create and share such lists?
    • can users create lists of any kind, or just by plugging values into existing query templates?

    Assuming you have a couple of pre-defined lists to display:

    Use of views offers a couple of advantages:

    • your code will be cleaner
    • the query to generate the views will not have to be parsed each time by mysql.

    I'm not sure about this: I don't think mysql caches views as Tomasz suggests - I don't think views contain "already preparted data".

    One disadvantage is that the logic involved in creating the list goes into the database instead of living in your PHP code - something I'm very averse to. In my world databases are for data, and code is for logic.

    Cheers

提交回复
热议问题