select * from stock where leechdomId in ( select leechdomId from collect where id not in ( select collectId from quote where type=0 and date >'2010-06-01 10:00:02' ) and date>'2010-06-01 10:00:02' ) and date>'2010-06-01 10:00:02'
in 嵌套 not in 加 三个where 有两个and 运行多次 一般需要 7秒; -------------------------------------------
in 里面的句子
select leechdomId from collect where id not in ( select collectId from quote where type=0 and date >'2010-06-01 10:00:02' ) and date>'2010-06-01 10:00:02'
也就是 在in 里 嵌套的句子同样需要 7秒 -------------------------------------- not in 最深层的句子
select collectId from quote where type=0 and date >'2010-06-01 10:00:02'
运行 显示为 0秒 -------------------------------------- 第二层 in 里面的句子 去掉一个条件 去掉时间判断:
select leechdomId from collect where id not in ( select collectId from quote where type=0 and date >'2010-06-01 10:00:02' )
或者去掉 not in:
select leechdomId from collect where date>'2010-06-01 10:00:02'
时间都会显示为 0秒 ------------------------------------
综合以上的结果来看,in 并没有显现降低效率(费解),如果把第二层的 not in 和判断时间的语句 放在一起的话 会降低效率,去掉一个就不会产生效率问题(同样费解)。 费解中。。。。 求指教,怎么样才能解决掉这种效率问题,还有今后怎么去避免这种问题,现在的数据是 大约是 3万条。。。。。。。。。 [解决办法] id 和 date 是单独建的索引。有没有id,date的联合索引 [解决办法] 最好改成NOT EXISTS, [解决办法] set statistics profile on
把执行计划贴出来看看。 [解决办法]
你怎么改的, [解决办法] 还没到那个层面,看看学习下 [解决办法] in , not in 查询很慢.
建议改为exists , not exists. 不过exists , not exists也比较慢,只是比in,not in稍好一些.