Greetings,
I have 3 servers all running SQL Server 2000 - 8.00.818. Lets call
them parent, child1, and child 2.
On parent, I create a view called item as follows:
CREATE view Item as
select * from child1.dbchild1 .dbo.Item union all
select * from child2.DBChild2 .dbo.Item
On child1 and child2, I have a table "item" with a column named "id"
datatype uniqueidentifie r (and many other columns). There is a
non-clustered index created over column "id".
When I connect to the parent server and select from the view
Select id, col1, col2, …. From item where id =
‘280A33E0-5B61-4194-B242-0E184C46BB59'
The query is distributed to the children "correctly" (meaning it
executes entirely (including the where clause) on the children server
and one row is returned to the parent).
However, when I select based on a list of ids
Select id, col1, col2, …. From item where id in
(‘280A33E0-5B61-4194-B242-0E184C46BB59',
‘376FA839-B48A-4599-BC67-25C6820FE105')
the plan shows that the entire contents of both children item tables
(millions of rows each) are pulled from the children to the parent,
and THEN the where criteria is applied.
Oddly enough, if I put the list of id's I want into a temp table
select * from #bv1
id
------------------------------------
280A33E0-5B61-4194-B242-0E184C46BB59
376FA839-B48A-4599-BC67-25C6820FE105
and then
Select id, col1, col2, …. From item where id in (select * from #bv1)
the query executes with the where criteria applied on the children
databases saving millions of rows being copied back to the parent
server.
So, I have a hack that works (using the temp table) for this case, but
I really don't understand the root cause. After reading online books,
in a way I am confused why ANY of the processing is done on the
children servers. I quote:
=============== =============== =============== ===
Remote Query Execution
SQL Server attempts to delegate as much of the evaluation of a
distributed query to the SQL Command Provider as possible. An SQL
query that accesses only the remote tables stored in the provider's
data source is extracted from the original distributed query and
executed against the provider. This reduces the number of rows
returned from the provider and allows the provider to use its indexes
in evaluating the query.
Considerations that affect how much of the original distributed query
gets delegated to the SQL Command Provider include:
• The dialect level supported by the SQL Command Provider
SQL Server delegates operations only if they are supported by the
specific dialect level. The dialect levels from highest to lowest are:
SQL Server, SQL-92 Entry level, ODBC core, and Jet. The higher the
dialect level, the more operations SQL Server can delegate to the
provider.
Note The SQL Server dialect level is used when the provider
corresponds to a SQL Server linked server.
Each dialect level is a superset of the lower levels. Therefore, if an
operation is delegated to a particular level, then Queries involving
the following are never delegated to a provider and are always it is
also delegated to all higher levels.
evaluated locally:
• bit
• uniqueidentifie r
=============== =============== =============== ===
This suggests to me that any query having where criteria applied to a
datatype uniqueidentifie r will have the where criteria applied AFTER
data is returned from the linked server.
Any ideas on the root problem, and a better solution to get the query
and all the where criteria applied on the remoted linked server?
Thanks,
Bernie
I have 3 servers all running SQL Server 2000 - 8.00.818. Lets call
them parent, child1, and child 2.
On parent, I create a view called item as follows:
CREATE view Item as
select * from child1.dbchild1 .dbo.Item union all
select * from child2.DBChild2 .dbo.Item
On child1 and child2, I have a table "item" with a column named "id"
datatype uniqueidentifie r (and many other columns). There is a
non-clustered index created over column "id".
When I connect to the parent server and select from the view
Select id, col1, col2, …. From item where id =
‘280A33E0-5B61-4194-B242-0E184C46BB59'
The query is distributed to the children "correctly" (meaning it
executes entirely (including the where clause) on the children server
and one row is returned to the parent).
However, when I select based on a list of ids
Select id, col1, col2, …. From item where id in
(‘280A33E0-5B61-4194-B242-0E184C46BB59',
‘376FA839-B48A-4599-BC67-25C6820FE105')
the plan shows that the entire contents of both children item tables
(millions of rows each) are pulled from the children to the parent,
and THEN the where criteria is applied.
Oddly enough, if I put the list of id's I want into a temp table
select * from #bv1
id
------------------------------------
280A33E0-5B61-4194-B242-0E184C46BB59
376FA839-B48A-4599-BC67-25C6820FE105
and then
Select id, col1, col2, …. From item where id in (select * from #bv1)
the query executes with the where criteria applied on the children
databases saving millions of rows being copied back to the parent
server.
So, I have a hack that works (using the temp table) for this case, but
I really don't understand the root cause. After reading online books,
in a way I am confused why ANY of the processing is done on the
children servers. I quote:
=============== =============== =============== ===
Remote Query Execution
SQL Server attempts to delegate as much of the evaluation of a
distributed query to the SQL Command Provider as possible. An SQL
query that accesses only the remote tables stored in the provider's
data source is extracted from the original distributed query and
executed against the provider. This reduces the number of rows
returned from the provider and allows the provider to use its indexes
in evaluating the query.
Considerations that affect how much of the original distributed query
gets delegated to the SQL Command Provider include:
• The dialect level supported by the SQL Command Provider
SQL Server delegates operations only if they are supported by the
specific dialect level. The dialect levels from highest to lowest are:
SQL Server, SQL-92 Entry level, ODBC core, and Jet. The higher the
dialect level, the more operations SQL Server can delegate to the
provider.
Note The SQL Server dialect level is used when the provider
corresponds to a SQL Server linked server.
Each dialect level is a superset of the lower levels. Therefore, if an
operation is delegated to a particular level, then Queries involving
the following are never delegated to a provider and are always it is
also delegated to all higher levels.
evaluated locally:
• bit
• uniqueidentifie r
=============== =============== =============== ===
This suggests to me that any query having where criteria applied to a
datatype uniqueidentifie r will have the where criteria applied AFTER
data is returned from the linked server.
Any ideas on the root problem, and a better solution to get the query
and all the where criteria applied on the remoted linked server?
Thanks,
Bernie
Comment