Hello,I have a view selecting from two tables that combines the results with a UNION ALL. Both SELECT statements are selecting from a column like as follows:SELECT CAST('ACTION' as NVARCHAR(255)) as TYPE,column(1)..column(2)..UNION ALLSELECT 'EVENTS',column(1)..column(2)..Then there's a stored procedure that selects a series of columns then does an ORDER BY by the TYPE column. I was told the ORDER BY the TYPE column is a must.Below is the code:[b]SELECT e.ID, e.TYPE, e.EVENT_DATE, e.TENANT_ID, e.WORKSPACE_ID, e.TOUCHPOINT_ID, e.INTERACTION_ID, e.PROPOSITION_ID, e.ACTIVITY_TYPE_ID, e.ACTION_ID, e.RECOGNITION_STATUS, e.CAUSE, e.IN_CONTROL_GROUP, e.IS_COMPLETE, COALESCE(tids.PRIMARY_TRACKER_ID, e.TRACKER_ID) TRACKER_ID FROM EVENTS e LEFT OUTER JOIN TRACKER_IDS tids ON e.TRACKER_ID = tids.TRACKER_ID AND e.TENANT_ID = tids.TENANT_ID AND e.WORKSPACE_ID = tids.WORKSPACE_ID WHERE COALESCE (tids.PRIMARY_TRACKER_ID_HASH, e.TRACKER_ID_HASH) BETWEEN @p1 AND @p2 AND e.DATE_ID >= @p3 ORDER BY e.TYPE DESC;[/b]Since I'm unable to create an indexed view due to the UNION BY, is there anything else I could do to enhance the performance of this query? Is there a way I could somehow index the TYPE, even though this doesn't exist within any of the tables?Thank you for your answers :)
↧