事例:
遇到个问题。一个单列条件的查询
select accept_flag from pacs_apply_record where accept_flag=0
1. 第一个可能是以为数量级的问题强制使用索引试试。
select /*+ INDEX(pacs_apply_record IX_PACS_AF) */
accept_flag from pacs_apply_record where accept_flag=0
结果是还是全表扫描。
2.经过一番网上搜索资料。可能是该列可为null ,
将索引改为:
create or replace IX_Pacs_AF pacs_apply_record (accept_flag ,0)
用伪列使索引可处理Null列。
结果可以走索引了。
3.在update时没有走索引,语句如下:
update accept_flag from pacs_apply_record where accept_flag=0
也需要强制索引才能走索引
4.最后发现accept_flag为varchar .条件用了数值。因为值转换所以没有走索引。
本文探讨了在特定情况下SQL查询为何未使用已有索引,包括数值与字符串类型不匹配导致的问题。通过调整索引定义及强制使用索引来提高查询效率。
2801

被折叠的 条评论
为什么被折叠?



