Knowage autogenerated query understanding

140 Views Asked by At

I'm using knowage software for data analysis, I'm facing performance issues, now I'm watching 'dataset audit' log to see what queries does the system perform. I found this one that, to me, is a nonsense:

SELECT COUNT(*) 
FROM 

(select TOP(100) PERCENT "ATC_1" AS "ATC_1" 
from 

    (SELECT [ID_AFo]
          ,[ATC]
          ,[ATC_1]
          ,[ATC_3]
          ,[ATC_4]
          ,[ATC_5]

      FROM [AFO]

        ) T  order by "ATC_1" ASC
) u

inner T query is the dataset definition query I entered that basically is a select * from [AFO] on my table, outer wrap are made by knowage (I never wrote them)

doesn't a select count (*) from T have performed the same calculation but avoiding a cexpensive order by?

EDIT: Backend (data source) is MSSQL, cache server is MYSQL so frequent queries are on mysql

1

There are 1 best solutions below

4
On

This query is equivalent to:

SELECT COUNT(*)
FROM [AFO];

The only reason that I can think of for constructing such a query is if the "100" could be set to another value. I'm not sure if SQL Server's optimizer is good enough to eliminate the ORDER BY in the subquery.