let’s say I have the following objects:
Site:
idSite,
name
and other static data.
Test:
idTest
idSite
name
and other static data.
Site Version:
idSiteVersion,
idSite
name of version
Test Result:
ןdTestResult
idSiteVersion,
idTest,
timeEnded
for each site, there is a list of tests that are registered for him.
now I want to know for each site version the latest testresults for them, grouped by idTest.
and also those who are not tested, with null as value.(b)
I’ve implimented a DB for this.
but I have trouble to get the query I’ve listed (b) , it takes a considerbly long time.
I’m thinking of remodeling it. any advices will help
the new one will consist of a table LATEST that will act as a cache,
so I’ll use triggers on insert to update the right row,
and will select from it.
is that right?
should I remodel this?
query:
select `tr1`.`id` AS `id`,
`dsv`.`idSite_id` AS `idSite`,
`tr1`.`idSiteVersion_id` AS `idSiteVersion`,
`tr1`.`idTest_id` AS `idTest`,
`tr1`.`result` AS `result`,
`tr1`.`timeStarted` AS `timeStarted`,
from
`dash`.`testresult` `tr1`
join `dash`.`siteversion` `dsv` on `dsv`.`id` = `tr1`.`idSiteVersion_id`
join `dash`.`test` `dtest` on `dtest`.`id` = `tr1`.`idTest_id`
where `dtest`.`ignored` = 0 and `tr1`.`timeEnd` =
( select max(`tr2`.`timeEnd`) from `dash`.`testresult` `tr2`
where
((`tr2`.`idTest_id` = `tr1`.`idTest_id`) and
(`tr2`.`idSiteVersion_id` = `tr1`.`idSiteVersion_id`) and
(`tr2`.`timeEnd` is not null)))
Try it like this:
Also, you definitely want to create an index on
dash.testresult (idTest_id, idSiteVersion_id, timeEnd)if you don’t already have one.