NOT IN 优化问题,谢谢?
SELECT * FROM TABLE T WHERE T.NO NOT IN(1`,12,37,14,20,29,33,44,56,73,87,...,99);
表TABLE的字段NO的数值从1到100,这个是否可以优化,谢谢?
------解决方案--------------------(1`,12,37,14,20,29,33,44,56,73,87,...,99)
这里面的数字貌似没啥规律呢?
------解决方案----------------------如果能明确是1-100,中间不间断,则可如下:
SELECT * FROM TABLE T WHERE T.NO NOT between 1 and 100
--如果不能明确,则建议将这些数据插入到一个表中,例如TB,列名为ID
select t.* from table t where not exists(select 1 from tb m where t.id = m.id)
select t.* from table t where id not in (select id from tb)
------解决方案--------------------用物化视图看看效果!
------解决方案--------------------在NO字段创建位图索引试试
------解决方案--------------------/*+no_concat*/