Oracle view execution plan in navicat, order by time index optimization

select * from TB_SS_INFORMATION_CN order by PUB_DATE desc ;

The table currently has 10w data, and if no index is built, the execution time of this SQL is 1min. You can view its execution plan:

先执行 EXPLAIN PLAN FOR select * from TB_SS_INFORMATION_CN order by PUB_DATE desc ;

Then execute select * from table(dbms_xplan.display); mainly look at rows. If it shows 100k, it means that it needs to be optimized.

For the optimization of ORDER BY time, first build the index of PUB_DATE field.

CREATE INDEX TB_PUBDATE_INDEX ON TB_SS_INFORMATION_CN(PUB_DATE);

Then add the where condition in the SQL statement, and take the value for the range of PUB_DATE. In this case, you can go to the index. This time interval ORACLE is also specially provided. Below are the records from the last month.

select * from TB_SS_INFORMATION_CN  where  IS_HOTTOPIC = 'Y' and  PUB_DATE>=add_months(trunc(SYSDATE),-1) and
PUB_DATE<= SYSDATE order by PUB_DATE desc ;

Check the execution plan again

 

Guess you like

Origin blog.csdn.net/weixin_42740540/article/details/123333475