zoukankan      html  css  js  c++  java
  • 使用相关子查询

    truncate t_target;  
    insert into t_target  
    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);
            这个语句很长时间都出不来结果,只看一下执行计划吧。

    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 | 997282 |     1.00 | Using where                  |
    +----+--------------------+-------+------------+------+---------------+------+---------+------+--------+----------+------------------------------+
    2 rows in set, 3 warnings (0.00 sec)
            主查询和相关子查询都是全表扫描,一共要扫描100万*100万数据行,难怪出不来结果。
    ---------------------

  • 相关阅读:
    JS---数组(Array)处理函数整理
    xStream完美转换XML、JSON
    DD_belatedPNG解决IE6下PNG不透明问题
    转 DataTorrent 1.0每秒处理超过10亿个实时事件
    转 Apache Kafka:下一代分布式消息系统
    Selenium(ThoughtWorks公司开发的web自动化测试工具)
    oracle 拆分字符串并转换为表
    C# winform 使用DsoFramer 创建 显示office 文档
    visual studio 2014 新特性
    转 管线开发
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11311195.html
Copyright © 2011-2022 走看看