<tfoot id='zsGVu'></tfoot>

        <bdo id='zsGVu'></bdo><ul id='zsGVu'></ul>
    1. <small id='zsGVu'></small><noframes id='zsGVu'>

      <i id='zsGVu'><tr id='zsGVu'><dt id='zsGVu'><q id='zsGVu'><span id='zsGVu'><b id='zsGVu'><form id='zsGVu'><ins id='zsGVu'></ins><ul id='zsGVu'></ul><sub id='zsGVu'></sub></form><legend id='zsGVu'></legend><bdo id='zsGVu'><pre id='zsGVu'><center id='zsGVu'></center></pre></bdo></b><th id='zsGVu'></th></span></q></dt></tr></i><div id='zsGVu'><tfoot id='zsGVu'></tfoot><dl id='zsGVu'><fieldset id='zsGVu'></fieldset></dl></div>
      1. <legend id='zsGVu'><style id='zsGVu'><dir id='zsGVu'><q id='zsGVu'></q></dir></style></legend>
      2. 当未指定 order by 时,SELECT TOP 如何工作?

        how does SELECT TOP works when no order by is specified?(当未指定 order by 时,SELECT TOP 如何工作?)

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

        • <tfoot id='ypDX6'></tfoot>

          <legend id='ypDX6'><style id='ypDX6'><dir id='ypDX6'><q id='ypDX6'></q></dir></style></legend>

            <tbody id='ypDX6'></tbody>

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

                  本文介绍了当未指定 order by 时,SELECT TOP 如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  功能,这意味着您的扫描将读取最近阅读的页面来自另一个并发扫描.

                  The msdn documentation says that when we write

                  SELECT TOP(N) ..... ORDER BY [COLUMN]
                  

                  We get top(n) rows that are sorted by column (asc or desc depending on what we choose)

                  But if we don't specify any order by, msdn says random as Gail Erickson pointed out here. As he points out it should be unspecified rather then random. But as Thomas Lee points out there that

                  When TOP is used in conjunction with the ORDER BY clause, the result set is limited to the first N number of ordered rows; otherwise, it returns the first N number of rows ramdom

                  So, I ran this query on a table that doesn't have any indexes, first I ran this..

                  SELECT *
                  FROM
                      sys.objects so
                  WHERE
                      so.object_id NOT IN (SELECT si.object_id
                                           FROM
                                               sys.index_columns si)
                      AND so.type_desc = N'USER_TABLE'
                  

                  And then in one of those tables, (in fact I tried the query below in all of those tables returned by above query) and I always got the same rows.

                  SELECT TOP (2) *
                  FROM
                      MstConfigSettings
                  

                  This always returned the same 2 rows, and same is true for all other tables returned by query 1. Now the execution plans shows 3 steps..

                  As you can see there is no index look up, it's just a pure table scan, and

                  The Top shows actual no of rows to be 2, and so does the Table Scan; Which is not the case (there I many rows).

                  But when I run something like

                  SELECT TOP (2) *
                  FROM
                      MstConfigSettings
                  ORDER BY
                      DefaultItemId
                  

                  The execution plan shows

                  and

                  So, when I don't apply ORDER BY the steps are different (there is no sort). But the question is how does this TOP works when there is no Sort and why and how does it always gives the same result?

                  解决方案

                  There is no guarantee which two rows you get. It will just be the first two retrieved from the table scan.

                  The TOP iterator in the execution plan will stop requesting rows once two have been returned.

                  Likely for a scan of a heap this will be the first two rows in allocation order but this is not guaranteed. For example SQL Server might use the advanced scanning feature which means that your scan will read pages recently read from another concurrent scan.

                  这篇关于当未指定 order by 时,SELECT TOP 如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)

                    <tbody id='Skbrg'></tbody>

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

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

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