mysql query sql 效能调优记录-排序时最快的取出尽量少的字段且索引字段(三)


mysql> select company_albums.id,company.name as company_name,company.url as company_url,company_albums.name as company_albums_name,
    ->                 company_albums.url as company_albums_url,view_count,thumbnail_path,qq ,brand_shop_id
    -> from company,company_albums
    -> where company_albums.com_id=company.id
    -> ORDER BY `view_count` desc
    -> LIMIT 69600, 15 ;
+--------+--------------+--------------------------------+------------------------+------------------------------------------------------+------------+----------------+------------+---------------+
| id     | company_name | company_url                    | company_albums_name    | company_albums_url                                   | view_count | thumbnail_path | qq         | brand_shop_id |
+--------+--------------+--------------------------------+------------------------+------------------------------------------------------+------------+----------------+------------+---------------+
----------------------
+--------+--------------+--------------------------------+------------------------+------------------------------------------------------+------------+----------------+------------+---------------+
2 rows in set (3.10 sec)


mysql> explain select company_albums.id,company.name as company_name,company.url as company_url,company_albums.name as company_albums_name,
    ->                 company_albums.url as company_albums_url,view_count,thumbnail_path,qq ,brand_shop_id
    -> from company,company_albums
    -> where company.id=company_albums.com_id
    -> ORDER BY `view_count` desc
    -> LIMIT 69600, 15 \G;
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: company_albums
         type: ALL
possible_keys: com_idx
          key: NULL
      key_len: NULL
          ref: NULL
         rows: 72441
        Extra: Using filesort
*************************** 2. row ***************************
           id: 1
  select_type: SIMPLE
        table: company
         type: eq_ref
possible_keys: PRIMARY
          key: PRIMARY
      key_len: 4
          ref: test_01.company_albums.com_id
         rows: 1
        Extra:
2 rows in set (0.00 sec)





mysql> select company_albums.id,company_albums.name as company_albums_name,
    ->                 company_albums.url as company_albums_url,view_count,thumbnail_path,company.name as company_name,company.url as company_url,qq ,brand_shop_id
    -> from company_albums ,(select company_albums.id as ca_id
    -> from company,company_albums
    -> where company_albums.com_id=company.id
    -> ORDER BY `view_count` desc
    -> LIMIT 69600, 15
    -> ) as t,company  where company.id=company_albums.com_id and t.ca_id = company_albums.id order by view_count desc
    -> ;
   
2 rows in set (0.34 sec)


mysql> explain select company_albums.id,company_albums.name as company_albums_name,                 company_albums.url as company_albums_url,view_count,thumbnail_path,company.name as company_name,company.url as company_url,qq ,brand_shop_id  from company_albums ,(select company_albums.id as ca_id from company,company_albums where company_albums.com_id=company.id ORDER BY `view_count` desc  LIMIT 69510, 18 ) as t,company  where company.id=company_albums.com_id and t.ca_id = company_albums.id order by view_count desc \G;
*************************** 1. row ***************************
           id: 1
  select_type: PRIMARY
        table: <derived2>
         type: ALL
possible_keys: NULL
          key: NULL
      key_len: NULL
          ref: NULL
         rows: 18
        Extra: Using temporary; Using filesort
*************************** 2. row ***************************
           id: 1
  select_type: PRIMARY
        table: company_albums
         type: eq_ref
possible_keys: PRIMARY,com_idx
          key: PRIMARY
      key_len: 4
          ref: t.ca_id
         rows: 1
        Extra:
*************************** 3. row ***************************
           id: 1
  select_type: PRIMARY
        table: company
         type: eq_ref
possible_keys: PRIMARY
          key: PRIMARY
      key_len: 4
          ref: test_01.company_albums.com_id
         rows: 1
        Extra:
*************************** 4. row ***************************
           id: 2
  select_type: DERIVED
        table: company_albums
         type: ALL
possible_keys: com_idx
          key: NULL
      key_len: NULL
          ref: NULL
         rows: 72441
        Extra: Using filesort
*************************** 5. row ***************************
           id: 2
  select_type: DERIVED
        table: company
         type: eq_ref
possible_keys: PRIMARY
          key: PRIMARY
      key_len: 4
          ref: test_01.company_albums.com_id
         rows: 1
        Extra: Using index
5 rows in set (0.34 sec)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值