Welcome ...        
          
  ... Visiting Newsgroup Users!
 
  See "What makes SQLA different from the newsgroups?" in the FAQ.
 
vote up 4 vote down
star
1

How is performance impacted when you have a table that, lets say could have over 1M rows, and there are 3-5 columns that are consistently NULL.

Is it bad design to have data structures in place that support this? Should we look at normalizing it a little more?

Thanks! -Calvin

P.S. Love this place.

flag

3 Answers

vote up 4 vote down
check

Glad you like this place! It's only going to get better, when more people show up.

I'm not sure what you are asking in your second sentence, in particular I'm not sure what NULL has to do with normalization.

Tackling the first question...

I don't think NULL values cause performance problems per se, at least not that you'd notice. I know that historically, especially with those icky legacy DBMS products like [expletive deleted] and [bodily harm], folks used to worry a lot about fixed-versus-variable length columns, physical ordering of columns in rows, [excrement] like that.

What CAN hurt performance somewhat is inserting rows with all nulls, all zeroes, all empty character strings, and then later updating rows to fill in the values: instant row splits across multiple pages, instant fragmentation of your physical database storage. At least, that was true historically with SQL Anywhere... I am not absolutely sure V11 hasn't eased that problem, I will let Mr. Paulley et al fill in the blanks here.

I haven't run any INSERT/UPDATE/rowsplit tests lately, and when I did it wasn't easy to demonstrate the problem, you had to work at it. And it wasn't directly caused by NULLs per se, but by increasing value sizes over time.

I guess I'm saying, there are lots of reasons to hate NULLs but performance isn't one of them.

link|flag
I guess the question is: Is is good design to put similar things in only one table when some of them can't have values for a few fields whereas others can, or should one put the addional fields in a separate child table, i.e. the common question of OOP-Types/Subtypes and how to map them to a RDM. - Well, there's a whole ORM industry as an answer:) – Volker Barth Jan 15 at 9:12
3 
Breck is correct about causing row splits due to updates of columns that were initially NULL. Some of this can be mitigated through the use of new INLINE column specification modifier introduced in Version 10, but the behaviour remains. – Glenn Paulley Jan 15 at 13:22
Excellent! The main reason is for asking is we have had some debate on whether or not to place a column on a table, if say, 75% of the time, it would remain NULL. – Calvin Allen Jan 15 at 14:34
Gee, I didn't know you could upvote comments... cool! I like this SQLA thing! :) – Breck Carter Jan 15 at 23:03
@Volker: Are you saying nulls make ORMs harder? Are you trying to make me love nulls? <grad> – Breck Carter Jan 15 at 23:05
show 3 more comments
vote up 2 vote down

In addition to Breck's and Martin's responses, Nulls are quite ignorable w.r.t. to storage size:

From the SA 11 docs:

Column space utilization for NULL values is 1 bit per column and space is allocated in multiples of 8 bits. The NULL bit usage is fixed based on the number of columns in the table that allow NULL values.

link|flag
vote up 2 vote down

Answer is WRONG see comments!

I think I know another situation despite later updates like Breck said, where you have a negative performance impact: If it is a varchar column and you are searching for NULL values.

Like: select * from x where stringcolumn is null

here I see always a sequential scan as the index on that column will not be used in contrast to:

select * from x where stringcolumn = ''

here the index will be used. So if you don't need to differ between undefined strings and empty strings I prefer to use a default value of '' instead of NULL.

The above said is valid only for char columns, for example for Date columns a search for NULL values will be index based.

Anyone, please correct if my observation is biased. Otherwise a technical confirm is also appreciated.

link|flag
1 
This is not correct. IS NULL is a sargable predicate for all data types, including strings, so an index on a nullable string column can be used to find NULL values with an IS NULL predicate. – Glenn Paulley Jan 15 at 13:20
Thanks Glenn, I rechecked it and yes you are right, maybe it is something wrong with the column and index I used before. – Martin Jan 15 at 20:00
1 
@Martin: Thanks for editing your answer with the "Wrong!" preamble rather than rewriting it... IMO having a record of mistakes can be just as important as having a record of successes. In fact, my original profession (engineering) is obsessed with documenting and studying mistakes and it was one of the few things my teachers were successful at teaching me :) – Breck Carter Jan 15 at 23:01

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.