Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Better Choice: 1) NULL field, or 2) 0-byte VARCHAR field?

Status
Not open for further replies.

RICHINMINN

Programmer
Dec 31, 2001
138
Platform: IBM MVS mainframe running DB2 v9
Given: a table contains a column which is defined as VARCHAR(20), and which is nullable

Question: Which is more efficient (or simply better for whatever reason): 1) to use the NULL indicator to indicate the absence of a value in that particular column, or 2) to set the length of the field to 0 (zero)?

Thanks for your input!

RichinMinn
 
Well, as i'm anti-null, i'd choose the zero length. . .

If this was "my" data, i'd make the column not nullable. . .

 
An interesting question.

In terms of the amount of space being taken up, then VARCHAR is more efficient as a nullable column of 20 bytes will always take up 21 bytes, the extra being the null indicator. That happens irresepctive of whether the column contains a value or not. With VARCHAR, the column will always take up at least 1 byte, with a maximum of 21.

There's an overhead involved for DB2 to check whether the column contains a value, but I think that this overhead is the same for both VARCHAR and NULL columns.

N.B
I believe that there is a compress option available in DB2 that will compress data when it doesn't exist, but I don't think this is available on a mainframe.

Marc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top