I'm new with mysql and am a little confused about what cardinality means, I read that it means the number or unique rows but I'd like to know what it does mean in this case, this is my table definition
+-------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | revisado | varchar(10) | YES | MUL | NULL | | | total | int(11) | NO | MUL | NULL | | | busqueda | varchar(300) | NO | MUL | NULL | | | clave | bigint(15) | NO | | NULL | | | producto_servicio | varchar(300) | NO | | NULL | | +-------------------+--------------+------+-----+---------+----------------+ the total of records right now is 13621
I have this query
SELECT clave, producto_servicio FROM buscador_claves2 WHERE busqueda = 'FERRETERIA' AND total = 2 AND revisado = 'APROBADO'
And this the index definition of the table
+------------------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | +------------------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | buscador_claves2 | 0 | PRIMARY | 1 | id | A | 14309 | NULL | NULL | | BTREE | | | buscador_claves2 | 1 | idx_busqueda | 1 | busqueda | A | 14309 | 255 | NULL | | BTREE | | | buscador_claves2 | 1 | idx_total | 1 | total | A | 3 | NULL | NULL | | BTREE | | | buscador_claves2 | 1 | idx_revisado | 1 | revisado | A | 1 | NULL | NULL | YES | BTREE | | | buscador_claves2 | 1 | idx_compuesto1 | 1 | revisado | A | 1 | NULL | NULL | YES | BTREE | | | buscador_claves2 | 1 | idx_compuesto1 | 2 | total | A | 105 | NULL | NULL | | BTREE | | | buscador_claves2 | 1 | idx_compuesto1 | 3 | busqueda | A | 14309 | 255 | NULL | | BTREE | | | buscador_claves2 | 1 | idx_compuesto2 | 1 | busqueda | A | 14309 | 255 | NULL | | BTREE | | | buscador_claves2 | 1 | idx_compuesto2 | 2 | total | A | 14309 | NULL | NULL | | BTREE | | | buscador_claves2 | 1 | idx_compuesto2 | 3 | revisado | A | 14309 | NULL | NULL | YES | BTREE | | +------------------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ the query is taking idx_compuesto1 as the index to find the data, what means the cardinality in this case for the revisado, total and busqueda columns as part of the index idx_compuesto1? and why it takes idx_compuesto1 instead of idx_compuesto2, I can see the cardinality is different in both indexes
This is the output of the query explain
*************************** 1. row *************************** id: 1 select_type: SIMPLE table: buscador_claves2 type: ref possible_keys: idx_busqueda,idx_total,idx_revisado,idx_compuesto1,idx_compuesto2 key: idx_compuesto1 key_len: 804 ref: const,const,const rows: 1 Extra: Using where I hope you can help me to understand better this info, thank you.