 |
|
Oracle num_rows in dba_tables
Oracle Database Tips by Donald Burleson |
One of the most common problems (prior to Oracle
10g) was that Oracle DBA's would accidentally change the execution
behavior of their SQL by changing the num_rows for a table.
Sometimes a DBA wants to know the row count, and the data dictionary
view dba_tables has a column named num_rows.
However, num_rows was not put there to help the
DBA create management reports for his end-user managers! The
num_rows value was created to assist the cost-based SQL optimizer in
determining the optimal execution plan for any SQL that accesses the
table. The num_rows column of the dba_tables
view can be set with any of these commands:
analyze
table FRED;
EXEC
DBMS_UTILITY.analyze_schema('OWNER','FRED');
EXEC
DBMS_STATS.gather_table_stats('OWNER', 'FRED');
When tuning SQL for a whole database, you can
adjust many of the Oracle optimizer parameters, but for tuning an
individual SQL statement, there is nothing better than changing the
schema statistics. Small able can appear to be large, and this
will give you important clues about how num_rows is used to
optimize your query execution. In this example, we adjust
num_rows to one million, making a small table appear large to the
Oracle optimizer. In general a small num_rows will
increase the probability that the CBO will choose an index (as
opposed to a full-table scan).
exec
dbms_stats.set_table_stats(OWNNAME=>'FLINTSTONE', TABNAME=>'FRED',
NUMROWS=>100000000);
 |
I can't emphasize the importance of
understand the role of your schema statistics in your SQL
performance. If you like SQL tuning, I have over 100
pages dedicated to Oracle SQL optimizer tuning, and I have
some important real-world insights into Oracle tuning.
I also offer ready-to-use Oracle tuning scripts to help you
get started fast. You can get your copy of
Oracle Tuning, directly from the publisher at
this link below and you can instantly download he Oracle
tuning scripts to get started fast:
http://www.dba-oracle.com/bp/s_oracle_tuning_book.htm
|
|