Impossible WHERE noticed after reading const tables on EXPLAIN for a UPDATE statement in MYSQL

StackOverflow https://stackoverflow.com/questions/20074485

  •  31-07-2022
  •  | 
  •  

Domanda

I've the following UPDATE statement

UPDATE Table1 t1
INNER JOIN Table2 t2 ON (t1.Day = t2.Day AND t1.Id = t2.Id)
SET  
t1.Price = t2.Price,
t1.Name = t2.Name
WHERE t2.Id = 1
AND t2.Day = DATE_FORMAT(DATE_ADD('2013-11-01', INTERVAL 1 DAY),'%Y-%m-%d');

When running a EXPLAIN statement I get the message back as

Impossible WHERE noticed after reading const tables

At the moment selecting a range of 21 records is returned in about 0.400 seconds on average.

I've already added a Index on the fields t2.Id and t2.Day. Basically the requirement of this update statement is to take all records that exist in Table2 with the Id of 1 for each Day (or all Dates between DayStart and DayEnd, which I have access to).

Is there anyway on improving this in terms of performance, or should I not worry about the EXPLAIN result ?

È stato utile?

Soluzione

I assume that

SELECT * FROM Table1 t1
INNER JOIN Table2 t2 ON (t1.Day = t2.Day AND t1.Id = t2.Id)
WHERE t2.Id = 1
AND t2.Day = DATE_FORMAT(DATE_ADD('2013-11-01', INTERVAL 1 DAY),'%Y-%m-%d');

will return an empty result.

Impossible WHERE noticed after reading const tables is not performance related. The EXPLAIN is just telling you that there is no dataset found with your given WHERE condition. So maybe there are no datasets in Table2 with Id = 1 OR Day = '2013-11-02'?

If you solved the Impossible WHERE... you can start optimizing your query with the EXPLAIN result (400ms seems to be very slow).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top