tags:

views:

38

answers:

1

Hi all,

I have a column with it's structure as TEXT. I would like to know how much space the 3 rows take up considering the following data in it against the TEXT column.

       TEXT column
ROW1
ROW2   Hi
ROW3   ABCDEFGHIJKLMNOPQRSTUVWXYZ... (really long, let's say 1500 characters)

We have 3 rows above. Row1 is empty. Row2 has only 2 characters in it. And Row3 has upto 1500 characters. So I would like to know what is the space taken up by:

Row1:

Row2:

Row3:

The manual says: TEXT: L + 2 bytes, where L < 216 but I am a little unclear on how it works in the above cases. I also ask this because I am thinking of normalizing my DB further based on the space taken up by the TEXT column, as my application uses quite a bit of them.

Thank you.

+2  A: 

No, other cells size doesn't align by the max one, if it's what you were asking.
So, it's no more than just actual data size stored in these fields

What do you call "normalizing"?

Col. Shrapnel
Thanks for the reply. For me and my app., Normalizing would be to have column that may or may not consist of any data for a row, to be shifted to another table of it's own and referenced by PK. What I meant to ask is the space usage in the conditions as described. Any suggestions?
Devner
@Denver the only one suggestion of premature optimization. Any optimization must be a result of `profiling`, not of some idle thoughts. And I see nothing can be called normalization in your moves. Looks like you took database too dumb and want to implement it's duties manually. Why do you think that database can't handle your empty rows and such?
Col. Shrapnel
@Col. I didn't mean to say that DB cannot handle empty rows. I just want my DB to use as less space as possible. I would prefer to have a column that may or may not have data in another table of it's own, rather than having a column which takes up space irrespective of whether it has data in it or not (even if that means a byte or two). So my attempts here are to save space that the DB uses and not in questioning it's integrity to handle empty rows. Hope what I am saying makes sense. Any space usage statistics now?
Devner
@Denver modern databases don't waste space. you can trust to mysql documentation which says that empty text field would occupy only 2 bytes.
Col. Shrapnel
@Col Thanks for the reply. I believe it answers the space usage for row 1 i.e takes up only 2 bytes. For Row 2, I am assuming: 2 + 2 = 4 bytes and for 3rd Row, I am assuming: 1500 char + 2 bytes = 1502 bytes in total. Am I correct?
Devner
@Denver yes, think so. Though I've never concerned of bytes. Wonder, why you do.
Col. Shrapnel
@Col. Ok, great. It's just that millions of records add up to a larger amount even if it is a byte or two. Hence the question. Thanks much.
Devner
@Denver 2 millions of bytes is just 2 megabytes. That's less than nothing.
Col. Shrapnel