Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Design

Database Design: How Table Normalization Can Improve Performance


Three Designs

We'll try to measure the relative costs of a database which degrades through a comparison between three designs--denormalized, partially normalized, and fully normalized.

  • The denormalized design is the original MESS design.

  • The partially normalized design partitions columns into "core" and "extension" using a rough estimation of the relative frequency of update. Attributes which are rarely or never updated are part of the core, and will be quite compact. Attributes which are updated--in particular, those with an initial value of NULL--go in the extension. The extension is expected to fragment, but the fragmentation will be isolated and (hopefully) under some control.

  • The fully normalized design partitions columns into the dimension and a fact table that records each individual event in a separate row. The idea is that events accrete. Instead of updating a NULL value, a row is inserted to reflect a change in the prospect.

    Listing One is the denormalized MESS design. The evs are "Events" which are filled in by updates, leading to fragmentation. The business processing makes ev1 mandatory, and the other events may, or may not happen.

    CREATE TABLE MESS(
    key VARCHAR(20),
    ev1text VARCHAR(100),
    ev1date TIMESTAMP,
    ev2text VARCHAR(100),
    ev2date TIMESTAMP,
    ev3text VARCHAR(100),
    ev3date TIMESTAMP );
    
    
    Listing One: Denormalized MESS design.

    Listing Two shows a normalized design which controls fragmentation by isolating ev2 and ev3 event data into a separate table. The M2 table can be sparse and can fragment.

    CREATE TABLE M1C(
    key VARCHAR(20),
    ev1text VARCHAR(100),
    ev1date TIMESTAMP );
    CREATE TABLE M1X(
    key VARCHAR(20),
    ev2text VARCHAR(100),
    ev2date TIMESTAMP,
    ev3text VARCHAR(100),
    ev3date TIMESTAMP );
    CREATE UNIQUE INDEX M1C_X1 ON M1C( key );
    CREATE UNIQUE INDEX M1X_X1 ON M1X( key );
    
    
    Listing Two: Normalized design.

    The most interesting design is in Listing Three. This uses inserts instead of updates to fold in the additional data.

    CREATE TABLE M2C(
    key VARCHAR(20) );
    CREATE TABLE M2E(
    key VARCHAR(20),
    evt NUMBER,
    evtext VARCHAR(100),
    evdate TIMESTAMP );
    CREATE UNIQUE INDEX M2C_X1 ON M2C( key );
    CREATE INDEX M2E_X1 ON M2E( key );
    
    Listing Three: Using inserts instead of updates.

    I used three update scenarios for each design. The first job did only two updates--one to update each sub-entity's attributes. I compared this with scenarios doing 5 updates and 10 updates. The higher number of updates would show the effects of any storage reclamation strategy the RDDBMS used.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.