INFORMIX
Informix Guide to SQL: Reference
Chapter 1: System Catalog
Home Contents Index Master Index New Book

Using the System Catalog

The database server accesses the system catalog constantly. You can access the information in the system catalog tables as well. Each time an SQL statement is processed, the database server accesses the system catalog to determine system privileges, add or verify table names or column names, and so on. For example, the CREATE SCHEMA block in Figure 1-1 adds the customer table, with its respective indexes and privileges, to the stores7 database. This block also adds a view, california, that restricts the information accessible in the customer table to only the first and last names of the customer, the company name, and the phone number of all customers who reside in California.

Figure 1-1
Sample CREATE SCHEMA block

To process this CREATE SCHEMA block, the database server first accesses the system catalog to verify the following information:

In addition to verifying this information and creating two new tables, the database server adds new rows to the following system catalog tables:

The following two new rows of information are added to the systables system catalog table after the CREATE SCHEMA block shown in Figure 1-1 is run.

The CREATE SCHEMA block adds 14 rows to the syscolumns system catalog table. These rows correspond to the columns in the table customer and the view california, as the following example shows.

In the syscolumns system catalog table, each column within a table is assigned a sequential column number, colno, that uniquely identifies the column within its table. In the colno column, the fname column of the customer table is assigned the value 2 and the fname column of the view california is assigned the value 1. The colmin and colmax columns contain no entries. These two columns contain values when a column is the first key in a composite index or is the only key in the index, has no null or duplicate values, and the UPDATE STATISTICS statement has been run.

The rows shown in the following example are added to the sysviews system catalog table. These rows correspond to the CREATE VIEW portion of the CREATE SCHEMA block.

The sysviews system catalog table contains the CREATE VIEW statement that creates the view. Each line of the CREATE VIEW statement in the current schema is stored in this table. In the viewtext column, the x0 that precedes the column names in the statement (for example, x0.fname) operates as an alias name that distinguishes among the same columns that are used in a self-join.

The CREATE SCHEMA block also adds rows to the systabauth system catalog table. These rows correspond to the user privileges granted on customer and california tables, as the following example shows.

The tabauth column of this table specifies the table-level privileges granted to users on the customer and california tables. This column uses an 8-byte pattern-s (select), u (update), * (column-level privilege), i (insert),
d (delete), x (index), a (alter), r (references)-to identify the type of privilege. In this example, the user nhowe has column-level privileges on the customer table.

If the tabauth privilege code is uppercase (for example, S for select), the user who is granted this privilege can also grant it to others. If the tabauth privilege code is lowercase (for example, s for select), the user who has this privilege cannot grant it to others.

In addition, three rows are added to the syscolauth system catalog table. These rows correspond to the user privileges that are granted on specific columns in the customer table, as the following example shows.

The colauth column specifies the column-level privileges that are granted on the customer table. This column uses a 3-byte pattern-s (select), u (update), r (references)-to identify the type of privilege. For example, the user nhowe has update privileges on the second column (because the colno value is 2) of the customer table (indicated by tabid value of 101).

The CREATE SCHEMA block adds two rows to the sysindices system catalog table. These rows correspond to the indexes created on the customer table, as the following example shows.

In this table, the idxtype column identifies whether the created index is unique or a duplicate. For example, the index c_num_ix that is placed on the customer_num column of the customer table is unique.

Accessing the System Catalog

Normal user access to the system catalog is read only. Users with the Connect or Resource privileges cannot alter the system catalog. They can, however, access data in the system catalog tables on a read-only basis using standard SELECT statements. For example, the following SELECT statement displays all the table names and corresponding table ID numbers of user-created tables in the database:

Warning: Although user informix and DBAs can modify most system catalog tables (only user informix can modify systables), Informix strongly recommends that you do not update, delete, or insert any rows in them. Modifying the system catalog tables can destroy the integrity of the database. Informix supports using the ALTER TABLE statement to modify the size of the next extent of system catalog tables. However, in certain cases it is valid to add entries to the system catalog tables, for instance, in the case of the syserrors system catalog table and the systracemsgs system catalog table, where a developer of DataBlade modules can add message entries that appear in these catalog tables.

Updating System Catalog Data

The fact that the optimizer in Informix database servers determines the most efficient strategy for executing SQL queries allows you to query the database without having to fully consider which tables to search first in a join or which indexes to use. The optimizer uses information from the system catalog table to determine the best query strategy.

By using the UPDATE STATISTICS statement to update the system catalog table, you can ensure that the information provided to the optimizer is current. When you delete or modify a table, the database server does not automatically update the related statistical data in the system catalog table. For example, if you delete rows in a table using the DELETE statement, the nrows column in the systables system catalog table, which holds the number of rows for that table, is not updated. The UPDATE STATISTICS statement causes the database server to recalculate data in the systables, sysdistrib, syscolumns, and sysindices system catalog tables. After you run UPDATE STATISTICS, the systables system catalog table holds the correct value in the nrows column. If you use the medium or high mode with the UPDATE STATISTICS statement, the sysdistrib system catalog table holds the updated data-distribution data after you run UPDATE STATISTICS.

Whenever you modify a table extensively, use the UPDATE STATISTICS statement to update data in the system catalog tables. For more information on the UPDATE STATISTICS statement, see Chapter 1 of the Informix Guide to SQL: Syntax.




Informix Guide to SQL: Reference, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.