I am trying to get partitioned views to work, and still see query optimizer scanning both tables. Here is my script:
CREATE TABLE A(DataDate [date] NOT NULL CHECK(datepart(yy, DataDate) <= 2010))
CREATE TABLE B(DataDate [date] NOT NULL CHECK(datepart(yy, DataDate) > 2010))
CREATE VIEW V AS SELECT * FROM A UNION ALL SELECT * FROM B
select * from V where datepart(yy, DataDate) = 2009
But when I look at the execution plan I see that both table A and table B were scanned and the "Number of Executions" for both tables is 1. I would expect table A to have Number of Executions = 1, and table B to have Number of Executions = 0. I am on SQL Server 2012.
Can somebody clarify how this is supposed to work? Thank you.
Is supposed to work like this: