考虑这种表格:
create table t (
id number, -- and many many other columns of course
record_date date -- the date when the rows is inserted
);
在此表中,我们每小时添加400k行。每小时,我们使用最后一小时的数据启动查询。像SQL
一样:
SELECT
...
FROM t
INNER JOIN ... -- t is joined with many other tables
INNER JOIN ...
INNER JOIN ...
INNER JOIN ...
WHERE
t.record_date >= :my_current_date - 1/24
;
我们遇到的问题是,这种情况往往是计划不好。原因如下:
当Oracle
计算表的统计数据时,它将max(record_date)
存储在名为high_value的统计信息中。因此,当SQL
启动时,Oracle
比较过滤器t.record_date >= :my_current_date - 1/24
白色record_date
列的high_value,并认为几乎不会返回任何行(而不是400k)。因此,以下连接的优化不能很好......
在这种情况下,最佳解决方案是什么?我可以用一个提示例如......
我使用提示OPT_ESTIMATE(表t MIN = 400000),它到目前为止工作。谢谢piezol!