我对表格有一个疑问:
select m.id from mytable m
left outer join othertable o on o.m_id = m.id
and o.col1 is not null and o.col2 is not null and o.col3 is not null
where o.id is null
该查询返回几百条记录,尽管这些表有数百万行,而且运行起来需要很长时间(大约一个小时).
当我使用以下工具判断索引统计信息时:
select * from pg_stat_all_indexes
where schemaname <> 'pg_catalog' and (indexrelname like 'othertable_%' or indexrelname like 'mytable_%')
我看到只使用了其他table.m_id的索引,而根本没有使用col1..3的索引.这是为什么呢?
我在fewplaces中读到,PG传统上不能索引空值.然而,我读到这应该是从第8.3页开始改变的吧?我目前在Ubuntu10.04上使用PostgreSQL8.4.我是否需要专门创建一个"部分"或"函数"索引来加速IS NOT NULL查询,或者它已经在索引NULL而我只是误解了这个问题?