P
P
Pavel2016-04-07 23:14:20
MySQL
Pavel, 2016-04-07 23:14:20

MySQL magic, or why does DELETE take forever?

There is a table with 100000 records. The table looks like this:

incrementdata [text]dataId[varchar45]userId[int11]
We make a request to delete fields with a nested select from another table.
DELETE 
  FROM userdata 
  WHERE dataId in (
    SELECT concat('ufi',dbIncrement) 
    FROM ufields 
    WHERE podvedId='val' 
      and formId='val' 
      and parentContainerId='val' 
      and (descriptor_x='val' or descriptor_y='val')
  )
// очень долго выполняется, сервер падает

Separately , requests are executed quickly, but in a single request, execution puts the server.
We tried to index the fields on which the selection takes place, but this did not affect the execution time.
What could be the reason for this behaviour? Why does the simplest DELETE, which is to remove two fields, put the server?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2016-04-08
@Carduelis

DELETE `ud`.*
  FROM `userdata` AS `ud`
  JOIN `ufields` AS `uf` 
    ON `ud`.`dataId` = CONCAT('ufi', `uf`.`dbIncrement`) 
    AND `uf`.`podvedId` = 'val' 
    AND `uf`.`formId` = 'val' 
    AND `uf`.`parentContainerId` = 'val' 
    AND (`uf`.`descriptor_y` = 'val' OR `uf`.`descriptor_y` = 'val')

A
Artyom Karetnikov, 2016-04-07
@art_karetnikov

Push result in the temporary table and make selection from it. Where it will no longer be necessary to perform concat.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question