View Full Version : How to Use Variable-Length Fields
Guest.Visitor
12-31-1969, 06:33 PM
** This thread discusses the article: How to Use Variable-Length Fields (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=3896) **
What I have never found on this subject is a description of the true cost of the use of variable-length fields; I feel I need to know this in order to decide whether to use them when designing a database. A record containing variable-length fields has, for each, a 2-byte binary length and, I believe, a 1-byte hidden field. In those cases where there is an extended part to be stored, it is kept in a separate space. Somehow, DB2 must record the location of that part in the space. It possibly also stores in the space the identity of the record and field to which that part belongs. 1. What is the storage cost of these locators or pointers? 2. What is the cost in execution-time for the use of records with variable-length fields?
Guest.Visitor
12-31-1969, 06:33 PM
** This thread discusses the article: How to Use Variable-Length Fields (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=3896) **
Thanks for your two replies, Bob. When Variable-length fields first became available, they opened-up some interesting approaches to relational db design. Take, e.g., the case of recording customers' telephone-nos. The real world we attempt to model in our database could have none, one or several per customer. Bad but intuitive, Flat-file Design would have us provide in a customer-record a field for just one (sometimes inadequate) or perhaps an array for several (often many unused but occasionally still inadequate). Of course, In Codd We Trust, so Good Design has us create a separate PF of telephone-nos. -- that, though, means an extra file, an extra READE-loop etc. A variable-length field facilitates a safely generous array of say 32 telephone-numbers; one's intuitive concept is "here's the list of telephone-numbers"; its processing is easy and we don't have an extra file to maintain, save, restore, reorganize, journal etc. Of course, one does have to remember that little bit about setting the length correctly! Now, suppose I wished to find a customer by telephone-number. I can use Substring and a logical file viewing my one Customer-file member 32 times; easy to code and a CHAIN will find my customer ommediately, whichever of the 32 elements his number is in.
R.Cozzi
12-31-1969, 06:33 PM
** This thread discusses the article: How to Use Variable-Length Fields (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=3896) **
Nigel, I'm looking into the specifics regarding the overhead for using a variable length field. Obviously using a variable length in a database file has different issues than using one as a stand-alone field in RPG IV. As soon as I locate the details, I'll post them here. FWIW, the things I believe to be true include the following: 2-byte current length 8-byte pointer to extended data space (DB2/400 files only) 2-byte max length 2-byte minimum length So that makes it 14 bytes of data overhead per VARLEN field, in a database file. The Minimum length is the value that follows the VARLEN(xx) parameter. It identifies the portion of the field that you want stored in the database file, the remainder (if any) is stored in the extended area, and the pointer is used to address where the data is in that extended area. Bob
R.Cozzi
12-31-1969, 06:33 PM
** This thread discusses the article: How to Use Variable-Length Fields (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=3896) **
Okay, for the source... The data over head in RPG IV for a variable length field is no more than 2 bytes. However, the performance implications can be good. Meaning that RPG optimizes variable length fields by only working with the "current" length. So that if a 32000 byte field is currently only 20 bytes, only 20 bytes are moved, copied, comparied scanned. So you do benefit from a performance perspective, however... There is no storage saving going with variable length fields over fixed-length fields.
V.Mack
12-31-1969, 06:33 PM
** This thread discusses the article: How to Use Variable-Length Fields (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=3896) **
** This thread discusses the Content article: How to Use Variable-Length Fields (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=3896) **
This is a discussion about How to Use Variable-Length Fields.<p align='center'><a href=http://www.mcpressonline.com/mc?1@232.1KNKfHX1eQT.17@.4e67f325>Click here for the article</a>.</p>
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.