Strange SQL Query

Hi,

the following SQL Query is executed from the privacyIDEA Application against our MySQL Server:

SELECT COUNT ( * ) AS `count_1`
  FROM 
    (SELECT DISTINCTROW `tokenowner` . `resolver` AS `tokenowner_resolver` ,
       `tokenowner` . `user_id` AS `tokenowner_user_id`
      FROM `tokenowner` , `token`
     WHERE `token` . `active` = TRUE
       AND `token` . `id` = `tokenowner` . `token_id` ) AS `anon_1`

With this query our CPU on the database server is at 100% utilization. As far as I can tell, no indices are missing either. Since I cannot find the query in the source code: Where does this come from and how can we turn it off? Is this even used by privacyIDEA? Or is it something from the SQLAlchemy Code?

Regards

Stephan

The queries are all created by SQLAlchemy, which is the abstraction layer.
In the code you will find Python classes and methods on python Objects. So the query is initiated by privacyIDEA, but it is not written in the code in this wording.