执行计划不准确
http://social.msdn.microsoft.com/Forums/en/sqldatabaseengine/thread/35d3df7d-ff82-48a4-bfbc-ffb95e31017f
没人鸟我...来csdn发个..
多谢
I have a typical fact - dimensional data warehouse, and when I am querying data from it I see strange thing happens...
sample query(query 1):
Select count(1) from fct_device tWhere t.monitored_Id=2 and t.data_time_id in ( [b] select data_time_id from dim_date t where data_date >= 28 and not exists(select 1 from dim_date where data_date > t.data_date and data_year = t.data_year and data_month = t.data_month )[/b] )
Select count(1) from fct_device tWhere t.monitored_Id=2 and t.data_time_id in ( 20111031,20111130,20111231,20120131,20120229,20120331,20120430 )
Select count(1) from fct_device tWhere t.monitored_Id=2 and t.data_time_id in ( select [b]Cast(data_time_id as char)[/b] from dim_date t where data_date >= 28 and not exists(select 1 from dim_date where data_date > t.data_date and data_year = t.data_year and data_month = t.data_month ) )
Query 3 takes less than 1 min(still more than what query 2 takes of cause but better than query 1)
Plan for query 3:
|--Compute Scalar(DEFINE:([Expr1011]=CONVERT_IMPLICIT(int,[globalagg1014],0)))
|--Stream Aggregate(DEFINE:([globalagg1014]=SUM([partialagg1013])))
|--Parallelism(Gather Streams)
|--Stream Aggregate(DEFINE:([partialagg1013]=Count(*)))
|--Hash Match(Right Semi Join, HASH:([Expr1012])=([t].[Data_time_Id]), RESIDUAL:(fct_device.[Data_time_Id]=[Expr1012]))
|--Bitmap(HASH:([Expr1012]), DEFINE:([Bitmap1015]))
| |--Parallelism(Distribute Streams, Broadcast Partitioning)
| |--Nested Loops(Left Anti Semi Join, WHERE:(dim_date.[DATA_DATE]>fct_device.[DATA_DATE]...)
| |--Compute Scalar(DEFINE:([Expr1012]=CONVERT_IMPLICIT(int,CONVERT(char(30)...)
| | |--Clustered Index Scan(OBJECT:(dim_date where data_date>=(28))
| |--Clustered Index Scan(OBJECT:(dim_date)
|--Table Scan(OBJECT:(fct_device where monitor_id =2 and PROBE([Bitmap1015])
Seems the CONVERT makes the optimizer decide to execute the sub-query first, and apparently it made a very well decision..
I think the key is to take advantage of the partition table but I am not an expert.. So can someone please help me understand what's going on here it would be great!
thanks
p.s Where can I find some really good articles which can help me understand what execution plan shows(e.g. what is RESIDUAL in query plan)? many thanks
p.p.s
----update-----
The estimated execution gives the estimated cost:
Query 1 25% (actual: more than 1min)
Query 2 12% (actual: 15 sec)
Query 3 63%(actual: ~50 sec)
And I already updated the statistics for both tables before querying.
[解决办法]
那是MSDN,csdn请用中文描述问题,看到英语偶头疼
[解决办法]
满屏的英格里许哦,头痛啊