一个大查询或多个小查询哪个更好?

which is better one big query or multiple small query?

哪个更好更高效?一个大查询然后只处理 php 或 php 函数中获取的查询将只创建一个查询小数据的循环函数。还请考虑 table 可能很大(数以千计的原始数据)。谢谢

评论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   

预期输出是这样的:

        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
                )

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

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

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?

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

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