Code: Select all
-- organization: ~6,000 rows
CREATE TABLE organization (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
headquarterId INT,
-- other fields omitted
FOREIGN KEY (headquarterId) REFERENCES city(id)
);
-- city: ~150,000 rows
CREATE TABLE city (
id INT PRIMARY KEY AUTO_INCREMENT,
cityName VARCHAR(255) NOT NULL,
-- other fields omitted
INDEX idx_city_name (cityName DESC, id)
);
Ich habe eine mehr komplexe Abfrage , die:
- mehrere linke Join (ca. 4),
- mehrere Subquerien in beiden Selektionen in beiden Selektionen in beiden Selektionen in beiden Selektionen> und in beiden Selektionen in beiden Selektionen> und in beiden Selektionen in beiden Fällen in beiden Selektionen> und in beiden Fällen in beiden Selektionen> und in beiden Fällen haben die Auswachung. Klauseln,
- Ein Limit 15 Für die Pagination.
Code: Select all
SELECT *
FROM organization
LEFT JOIN city ON city.id = organization.headquarterId
ORDER BY city.cityName DESC;
Warum ist diese Abfrage trotz des Index auf der Stadt immer noch langsam. Tabellen? < /li>
Würde die Abfrage umstrukturieren oder mit einer Unterabfrage vorstellen?-> Sort row IDs: city.`cityName` DESC (actual time=96.1..99.2 rows=9133 loops=1)
-> Table scan on (cost=5053..5170 rows=9143) (actual time=82.6..86.1 rows=9133 loops=1)
-> Temporary table (cost=5053..5053 rows=9143) (actual time=82.6..82.6 rows=9133 loops=1)
-> Nested loop left join (cost=4139 rows=9143) (actual time=0.0893..21.9 rows=9133 loops=1)
-> Table scan on organization (cost=939 rows=9143) (actual time=0.072..10.4 rows=9133 loops=1)
-> Single-row index lookup on city using PRIMARY (id=organization.headquarterId)
(cost=0.25 rows=1) (actual time=0.001..0.00103 rows=1 loops=9133)
< /code>
Was ich bisher gefunden habe. Desc < /code> und id < /code>). src = "https://i.static.net/6jmtoubm.png"/>