tsql - Tableau-Generated Query Not Hitting the Optimal Table Index -
i have tableau-generated query looks like:
select (((datepart(year,(case when 0 = isdate(cast([table1].[m_date] varchar)) null else dateadd(day, datediff(day, 0, cast(cast([table1].[m_date] varchar) datetime)), 0) end)) * 10000) + (datepart(month,(case when 0 = isdate(cast([table1].[m_date] varchar)) null else dateadd(day, datediff(day, 0, cast(cast([table1].[m_date] varchar) datetime)), 0) end)) * 100)) + datepart(day,(case when 0 = isdate(cast([table1].[m_date] varchar)) null else dateadd(day, datediff(day, 0, cast(cast([table1].[m_date] varchar) datetime)), 0) end))) [md:m_date:ok] [tbl].[table] [table1] group (((datepart(year,(case when 0 = isdate(cast([table1].[m_date] varchar)) null else dateadd(day, datediff(day, 0, cast(cast([table1].[m_date] varchar) datetime)), 0) end)) * 10000) + (datepart(month,(case when 0 = isdate(cast([table1].[m_date] varchar)) null else dateadd(day, datediff(day, 0, cast(cast([table1].[m_date] varchar) datetime)), 0) end)) * 100)) + datepart(day,(case when 0 = isdate(cast([table1].[m_date] varchar)) null else dateadd(day, datediff(day, 0, cast(cast([table1].[m_date] varchar) datetime)), 0) end)))
table 'table' has 2 indexes:
- a clustered index on columns [m_date], [team], [player], [second].
- a non-unique, non-clustered index on columns [player], [m_date], [team]
when @ execution plan query, tells me second index being used. seems strange me because thought index used if columns involved form 'a leftmost prefix of index' (as explained here) query not. if explain not understanding, or if odd case incorrect index getting used, appreciated!
Comments
Post a Comment