gpt4 book ai didi

sql - 永无止境的查询

转载 作者:行者123 更新时间:2023-12-05 06:45:18 24 4
gpt4 key购买 nike

到目前为止,我的查询工作正常。

我想索引有问题。

注意:在列type上(在table_1中)有索引,type在table_1中不是唯一的

下面是类似的查询:

--works fine(finish in 5 seconds)
select *
from table_1 a,table_2 b
where a.id=b.id
and a.date < date'2014-6-31'
and a.type=2

当我增加日期范围(包括 1 个月以上,即大约 1000 条记录)时,它没有完成,所以我必须停止它。

--never ending
select *
from table_1 a,table_2 b
where a.id=b.id
and a.date < date'2014-7-31'
and a.type=2

但是当我省略有索引的列时,没关系:

--works fine
select *
from table_1 a,table_2 b
where a.id=b.id
and a.date < date'2014-7-31'

如有任何提示,我将不胜感激。

最佳答案

尝试以这种方式禁用索引:

ALTER INDEX idxname DISABLE;

也可以重建索引

ALTER INDEX idxname REBUILD;

或者在表上收集统计信息

EXEC DBMS_STATS.GATHER_TABLE_STATS ('yourschema', 'table');

但要小心,这可能需要很长时间!

关于sql - 永无止境的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25164033/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com