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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37381532/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:13:04  来源:igfitidea点击:

which is better one big query or multiple small query?

phpmysqlarrayscodeigniterhierarchy

提问by Bry

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
                )