31.07.2013 Views

MySQL Cluster Tutorial - cdn.oreillystatic.com

MySQL Cluster Tutorial - cdn.oreillystatic.com

MySQL Cluster Tutorial - cdn.oreillystatic.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Schema considerations<br />

Develop for <strong>MySQL</strong> <strong>Cluster</strong><br />

Going from one storage engine is relatively easy with <strong>MySQL</strong>, but it usually isn't the best<br />

way forward. If you go for example from MyISAM to InnoDB, you'll need to tune a<br />

<strong>com</strong>pletely different set of options to make run smoothly. The same is true when you alter<br />

tables to use the NDB<strong>Cluster</strong> storage engine:<br />

ALTER TABLE employees ENGINE=NDB<strong>Cluster</strong><br />

One example where it can go wrong are with some of the restrictions and limitations found<br />

in <strong>MySQL</strong> <strong>Cluster</strong>. The following table <strong>com</strong>pares a few differences between NDB<strong>Cluster</strong>,<br />

InnoDB and MyISAM:<br />

NDB<strong>Cluster</strong> InnoDB MyISAM<br />

Columns per table 128 1000 4096<br />

Row size 8052 bytes ±8kB* 64kB<br />

(*Excluding variable-lenght columns)<br />

If one of your tables would have 200 columns, it would not be possible to store it in<br />

<strong>MySQL</strong> <strong>Cluster</strong>.<br />

More on limitations within <strong>MySQL</strong> and <strong>MySQL</strong> <strong>Cluster</strong> in the <strong>MySQL</strong> Manual:<br />

http://dev.mysql.<strong>com</strong>/doc/refman/5.1/en/restrictions.html<br />

http://dev.mysql.<strong>com</strong>/doc/refman/5.1/en/mysql-cluster-limitations.html<br />

http://dev.mysql.<strong>com</strong>/doc/refman/5.1/en/innodb-restrictions.html<br />

http://dev.mysql.<strong>com</strong>/doc/refman/5.1/en/myisam-storage-engine.html<br />

Re-normalization<br />

When you have an existing project, you probably did normalize your data. If you want to<br />

get your project into <strong>MySQL</strong> <strong>Cluster</strong>, you'll have to check if your schema still fits.<br />

The Row Size is a <strong>com</strong>mon pitfall. As we seen earlier, it is limited to 8052 bytes. Your<br />

InnoDB tables will not work.<br />

To demonstrate, lets create a table with two rather big VARCHAR fields:<br />

CREATE TABLE t1 (<br />

c1 INT NOT NULL KEY,<br />

c2 VARCHAR(4000),<br />

c3 VARCHAR(4000)<br />

) ENGINE=NDB<strong>Cluster</strong> DEFAULT CHARSET=Latin1<br />

This works, as we keep under the 8052 bytes. Notice also that we use a 1-byte character set,<br />

latin1. If we would use UTF-8 as character set, it would fail:<br />

CREATE TABLE t1 (<br />

c1 INT NOT NULL KEY,<br />

c2 VARCHAR(4000),<br />

c3 VARCHAR(4000)<br />

) ENGINE=NDB<strong>Cluster</strong> DEFAULT CHARSET=UTF-8<br />

Copyright © 2010, Oracle and/or its affiliates. All rights reserved. 68/81

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!