I hope you could help me on the following problem. I have the below query which is taking too munch time (hours) and it is eating all the resources available ( currently I have 2 engines of sybase ase 15 and 4GB of memory assigned to them).
The query
SELECT
COUNT(a.item_nb),
b.status,
a.category,
a.date
FROM t_item a
JOIN (
SELECT item_nb, status, MAX(date) AS max_date
FROM t_item_transition
WHERE date <= '2028-08-13 23:59:59'
GROUP BY item_nb
) AS b ON a.item_nb = b.item_nb AND a.date = b.max_date
GROUP BY b.status, a.category
The table t_item contains around 5M of records and the item_transition could contain more records because it store all status changes. What I'm trying to do is to select from the item_transiton only the last transition for all item_nb which is < of a specific date. Currently, I have the index on date, state, item_category and item_nb.
Do you think there is a way to improve? or do I need to upgrade the server adding more memory?
Thanks