"Impossible WHERE noticed ..." with MySQL INNER JOIN on LONGTEXT cols. Options?

I am studying a slow SQL query in the mySQL production database and am looking for options to improve performance. I have not developed or implemented this, but I need to fix it.

The intended purpose of SQL is to check whether the same datapack was previously inserted, and if so, return the identifiers of previously inserted rows so that the inserted data is not duplicate. He tries to do this with an INNER JOIN on his own through the LONGTEXT 'datapacket' column (which contains up to 60,000 characters of JSON data). This table currently has about 1 million records, it takes about 30-60 seconds to execute SQL, and this query is executed hundreds of thousands of times every day.

CREATE TABLE `T_Upload` (
  `id`          int(11) NOT NULL AUTO_INCREMENT,
  `type`        varchar(30) NOT NULL,
  `datapacket`  longtext,
  `timestamp`   timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_uploadtype` (`type`),
  KEY `idx_timestamp` (`timestamp`)
) ENGINE=InnoDB CHARSET=ascii;


EXPLAIN
SELECT priorDuplicate.id
FROM T_Upload u INNER JOIN T_Upload priorDuplicate ON priorDuplicate.files = u.files
                                               AND u.id > priorDuplicate.id 
WHERE u.id = 3277515 
AND u.type = 'mobile'

EXPLAIN SQL, ... ", WHERE const".

, :

  • SQL "EXPLAIN" , , ?

  • LONGTEXT VARCHAR (65000) 20 ( ) ?

+4

Source: https://habr.com/ru/post/1624000/


All Articles