/ / Date = max (Date) courant lentement - mysql, sql

Date = max (Date) courant lentement - mysql, sql

J'ai environ 6 millions de disques dans letable_historique. J'essaie de trouver tous les symboles dont la dernière ligne enregistrée ne correspond pas à la date la plus élevée de la table. Je crois que cette requête fonctionnera, mais son exécution prend une éternité. Si longtemps en fait, il met fin à la connexion à chaque fois. Est-il possible d'accélérer l'exécution de cette requête?

select symbol, histDate
from historical_data as a
where histDate =
(select max(histDate)
from historical_data as b
where a.symbol = b.symbol);

Réponses:

1 pour la réponse № 1

Vous voulez un index pour cette requête. Le meilleur indice est historical_data(symbol, histdate).

Vous trouverez peut-être plus rapide de formuler la requête en tant que:

select hd.*
from historical_data hd join
(select symbol, max(histDate) as maxhd
from historical_data
group by symbol
) s
on hd.histDate = s.histDate;

MODIFIER:

Oops. Votre exemple de requête ne "fait pas ce que le texte dit que vous voulez. Pour cela:

select symbol
from historical_data hd cross join
(select max(histDate) as maxhd from historical_data) m
group by symbol, maxhd
having max(hd.histDate) <> maxhd;