나는 완전히 mysql에 익숙하며 아래의 mysql 쿼리를 실행하려고 시도했지만 엄청나게 천천히 달리고있는 것으로 보인다. 표는 약 100MB이고 약 2 백만 행이 들어 있습니다.매우 느린 쿼리
Create TEMPORARY table temp_table as
(
SELECT
pcur.RECORD_ID,
pcur.Price,
(pcur.Price - plast.Price) as 'Price_Difference',
CASE
when plast.Price between 0 and 0.25 then ((pcur.Price - plast.Price)/0.001)
when plast.Price between 0.2501 and 0.5 then ((pcur.Price - plast.Price)/0.005)
when plast.Price between 0.5001 and 10 then ((pcur.Price - plast.Price)/0.01)
when plast.Price between 10.0001 and 20 then ((pcur.Price - plast.Price)/0.02)
when plast.Price between 20.0001 and 100 then ((pcur.Price - plast.Price)/0.05)
when plast.Price between 100.0001 and 200 then ((pcur.Price - plast.Price)/0.1)
when plast.Price between 200.0001 and 500 then ((pcur.Price - plast.Price)/0.2)
when plast.Price between 500.0001 and 1000 then ((pcur.Price - plast.Price)/0.5)
when plast.Price between 1000.0001 and 2000 then ((pcur.Price - plast.Price)/1)
when plast.Price between 2000.0001 and 5000 then ((pcur.Price - plast.Price)/2)
when plast.Price between 5000.0001 and 9995 then ((pcur.Price - plast.Price)/5)
END AS Price_Diff_Ticks
FROM
/* First aliased table is the current record */
00005 pcur
/* Second aliased table is the previous one, whose id is one behind */
LEFT JOIN 00005 plast ON (pcur.Record_ID = plast.Record_ID + 1)
)
;
테이블의 인덱스 보고서.
"Table" "Non_unique" "Key_name" "Seq_in_index" "Column_name" "Collation" "Cardinality" "Sub_part" "Packed" "Null" "Index_type" "Comment" "Index_comment"
============================================================================================
"00005" "0" "PRIMARY" "1" "RECORD_ID" "A" "2275579" "" "" "" "BTREE" "" ""
무엇이 잘못 되었나요? 또는 내가 느리게 만들 수 없었던 것은 무엇입니까?
길이가 길어질 수 있습니다. 어쩌면 테이블을 만든 다음 데이터를 따로 삽입 해보십시오. 나는 모른다. –
인덱스가 클러스터되지 않은 경우 클러스터 된 상태로 만들거나 포함 된 열로 "Price"를 추가 할 수 있습니다. 그렇지 않으면, 조회는 비용이 많이 드는 색인 스캔을 반복해야합니다. – McGarnagle
여기에 문제가 될만한 것이 없습니다. 인덱스가 있으므로 조인이 나쁘지 않습니다. 비 클러스터형이라 할지라도 2 백만 건의 조회 만 있습니다. 이 사건은 매우 간단합니다. 그래서 나는 다른 문제를 의심 할 것입니다 :이 테이블이 사용 중입니까? 어쩌면 당신의 프로세스는 테이블을 잠그고있는 다른 사람들에 의해 굶어 죽을지도 모릅니다. IO는 어떤가? 어쩌면이 테이블을 만들 때 공간을 할당하거나 소스를 읽을 가능성이 적습니다. –