亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 5501 | 回復(fù): 5
打印 上一主題 下一主題

達人解釋下關(guān)于Using index for group-by和Using index [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2010-06-11 11:50 |只看該作者 |倒序瀏覽
root@localhost[test] 11:40>create table cu2 like cu;
Query OK, 0 rows affected (0.03 sec)

root@localhost[test] 11:41>show create table cu2\G
*************************** 1. row ***************************
       Table: cu2
Create Table: CREATE TABLE `cu2` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `uid` int(11) DEFAULT NULL,
  `cid` int(11) DEFAULT NULL,
  `time` int(11) DEFAULT NULL,
  `ip` varchar(45) DEFAULT NULL,
  `state` int(11) DEFAULT NULL,
  `admin_id` double DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `index_cu_cid_uid_time` (`cid`,`uid`,`time`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

root@localhost[test] 11:42>insert into cu2 select * from cu;
Query OK, 6966 rows affected (0.03 sec)
Records: 6966  Duplicates: 0  Warnings: 0

兩個幾乎一樣的表,一樣的sql執(zhí)行計劃卻不同
root@localhost[test] 11:42>explain select uid,max(time) from cu where cid<4 group by cid,uid\G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: cu
         type: range
possible_keys: index_cu_cid_uid_time
          key: index_cu_cid_uid_time
      key_len: 10
          ref: NULL
         rows: 2
        Extra: Using where; Using index for group-by
1 row in set (0.00 sec)

root@localhost[test] 11:46>explain select uid,max(time) from cu2 where cid<4 group by cid,uid\G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: cu2
         type: range
possible_keys: index_cu_cid_uid_time
          key: index_cu_cid_uid_time
      key_len: 5
          ref: NULL
         rows: 1511
        Extra: Using where; Using index
1 row in set (0.00 sec)

???這是為什么呢...

論壇徽章:
8
綜合交流區(qū)版塊每周發(fā)帖之星
日期:2015-12-02 15:03:53數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2015-10-02 06:20:00IT運維版塊每日發(fā)帖之星
日期:2015-10-02 06:20:00IT運維版塊每日發(fā)帖之星
日期:2015-09-14 06:20:00金牛座
日期:2014-10-10 11:23:34CU十二周年紀念徽章
日期:2013-10-24 15:41:34酉雞
日期:2013-10-19 10:17:1315-16賽季CBA聯(lián)賽之北京
日期:2017-03-06 15:12:44
2 [報告]
發(fā)表于 2010-06-11 12:48 |只看該作者
分析下2個表后再explain看看

論壇徽章:
0
3 [報告]
發(fā)表于 2010-06-22 09:50 |只看該作者
一個rows 2,一個rows 1511 數(shù)據(jù)量不一樣,計劃不同,正常。

論壇徽章:
9
每日論壇發(fā)貼之星
日期:2016-01-04 06:20:00數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-01-04 06:20:00每日論壇發(fā)貼之星
日期:2016-01-04 06:20:00數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-01-04 06:20:00IT運維版塊每日發(fā)帖之星
日期:2016-01-04 06:20:00IT運維版塊每日發(fā)帖之星
日期:2016-01-04 06:20:00綜合交流區(qū)版塊每日發(fā)帖之星
日期:2016-01-04 06:20:00綜合交流區(qū)版塊每日發(fā)帖之星
日期:2016-01-04 06:20:00數(shù)據(jù)庫技術(shù)版塊每周發(fā)帖之星
日期:2016-03-07 16:30:25
4 [報告]
發(fā)表于 2010-06-22 10:20 |只看該作者
analyze table 以后再試試

論壇徽章:
0
5 [報告]
發(fā)表于 2010-06-22 13:15 |只看該作者
回2,4樓analyze之后都是using index了,可是為什么不出現(xiàn)Using for order-by呢

論壇徽章:
9
每日論壇發(fā)貼之星
日期:2016-01-04 06:20:00數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-01-04 06:20:00每日論壇發(fā)貼之星
日期:2016-01-04 06:20:00數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-01-04 06:20:00IT運維版塊每日發(fā)帖之星
日期:2016-01-04 06:20:00IT運維版塊每日發(fā)帖之星
日期:2016-01-04 06:20:00綜合交流區(qū)版塊每日發(fā)帖之星
日期:2016-01-04 06:20:00綜合交流區(qū)版塊每日發(fā)帖之星
日期:2016-01-04 06:20:00數(shù)據(jù)庫技術(shù)版塊每周發(fā)帖之星
日期:2016-03-07 16:30:25
6 [報告]
發(fā)表于 2010-06-22 13:41 |只看該作者
cu 可能之前是亂序插入更新的吧,導(dǎo)致一些表的meatdata不是很準確~~
所以sql優(yōu)化器在決定執(zhí)行計劃的時候出現(xiàn)偏差。
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP