Question
Ramesh Ramachandran · Jul 1

MAXLEN usage for strings

Is it a good practice to set the MAXLEN value of %Library.String property type?  Will it lead to wasted storage if its not really using it?

For example, I have to store a 5 characters long string into the below str field. Which of the statement is recommended? 

Property str As %String;

vs

Property str As %String(MAXLEN="5");

 

 

Product version: HealthShare 2018.1
0
0 139
Discussion (2)3
Log in or sign up to continue

It is a best data management practice to add restrictions to fields if they have them. So adding the maxlen is "recommended"

Adding the maxlen won't result in wasted storage since storage is not reserved based on field definitions. If that were the case, in your particular scenario, you'd be actually saving storage since all string fields are defaulted to maxlen = 50 if you don't specify a value. 

Hi Ramesh,

Good questions.

Either statement is correct.

By default MAXLEN is 50 characters.

Also there is a TRUNCATE parameter which is "0" false by default.

This means if the string was more than 50 characters you will get a validation error if you try to save a large string.

Setting TRUNCATE to "1" will sliently remove content over the default 50 characters.

No there is not any wasted storage if you don't define a MAXLEN parameter.

In default IRIS storage all of the simple properties (Strings, Numbers) of a record are stored in a list.

This list cannot exceed approximately 32K in length.

So maybe one reason to set your MAXLEN on all properies, for big tables, is to have documented sizes, to easly get total maximum size of the underlying storage list. Know if approaching 32K before you add more properties.

Then new properies can be mapped to a different subscript (storage list) to avoid a storage limitation.

Hope this helps.