Ich habe Aktivität, Kontakt, Benutzer, deleted_contact Tabelle in meiner Datenbank.Zeilen aus 4 Tabellen in MySQL mit schwerer Datenbank holen
- Aktivitätstabelle hat 5 Millionen Zeilen
- Kontakttabelle hat 5 Millionen Zeilen
- Benutzertabelle hat 5000 Zeilen
- delete_contact Tabelle hat 850.000 Zeilen
Nun mein Problem ist, dass, wenn ich Ich versuche, holen nur 10 Zeilen von beitreten alle Tabellen, nimmt mysql zu viel Last und irgendwann meine App totall y hört auf zu arbeiten.
Ich bin links verbinden. Bitte schlagen Sie mir den besten Weg vor, nur 10 Reihen von über vier Tischen zu nehmen.
Ich habe folgende Anfrage: -
SELECT activity.id,
activity.ipaddress,
deleted_contact.name,
activity.city,
activity.country,
activity.state,
activity.user_agent,
activity.browser_name,
activity.os_platform,
activity.details AS details,
activity.file_name AS filename,
activity.created_at AS Date,
activity.model_id,
activity.user_id,
activity.contact_id,
activity.type,
activity.city,
activity.state,
activity.country,
contact.name AS Contact,
email.subject AS emailsubject,
email.opened,
email.schedule_date,
email.schedule_timezone,
FROM activity
LEFT JOIN contact ON activity.contact_id = contact.id
LEFT JOIN email ON activity.model_id = email.id
LEFT JOIN user ON activity.user_id = user.id
LEFT JOIN deleted_contact ON deleted_contact.contact_id = activity.contact_id
WHERE activity.user_id IN (2,
56,
78,
93,
105,
2004,
345,
450,
321,
456)
GROUP BY activity.id,
email.id
ORDER BY activity.id DESC LIMIT 0,
10
Bitte fügen Sie die Abfrage und einige weitere Informationen über die Tabellenstruktur wie die Indizes usw. – Sirko
Wie lange dauert es Wenn Sie die Abfrage in mysql (im Gegensatz zu in der App) –
In meiner Aktivität Tabelle I Indizes für user_id nicht eindeutig, model_id nicht eindeutig, contact_id nicht eindeutig, Benachrichtigung nicht eindeutig und created_at nicht eindeutig. –