<i id='Q6Y6V'><tr id='Q6Y6V'><dt id='Q6Y6V'><q id='Q6Y6V'><span id='Q6Y6V'><b id='Q6Y6V'><form id='Q6Y6V'><ins id='Q6Y6V'></ins><ul id='Q6Y6V'></ul><sub id='Q6Y6V'></sub></form><legend id='Q6Y6V'></legend><bdo id='Q6Y6V'><pre id='Q6Y6V'><center id='Q6Y6V'></center></pre></bdo></b><th id='Q6Y6V'></th></span></q></dt></tr></i><div id='Q6Y6V'><tfoot id='Q6Y6V'></tfoot><dl id='Q6Y6V'><fieldset id='Q6Y6V'></fieldset></dl></div>

          <bdo id='Q6Y6V'></bdo><ul id='Q6Y6V'></ul>

        <small id='Q6Y6V'></small><noframes id='Q6Y6V'>

        <legend id='Q6Y6V'><style id='Q6Y6V'><dir id='Q6Y6V'><q id='Q6Y6V'></q></dir></style></legend>
      1. <tfoot id='Q6Y6V'></tfoot>
      2. 选择所有列对性能不利吗?

        时间:2023-10-08

      3. <tfoot id='B1zCE'></tfoot>
      4. <i id='B1zCE'><tr id='B1zCE'><dt id='B1zCE'><q id='B1zCE'><span id='B1zCE'><b id='B1zCE'><form id='B1zCE'><ins id='B1zCE'></ins><ul id='B1zCE'></ul><sub id='B1zCE'></sub></form><legend id='B1zCE'></legend><bdo id='B1zCE'><pre id='B1zCE'><center id='B1zCE'></center></pre></bdo></b><th id='B1zCE'></th></span></q></dt></tr></i><div id='B1zCE'><tfoot id='B1zCE'></tfoot><dl id='B1zCE'><fieldset id='B1zCE'></fieldset></dl></div>

                  <tbody id='B1zCE'></tbody>

                <small id='B1zCE'></small><noframes id='B1zCE'>

                  <bdo id='B1zCE'></bdo><ul id='B1zCE'></ul>
                • <legend id='B1zCE'><style id='B1zCE'><dir id='B1zCE'><q id='B1zCE'></q></dir></style></legend>
                  本文介绍了选择所有列对性能不利吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  一次 SELECT 所有列是不是很糟糕,即使您可能不需要所有列?但是,您可能在另一个任务中需要它们,但是您懒得为每个任务编写查询.

                  Is it bad to SELECT all columns at once even though you probably don't neeed all of them? However you might need them in another task but you are to lazy to write queries for every task.

                  您是否应该只在SELECT 只需要列的地方执行查询,如果需要另一列,则再次执行此查询?

                  Should you only do queries where you SELECT only columns you need and do this query again if you need another column?

                  所以基本上问题是:SELECT 一列与多列对性能有什么影响吗?

                  So basically the question is: Does it has any effect on performance to SELECT one column vs multiple columns?

                  查询非常简单(没有函数、连接等)例如:

                  The query is very simple (no functions, joins etc.) For example:

                  SELECT
                  id, name, status, date
                  FROM user_table
                  WHERE user_id = :user_id
                  

                  推荐答案

                  这里的问题与其说是数据库服务器的问题,不如说是网络通信问题.通过一次选择所有列,您告诉服务器立即返回给您,所有列.至于对 IO 和所有这些的关注,这些问题在问题和答案@Karamba 中得到了很好的解决发表评论:select * vs select column.但是对于大多数实际应用程序(我在任何意义上都使用应用程序"),主要关注的只是网络流量以及序列化、传输和反序列化数据所需的时间.虽然实际上,答案是相同的.

                  The issue here isn't so much a matter of the database server, as just the network communication. By selecting all columns at once, you're telling the server to return to you, all columns at once. As for concerns over IO and all that, those are addressed nicely in the question and answer @Karamba gave in a comment: select * vs select column. But for most real-world applications (and I use "applications" in every sense), the main concern is just network traffic and how long it takes to serialize, transmit, then deserialize the data. Although really, the answer is the same either way.

                  因此,如果您打算全部使用它们,那么撤回所有列是很好的,但这可能需要大量额外的数据传输,特别是如果您在列中存储了很长的字符串.当然,在许多情况下,差异是无法察觉的,而且大多只是一个原则问题.不是全部,而是绝大多数.

                  So pulling back all the columns is great, if you intend to use them all, but that can be a lot of extra data transfer, particularly if you store, say, lengthy strings in your columns. In many cases, of course, the difference will be undetectable and is mostly just a matter of principle. Not all, but a significant majority.

                  这实际上只是您现在提到的懒惰(相信我,我们都有这种感觉)与性能真正的重要性之间的权衡.

                  It's really just a trade-off between your aforementioned laziness (and trust me, we all feel that way) now and how important performance really is.

                  总之,如果您确实打算使用所有列值,那么最好一次性将它们全部拉回来,然后提交一堆查询.

                  That all said, if you do intend to use all the column values, you're much better off pulling them all back at once then you are filing a bunch of queries.

                  把它想象成一个网络搜索:你搜索,你找到你的页面,你只需要一个细节.您可以阅读整个页面并了解有关该主题的所有信息,或者您可以直接跳到有关您正在寻找和完成的部分.如果这就是你想要的,后者要快得多,但是如果你那时必须了解其他方面,那么第一次阅读它们比不得不再次搜索并找到要好得多谈论它的网站.

                  Think of it like doing a web search: you do your search, you find your page, and you only need one detail. You could read the entire page and know everything about the subject, or you could just jump to the part about what you're looking for and be done. The latter is a lot faster if that's all you ever want, but if you're then going to have to learn about the other aspects, you'd be way better off reading them the first time than having to do your search again and find the site to talk about it.

                  如果您不确定将来是否需要其他列值,那么这是您作为开发人员的决定,哪种情况更有可能发生.

                  If you aren't sure whether you'll need the other column values in the future, then that's your call to make as the developer for which case is more likely.

                  这完全取决于您的应用程序是什么、您的数据是什么、您如何使用它以及性能对您真正有多重要.

                  It all depends on what your application is, what your data is, how you're using it, and how important performance really is to you.

                  这篇关于选择所有列对性能不利吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:是否可以在 MySQL 中使用 Crosstab/Pivot Query? 下一篇:在 Select 中合并两个表 (SQL Server 2008)

                  相关文章

                    <i id='Jj5b2'><tr id='Jj5b2'><dt id='Jj5b2'><q id='Jj5b2'><span id='Jj5b2'><b id='Jj5b2'><form id='Jj5b2'><ins id='Jj5b2'></ins><ul id='Jj5b2'></ul><sub id='Jj5b2'></sub></form><legend id='Jj5b2'></legend><bdo id='Jj5b2'><pre id='Jj5b2'><center id='Jj5b2'></center></pre></bdo></b><th id='Jj5b2'></th></span></q></dt></tr></i><div id='Jj5b2'><tfoot id='Jj5b2'></tfoot><dl id='Jj5b2'><fieldset id='Jj5b2'></fieldset></dl></div>
                    1. <small id='Jj5b2'></small><noframes id='Jj5b2'>

                      <legend id='Jj5b2'><style id='Jj5b2'><dir id='Jj5b2'><q id='Jj5b2'></q></dir></style></legend>
                      <tfoot id='Jj5b2'></tfoot>
                      • <bdo id='Jj5b2'></bdo><ul id='Jj5b2'></ul>