T_target TRUNCATE;
INSERT INTO T_target
SELECT DISTINCT from t_source T1 * T1 WHERE item_id in.
(SELECT min (item_id) from t_source T2 WHERE t1.created_time = t2.created_time and t1.item_name = t2.item_name);
this statement for a long time get out the results, just by looking at the implementation plan.
mysql> explain select distinct t1.* from t_source t1 where item_id in
-> (select min(item_id) from t_source t2 where t1.created_time=t2.created_time and t1.item_name=t2.item_name);
+----+--------------------+-------+------------+------+---------------+------+---------+------+--------+----------+------------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+--------------------+-------+------------+------+---------------+------+---------+------+--------+----------+------------------------------+
| 1 | PRIMARY | t1 | NULL | ALL | NULL | NULL | NULL | NULL | 997282 | 100.00 | Using where; Using temporary |
| 2 | DEPENDENT SUBQUERY | T2 | NULL | ALL | NULL | NULL | NULL | NULL | 997 282 | 1.00 | the Using the WHERE |
+ ---- + ----------------- --- + ------- + ------------ + ------ + --------------- + - ---- + ------ + --------- + -------- + -------- + ---------- + ----------------------
2 rows in the SET, 3 Represents warnings (0.00 sec)
main query and sub-queries are related to full table scan, a total of 100 to be scanned Wan * 1 million rows of data, no wonder not get results.
---------------------