Question

We are implementing a file upload and storage field in our DB2 database. Right now the file upload column is defined as BLOB(5242880) as follows:

CREATE TABLE MYLIB.MYTABLE ( 
    REC_ID FOR COLUMN RECID      DECIMAL(10, 0) GENERATED ALWAYS AS IDENTITY ( 
    START WITH 1 INCREMENT BY 1 
    NO MINVALUE NO MAXVALUE 
    NO CYCLE NO ORDER 
    CACHE 20 ) 
    , 

    [other fields snipped]

    FORM_UPLOAD FOR COLUMN F00001 BLOB(5242880) DEFAULT NULL , 
    CONSTRAINT MYLIB.MYCONSTRAINT PRIMARY KEY( REC_ID ) )   
    RCDFMT MYTABLER ; 

Is this the correct way to do this? Should it be in its own table or defined a different way? I'm a little nervous that it's showing it as a five-megabyte column instead of a pointer to somwhere else, as SQL Server does (for example). Will we get into trouble defining it like this?

Was it helpful?

Solution

There's nothing wrong with storing the BLOB in a DB2 column, but if you prefer to store the pointer, look at DataLinks. http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/topic/sqlp/rbafyusoocap.htm

OTHER TIPS

Unless you specify the ALLOCATE clause, the data itself is stored in the "variable length" aka "overflow" space of the table. Not the fixed length space where the rest of the row is.

So if you don't have ALLOCATE and the file is only 1MB, you only use 1MB of space to store it, not the 5MB max you've defined.

Note this means means the system has to do twice the I/O when accessing data from both areas.

Datalinks have the same I/O hit.

From a performance standpoint, - Make sure you only read the BLOB if you need to. - if 90% or more of the BLOBs are say < 1MB, you could improve performance at the cost of space by saying ALLOCATE(1048576) while still allowing for the full 5MB to be stored. The first 1MB would be in the row the last 4MB in the overflow.

Charles

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top