
DROP DATABASE bug_count;
CREATE DATABASE bug_count;
USE bug_count;

CREATE TABLE tbl_aaa (
  id int(11) PRIMARY KEY AUTO_INCREMENT,
  nombre varchar(255) NOT NULL DEFAULT ''
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;

INSERT INTO tbl_aaa VALUES
(1,'1 asda asd asd asd as'),
(2,'2 asda asd asd asd as'),
(3,'3 asda asd asd asd as'),
(4,'4 asda asd asd asd as'),
(5,'5 asda asd asd asd as'),
(6,'6 asda asd asd asd as'),
(7,'7 asda asd asd asd as'),
(8,'8 asda asd asd asd as'),
(9,'9 asda asd asd asd as'),
(10,'10 asda asd asd asd as');

CREATE TABLE tbl_bbb (
	id int(11) PRIMARY KEY AUTO_INCREMENT,
	id_aplicacion int(11) NOT NULL DEFAULT 0,
	id_registro int(11) NOT NULL DEFAULT 0,
	nombre MEDIUMTEXT NOT NULL DEFAULT ''
) ENGINE=Mroonga DEFAULT CHARSET=utf8mb4;

INSERT INTO tbl_bbb VALUES
(1,21,1,'1 asd asd sd asd'),
(2,21,2,'2 asd asd sd asd'),
(3,21,3,'3 asd asd sd asd'),
(4,21,4,'4 asd asd sd asd'),
(5,21,5,'5 asd asd sd asd'),
(6,21,6,'1 asd asd sd asd'),
(7,21,7,'2 asd asd sd asd'),
(8,21,8,'3 asd asd sd asd'),
(9,21,9,'4 asd asd sd asd'),
(10,21,10,'5 asd asd sd asd');

INSERT INTO tbl_bbb VALUES
(306,22,6,'306 asd asd sd asd'),
(307,22,7,'307 asd asd sd asd'),
(308,22,8,'308 asd asd sd asd'),
(309,22,9,'309 asd asd sd asd'),
(310,22,10,'310 asd asd sd asd'),
(311,22,11,'311 asd asd sd asd'),
(312,22,12,'312 asd asd sd asd'),
(313,22,13,'313 asd asd sd asd'),
(314,22,14,'314 asd asd sd asd'),
(315,22,15,'315 asd asd sd asd');

SELECT COUNT(*) FROM tbl_aaa;

SELECT COUNT(*) FROM tbl_bbb;

SELECT COUNT(*)
FROM (
	SELECT a.id
	FROM tbl_aaa a
	LEFT JOIN tbl_bbb b ON b.id_aplicacion=21 AND b.id_registro=a.id
) c;

CREATE INDEX ccc ON tbl_bbb (id_registro);

SELECT COUNT(*)
FROM (
	SELECT a.id
	FROM tbl_aaa a
	LEFT JOIN tbl_bbb b ON b.id_aplicacion=21 AND b.id_registro=a.id
) c;
