Should I use one big SQL Select statement or several small ones?

后端 未结 7 610
一整个雨季
一整个雨季 2021-01-17 08:54

I\'m building a PHP page with data sent from MySQL.

Is it better to have

  • 1 SELECT query with 4 table joins, or
  • 4 small SELE
7条回答
  •  时光说笑
    2021-01-17 09:26

    You should run a profiling tool if you're truly worried cause it depends on many things and it can vary but as a rule its better to have fewer queries being compiled and fewer round trips to the database.

    Make sure you filter things as well as you can using your where and join on clauses.

    But honestly, it usually doesn't matter since you're probably not going to be hit all that hard compared to what the database can do, so unless optimization is your spec you should not do it prematurely and do whats simplest.

提交回复
热议问题