Which best Mysql index

Asked

Viewed 122 times

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?

  • Fabio, you managed to watch the video?

  • The best index is that it makes your readings faster without causing writing to become a garbling it. The amount of rows in charge EXPLAIN is an estimate (for Innodb tables). In the case of your query the expensive part seek the id_movel on the table ordem_atendimento_envio for each row of the query in the table imovel. The index in id_imovel solves this. The compound index with id_ordem_atendimento guarantees quick access to all orders of each property, thus only remaining to cross the dates in a minimum set date.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.