SQL Server performance and fully qualified table names

后端 未结 5 1573
感动是毒
感动是毒 2021-01-12 02:30

It seems to be fairly accepted that including the schema owner in the query increases db performance, e.g.:

SELECT x FROM [dbo].Foo vs SELECT x FR

相关标签:
5条回答
  • 2021-01-12 02:46

    SQL server will not make an extra look up if the default schema is the same. It should be included if it's not and it's a query that is used a lot.

    The database name will not benefit the query performance. I think this could be seen with the Estimated Execution Plan in the Management Studio.

    0 讨论(0)
  • 2021-01-12 02:47

    In this case I would personally prefer readability over the tiny performance increase that this could possibly cause, if any.

    SELECT * FROM Foo 
    

    Seems a lot easier to scan than:

    SELECT * FROM MyDatabase.[dbo].Foo
    
    0 讨论(0)
  • 2021-01-12 02:50

    One thing to keep in mind is that this is a compilation binding, not an execution one. So if you execute the same query 1 million times, only the first execution will 'hit' the look up time, the rest will reuse the same plan and plans are pre-bound (names are already resolved to object ids).

    0 讨论(0)
  • 2021-01-12 02:50

    As Spencer said - try it, of course make sure you clear the cache each time as this will interfere with your results.

    http://www.devx.com/tips/Tip/14401

    I also would be suprised if it made any apprecible difference.

    0 讨论(0)
  • 2021-01-12 02:56

    Try it out? Just loop through a million queries of both and see which one finishes first.

    I'm guessing it's a load of bunk though. The developers of MS SQL spend millions of hours researching efficiency for search algorithms and storage methods only to be thwarted by users not specifying fully qualified table names? Laughable.

    0 讨论(0)
提交回复
热议问题