zoukankan      html  css  js  c++  java
  • 表连接

    truncate t_target;  
    insert into t_target  
    select distinct t1.* from t_source t1,  
    (select min(item_id) item_id,created_time,item_name from t_source group by created_time,item_name) t2  
    where t1.item_id = t2.item_id;
            本次用时13秒,查询计划如下:

    mysql> explain select distinct t1.* from t_source t1,  
        -> (select min(item_id) item_id,created_time,item_name from t_source group by created_time,item_name) t2  
        -> where t1.item_id = t2.item_id;  
    +----+-------------+------------+------------+-------+---------------+-------------+---------+-----------------+--------+----------+------------------------------+
    | id | select_type | table      | partitions | type  | possible_keys | key         | key_len | ref             | rows   | filtered | Extra                        |
    +----+-------------+------------+------------+-------+---------------+-------------+---------+-----------------+--------+----------+------------------------------+
    |  1 | PRIMARY     | t1         | NULL       | ALL   | NULL          | NULL        | NULL    | NULL            | 997281 |   100.00 | Using where; Using temporary |
    |  1 | PRIMARY     | <derived2> | NULL       | ref   | <auto_key0>   | <auto_key0> | 5       | test.t1.item_id |     10 |   100.00 | Distinct                     |
    |  2 | DERIVED     | t_source   | NULL       | index | idx_sort      | idx_sort    | 94      | NULL            | 997281 |   100.00 | Using index                  |
    +----+-------------+------------+------------+-------+---------------+-------------+---------+-----------------+--------+----------+------------------------------+
    3 rows in set, 1 warning (0.00 sec)
            和没有索引相比,子查询虽然从全表扫描变为了全索引扫描,但还是需要扫描100万行记录。因此查询性能提升并不是明显。
    ---------------------

  • 相关阅读:
    JavaScript浏览器对象模型(BOM)之location对象
    JavaScript浏览器对象模型(BOM)之window对象
    8-python模拟登入(无验证码)
    7-python自定义opener
    6-豆瓣剧情排行爬虫
    2-chrome无法添加扩展程序
    5-有道爬虫demo(post)
    4-fiddler抓包中文乱码:
    3-百度贴吧爬虫
    2-python代码坑点
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11311216.html
Copyright © 2011-2022 走看看