[ic] Table::DBI set_slice and undefined values

Bill Carr interchange-users@interchange.redhat.com
Thu May 16 10:46:01 2002


On Thu, 2002-05-16 at 10:21, cfm@maine.com wrote:
> On Thu, May 16, 2002 at 09:50:16AM -0400, Bill Carr wrote:
> > In an effort to optimize MySQL I have added NOT NULL DEFAULT <some
> > value> to most of my column definitions. According to the Mysql manual
> > this will result in a smaller data file size and make everything faster.
> > 
> > Now when I insert a row using mv_todo=set I receive an error message:
> > column can not be NULL.
> > 
> > If I INSERT using the mysql command line any missing fields will be will
> > contain the DEFAULT values from their column definitions.
> > 
> > Using IC to insert into a database Interchange will make an insert like
> > this:
> > 	insert into <table_name> (a,b,c) VALUES ('defined value',undef,undef)
> > 
> > How can I get it to do this instead
> > 	insert into <table_name> (a) VALUES ('defined value')
> 
> It is probably safer if you provide the values.  It gets really slippery
> otherwise to know what undefined values one wants and which one does
> not want.
> 
> 
> for(columns_in_my_table) {
>   $v->{$_}||='';
>   }
I thought someone would say that.
> 
> where $v is a hashref for that record. 
> 
> Be careful, though, some of your perl might respond differently to ''
> than to NULL undef.
> 
> --
> 
> Are you sure this improves speed?  Yes, absolutely if the columns are
> not indexed and an index will help.  But as a rule I'd be surprised.
I have not tested it but according to the Mysql manual it does.
http://mysql.com/documentation/mysql/bychapter/manual_MySQL_Optimisation.html#Optimising_Database_Structure
"# Declare columns to be NOT NULL if possible. It makes everything
faster and you save one bit per column. Note that if you really need
NULL in your application you should definitely use it. Just avoid having
it on all columns by default."

-- 
Bill Carr
Worldwide Impact
bill@worldwideimpact.com
413-253-6700