MySQL query stucks with state "Sending Data"
I have following MySQL query which is stucked with state "Sending Data"
and running from past 14 hours. Query has 3 parts. First part is a self
join on table AGG_EI which fetches DISTINCT combination of
uuid,cmp_id,lTypeId for the max date. Second part fetches
uuid,cmp_id,lType_id,date from table CUL. First and second part are joined
and stored in a temporary table. Third part selects data from temporary
table and stores in CUL table. AGG_EI table has 4.5 million
records(duplicate uuid,cmp_id,lTypeId,date combination with other columns
not used in query) and CUL has 0.7 million records(unique combination of
uuid,cmp_id,lTypeId,date)
CREATE TEMPORARY TABLE IF NOT EXISTS temp_lt
SELECT cLType.uuid AS uuid,
cLType.cmp_id AS cmp_id,
cLType.lTypeId AS lTypeId,
(CASE WHEN cLType.lTypeId = eLType.lTypeId THEN eLType.lFrom
WHEN eLType.lFrom IS NULL THEN DATE_FORMAT(now(),'%Y%m%d')
ELSE cLType.lFrom END) AS lFrom
FROM
(
SELECT DISTINCT d1.ei_uuid AS uuid,
d1.cmp_id AS cmp_id,
d1.ei_type AS lTypeId,
d1.datedm_id AS lFrom
FROM AGG_EI d1
LEFT OUTER JOIN AGG_EI d2
ON (d1.ei_uuid = d2.ei_uuid
AND d1.cmp_id = d2.cmp_id
AND d1.datedm_id <
d2.datedm_id )
WHERE d2.ei_uuid IS NULL AND d2.cmp_id IS NULL
) AS cLType
LEFT OUTER JOIN
(
SELECT uuid AS uuid,
cmp_id AS cmp_id,
ei_type AS lTypeId,
lFrom AS lFrom
FROM
CUL
) AS eLType
ON cLType.uuid = eLType.uuid AND cLType.cmp_id = eLType.cmp_id;
INSERT INTO `CUL` (`uuid`,`cmp_id`,`ei_type`,`lFrom`)
SELECT uuid,cmp_id,lTypeId,lFrom FROM temp_lt;
Why does this query gets stucked at state "sending data"
No comments:
Post a Comment