All MySQL column types can be indexed. Use of indexes on the
relevant columns is the best way to improve the performance of
SELECT
operations.
The maximum number of indexes per table and the maximum index length is defined per storage engine. See Capítulo 14, Motores de almacenamiento de MySQL y tipos de tablas. All storage engines support at least 16 indexes per table and a total index length of at least 256 bytes. Most storage engines have higher limits.
With
syntax in an index specification, you can create an index that
uses only the first col_name
(length
)length
characters
of a CHAR
or VARCHAR
column. Indexing only a prefix of column values like this can
make the index file much smaller.
The MyISAM
and InnoDB
storage engines also support indexing on BLOB
and TEXT
columns. When indexing a
BLOB
or TEXT
column, you
must specify a prefix length for the index.
For example:
CREATE TABLE test (blob_col BLOB, INDEX(blob_col(10)));
Im MySQL 5.0, prefixes can be up to 1000 bytes long for
MyISAM
and InnoDB
tables.
Note that prefix limits are measured in bytes, whereas the
prefix length in CREATE TABLE
statements is
interpreted as number of characters. Be sure to take
this into account when specifying a prefix length for a column
that uses a multi-byte character set.
You can also create FULLTEXT
indexes. These
are used for full-text searches. In MySQL 5.0, only the
MyISAM
storage engine supports
FULLTEXT
indexes and only for
CHAR
, VARCHAR
, and
TEXT
columns. Indexing always takes place
over the entire column and partial (prefix) indexing is not
supported. See Sección 12.7, “Funciones de búsqueda de texto completo (Full-Text)” for details.
In MySQL 5.0, you can also create indexes on spatial column
types. Spatial types are supported only by the
MyISAM
storage engine. Spatial indexes use
R-trees.
The MEMORY
(HEAP
) storage
engine uses hash indexes by default, but also supports B-tree
indexes in MySQL 5.0.
Ésta es una traducción del manual de referencia de MySQL, que puede encontrarse en dev.mysql.com. El manual de referencia original de MySQL está escrito en inglés, y esta traducción no necesariamente está tan actualizada como la versión original. Para cualquier sugerencia sobre la traducción y para señalar errores de cualquier tipo, no dude en dirigirse a mysql-es@vespito.com.