SELECT * FROM tbl_name LIMIT 0 , 30 就这么一条sql语句,执行时间要超过1秒,数据差不多14万 另外一个表,数据量9万,执行同样的sql差不多0.005百思不得其解啊

解决方案 »

  1.   

    表中是否有索引
    EXPLAIN SELECT * FROM tbl_name LIMIT 0 , 30 
      

  2.   

    EXPLAIN SELECT * FROM tbl_name LIMIT 0 , 30 看看
      

  3.   

    表没有做关联的。现在我做了这样一个测试,我复制了一模一样的一张表,就是比较慢的那张表(tbl1),重命名为tbl2然后同样的sql语句在tbl2中执行,速度就快了,我在想会不会是程序问题而拖慢了tbl1因为tbl2没有程序在使用,所以就快了
      

  4.   

    执行EXPLAIN SELECT * FROM tbl1 LIMIT 0 , 30 的结果
    id  select_type  table  type  possible_keys  key  key_len  ref  rows  Extra  
    1   SIMPLE       tbl1   ALL   NULL           NULL   NULL   NULL 170880   
      

  5.   

    没有用到索引 ,
    SHOW INDEX FROM TBNAME
      

  6.   

    show create table tbl_name ;贴出来看一下。
      

  7.   

    CREATE TABLE `tbl1` (
     `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
     `gid` char(9) DEFAULT '012',
     `SelectU` int(11) DEFAULT NULL,
     `userID` int(11) NOT NULL DEFAULT '0',
     `houseID` text,
     `type_ix` smallint(2) unsigned NOT NULL DEFAULT '1',
     `poster` char(32) NOT NULL DEFAULT '0',
     `password` char(32) NOT NULL DEFAULT '0',
     `classify_ix` smallint(2) NOT NULL DEFAULT '0',
     `area` float NOT NULL DEFAULT '0',
     `floor` char(32) DEFAULT NULL,
     `contacts` varchar(100) DEFAULT NULL,
     `tel` varchar(64) NOT NULL DEFAULT '0',
     `location` char(64) NOT NULL,
     `city` char(30) DEFAULT NULL,
     `part` char(20) NOT NULL DEFAULT '0',
     `memo` varchar(500) DEFAULT NULL,
     `created` int(10) NOT NULL DEFAULT '0',
     `expired` int(10) NOT NULL DEFAULT '0',
     `ontopexpired` int(10) DEFAULT NULL,
     `passed` int(1) NOT NULL DEFAULT '0',
     `approved` int(10) NOT NULL DEFAULT '0',
     `plan_picture` char(128) NOT NULL DEFAULT '0',
     `on_top` smallint(1) NOT NULL DEFAULT '0',
     `userUp` tinyint(1) unsigned NOT NULL DEFAULT '0',
     `updated` int(10) NOT NULL DEFAULT '0',
     `price_unit` smallint(6) NOT NULL DEFAULT '0' COMMENT '价格单位',
     `price` float NOT NULL DEFAULT '0',
     `build_date` int(10) NOT NULL DEFAULT '0',
     `basic` char(100) DEFAULT NULL,
     `home_ea` char(100) DEFAULT NULL,
     `fitment` char(100) DEFAULT NULL,
     `real_photo` char(128) NOT NULL DEFAULT '0',
     `click_count` int(11) DEFAULT '0',
     `ip` char(15) NOT NULL DEFAULT '0',
     `keyword` text,
     `UclassID` int(11) DEFAULT NULL,
     `imgcode` text,
     `mappoint` varchar(50) DEFAULT NULL,
     `manualKeyword` varchar(50) DEFAULT NULL,
     `autoUpdate` int(1) NOT NULL DEFAULT '0',
     `allowComments` int(1) NOT NULL DEFAULT '1',
     `msgUniqueID` varchar(7) DEFAULT NULL,
     `agree` int(11) NOT NULL DEFAULT '0',
     `disagree` int(11) NOT NULL DEFAULT '0',
     `needclose` int(11) DEFAULT '0' COMMENT '标识需要关闭的房产信息',
     PRIMARY KEY (`id`),
     KEY `userUp` (`userUp`),
     KEY `userID` (`userID`,`type_ix`),
     KEY `type_ix` (`type_ix`,`passed`),
     KEY `classify_ix` (`classify_ix`,`passed`),
     KEY `on_top` (`on_top`,`passed`),
     KEY `tel` (`tel`),
     KEY `expired` (`expired`),
     KEY `updated` (`updated`),
     KEY `gid` (`gid`),
     KEY `passed` (`passed`),
     FULLTEXT KEY `keyword` (`keyword`)
    ) ENGINE=MyISAM AUTO_INCREMENT=4304501 DEFAULT CHARSET=gbk
      

  8.   

    只是简单的 select *  from `tbl1` limit 30 应该不会慢啊。show profiles 看一下时间都分配在什么步骤上了。再试一下  select *  from `tbl1` order by id  limit 30
      

  9.   

    SHOW PROCESSLIST 看一下同时有哪些进程在操作数据库。特别是锁表,会影响你的操作。