是呀,索引是很重要的,EXPLAIN SELECT select_options
看看结果呢

解决方案 »

  1.   

    我用到两个表,两个表的结构如下:
    CREATE TABLE mtq (
      id bigint(20) NOT NULL default '0',
      born bigint(20) NOT NULL default '0',
      lastAccess bigint(20) default NULL,
      state int(11) default '0',
      credit int(11) default '0',
      priority int(11) default '0',
      receiver varchar(21) NOT NULL default '',
      message varchar(160) binary NOT NULL default '',
      msgFormat int(11) default '0',
      feeType int(11) default '0',
      feeValue int(11) default '0',
      msgLevel int(11) default NULL,
      payer varchar(21) default NULL,
      sender varchar(21) default NULL,
      svcType varchar(8) default NULL,
      reportFlag int(11) default '0',
      atTime bigint(20) default NULL,
      expireTime bigint(20) default NULL,
      idSession int(11) default NULL,
      idRemote bigint(20) default NULL,
      error_code int(11) default '0',
      PRIMARY KEY  (id)
    ) TYPE=MyISAM;CREATE TABLE mrq (
      id bigint(20) NOT NULL default '0',
      born bigint(20) NOT NULL default '0',
      lastAccess bigint(20) default NULL,
      state int(11) default '0',
      credit int(11) default '0',
      priority int(11) default '0',
      smg_id bigint(20) default NULL,
      status char(7) NOT NULL default '',
      PRIMARY KEY  (id)
    ) TYPE=MyISAM;两个表中的记录大概会有几十万条左右,而且会越来越多,其中mrq中的id和mtq中的idremote是一一对应的,现在要查找出mrq中的id和mtq中的idremote匹配不上的mrq中的记录
    我用的语句是这样的:
    select mrq.* from mrq left join mtq on mrq.id=mtq.id where mtq.id is null;
    但是执行起来出现内存溢出错误,服务器的内存为1G加上虚拟内存大概在2.5G左右.后来我实在不行,只能用程序来实现,逐条找出mrq中记录,和mtq中的每一条记录去匹配,这样执行起来虽然不会出现内存溢出,但是执行起来的效率超级慢,大概花了几个小时才做完,真是晕呀~~
    有什么好的解决方案吗?我现在都不敢在服务器上乱试了,服务器已经被我搞死了好几次了~55555555
      

  2.   

    1. id not auto increased?
    2. in linux or unix?
    3. do you have an extra db only for testing? it is better to test ur statement in developing or testing server instead of the production server so that you need not test so many rows.. just some thousand rows are quite enough..with best wishessandy
      

  3.   

    回楼上:
    1.mrq中的id不是自动增加的,是从mtq的idremote中获取过来的,两者是对应一致的
    2.在windows 2k serv环境下
    3.我在本地建立一个测试的同型数据库,由于数据量放置较少,大概在几十条左右,执行上述语句很快,但数据量大的时候,就会出现内存溢出的情况您有好的解决方案吗?非常感想楼上各位对我的解答,不管最终能不能得到一个圆满的答案,我还是非常感激各位能参与我的问题!yecool