临时表增加查询速度

比较下面两个SQL语句:

  select *from erp_purchase A join erp_purchasedetails B on A.id=B.id;

     ( 77,335 总计, 查询花费 0.0013 秒)

  select *from erp_purchase A join (select *from erp_purchasedetails) as B on A.id=B.id;

              ( 82,438 总计, 查询花费 2.5800 秒)

语句的作用都是相同的,第二条查询时间要久得多。

也许有人会问,别蠢,第二条这么写干吊。

换一个例子:

 

SELECT * 
FROM erp_purchase A
JOIN (
SELECT C.id AS id, C.price, D.payerFROM erp_purchasedetails C
JOIN erp_purchasepay D ON C.ipurchaseID = D.ipurchaseID
) AS B ON A.id = B.id order by A.id
LIMIT 0 , 30

 ( 30 总计, 查询花费 6.1111 秒) [id: 175 - 211]


SELECT
* FROM erp_purchase A JOIN erp_purchasedetails C ON A.id = C.id JOIN erp_purchasepay D ON C.ipurchaseID = D.ipurchaseID LIMIT 0 , 30

( 149,273 总计, 查询花费 0.0017 秒)   

 

好吧,本来是要说临时表的好处的,刚发现貌似用不到啊。我日。

 

 

 

 

 

posted @ 2014-06-09 19:12  UCanBeFree  阅读(405)  评论(0编辑  收藏  举报