21 Ağustos 2023 Pazartesi

EXPLAIN ANALYZE

JSON Çıktı
Açıklaması şöyle
Starting from MySQL 9.0.0, it is now possible to save the JSON output of the EXPLAIN ANALYZE command into a user variable using the following new syntax:
EXPLAIN ANALYZE FORMAT=JSON INTO @variable select_stmt
Açıklaması şöyle
The INTO clause is only supported with FORMAT=JSON; FORMAT must be explicitly specified. This form of EXPLAIN ANALYZE also supports optional FOR SCHEMA or FOR DATABASE clauses.


Table Scan
Full Scan anlamına gelir. 
Örnek
Şöyle yaparız. id alanında index veya primary key olmadığı için tüm tabloyu tarar
mysql> explain analyze select * from employee1 where id = 3456;
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| EXPLAIN                                                                                                                                                                                               |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| -> Filter: (employee1.id = 3456)  (cost=1989 rows=1965) (actual time=5.24..29.3 rows=1 loops=1)
    -> Table scan on employee1  (cost=1989 rows=19651) (actual time=0.0504..27.3 rows=20000 loops=1)
 |
+--------------------------------------------------------------------------------------------------------
Index lookup
Örnek
Tablo için bir indeks yaratalım
CREATE INDEX index1 ON employee1 (FirstName);
Şöyle yaparız. FirstName alanında index olduğu için tüm indeksi tarar
mysql> explain analyze select * from employee1 where FirstName = 'user-13456';
+-------------------------------------------------------------------------------------------------------------------------------------+
| EXPLAIN                                                                                                                             |
+-------------------------------------------------------------------------------------------------------------------------------------+
| -> Index lookup on employee1 using index1 (FirstName='user-13456')  (cost=0.35 rows=1) (actual time=0.0594..0.0669 rows=1 loops=1)
 |
+-------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

Hiç yorum yok:

Yorum Gönder

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 ...