Previous Topic

Next Topic

optimizedb Command—Generate Statistics for the Query Optimizer

The optimizedb command generates statistics that are used by the Ingres Query Optimizer to select an efficient query processing strategy.

Statistics are generated on the specified columns, and stored in system catalogs (iistats and iihistograms).

Complete and accurate statistics in the system catalogs result in more efficient query execution strategies and faster system performance. The process of generating complete and accurate statistics requires time, but a balance between accurate statistics and the time to generate them can be achieved by specifying the -zx or -zs flag. Statistics need to be refreshed only when a significant change in the distribution of a column's values has occurred.

The statistics generated by the optimizedb command for any column consist of two elements:

  1. The number of unique values in a column
  2. A histogram with a variable number of variable-width cells

The accuracy of the histograms can be controlled by the -zu# and -zr# flags described below. Increasing the number of cells in the histograms increases the amount of space required for the iihistograms table and thus increases somewhat the amount of space and time used by the optimizer. However, the increased accuracy of the statistics generally results in more efficient query execution strategies.

We recommend that you generate the statistics for all columns that appear in the qualification (where clause) of a query statement. If statistics are missing or incorrect, the query will still execute, but the speed of query processing can be affected.

After running optimizedb, it is prudent to run sysmod. This is especially true the first time optimizedb is run on a database.

Note: Although optimizedb does not lock the database or individual tables while it is retrieving values and generating statistics, after the statistics have been collected and stored in the appropriate catalogs, optimizedb takes an exclusive lock on the database or individual tables to complete its task.

For additional information on the Ingres Query Optimizer and the use of the optimizedb command, see the Database Administrator Guide.

The optimizedb command has the following format:

optimizedb [SQL option flags][-i filename] [-o filename] [-z flags]
dbname[/server_class
] {-rtablename {-acolumnname}} | {-xrtablename} [-help]

Previous Topic

Next Topic

Optimizedb -z Flags

The –z flags on the optimizedb command are as follows:

Previous Topic

Next Topic

optimizedb Example: Generate Full Statistics for a Database

This command generates full statistics for all columns in all tables in the empdata database:

optimizedb empdata

Previous Topic

Next Topic

optimizedb Example: Generate Statistics for Certain Columns

This command generates statistics for key or indexed columns in the employee and dept tables and for the dno column in the dept table:

optimizedb -zk empdata -remployee -rdept -adno

This command performs the same operation as the previous example, but from a file:

optimizedb -zf flagfile

where flagfile contains:

-zk
empdata
-remployee
-rdept
-adno

Previous Topic

Next Topic

optimizedb Example: Generate Statistics for Certain Columns and Values, in Verbose Mode

The following command does the following:

Previous Topic

Next Topic

optimizedb Example: Allow Unique Values from Each Column in a Table

This command allows up to 100 unique values from each column in the employee table before merging adjacent values into the same histogram cell:

optimizedb
   -zu100
   empdata
   -remployee;


© 2007 Ingres Corporation. All rights reserved.