5
I have a query that is taking time to be executed, analyzing the explain I see that Mysql is not using the Word in one of the tables.
Tables:
CREATE TABLE `rel_financeiro` (
`protocolo` char(13) NOT NULL,
`aceito` datetime DEFAULT NULL,
`processado` datetime DEFAULT NULL,
`valor_previsto` decimal(10,2) NOT NULL DEFAULT '0.00',
`valor_pago` decimal(10,2) NOT NULL DEFAULT '0.00',
PRIMARY KEY (`registro`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `emails` (
`id` char(36) NOT NULL,
`data` datetime NOT NULL,
`de` varchar(200) NOT NULL,
`para` varchar(200) NOT NULL,
`protocolo` varchar(13) DEFAULT NULL,
`assunto` varchar(255) NOT NULL,
`pasta` varchar(60) NOT NULL,
`lido` tinyint(1) NOT NULL DEFAULT '0',
`headers` text NOT NULL,
`mensagem` text NOT NULL,
PRIMARY KEY (`id`),
KEY `protocolo` (`protocolo`),
KEY `pasta` (`pasta`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query:
SELECT r.protocolo, r.aceito, r.valor_previsto
FROM rel_financeiro r
INNER JOIN emails e ON r.protocolo = e.protocolo
WHERE e.id IN ('e665a3e5-098f-a754-d4fe-5602a15aa191', '39b191b3-8f04-11e5-b9b8-040166406e01', '3e6c68ee-8f04-11e5-b9b8-040166406e01');
Explain result:
+----+-------------+-------+-------+-------------------+---------+---------+-------+---------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+-------------------+---------+---------+-------+---------+-------------+
| 1 | SIMPLE | e | const | PRIMARY,protocolo | PRIMARY | 108 | const | 1 | |
| 1 | SIMPLE | r | ALL | NULL | NULL | NULL | NULL | 5197139 | Using where |
+----+-------------+-------+-------+-------------------+---------+---------+-------+---------+-------------+
I’ve tried so many different ways and so far nothing.
Tarcio, glad you solved your problem. If you want to post a reply with the commands
INSERT \ SELECT
who solved their problem I’m sure the information will be welcome to the community. That said, it would be nice to get somedumps
that reproduced the problem, in that way we came out of this impasse of a no-question with two or three no-answers.– Anthony Accioly
When I created the tables hiding confidential information (as you suggested), everything worked, then I came up with the solution, it’s crazy, but that’s it. If I provide a dump it will be just from the table without the problem.
– Vieira
Tarcio, I reversed your edits. The first invalidated the existing answers. The second is better to post there below, in the area of answers. It is OK to answer the question itself, but you need to use the bottom part, and not embed the answer in the question.
– bfavaretto