- Avoid variable columns if a sufficient disk space is available to store the data using fixed columns. The general rule is: disk is cheap! Trading the cost of disk for more efficient development and subsequent performance is often an easy decision to make.
- Though this may be obvious, do not define a variable column when the data does not vary from row to row.
- Do not define a variable columns if its maximum length is less than 30 bytes. Furthermore, do not define a variable column if its maximum length is within 10 bytes of the average length of the column. Adhering to these two rules will cause you to choose VARCHAR data types only when they can potentially provide enough DASD savings to offset other costs.
- Consider redefining variable columns by placing multiple rows of fixed length columns in another table or by shortening the columns and placing the overflow in another table.
If, after following these guidelines, VARCHAR columns need to be implemented, go ahead and do so. However, it is wise to continuously re-assess the decision to use variable character data.
SELECT COL_LGTH, COUNT(*) FROM (SELECT LENGTH(PROJNAME) AS COL_LENGTH FROM DSN81010.PROJ
) GROUP BY COL_LGTH ORDER BY COL_LGTH;
SELECT 24*COUNT(*), SUM(2+LENGTH(PROJNAME)), 24*COUNT(*)-SUM(2+LENGTH(PROJNAME)), 24, AVG(2+LENGTH(PROJNAME)), 24-AVG(2+LENGTH(PROJNAME)) FROM DSN81010.PROJ;
SPACE SPACE TOTAL AVG. AVG. AVG. USED AS USED AS SPACE SPACE AS SPACE AS SPACE CHAR(24) VARCHAR(24) SAVED CHAR(24) VARCHAR(24) SAVED -------- ----------- ------ --------- ----------- ----- 158058 96515 61543 24 16 8
Definition
|
Calculation
|
Space
Used As CHAR(24)
|
24*COUNT(*)
|
Space
Used As VARCHAR(24)
|
SUM(2+LENGTH(PROJNAME))
|
Total
Space Saved Using VARCHAR
|
24*COUNT(*)-SUM(2+LENGTH(PROJNAME))
|
Avg.
Space Used As CHAR(24)
|
24
|
Avg.
Space Used As VARCHAR(24)
|
AVG(2+LENGTH(PROJNAME))
|
Avg.
Space Saved Using VARCHAR
|
24-AVG(2+LENGTH(PROJNAME))
|