[Helma-user] allowing NULL VALUES in foreign keys

nex nex at o-slash.org
Tue Aug 22 00:21:02 CEST 2006


Julian Tree wrote:
> the CTO at the time eventally replaced all the NULL with zero and the  
> system speed up.
that is possible, but my guess is that he actually also set the column 
NOT NULL; that way i can see how index-related operations became faster. 
but if you leave that bit of information out, it seems unbelievable, so 
i also agree with nighthawk :-)

> I don't have to check
> if(user_id == 0 or user_id == null)
if you're making that check, your system is probably broken anyway. if 
there both is the possibility of a null value, and a magic value, and 
they have different meanings, then this line would make sense, but 
whether the data schema would make sense is another question :-) also, 
this looks like you're making the performance issuse here out to be the 
two comparisons instead of one. that doesn't seem likely to me ... 
although if it was true and null values were _very_ common in that 
column, you could speed it up by rewriting it to:
if(user_id == null or user_id == 0)
as that way it would short-circuit half of the time or so.

anyway, a system that uses null values where they make sense is better 
designed than a system that uses magic values; i.e. it's less 
error-prone and easier to maintain. therefore, you should start out with 
the first option and only use magic values if benchmarking has 
definitely shown a clear advantage.

don't forget: premature optimization is the root of all evil.

~nex


More information about the Helma-user mailing list