Erstellen Sie Multi -Tabellen -Index-/Verbundtaste

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Erstellen Sie Multi -Tabellen -Index-/Verbundtaste

by Anonymous » 18 Aug 2025, 11:45

Ich habe eine Abfrage, die 3 Tabellen enthält. Wenn die abgerufene Datenlänge gering ist (ca. 50.000), funktioniert sie sehr schnell (fast unter einer Sekunde), aber wenn die Daten überschreiten, wird sie langsamer (9 Sekunden für
SELECT
U.user_name, S.department, S.service_code, S.service_name,
T.UniquePaymentRequestId, T.TransactionNumber, T.CustomerNumber, T.OrderId,
T.Amount, T.UserCharge, T.DepartmentCharge, T.creation_time
FROM transactions AS T
INNER JOIN (
SELECT user_id, user_name FROM users
WHERE user_type = 5
) AS U ON U.user_id = T.user_id
LEFT JOIN (
SELECT SD.title AS department, S.service_code, S.title AS service_name FROM services AS S
INNER JOIN service_departments AS SD ON SD.type = "non" AND SD.id = S.service_department_id
) AS S ON S.service_code = T.ServiceCode
WHERE T.payment_date >= '2025-07-19'
ORDER BY T.creation_time DESC
< /code>
Erklären Sie: < /p>
id select_type table type possible_keys key key_len ref rows Extra
------ ----------- ------ ------ ---------------------------------- --------------------- ------- ----------------------------- ------ -----------------------------
1 SIMPLE T ALL user_index,payment_date (NULL) (NULL) (NULL) 206192 Using where; Using filesort
1 SIMPLE users eq_ref PRIMARY,user_type PRIMARY 4 gramaone_production.T.user_id 1 Using where
1 SIMPLE SD ref PRIMARY,type type 63 const 8 Using where
1 SIMPLE S ref service_code,service_department_id service_department_id 5 gramaone_production.SD.id 3 Using where
[/code]
Wie behebe ich dieses Problem?

Top