日期:2014-05-17 浏览次数:20672 次
CREATE TABLE film (id INT PRIMARY KEY , filmname VARCHAR(20), paici VARCHAR(20)) INSERT INTO film SELECT 1 ,'测试影片a' ,'2222222' UNION ALL SELECT 2 ,'测试影片b' ,'2222222' UNION ALL SELECT 3 ,'测试影片c' ,'2222222' UNION ALL SELECT 4 ,'测试影片d' ,'2222222' UNION ALL SELECT 5 ,'测试影片e' ,'2222222' CREATE TABLE DATA(id INT, playdate datetime,filmid CHAR(1), piaofang VARCHAR(20) ) INSERT INTO DATA SELECT 1, '2012-09-01', 1 ,'2222222' UNION ALL SELECT 2 ,'2012-09-02', 1 ,'2222222' UNION ALL SELECT 3 ,'2012-09-03', 1 ,'2222222' UNION ALL SELECT 4 ,'2012-09-04' ,1 ,'2222222' UNION ALL SELECT 5 ,'2012-09-01', 1 ,'2222222' --1. select A.* from ( select * from data where playdate between '2012-09-01' and '2012-09-20' )A left join film on a.filmid=film.id --2. select * from data d left join film f on d.filmid=f.id where d.playdate between '2012-09-01' and '2012-09-20'
------解决方案--------------------
如果输出的列一样,那就会生成一样的执行计划,速度是一样的,在Playdate列键建索引是十分必要的,当然不是针对这两三条数的时候,当你的数据变多,这个索引就会起作用,做性能测试的时候数据量一定要和时间数据相当,不能是这样的小模型,这是不准确的