Oracle Database 11g 11.2.0.1.0版 - 64位生产。
我想在具有BINARY_DOUBLE列的表上收集直方图统计信息。
然而,oracle似乎无法正确地执行此操作。
将列更改为NUMBER数据类型后,它按预期工作。
为了重现这个问题,我创建了以下脚本:
create table a(
val binary_double not null
);
create table b(
val number not null
);
BEGIN
FOR i IN 0..49
LOOP
INSERT INTO a(val) (select dbms_random.value(10000, 50000) num from dual);
INSERT INTO a(val) (select dbms_random.value(100000, 300000) num from dual);
INSERT INTO b(val) (select dbms_random.value(10000, 50000) num from dual);
INSERT INTO b(val) (select dbms_random.value(100000, 300000) num from dual);
END LOOP;
END;
EXECUTE DBMS_STATS.GATHER_TABLE_STATS(OWNNAME => 'SYS', TABNAME => 'a', METHOD_OPT => 'FOR COLUMNS SIZE 4 val', estimate_percent => 100);
EXECUTE DBMS_STATS.GATHER_TABLE_STATS(OWNNAME => 'SYS', TABNAME => 'b', METHOD_OPT => 'FOR COLUMNS SIZE 4 val', estimate_percent => 100);
检查DBA_HISTOGRAMS表a
SELECT ENDPOINT_NUMBER, ENDPOINT_VALUE
FROM DBA_HISTOGRAMS
WHERE OWNER = 'SYS' AND TABLE_NAME = 'A';
结果
ENDPOINT_NUMBER | ENDPOINT_VALUE
0 0
1 0
2 0
3 0
4 0
检查DBA_HISTOGRAMS表b
SELECT ENDPOINT_NUMBER, ENDPOINT_VALUE
FROM DBA_HISTOGRAMS
WHERE OWNER = 'SYS' AND TABLE_NAME = 'B';
结果
ENDPOINT_NUMBER | ENDPOINT_VALUE
0 10976.7485097398
1 31489.048616045
2 49201.0216533027
3 200759.370719409
4 296991.623064998
有人知道为什么会这样,以及如何处理它? (最好不要改变列的数据类型)