Neoview SQL Reference Manual (R2.4 SP2)
Column Lists and Access Plans
Generate statistics for columns most often used in data access plans for a table—that is, the
primary key, indexes defined on the table, and any other columns frequently referenced in
predicates in WHERE or GROUP BY clauses of queries issued on the table. Use the EVERY
COLUMN option to generate histograms for every individual column or multicolumns that
make up the primary key and indexes.
The EVERY KEY option generates histograms that make up the primary key and indexes.
If you often perform a GROUP BY over specific columns in a table, use multi-column lists in the
UPDATE STATISTICS statement (consisting of the columns in the GROUP BY clause) to generate
histogram statistics that enable the optimizer to choose a better plan. Similarly, when a query
joins two tables by two or more columns, multi-column lists (consisting of the columns being
joined) help the optimizer choose a better plan.
Examples of UPDATE STATISTICS
• This example generates four histograms for the columns jobcode, empnum, deptnum, and
(empnum, deptnum) for the table EMPLOYEE. Depending on the table’s size and data
distribution, each histogram should contain ten intervals.
UPDATE STATISTICS FOR TABLE employee
ON (jobcode),(empnum, deptnum)
GENERATE 10 INTERVALS;
--- SQL operation complete.
• This example generates histogram statistics using the ON EVERY COLUMN option for the
table DEPT. This statement performs a full scan, and Neoview SQL determines the default
number of intervals.
UPDATE STATISTICS FOR TABLE dept
ON EVERY COLUMN;
--- SQL operation complete.
• Suppose that a construction company has an ADDRESS table of potential sites and a
DEMOLITION_SITES table that contains some of the columns of the ADDRESS table. The
primary key is ZIP. Join these two tables on two of the columns in common:
SELECT COUNT(AD.number), AD.street,
AD.city, AD.zip, AD.state
FROM address AD, demolition_sites DS
WHERE AD.zip = DS.zip AND AD.type = DS.type
GROUP BY AD.street, AD.city, AD.zip, AD.state;
To generate statistics specific to this query, enter these statements:
UPDATE STATISTICS FOR TABLE address
ON (street), (city), (state), (zip, type);
UPDATE STATISTICS FOR TABLE demolition_sites
ON (zip, type);
• This example removes all histograms for table DEMOLITION_SITES:
UPDATE STATISTICS FOR TABLE demolition_sites CLEAR;
• This example selectively removes histograms for column STREET in table ADDRESS:
UPDATE STATISTICS FOR TABLE address ON street CLEAR;
UPDATE STATISTICS Statement 207