Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-6921

poorly optimized UPDATE/DELETE ()=() with primary key

    XMLWordPrintable

Details

    • Task
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • None
    • Optimizer
    • None

    Description

      hi guys, a poorly optimized UPDATE/DELETE (with select it's ok )

      explain

      UPDATE spamov_itens SET cur_oe=(
        SELECT cur_oe FROM spamov WHERE (unidade_id,lote_tipo,lote_spa)=(1009,'v',105248)
      ),cur_oe_seq=(
        SELECT cur_oe_seq FROM spamov WHERE (unidade_id,lote_tipo,lote_spa)=(1009,'v',105248)
      ) 
      WHERE (unidade_id,lote_tipo,lote_spa)=(1009,'v',105248)

      id select_type table type possible_keys key key_len ref rows Extra
      1 PRIMARY spamov_itens ALL         248896 Using where
      3 SUBQUERY spamov const PRIMARY,spamov_unidade_id,spamov_oe,spamov_op,estorno,orc PRIMARY 14 const,const,const 1  
      2 SUBQUERY spamov const PRIMARY,spamov_unidade_id,spamov_oe,spamov_op,estorno,orc PRIMARY 14 const,const,const 1  

      the not optimized part is the update where (the last where)

      WHERE (unidade_id,lote_tipo,lote_spa)=(1009,'v',105248)
       
      change to:
      WHERE unidade_id=1009 and lote_tipo='v' and lote_spa=105248

      id select_type table type possible_keys key key_len ref rows Extra
      1 PRIMARY spamov_itens range PRIMARY,spamov_itens_op,spamov_itens_simula_carga,spamov_itens_unidade_id,spamov_itens_itens PRIMARY 14   10 Using where
      3 SUBQUERY spamov const PRIMARY,spamov_unidade_id,spamov_oe,spamov_op,estorno,orc PRIMARY 14 const,const,const 1  
      2 SUBQUERY spamov const PRIMARY,spamov_unidade_id,spamov_oe,spamov_op,estorno,orc PRIMARY 14 const,const,const 1  

      with DELETE i have:
      DELETE FROM xxxx WHERE (primary key)=(consts) -> not optimized
      DELETE xxxx FROM xxxx WHERE (primary key)=(consts) -> this one is optimized

      Attachments

        Activity

          People

            sanja Oleksandr Byelkin
            rspadim roberto spadim
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.