我在mysql
db
CREATE TEMPORARY TABLE test ( ic_id INT UNSIGNED );
然后只插入一个这样的值
insert into test values (1527);
然后执行此查询
SELECT Count(ai.id)
FROM car_details AS cd,
car_invoices AS ai,
numbers AS pn
WHERE cd.car_invoice_id = ai.id
AND cd.number_id = pn.id
AND cd.code = 'R'
AND ai.car_id IN (SELECT ic_id
FROM test);
上面的查询需要花费大量的时间来执行,但是在没有临时表的情况下执行非常快的情况下执行相同的查询
SELECT Count(ai.id)
FROM car_details AS cd,
car_invoices AS ai,
numbers AS pn
WHERE cd.car_invoice_id = ai.id
AND cd.number_id = pn.id
AND cd.code = 'R'
AND ai.car_id IN ( 1527 );
这是什么原因?
我的max_heap_table_size
是16777216,和
tmp_table_size
是16777216,
我该如何解决这个问题?
非常感谢。