I migrated data from a MyISAM database to InnoDB and some VIEW
were extremely slow (on average 15x slower), after much research I found this answer from @maniero and it compares the two engines.
In his response I noticed that InnoDB is slow with clause COUNT(*)
so I removed COUNT(*)
from SELECT
within VIEW
and here is the result:
310x faster.
The query I am running is this (Decreases to become more readable):
SELECT DISTINCT
'a'.'ASSINATURAS_ID' AS 'ASSINATURAS_ID',
'pd'.'PEDIDOS_DETALHES_Descricao_Produto' AS 'PEDIDOS_DETALHES_Descricao_Produto',
'pd'.'FK_PRODUTO' AS 'FK_PRODUTO',
(SELECT
COUNT(*)
FROM
'licencas'
WHERE
('licencas'.'FK_PEDIDO' = 'p'.'PEDIDOS_ID')) AS 'TotalDownloadSubscriptionCount',
FROM
(('n_assinaturas' 'a'
JOIN 'pedidos' 'p' ON (('p'.'PEDIDOS_ID' = 'a'.'FK_PEDIDO')))
JOIN 'planos_conta' 'pc' ON (('pc'.'ID_PLANOS_Conta' = 'p'.'FK_PLANOS_Conta')))
Is there an option to COUNT(*)
in InnoDB ?