469,282 Members | 2,034 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

memory alignment in MySQL

Joy
CREATE TABLE my table
(coll_a INT NOT NULL,
coll_b SMALLINT,
coll_c SMALLINT,
INDEX b_index (coll_b)
);

Above is the table I will created. I declare coll_b and coll_c, which
together will cose me 4 bytes in one row. Is it? What if I declare
both of them as INT, will it cost me more memory? How about the
memory needed for the index b_index? Not sure how memory alignment
will affect MySQL. Thanks.
Jul 20 '05 #1
1 1275
On 30 Jul 2004 19:26:49 -0700, in mailing.database.mysql
kp*******@yahoo.com (Joy) wrote:
| CREATE TABLE my table
| (coll_a INT NOT NULL,
| coll_b SMALLINT,
| coll_c SMALLINT,
| INDEX b_index (coll_b)
| );
|
| Above is the table I will created. I declare coll_b and coll_c, which
| together will cose me 4 bytes in one row. Is it? What if I declare
| both of them as INT, will it cost me more memory? How about the
| memory needed for the index b_index? Not sure how memory alignment
| will affect MySQL. Thanks.


It's not about 'memory alignment' but more about using the correct
datatype for your data.
----------------------------------
SMALLINT[(M)] [UNSIGNED] [ZEROFILL]
A small integer. The signed range is -32768 to 32767. The unsigned
range is 0 to 65535.

INT[(M)] [UNSIGNED] [ZEROFILL]
A normal-size integer. The signed range is -2147483648 to 2147483647.
The unsigned range is 0 to 4294967295.
----------------------------------

So if your coll_b and coll_c fields will never overflow the maximum
values of smallint then by all means use these datatypes.

As for indices, these assist the database to search for your data.
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Joy | last post: by
18 posts views Thread by Tron Thomas | last post: by
7 posts views Thread by serikas | last post: by
13 posts views Thread by Kutty Banerjee | last post: by
13 posts views Thread by sachin_mzn | last post: by
7 posts views Thread by Dhirendra Pal Singh | last post: by
11 posts views Thread by simonp | last post: by
13 posts views Thread by Chris Thomasson | last post: by
8 posts views Thread by ramsatishv | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.