Back to Top

To learn MySQL PACK_KEYS with example

Pack keys in MySQL

PACK_KEYS is the MySQL features used to generate packed index for MYISAM storage engines. PACK_KEYS is an optional option, used with the MySQL CREATE TABLE statement which indicates whether to put the keys.

PACK_KEYS is applicable to only on MyISAM storage engine. PACK_KEYS means to packs the keys to reduce the size of the index file.With PACK_KEYS,Query performance is quite good. PACK_KEYS keep only the difference from the previous key so its decreases the duplicate keys.

You can set following values for PACK_KEYS:

  1. Default – is used to pack only CHAR, VARCHAR, BINARY, or VARBINARY columns.
  2. 0 – is used to disables all packing of keys
  3. 1 – is used for smaller indexes – slow down the updates and speed up the reading query.

Read about: Table Optimization in MySQL

For example, one field in your table to store PDFs filename, so you will store it name with the extension like ‘mypdf.pdf’ . So it’s waste of space to store the ‘.pdf’ for every node in MySQL. It is a common value which can be a duplicate in each and every row. So, PACK_KEYS will compress the common prefix so that it takes less space for values.

Let’s have a look into CREATE TABLE code with PACK_KEYS

To apply PACK_KEYS on existing tables without doing a dump.

Must Read: MySQL CURSOR Explained

NOTE:If PACK_KEYS option is not used for table, the default value is set for that table and will be apply to only strings, not numbers. You can use PACK_KEYS = 1 to apply compression for string and numbers both.

That’s it.Share your thoughts if you any other simple way to get auto increment value from table.

If you have any query or question,tell us in the comment section :). Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Leave a Reply

Your email address will not be published. Required fields are marked *

Most Popular Posts

How To use Pagination in Joomla

Posted on 6 years ago

Bhumi

To get Last auto increment id in WordPress

Posted on 3 years ago

Bhumi

How to create MySQL User Defined Functions

Posted on 5 years ago

Bhumi

Warning: Ignoring WordPress Can Be a Blunder

Posted on 5 years ago

Nick Carter

The Reader’s Poll – June 2015

Posted on 2 years ago

Bhumi

Overview of ECMAScript 6 new Features

Updated 18 years ago

Bhumi

Getting started with Amazon Web Services

Updated 18 years ago

Bhumi

Facade implementation in Laravel

Updated 18 years ago

Bhumi

The Reader’s Poll – June 2015

Posted on 2 years ago

Bhumi

The Reader’s Poll – August 2014

Posted on 3 years ago

Bhumi

The Reader’s Poll – June 2014

Posted on 3 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 3 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 4 years ago

Bhumi