0
我在MySQL特定查詢它使用整理兩個不同的表(索引)比較值,但這並不執行了幾個小時。查詢提供如下:MySQL的分頁查詢運行永遠
create temporary table elig_temp
select id from table_elig;
create index elig_temp on elig_temp(id);
create temporary table med_temp
select id from table_med;
create index med_temp on med_temp(id);
select COUNT(1) as result
from med_temp a
where exists
(
select 1
from elig_temp b
where a.id collate latin1_general_cs = b.id collate latin1_general_cs
)
FYI的elig_temp表有70K的記錄,而med_temp有100萬條記錄。
另外,table_elig的id字段和table_med表是從同一個表加密另一個字段的值的哈希值。因此,我嘗試使用二進制排序規則技術,如udf8_bin和latin1_bin使查詢運行,但我再次卡住。
我甚至通過用相同的排序規則的技術限定,即我與查詢中使用,用於table_med和table_elig但沒有運氣每個字段(VARCHAR和焦炭)嘗試。
請與有效執行此查詢時間的任何可能的解決方案建議我。
感謝戈登的建議。是的,查詢在沒有整理的情況下運行。當我嘗試使用下面的解決方案**中的代碼時,elig_temp和med_temp中的字段名稱顯示爲** id collate latin1_general_cs **,這不正確。 – Syrus 2014-09-02 09:21:12
@Syrus。 。 。只需使用'as'來設置正確的列名。 – 2014-09-02 12:04:09
糟糕!我錯過了什麼,沒有我。非常感謝,這解決了我的問題。 – Syrus 2014-09-03 06:11:06