查询、导出的一个奇怪问题!大家进来看看!

[复制链接]
查看11 | 回复4 | 2008-2-13 12:43:03 | 显示全部楼层 |阅读模式
表、索引结构如下:
desc s
Name
Type Nullable Default Comments
-------------- ------------ -------- ------- --------

F
NUMBER(10) 0

B
NUMBER(10)
0

C
NUMBER(10)
0


SQL>select index_name,index_type,table_name,uniqueness,status from user_indexes where table_name like 'S';

INDEX_NAMEINDEX_TYPE
TABLE_NAME
UNIQUENESSSTATUS
--------------------- --------------------------- ----------------------------------------
--------
IDX_S_F
NORMAL
S
NONUNIQUE VALID
SQL> select index_name,table_name,column_name,descend from dba_ind_columns where table_name='STOCK';

INDEX_NA
TABLE_NAME
COLUMN_NAME
DESCEND
-------------------- ------------------------- ------------------------------------ -------
IDX_S_F
S
F
ASC
数据库优化器是基于规则的。
问题:
当使用select *from s where bc查询没有结果返回;但是使用select *from s where bc and f=xxx有结果返回!!
开始怀疑索引或表有坏块,dbv检查未发现任何错误,annlyze index idx_s_f validate structure online,analyze table s validate structure online,未发现任何错,alert日志中也未发行任何错误。分析后,select *from s where bc、select *from s where bc and f=xxx均没有结果返回,正常了!
第二天,又出现了这个问题!分析表和索引后,问题没有解决!select *from s where bc查询没有结果返回;但是使用select *from s where bc and f=xxx有结果返回!!slect count(*) from s的纪录数为N。
于是,exp出表s,create table s1 as select * from s,备份表s,然后使用drop table s cascade constraints删除表,最后imp表s,导入后slect count(*) from s的纪录数为N,slect count(*) from s1的纪录数也一样是N!此时select *from s where bc、select *from s where bc and f=xxx均没有结果返回!!
请问:
1、导出、导入前后表的纪录数相同,应该说导出、导入前后的表s的内容是一样的,但是为什么select *from s where bc and f=xxx导出前有结果,导出后没有结果?会不会exp的时候有数据没有导出,而且select count(*) from s的时候也不会将这些数据统计进来?
2、相同的表s,select *from s where bc没有结果,select *from s where bc and f=xxx却有结果?如果只是索引的问题,那么导出、导入后的纪录数一样,查询的结果也一样才对!
请各位大虾帮忙分析一下!谢谢!
回复

使用道具 举报

千问 | 2008-2-13 12:43:03 | 显示全部楼层
我觉得是索引的更新出了问题, 我猜是你运行第一个查询的时候, 用的全表扫描, 而运行第二个的时候, 因为在F列上有索引, 而且F列上的索引由于某种原因, 有已经删除的值存在, 所以会出这个问题.
我建议你下次遇到这个问题的时候, 可以先看看2个查询的执行计划, 如果是跟我说的一样, 你可以把F列上的索引重建或者删除再试试
回复

使用道具 举报

千问 | 2008-2-13 12:43:03 | 显示全部楼层
关注一下
回复

使用道具 举报

千问 | 2008-2-13 12:43:03 | 显示全部楼层
学习一下
回复

使用道具 举报

千问 | 2008-2-13 12:43:03 | 显示全部楼层
看一下执行计划
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行