I have a table with a column created_time
(DateTime) and a foreign_key i need to retrieve all the rows with x
foreign_key that the last row created with x
foreign_key was lets say over 2 minutes (and retrieve all the rows with that date)
My question: what is better for performance, to add a column that stores the last row created date every time i create a row, or to use a more complex query to retrieve those rows with the last row joined?
Essentially the question is "Should I denormalize the created_time?" The answer here is that from performance point of view the difference with correct indexes set is negligible and if denormalized this will lead to data duplication across your schema which may trigger one day other problems. From this point of view my recommendation is to not do it and use the expressive powers of SQL to retrieve what you need.