Hi.
On Mon 2002-11-18 at 17:05:23 -0800, [EMAIL PROTECTED] wrote:
> Hello ,
> I need help with heap tables and calculating memory usage. I checked
> in the Manual and found a formula, but I need help
> deciphering it ;)
>
> " The memory needed for one row in a HEAP table is:
>
> sizeof(char*) is 4 on 32-bit machines and 8 on 64-bit machines. "
You have to know which kind of machine you have. E.g. a x86 is a
32-bit machine. So let's presume sizeof(char*) to be 4 from now on. If
you have a 64-bit machine, you have to adjust accordingly.
> SUM_OVER_ALL_KEYS(max_length_of_key + sizeof(char*) * 2)
For all keys on the table,
calculate the maximum length of that key
and then add 4 * 2
Sum all that up.
> + ALIGN(length_of_row+1, sizeof(char*))
Calculate the length of one row, then add 1. Then round that up to the
next multiple of 4 (sizeof(char*)).
Which size the columns types have and how to calculate the length of a
row is described in the manual.
> can anyone explain me what this means?
Example:
CREATE TABLE (id INT PRIMARY KEY, name CHAR(20), UNIQUE(name));
For all keys on the table:
PRIMARY KEY: int 4 bytes => 4 + 4*2 = 12
UNIQUE(name): char(20) 20 bytes => 20 + 4*2 = 28
Sum all that up: 12 + 28 = 40
SUM_OVER_ALL_KEYS(4 + 4*2, 20 + 4*2) = 40
Length of row: Don't know it from head and don't have time to look it
up. It is at least 4 (int) + 20 (char(20)) = 24. There is some
overhead, e.g. for NULL bit, say, 2 bytes. => 26 bytes. The formula
says: add 1 (=> 27 bytes) and take the next multiple of 4 (sizeof(char*)),
which is 28.
ALIGN(26+1, 4) = 28
So in the example, the memory usage per row would 40 + 28 = 68 bytes,
presumed I did not make any mistakes.
Bye,
Benjamin.
--
[EMAIL PROTECTED]
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php