一个大查询还是多个小查询哪个更好? [英] which is better one big query or multiple small query?

查看:86
本文介绍了一个大查询还是多个小查询哪个更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪个更好,更有效?一个大查询然后仅在php中或从php函数中处理获取的查询,将创建一个查询小数据的循环函数.还请考虑该表可能很大(成千上万个原始表).谢谢.

评论表

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
                )

解决方案

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

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

效果更好返回一个大查询还是几个小查询?

多个小型查询与单个长查询相比.哪个效率更高?

一个大查询与许多小查询?

哪个是更快的单个大查询或几个小的查询?

什么是更快的,包含更多PHP的大型联合查询或包含更少PHP的多个小型选择?

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

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

https://dba.stackexchange.com/questions/35277/is-it-更好地将一个大查询分离成多个较小的查询

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.

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
                )

解决方案

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?

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

这篇关于一个大查询还是多个小查询哪个更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆