Hi,
I need some help! we are running a query in NDBCLUSTER enviroment and is not using the proper indexes (Optimizer) as in INNODB.
While in INNODB the query runs on 0,01s flat on NDBCLUSTER takes ~5s.
Here is the query and the following info of each table in the query:
"SHOW CREATE TABLE foto\G -- engine, indexes"
"SHOW TABLE STATUS LIKE 'galeria_foto'\G -- sizes"
EXPLAIN.
QUERY:
"SELECT F.* FROM foto F INNER JOIN galeria_foto FG ON F.id_foto = FG.id_foto INNER JOIN galeria G ON FG.id_galeria = G.id_galeria WHERE G.historica = 1 ORDER BY fecha_hora_subida DESC LIMIT 10;"
Here are de results in INNODB:
EXPLAIN SELECT F.* FROM foto F INNER JOIN galeria_foto FG ON F.id_foto = FG.id_foto INNER JOIN galeria G ON FG.id_galeria = G.id_galeria WHERE G.historica = 1 ORDER BY fecha_hora_subida DESC LIMIT 10;
mysql> EXPLAIN SELECT F.* FROM foto F INNER JOIN galeria_foto FG ON F.id_foto = FG.id_foto INNER JOIN galeria G ON FG.id_galeria = G.id_galeria WHERE G.historica = 1 ORDER BY fecha_hora_subida DESC LIMIT 10;
+----+-------------+-------+--------+----------------------+-------------------+---------+----------------------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+--------+----------------------+-------------------+---------+----------------------+------+-------------+
| 1 | SIMPLE | F | index | PRIMARY | fecha_hora_subida | 4 | NULL | 10 | |
| 1 | SIMPLE | FG | ref | PRIMARY,galeria_foto | galeria_foto | 4 | MATIAS.F.id_foto | 1 | Using index |
| 1 | SIMPLE | G | eq_ref | PRIMARY,historica | PRIMARY | 4 | MATIAS.FG.id_galeria | 1 | Using where |
+----+-------------+-------+--------+----------------------+-------------------+---------+----------------------+------+-------------+
3 rows in set (0.00 sec)
---------------
SHOW TABLE STATUS LIKE 'foto'\G -- sizes
*************************** 1. row ***************************
Name: foto
Engine: InnoDB
Version: 10
Row_format: Compact
Rows: 230740
Avg_row_length: 912
Data_length: 210518016
Max_data_length: 0
Index_length: 23134208
Data_free: 9437184
Auto_increment: 364113
Create_time: 2014-08-27 19:38:32
Update_time: NULL
Check_time: NULL
Collation: latin1_swedish_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.01 sec)
-------------
SHOW TABLE STATUS LIKE 'galeria_foto'\G -- sizes
*************************** 1. row ***************************
Name: galeria_foto
Engine: InnoDB
Version: 10
Row_format: Compact
Rows: 301326
Avg_row_length: 398
Data_length: 120209408
Max_data_length: 0
Index_length: 5783552
Data_free: 9437184
Auto_increment: NULL
Create_time: 2014-08-27 19:43:08
Update_time: NULL
Check_time: NULL
Collation: latin1_swedish_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec)
-------------
SHOW TABLE STATUS LIKE 'galeria'\G -- sizes
*************************** 1. row ***************************
Name: galeria
Engine: InnoDB
Version: 10
Row_format: Compact
Rows: 404
Avg_row_length: 446
Data_length: 180224
Max_data_length: 0
Index_length: 163840
Data_free: 9437184
Auto_increment: 548
Create_time: 2014-08-27 19:43:07
Update_time: NULL
Check_time: NULL
Collation: latin1_swedish_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec)
-------------
SHOW CREATE TABLE foto\G -- engine, indexes
*************************** 1. row ***************************
Table: foto
Create Table: CREATE TABLE `foto` (
`id_foto` int(10) NOT NULL AUTO_INCREMENT,
`nombre` varchar(100) DEFAULT NULL,
`nombre_original` varchar(100) DEFAULT NULL,
`epigrafe` varchar(500) DEFAULT NULL,
`mime` varchar(100) DEFAULT NULL,
`path` varchar(255) DEFAULT NULL,
`width` int(10) DEFAULT NULL,
`height` int(10) DEFAULT NULL,
`tamanio` int(10) DEFAULT NULL,
`fecha_hora_subida` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`id_fotografo` int(10) DEFAULT NULL,
`id_categoria` int(10) DEFAULT NULL,
`id_derecho` int(11) DEFAULT NULL COMMENT 'Son los derechos que puede tener una imagen. Copyright',
PRIMARY KEY (`id_foto`),
KEY `id_fotografo` (`id_fotografo`),
KEY `id_categoria` (`id_categoria`),
KEY `id_derecho` (`id_derecho`),
KEY `fecha_hora_subida` (`fecha_hora_subida`)
) ENGINE=InnoDB AUTO_INCREMENT=364113 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
------------------
SHOW CREATE TABLE galeria_foto\G -- engine, indexes
*************************** 1. row ***************************
Table: galeria_foto
Create Table: CREATE TABLE `galeria_foto` (
`id_galeria` int(10) NOT NULL,
`id_foto` int(10) NOT NULL,
`epigrafe` varchar(500) DEFAULT NULL,
`orden` int(10) NOT NULL DEFAULT '0',
PRIMARY KEY (`id_galeria`,`id_foto`),
KEY `galeria_foto` (`id_foto`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
------------------
SHOW CREATE TABLE galeria\G -- engine, indexes
*************************** 1. row ***************************
Table: galeria
Create Table: CREATE TABLE `galeria` (
`id_galeria` int(10) NOT NULL AUTO_INCREMENT,
`id_categoria` int(10) DEFAULT NULL,
`id_tipo` int(10) DEFAULT NULL,
`id_foto_principal` int(10) DEFAULT NULL,
`id_pais` int(10) DEFAULT NULL,
`id_ciudad` int(10) DEFAULT NULL,
`titulo` varchar(255) DEFAULT NULL,
`descripcion` text,
`fecha` date NOT NULL,
`hora` time NOT NULL,
`id_destino` int(10) DEFAULT NULL,
`id_especial` int(10) DEFAULT NULL,
`path_zip` varchar(255) DEFAULT NULL,
`activo` char(1) NOT NULL DEFAULT 'S',
`historica` int(1) DEFAULT NULL,
PRIMARY KEY (`id_galeria`),
KEY `gal_cat` (`id_categoria`),
KEY `gal_tipo` (`id_tipo`),
KEY `gal_foto` (`id_foto_principal`),
KEY `id_pais` (`id_pais`),
KEY `id_ciudad` (`id_ciudad`),
KEY `fecha` (`fecha`),
KEY `id_destino` (`id_destino`),
KEY `id_especial` (`id_especial`),
KEY `activo` (`activo`),
KEY `historica` (`historica`)
) ENGINE=InnoDB AUTO_INCREMENT=548 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
-------------
An here is the info for NDBCLUSTER:
EXPLAIN SELECT F.* FROM foto F INNER JOIN galeria_foto FG ON F.id_foto = FG.id_foto INNER JOIN galeria G ON FG.id_galeria = G.id_galeria WHERE G.historica = 1 ORDER BY fecha_hora_subida DESC LIMIT 10;
+----+-------------+-------+--------+------------------------+----------------+---------+---------------------------+------+------------------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+--------+------------------------+----------------+---------+---------------------------+------+------------------------------------------------------------+
| 1 | SIMPLE | G | ref | PRIMARY,historica | historica | 5 | const | 7 | Parent of 3 pushed join@1; Using temporary; Using filesort |
| 1 | SIMPLE | FG | ref | PRIMARY,idx_id_galeria | idx_id_galeria | 4 | editor_telam.G.id_galeria | 823 | Child of 'G' in pushed join@1 |
| 1 | SIMPLE | F | eq_ref | PRIMARY | PRIMARY | 4 | editor_telam.FG.id_foto | 1 | Child of 'FG' in pushed join@1 |
+----+-------------+-------+--------+------------------------+----------------+---------+---------------------------+------+------------------------------------------------------------+
3 rows in set (0.00 sec)
------------
The tables are created the same way but the ENGINE=ndbcluster.
The query execution plan for INNODB and NDBCLUSTER are different.
Can any one help us on how to correct this issue. We need to use this kind of query in serveral places in our proyect, and we really need to improve the performace and take advatages of NDBCLUSTER.
Thank you
Regards
Matias
I need some help! we are running a query in NDBCLUSTER enviroment and is not using the proper indexes (Optimizer) as in INNODB.
While in INNODB the query runs on 0,01s flat on NDBCLUSTER takes ~5s.
Here is the query and the following info of each table in the query:
"SHOW CREATE TABLE foto\G -- engine, indexes"
"SHOW TABLE STATUS LIKE 'galeria_foto'\G -- sizes"
EXPLAIN.
QUERY:
"SELECT F.* FROM foto F INNER JOIN galeria_foto FG ON F.id_foto = FG.id_foto INNER JOIN galeria G ON FG.id_galeria = G.id_galeria WHERE G.historica = 1 ORDER BY fecha_hora_subida DESC LIMIT 10;"
Here are de results in INNODB:
EXPLAIN SELECT F.* FROM foto F INNER JOIN galeria_foto FG ON F.id_foto = FG.id_foto INNER JOIN galeria G ON FG.id_galeria = G.id_galeria WHERE G.historica = 1 ORDER BY fecha_hora_subida DESC LIMIT 10;
mysql> EXPLAIN SELECT F.* FROM foto F INNER JOIN galeria_foto FG ON F.id_foto = FG.id_foto INNER JOIN galeria G ON FG.id_galeria = G.id_galeria WHERE G.historica = 1 ORDER BY fecha_hora_subida DESC LIMIT 10;
+----+-------------+-------+--------+----------------------+-------------------+---------+----------------------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+--------+----------------------+-------------------+---------+----------------------+------+-------------+
| 1 | SIMPLE | F | index | PRIMARY | fecha_hora_subida | 4 | NULL | 10 | |
| 1 | SIMPLE | FG | ref | PRIMARY,galeria_foto | galeria_foto | 4 | MATIAS.F.id_foto | 1 | Using index |
| 1 | SIMPLE | G | eq_ref | PRIMARY,historica | PRIMARY | 4 | MATIAS.FG.id_galeria | 1 | Using where |
+----+-------------+-------+--------+----------------------+-------------------+---------+----------------------+------+-------------+
3 rows in set (0.00 sec)
---------------
SHOW TABLE STATUS LIKE 'foto'\G -- sizes
*************************** 1. row ***************************
Name: foto
Engine: InnoDB
Version: 10
Row_format: Compact
Rows: 230740
Avg_row_length: 912
Data_length: 210518016
Max_data_length: 0
Index_length: 23134208
Data_free: 9437184
Auto_increment: 364113
Create_time: 2014-08-27 19:38:32
Update_time: NULL
Check_time: NULL
Collation: latin1_swedish_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.01 sec)
-------------
SHOW TABLE STATUS LIKE 'galeria_foto'\G -- sizes
*************************** 1. row ***************************
Name: galeria_foto
Engine: InnoDB
Version: 10
Row_format: Compact
Rows: 301326
Avg_row_length: 398
Data_length: 120209408
Max_data_length: 0
Index_length: 5783552
Data_free: 9437184
Auto_increment: NULL
Create_time: 2014-08-27 19:43:08
Update_time: NULL
Check_time: NULL
Collation: latin1_swedish_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec)
-------------
SHOW TABLE STATUS LIKE 'galeria'\G -- sizes
*************************** 1. row ***************************
Name: galeria
Engine: InnoDB
Version: 10
Row_format: Compact
Rows: 404
Avg_row_length: 446
Data_length: 180224
Max_data_length: 0
Index_length: 163840
Data_free: 9437184
Auto_increment: 548
Create_time: 2014-08-27 19:43:07
Update_time: NULL
Check_time: NULL
Collation: latin1_swedish_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec)
-------------
SHOW CREATE TABLE foto\G -- engine, indexes
*************************** 1. row ***************************
Table: foto
Create Table: CREATE TABLE `foto` (
`id_foto` int(10) NOT NULL AUTO_INCREMENT,
`nombre` varchar(100) DEFAULT NULL,
`nombre_original` varchar(100) DEFAULT NULL,
`epigrafe` varchar(500) DEFAULT NULL,
`mime` varchar(100) DEFAULT NULL,
`path` varchar(255) DEFAULT NULL,
`width` int(10) DEFAULT NULL,
`height` int(10) DEFAULT NULL,
`tamanio` int(10) DEFAULT NULL,
`fecha_hora_subida` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`id_fotografo` int(10) DEFAULT NULL,
`id_categoria` int(10) DEFAULT NULL,
`id_derecho` int(11) DEFAULT NULL COMMENT 'Son los derechos que puede tener una imagen. Copyright',
PRIMARY KEY (`id_foto`),
KEY `id_fotografo` (`id_fotografo`),
KEY `id_categoria` (`id_categoria`),
KEY `id_derecho` (`id_derecho`),
KEY `fecha_hora_subida` (`fecha_hora_subida`)
) ENGINE=InnoDB AUTO_INCREMENT=364113 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
------------------
SHOW CREATE TABLE galeria_foto\G -- engine, indexes
*************************** 1. row ***************************
Table: galeria_foto
Create Table: CREATE TABLE `galeria_foto` (
`id_galeria` int(10) NOT NULL,
`id_foto` int(10) NOT NULL,
`epigrafe` varchar(500) DEFAULT NULL,
`orden` int(10) NOT NULL DEFAULT '0',
PRIMARY KEY (`id_galeria`,`id_foto`),
KEY `galeria_foto` (`id_foto`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
------------------
SHOW CREATE TABLE galeria\G -- engine, indexes
*************************** 1. row ***************************
Table: galeria
Create Table: CREATE TABLE `galeria` (
`id_galeria` int(10) NOT NULL AUTO_INCREMENT,
`id_categoria` int(10) DEFAULT NULL,
`id_tipo` int(10) DEFAULT NULL,
`id_foto_principal` int(10) DEFAULT NULL,
`id_pais` int(10) DEFAULT NULL,
`id_ciudad` int(10) DEFAULT NULL,
`titulo` varchar(255) DEFAULT NULL,
`descripcion` text,
`fecha` date NOT NULL,
`hora` time NOT NULL,
`id_destino` int(10) DEFAULT NULL,
`id_especial` int(10) DEFAULT NULL,
`path_zip` varchar(255) DEFAULT NULL,
`activo` char(1) NOT NULL DEFAULT 'S',
`historica` int(1) DEFAULT NULL,
PRIMARY KEY (`id_galeria`),
KEY `gal_cat` (`id_categoria`),
KEY `gal_tipo` (`id_tipo`),
KEY `gal_foto` (`id_foto_principal`),
KEY `id_pais` (`id_pais`),
KEY `id_ciudad` (`id_ciudad`),
KEY `fecha` (`fecha`),
KEY `id_destino` (`id_destino`),
KEY `id_especial` (`id_especial`),
KEY `activo` (`activo`),
KEY `historica` (`historica`)
) ENGINE=InnoDB AUTO_INCREMENT=548 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
-------------
An here is the info for NDBCLUSTER:
EXPLAIN SELECT F.* FROM foto F INNER JOIN galeria_foto FG ON F.id_foto = FG.id_foto INNER JOIN galeria G ON FG.id_galeria = G.id_galeria WHERE G.historica = 1 ORDER BY fecha_hora_subida DESC LIMIT 10;
+----+-------------+-------+--------+------------------------+----------------+---------+---------------------------+------+------------------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+--------+------------------------+----------------+---------+---------------------------+------+------------------------------------------------------------+
| 1 | SIMPLE | G | ref | PRIMARY,historica | historica | 5 | const | 7 | Parent of 3 pushed join@1; Using temporary; Using filesort |
| 1 | SIMPLE | FG | ref | PRIMARY,idx_id_galeria | idx_id_galeria | 4 | editor_telam.G.id_galeria | 823 | Child of 'G' in pushed join@1 |
| 1 | SIMPLE | F | eq_ref | PRIMARY | PRIMARY | 4 | editor_telam.FG.id_foto | 1 | Child of 'FG' in pushed join@1 |
+----+-------------+-------+--------+------------------------+----------------+---------+---------------------------+------+------------------------------------------------------------+
3 rows in set (0.00 sec)
------------
The tables are created the same way but the ENGINE=ndbcluster.
The query execution plan for INNODB and NDBCLUSTER are different.
Can any one help us on how to correct this issue. We need to use this kind of query in serveral places in our proyect, and we really need to improve the performace and take advatages of NDBCLUSTER.
Thank you
Regards
Matias