Quantcast
Channel: SQL Server Master Data Services forum
Viewing all articles
Browse latest Browse all 1311

Why do the dynamically built subscription views use an inline function?

$
0
0

I am using Master Data Services for SQL Server 2012 SP2.  All the subscription views that are created use code similar to:

ALTER VIEW [mdm].[MdsView]
/*WITH ENCRYPTION*/
AS SELECT
	T.ID AS ID
	,T.MUID AS MUID

	/* More Columns */

FROM mdm.[tbl_3_36_EN] AS T
INNER JOIN mdm.tblModelVersion AS V ON V.ID = T.Version_ID
	AND V.ID = [mdm].[udfModelVersionIDGetbyFlagID](3)
LEFT JOIN mdm.tblModelVersionFlag AS DV ON DV.ID =  V.VersionFlag_ID
WHERE T.Status_ID = 1
	AND T.Version_ID = [mdm].[udfModelVersionIDGetbyFlagID](3);

In that first inner join with mdm.tblModelVersion MDS subcription views are using a inline function mdm.udfModelVersionIDGetbyFlagID(3).  This seems to be redundant because the where clause filters the tblModelVersion table on the same call to mdm.udfModelVersionIDGetbyFlagID(3). 

Regardless of the redundancy it would be great if this inline call was converted just another clause to filter the mdm.tblModelVersion on the version flag ID because when the query optimizer decides to join one of these views using a loop join it can take hours to execute for a view with thousands of rows as the inline function was being called twice for every row in the joined view.

We ran into this problem when we had a stored procedure call two levels deep into a call stack join against multiple MDS views.

We worked around the problem by specifying HASH or MERGE joins explicitly when joining MDS subscription views.



Viewing all articles
Browse latest Browse all 1311

Trending Articles