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

后端 未结 7 616
一整个雨季
一整个雨季 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:31

    Well under Oracle you'd want to take advantage of the query caching, and if you have a lot of small queries you are doing in your sequential processing, it would suck if the last query pushed the first one out of the cache...just in time for you to loop around and run that first query again (with different parameter values obviously) on the next pass.

    We were building an XML output file using Java stored procedures and definitely found the round trip times for each individual query were eating us alive. We found it was much faster to get all the data in as few queries as possible, then plug those values into the XML DOM as needed.

    The only downside is that the Java code was a bit less elegant, as the data fetch was now remote from its usage. But we had to generate a large complex XML file in as close to zero time as possible, so we had to optimize for speed.

    0 讨论(0)
提交回复
热议问题