11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 28 • MYSQL STORAGE ENGINES AND DATA TYPESwww.it-ebooks.info■ Note As of version 4.1, this storage engine was renamed from HEAP to MEMORY. However, because thisstorage engine has long been a part of <strong>MySQL</strong>, you’ll still see it commonly referred to by its old name indocumentation. Additionally, HEAP remains a synonym of MEMORY.This gain in speed comes at a cost of several drawbacks. For example, MEMORY tables do notsupport the VARCHAR, BLOB, or TEXT data types because this table type is stored in fixed-record-lengthformat. In addition, if you’re using a version of <strong>MySQL</strong> prior to 4.1.0, automatically incrementingcolumns (via the AUTO_INCREMENT attribute) are not supported. Of course, you should keep in mind thatMEMORY tables are intended for a specific scope and are not intended for long-term storage of data.You might consider using a MEMORY table when your data is:• Negligible: The target data is relatively small in size and accessed very frequently.Remember that storing data in memory prevents that memory from being usedfor other purposes. Note that you can control the size of MEMORY tables with theparameter max_heap_table_size. This parameter acts as a resource safeguard,placing a maximum limit on the size of a MEMORY table.• Transient: The target data is only temporarily required, and during its lifetimemust be made immediately available.• Relatively inconsequential: The sudden loss of data stored in MEMORY tableswould not have any substantial negative effect on application services, andcertainly should not have a long-term impact on data integrity.Both hashed and B-tree indexes are supported. The advantage of B-tree indexes over hashes is thatpartial and wildcard queries can be used, and operators such as , and >= can be used to facilitate datamining.You can specify the version to use with the USING clause at table creation time. The followingexample declares a hashed index on the username column:CREATE TABLE users (id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,username VARCHAR(15) NOT NULL,pswd VARCHAR(15) NOT NULL,INDEX USING HASH (username),PRIMARY KEY(id)) ENGINE=MEMORY;By comparison, the following example declares a B-tree index on the same column:CREATE TABLE users (id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,username VARCHAR(15) NOT NULL,pswd VARCHAR(15) NOT NULL,INDEX USING BTREE (username),PRIMARY KEY(id)) ENGINE=MEMORY;532

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

Saved successfully!

Ooh no, something went wrong!