我需要優化以下sql查詢,因爲我一直在等待它的過去45分鐘執行。我需要優化以下sql查詢
create database comparelogs;
use comparelogs;
create table compare(field varchar(1080));
load data local infile 'c:/path/text.txt'
into table compare
lines terminated by '\n';
以下查詢是消耗時間的查詢。
SELECT
field,
(SELECT COUNT(*) FROM compare T2 WHERE T2.field = T1.field) AS Count,
@row_num := if(@prev_value=field,@row_num+1,1) as Occurrence,
@prev_value := field as previous_value
FROM compare T1
order by field;
input data:(from text.txt file)
/Jols/AAP/AAP.36/Ads\AdS_7.75x10_1.29.75_k
/Jols/AAP/AAP.36/Ads\PhyJobPl4x1034_BW_1.5.pdf
/Jls/AAP/AAP.36Ads\Cusins BW_rint_FPbw_1.3.pdf
/Jouals/AAP/AAP.36Ads\GeneryjWebdBW_1.6.pdf AAR356BF
/Jals/AAP/AAP.36Ads\GeneralWyjyjyAW_1.6.pdf AAR356BF
/Jls/AAP/AAP.36Ads\XtraCredit filler ad - PROPRIETARY ONLY_4C_1.0.pdf
/Jos/AAP/AAP.36Ads\AAP_May-Jun_10_Havel's_EchoBlock_1.0.pdf
/Jls/AAP/AAP.36//As\Roc76SolidAdbw_1.0.pdf
/Jls/AAP/AAP.36//A\RAPM_fi7ul ad_BW_1.0.pdf
/Jls/AAP/AAP.36/As\AAP_1_11_Bjhkytaun_Dyjidance_1.0.pdf
/Jls/AAP/AAP.36/s\AAPyjs36_yj.2.pdf
..........................................upto 200000 records.
它已經超過45分鐘,它仍在執行,我怎麼能優化這個來快速得到結果。 我正在使用mysql56。
加載成功完成。我在執行查詢時執行最終查詢 – user3111030