A
A
Anton2018-12-06 11:31:07
SQLite
Anton, 2018-12-06 11:31:07

How can I optimize a select query on two dates from a Sqlite DB?

Compiled a query to select the maximum values ​​from two fields with dates, using several related tables:

SELECT mes.measureCommFromTab, p.XMLizmerenije, p.XMLdatetime, p.measureComm_id 
FROM `xmlmessagetab` p 
INNER JOIN `indexobjectstab` ps 
ON ps.keyID = p.indexObjectsTab_id 
INNER JOIN `measurecommtab` mes 
ON mes.keyID = p.measureComm_id 
WHERE ps.indexObject = '55285' 
AND p.XMLdatetime = (SELECT max(p.XMLdatetime) 
FROM `xmlmessagetab` p 
INNER JOIN `indexobjectstab` ps 
ON ps.keyID = p.indexObjectsTab_id 
WHERE ps.indexObject = '55285' ) 
AND p.datetimeMess = (SELECT max(p.datetimeMess) FROM `xmlmessagetab` p INNER JOIN `indexobjectstab` ps ON ps.keyID = p.indexObjectsTab_id WHERE ps.indexObject = '55285' )

The query runs for two and a half minutes, which is unbearably long:(
1. Please tell me, is there a way to optimize this query?
2. Is there a plan "B", when writing data to the database, duplicate the last date of the "XMLdatetime" field and then use it for compiling a query for a selection by the latest date, what do you think about this option?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question