у меня есть индексация, включенные для всех столбцов (кроме текстового данного данных) для всех таблиц вместе с композитными кошачьями (в то время как исследование для Cure), но не может преодолеть это. Несмотря на то, что у меня есть лицензионная страница, и я получаю 50 записей на страницу.
Код: Выделить всё
CREATE TABLE `users` (
`id` BIGINT UNSIGNED AUTO_INCREMENT,
`user_name` VARCHAR(20) DEFAULT NULL,
...
PRIMARY KEY (`id`),
KEY `user_name`(`user_name`),
...
);
CREATE TABLE `transactions` (
`user_id` BIGINT UNSIGNED,
`UniquePaymentRequestId` VARCHAR(100),
`TransactionNumber` VARCHAR(100),
`CustomerNumber` VARCHAR(100),
`OrderId` VARCHAR(40),
`Amount` DECIMAL(12,6),
`UserCharge` DECIMAL(12,6),
`DepartmentCharge` DECIMAL(12,6),
`ServiceCode` INT UNSINGED,
`payment_date` date GENERATED ALWAYS AS (cast(`creation_time` as date)) VIRTUAL,
`creation_time` DATETIME,
...
KEY `UniquePaymentRequestId`(`UniquePaymentRequestId`),
KEY `TransactionNumber`(`TransactionNumber`),
KEY `CustomerNumber`(`CustomerNumber`),
KEY `OrderId`(`OrderId`),
KEY `Amount`(`Amount`),
KEY `UserCharge`(`UserCharge`),
KEY `ServiceCode`(`ServiceCode`),
KEY `DepartmentCharge`(`DepartmentCharge`),
KEY `creation_time`(`creation_time`),
KEY `payment_date` (`payment_date`),
KEY `transactions` (
`UniquePaymentRequestId`, `TransactionNumber`, `CustomerNumber`, `OrderId`,
`Amount`, `UserCharge`, `DepartmentCharge`, `creation_time`
)
);
CREATE TABLE `service_departments` (
`id` BIGINT UNSIGNED AUTO_INCREMENT,
`title` VARCHAR(255),
`type` VARCHAR(3) DEFAULT 'non',
...
PRIMARY KEY (`id`),
UNIQUE `title`(`title`),
KEY `type`(`type`),
...
);
CREATE TABLE `services` (
`service_department_id` BIGINT UNSIGNED,
`title` VARCHAR(255),
...
KEY `service_department_id`(`service_department_id`),
UNIQUE `title`(`title`),
...
);
< /code>
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>
Объясните: < /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
Подробнее здесь: https://stackoverflow.com/questions/797 ... posite-key
Мобильная версия