想用memory引擎的表,来保存一个查询子集,如下:
create table t4(id int,index using hash(id))engine=memory;
insert into t4(id) select emp_no from salaries where salary=90930;
用执行了下面的insert操作,发现不管后面的子查询结果集为多大,整个insert 操作都要用4sec多。
哪位大侠知道这是什么原因。难道heap的插入性能就是这么差吗?

解决方案 »

  1.   

    你自己子查询速度测过嘛?mysql> insert into t4(id) select id from test;
    Query OK, 262144 rows affected (0.31 sec)
    Records: 262144  Duplicates: 0  Warnings: 0
      

  2.   

    select emp_no from salaries where salary=90930
    是你这条语句慢吧
      

  3.   

    后面的查询速度一般时间不超过2sec,单独拿出来测试。整个表有2800000条记录。
      

  4.   

    我使用show profile发现sending data占用了98%的时间。请问sending data是做什么的?
      

  5.   

    重新描述一下:(CSDN竟不编辑发的贴子!!!)
    使用的测试数据库是mysql官网的:employees。
    想用memory引擎的表,来保存一个查询子集,如下:(salaries总共有2800000条,salary没有索引)
    create table t4(id int,index using hash(id))engine=memory;
    insert into t4(id) select emp_no from salaries where salary=90930;
    执行insert操作,发现不管后面的子查询结果集为多大,整个insert 操作都要用4sec多。
    当我单独把后面的select emp_no from salaries where salary=90930,拿来执行发现所用的时间
    为2sec左右。那么这个就否可以说明前面的insert 操作用了另外2sec,但是这个insert其实可能只
    insert 10几条记录。这个是为什么呢?查询是比较慢,但insert应该不至于。
    所以我又测试了另外一种情况:(300000条,emp_no是索引)
    insert into t4(id) select emp_no from employees;
    该过程总共才用了1sec左右。
    这是为什么?哪位同学帮忙解释一下。谢谢!
      

  6.   

    1 继续优化select
    2 每次insert测试的时候,请重新create,确保不会因为前面的insert扩大了内存分配的容量,导致后续insert沾光
      

  7.   

    我现在不是说select差,关键是select单独的话只用了2s,然后前面加了个insert就变成了4s.
      

  8.   

    所以让你确定一下,单独一个
    create table t4(id int,index using hash(id))engine=memory;
    insert into t4(id) select emp_no from salaries
    耗时多少