Entering content frame

 Tips on Database Design 

As well as search conditions, the following factors also affect the way SQL statements are processed, and therefore the performance of database applications.

·        Type of SQL statement (SELECT, INSERT, UPDATE, DELETE)

·        Elements of a SELECT statement (ORDER clause, UPDATE clause, DISTINCT specification, and specification of FOR REUSE)

·        Changes that are specified in the UPDATE statement

·        Type of physical storage of a table and the size of the tables (number of rows and B* tree pages)

Many performance problems can be avoided by implementing the following tips when you design your database:

·        Before you define your tables, examine the structures and use the results in your table definitions.  When you define the key columns, ensure that any especially selective columns, and any columns for which search conditions are specified especially often, are placed at the beginning of the key. This gives you the option of considering only a very small part of the table when processing a SELECT statement.

·        Only columns that are as selective as possible should be inverted. Do not choose columns such as gender or marital status as index keys, due to their low number of different values. These columns can only be used very rarely for a non-sequential search, since these searches would usually be more costly than a sequential search.

·        In the case of relatively static datasets, a large number of columns can be inverted. In doing so, you must ensure, as with the definition of the key columns, that you specify columns that are as selective as possible, and that are often used in equality conditions at the beginning of the index.

·        If possible, do not invert all of the columns that are used in search conditions. The space needed for the indexes and the cost of maintaining them is considerable.

·        If a large number of changes have been made in a table, you should run the UPDATE STATISTICS statement.

·        You should only formulate search conditions that cannot be fulfilled by all rows. Applications are often written so that the user determines the values of a search condition. If the user does not enter any values, default values are inserted into the search condition, so that it always returns “true”. The database system must now evaluate this ineffective search condition for every row that needs to be searched. It is better to execute different SELECT statements depending on the user input

·        You should place the most selective search conditions at the beginning of the condition, since it may be possible to terminate the check earlier.

·        The specification
columnx IN (1,13,24,...)
can be evaluated more efficiently by the Optimizer than the semantically identical specification
columnx=1 OR columnx=13 OR columnx=24 OR ...

 

Leaving content frame