good day everyone,
i'm having dificulties optimizing my tables
i have the following info:
id|Equipment|Date|Info1|info2|info3|info4|(9 columns total)
every day i get a report for that day that i insert into the DB for almost every equipment with the actual date but they might not be inserted everyday or in the correct date order so the highest ID will not always be the most recent.
in 3 months i have almost 1 million rows so my querys to check 2000 equipments latest info are taking about 1 minute now (using an i5 laptop to host the DB for development), so in a few more months i might well go for lunch while i wait...
to reduce the load on the queries i was thinking about using a table for the latest infos for each equipment and another to keep the history if i need to check.
i was thinking about using a trigger when i add info to the main table that would empty the latest records table and add the latest record for each equipment again(from my research i don't know if its possible)
right now the query i'm using is:
VIEW `metersbycontract` AS
SELECT
`equipments`.`Serial` AS `serial`,
`equipments`.`modelname` AS `model`,
`contracts`.`number` AS `contract`,
`contracts`.`customername` AS `customer`,
`meters`.`Date` AS `date`,
`meters`.`BlackPrints` AS `Black`,
`meters`.`ColourPrints` AS `Colour`,
`meters`.`TotalPrints` AS `Total`,
`meters`.`PageCount` AS `Pages`
FROM
((`equipments`
LEFT JOIN `contracts` ON ((`equipments`.`Serial` = `contracts`.`serial`)))
LEFT JOIN `meters` ON ((`contracts`.`serial` = `meters`.`Serial`)))
ORDER BY `meters`.`Date` DESC
this gives me all records by date and i have to group them by serial to only keep the latest(i wanted to avoid getting all the info if possible and accepting any ideas)
i attached an image of my existing tables(still in construction) i use an "equipments" table on the view but for now it can be ignored since its not adding any new info to the final data