• subscribe
July 05, 2000 02:55 PM

Querying Distributed Partitioned Views

SQL Server Pro
InstantDoc ID #9097
Learn how SQL Server distributes queries across nodes

Editor's Note: This is the second article in a three-part series about distributed partitioned views in SQL Server 2000.

Distributed partitioned views are the core component of Microsoft's scale-out strategy. (For more information, see "Scalability Wars," page 7.) In "Distributed Partitioned Views," August 2000, we introduced SQL Server 2000's distributed partitioned view technology and demonstrated how to set up and modify the views. In this article, we demonstrate how to query distributed partitioned views. We show you the execution plans for various queries so you can see how SQL Server distributes queries across the nodes. (You can download the code listings from the August article, which shows you how to set up the distributed partitioned views we use in this example, by entering InstantDoc ID 9086 at http://www.sqlmag.com/ and opening the 9086.zip file.)

Let's prepare to query the view that we created in last month's article by using the following script to populate the Orders view with all the rows from the Orders table in the Northwind database:

— Populate the Orders view
USE testdb
INSERT INTO Orders
  SELECT * FROM Northwind.dbo.Orders

Next, let's start the querying demonstration by executing simple select statements that retrieve all the rows from the Customers view.

SELECT * FROM Customers

Now look at the execution plan that Figure 1 shows. Notice that these statements query the local table CustomersAF. SQL Server issues a remote query against each of the other tables: Node2.testdb.dbo .CustomersGP and Node3.testdb.dbo.CustomersQZ. SQL Server concatenates the result of the queries and returns the result to the user.

Next, let's perform a query that requests rows only from the local table.

SELECT *
FROM Customers
WHERE customerid = 'ALFKI'

Now look at the execution plan for this query, which Figure 2 shows. The Startup Filters (the yellow filters in the plan) are the key building blocks that the optimizer uses to determine whether, at runtime, SQL Server needs to go to a particular node to get rows. If you hold your mouse pointer over the local Clustered Index Scan or over either of the two remote queries, you'll notice that the graphical execution plan incorrectly shows that SQL Server executed each of the queries once. But look at the textual output, which Figure 3, page 42, shows, of the statistics profile for the same query. This output (Executes = 0) shows that SQL Server executed neither of the remote queries. This fact significantly affects query performance. SQL Server accessed only the servers that contained rows that the query needed. Note that SQL Server won't always use the startup filter to determine at runtime whether it needs to access a remote node. SQL Server auto-parameterized the query above. In other words, SQL Server placed the query's execution plan in cache with a parameter for the customerid column that the example used in our search criteria. SQL Server reuses auto-parameterized plans when it runs a similar query with a different value in the search criteria, thus avoiding the expense of generating a new plan. For example, if you run the query above but replace the customer ID with another one, SQL Server will reuse the auto-parameterized plan.

SELECT *
FROM Customers
WHERE customerid = 'OLDWO'

The execution plan looks the same as the last one, of course, because it's the same plan. But if you look at the output of the statistics profile, you'll notice that SQL Server executed the remote query against Node3 once, whereas SQL Server didn't execute the queries against the local server (Node1) or the remote server (Node2). SQL Server is conservative in determining which queries to auto-parameterize. If even a slight chance exists that two queries that are similar but have different values in the search criteria will require different plans, SQL Server won't auto-parameterize the plans. For example, consider the following query and its execution plan, which Figure 4 shows:

SELECT *
FROM Customers
WHERE customerid = 'ALFKI'
   OR customerid = 'ANATR'


ARTICLE TOOLS

Comments
  • Pederb
    8 years ago
    Nov 26, 2004

    Hi
    I have a question regarding quering partitioned views in Sqlserver2000. If I query a partitioned view, but don't know the values in the where clause, i.e. select * from viewA where intVal in(select intVal from tbl1). Will this result in an optimized query that searches only the relevant tables?

  • Yumiko Takedomi
    8 years ago
    Mar 12, 2004

    I have SQL2K enterprise on W2K advance.
    I have tested a partitioned view. Only when the check constraints are added to the member tables during tables are created, this view works. But for the tables I added check constraints after the creation, the partitioned views don't work. (it is not SQL7)
    Another thing is when I don't have top in select SQL server access all member tables when only one member table is needed.
    Is it a bug or any configuration to be changed?

You must log on before posting a comment.

Are you a new visitor? Register Here
  • SP1?
    I know there is a SP1 for SQL 2008 R2 available....and there is a "feature pack" as well... ...
  • SQL database mirroring
    I have SQL Server 2008 R2 Enterprise 64bit on Windows 2008 R2 Enterprise 64bit.  Each SQL Server has...
  • Dell Compellent Disk Drive
    Does anybody has experience with Dell Compellent Disk Drive? Basically, this system manages all disk...
  • Sql server performance tuning
    I need to find a tool that help me to optimize sql server,queries,improve the performance and solve ...