Assume many modifications have been made to the employees table since the last time statistics were gathered. To ensure that the cost-based optimizer is still picking the best plan, statistics should be gathered once again; however, the user is concerned that new statistics will cause the optimizer to choose bad plans when the current ones are acceptable. The user can do the following:
BEGIN
DBMS_STATS.CREATE_STAT_TABLE ('hr', 'savestats');
DBMS_STATS.GATHER_TABLE_STATS ('hr', 'employees', stattab => 'savestats');
END;
This operation gathers new statistics on the employees table, but first saves the original statistics in a user statistics table: hr.savestats.
If the user believes that the new statistics are causing the optimizer to generate poor plans, then the original statistics can be restored as follows:
BEGIN
DBMS_STATS.DELETE_TABLE_STATS ('hr', 'employees');
DBMS_STATS.IMPORT_TABLE_STATS ('hr', 'employees', stattab => 'savestats');
END;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27036311/viewspace-751068/ ,如需转载,请注明出处,否则将追究法律责任。