5 Ocak 2025 Pazar

LIMIT ve Covering Index + Subquery

Örnek
Şöyle yaparız
SELECT t1.name, t1.age, t1.gender, t1.create_time FROM student as t1 
  INNER JOIN 
   (SELECT id FROM student ORDER BY create_time DESC LIMIT 1000000,10) AS t2 ON t1.id = t2.id;
Açıklaması şöyle
The key lies in that the subquery only retrieves the primary key IDs. By taking advantage of the index coverage technique, it first accurately locates a small number of primary key IDs that meet the conditions, and then queries based on these primary key IDs later, which significantly improves the query efficiency and reduces the query cost.

LIMIT ve Seek sayfalama : WHERE koşulu içerir

Giriş
Seek sayfalama aynı zamanda Starting ID Positioning Method olarak ta bilinir. Burada amaç Primary Key için bir where koşulu vermek. Böylece atlanması gereken satır sayısı yöntemi yerine direkt sayfaya gitmek mümkün. Açıklaması şöyle
The Starting ID Positioning Method means specifying a starting ID when using the LIMIT query. And this starting ID is the last ID of the previous query. For example, if the ID of the last record in the previous query is 990000, then we start scanning the table from 990001 and directly skip the first 990000 records, so the query efficiency will be improved.
Örnek
Şöyle yaparız
SELECT name, age, grade FROM student where id > 990000 ORDER BY id LIMIT 10;
Örnek
Şöyle yaparız. Burada sayfadaki en son satırın özelliğinden daha büyük olan sonraki satır isteniyor.
SELECT * FROM objects WHERE id >= 100 ORDER BY id LIMIT 3;

LIMIT ve Covering Index + Subquery

Örnek Şöyle yaparız SELECT t1.name, t1.age, t1.gender, t1.create_time FROM student as t1    INNER JOIN     (SELECT id FROM student ORDER BY ...