哪个更好又有效?一个大的查询然后只是处理php中的获取查询或从php函数将只创建一个查询小数据的循环函数。请注意表格可以很大(数千个原始)。感谢。
评论表
list = [#items]
for item in list: #instead of a while loop
#do something
print item
预期输出为:
id | parent | msg
---+--------+---------
1 | 0 | hello
2 | 1 | hi
3 | 2 | whats up
4 | 3 | yow
5 | 1 | hellow
6 | 2 | nice
7 | 0 | great
答案 0 :(得分:12)
根据经验,查询越少越好。
这是一个很好的问题,但已多次回答。
Is it better to return one big query or a few smaller ones?
Multiple small queries vs a single long query. Which one is more efficient?
One big query vs. many small ones?
Which one is faster single big query or few small queries?
What is faster, a big joined query with more PHP or multiple small selects with less PHP?
Should I use one big SQL Select statement or several small ones?
https://dba.stackexchange.com/questions/76973/what-is-faster-one-big-query-or-many-small-queries