views:

174

answers:

1

I have an app that will have entries of both varchar(max) and varbinary(max) data types. I was considering putting these both in a separate table, together, even if only one of the two will be used at any given time.

The question is whether storing them together has any impact on performance. Considering that they are stored in the heap, I'm thinking that having them together will not be a problem. However, the varchar(max) column will be probably have the text in row table option set.

I couldn't find any performance testing or profiling while "googling bing," probably too specific a question?

The SQL Server 2008 table looks like this:

Id
ParentId
Version
VersionDate
StringContent - varchar(max)
BinaryContent - varbinary(max)

The app will decide which of the two columns to select for when the data is queried. The string column will much used much more frequently than the binary column - will this have any impact on performance?

A: 

See this earlier answer and this answer.

text in row option is deprecated and applies the the text, ntext, image data types

varchar(max) by default stores the text in the row up to the limit and then outside the row above the limit unless large value types out of row option is set, in which it's always stored out of row - which would now mean you're storing the data out of the table and then out of that table, too ;-).

If you are already storing them in this separate table, that might not strictly be necessary unless you need the one-to-many relationship which your other columns suggest - since the size of the existing data in your parent row may force these elements out of row. With the data logically in a separate table, you do get more options, however.

Cade Roux
Ok, so that being the case (it's inline by default), does it make sense to split the string and binary columns into their own tables. Like I said: varchar(max) will be much more common that varbinary(max) - does having them together in the same table impact performance? The data is separated as I showed above, however, I'm concerned with the two max columns being side-by-side in the table.
Tony Basallo
@TonyBasallo how big are they going to be? When varchar(max) exists, will varbinary(max) exist, and will the size of one force the other out of the row? If they are always either NULL or bigger than 8000 - they are going to be stored out of the row every time they exist anyway. The only thing side-by-side means is that one might be in row forcing the other out. If they aren't in the row at all (large value types out of row = ON for this table), you'll get more rows per page, which can be efficient. It all depends on your data profile and usage patterns.
Cade Roux
@CadeRoux only one or the other will be used. I Do not expect for the limit to be exceeded very often. It seems that I am safe using them together since it's one or the other and will not (usually) exceed the limit.
Tony Basallo