爲什麼在這兩個查詢之間存在時間執行差異,即使它們從同一個表中檢索到相同數量的行?mysql查詢,=和IN之間的性能不同
select cognome, nome, lingua, count(*)
from archivio.utente
where cognome in ('rossi','pecchia','pirono')
group by cognome, nome, lingua;
... ...
…
| Rossi | Mario | it | 1 |
| Pironi | Luigi | it | 1 |
| Pecchia | Fabio | it | 1 |
+----------------------+---------+--------+----------+
779行中集合(0.03秒)
select cognome, nome, lingua, count(*)
from archivio.utente
where nome='corrado'
group by cognome, nome, lingua;
... ... ...
| Rossi | Mario | it | 1 |
| Pironi | Luigi | it | 1 |
| Pecchia | Fabio | it | 1 |
+----------------------+---------+--------+----------+
7 37行中的組(0.47秒)
也許第二個在冷藏緩存上運行(即它首先運行)。爲了比較時間,你需要多次運行查詢,並且要小心數據是否已經被讀入內存。 –
您正在測試兩個不同的列。也許'cognome'被索引,'name'不是? – tadman
他們不「檢索相同數量的行」; 779 vs 737. – HoneyBadger