which is better and efficient? one big query then just process the fetched query in the php or from php function will just create a loop function that queries small data. Please consider also that the table can be big (thousands of raw). Thanks.

哪个更好又有效?一个大的查询然后只是处理php中的获取查询或从php函数将只创建一个查询小数据的循环函数。请注意表格可以很大(数千个原始)。谢谢。

Comments table

评论表

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   

Expected output is this:

预期产量是这样的:

        Array
        (
            [0] => Array
                (
                    [id] => 1
                    [parent] => 0
                    [value] => hello
                    [child] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 2
                                    [parent] => 1
                                    [value] => hi
                                    [child] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [id] => 3
                                                    [parent] => 2
                                                    [value] => whats up
                                                    [child] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [id] => 4
                                                                    [parent] => 3
                                                                    [value] => yow
                                                                )
                                                        )
                                                )
                                            [1] => Array
                                                (
                                                    [id] => 6
                                                    [parent] => 2
                                                    [value] => nice
                                                )
                                        )
                                )
                            [1] => Array
                                (
                                    [id] => 5
                                    [parent] => 1
                                    [value] => hellow
                                )
                        )
                )
            [1] => Array
                (
                     [id] => 7
                    [parent] => 0
                    [value] => great
                )

1 个解决方案

#1


5

As a rule of thumb, the less queries the better.

根据经验,查询越少越好。

This is a good question but this has been answered multiple times.

这是一个很好的问题,但已经多次回答。

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?

什么是更快,一个大的连接查询与更多的PHP或多个小选择与较少的PHP?

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

我应该使用一个大的SQL Select语句还是几个小语句?

https://dba.stackexchange.com/questions/76973/what-is-faster-one-big-query-or-many-small-queries

https://dba.stackexchange.com/questions/76973/what-is-faster-one-big-query-or-many-small-queries

https://dba.stackexchange.com/questions/35277/is-it-better-to-separate-a-big-query-into-multiple-smaller-queries

https://dba.stackexchange.com/questions/35277/is-it-better-to-separate-a-big-query-into-multiple-smaller-queries

更多相关文章

  1. oracle中decode函数 VS mysql中的if函数和case函数
  2. Mysql语句 AND 和 OR 的运用
  3. MySQL学习笔记(十二)运算符和函数一
  4. 在我的sql中调用触发器中的函数
  5. MySQL 转换函数与运算符
  6. MySQL入门很简单-学习笔记 - 第13章 MySQL函数
  7. MyBatis排序时使用order by 动态参数时需要注意,用$而不是# 用$传
  8. MySQL常用的函数
  9. MySql 优化之like语句

随机推荐

  1. Android知识体系总结之Android部分Activi
  2. Android(安卓)2.3 r1 中文 API (57) ―― S
  3. android加载框效果《IT蓝豹》
  4. Android Market的 Loading效果
  5. listview原生态属性
  6. Android Gradle Plugin指南(一)——简介
  7. android创建菜单
  8. Android转场动画的学习
  9. Android 中service 详解
  10. Android Fresco属性大全,中文说明