1
Hello I have a question about explain, index in mysql
Real Estate Table 47.240 Table of Order of Attendance 1,887,421
SELECT
SQL_NO_CACHE
COUNT(*)
FROM
imoveis I
INNER JOIN situacao_cod_venda SCV ON SCV.flag_mostra_site = 1 AND SCV.id = I.situacao_codigo_venda
WHERE
NOT EXISTS
(
SELECT
id
FROM
ordem_atendimento_envio OAE
WHERE
I.data_alt_sit_ven = OAE.data_ultima_alteracao_situacao AND
OAE.id_imovel = I.id AND
OAE.id_ordem_atendimento = '69451'
)
when I create the index for id_imovel of the table order of service explain shows me 9438 and the query takes 5 seconds
when I create the index for id_ordem_attendance table order the explain shows me 478 and the query takes 15 seconds
in the immovable table in explain both returns 48253
when I create a compound index id_imovel, id_ordem_response is instantaneous, no second 0.412 milestones of seconds, but explain shows 9438.
Would you like to know why the index that got smaller got slower? What is the rule for checking checked lines ex: explain table immovable Rows 48253 table order Contact Rows 478
then checked Rows is 48253*478 = 23.064.934 (would that be?)
What sifinifies when ref leaves null, or const
see the video below that I exemplified in detail.
Mysql behavior makes no sense (VIDEO ON VIMEO)
Indice with less registration, slower.
Hugs
I think I understood your criticism. I could publish the DDL of these two tables so that we can better help?
– Fábio Jânio
Fabio, you managed to watch the video?
– kurole
The best index is that it makes your readings faster without causing writing to become a garbling it. The amount of
rows
in chargeEXPLAIN
is an estimate (for Innodb tables). In the case of your query the expensive part seek theid_movel
on the tableordem_atendimento_envio
for each row of the query in the tableimovel
. The index inid_imovel
solves this. The compound index withid_ordem_atendimento
guarantees quick access to all orders of each property, thus only remaining to cross the dates in a minimum set date.– Anthony Accioly