oracle 在count的時候很慢,特別是有where條件的時候,本來幾秒能執行完,但是要幾十秒才能執行完

select * from dba_tables where owner = 'user' and table_name='G_AR_METER';

由於我的數據庫表的num_rows 統計分析的是7250,但是實際只有2450行數據。

加上where條件count非常慢,但是不加where條件還算是hi正常。

執行下面腳本以後完美解決。

執行之前數據1600萬數據,用索引 count部分數據,需要70-80秒才能返回結果

EXEC dbms_stats.gather_table_stats('user','G_AR_METER',cascade=>true);

EXEC dbms_stats.gather_schema_stats('user',estimate_percent=>100,cascade=> TRUE);

執行完成以後數據1600萬數據,用索引 count部分數據,3-4秒能返回結果

暫時不確定爲什麼需要這樣執行

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章