I have a table with millions of rows and a Timestamp column which hold datetime with milliseconds in UTC.
We have a SaaS where clients are connecting from different timezones and thus we need to convert to local timezone of the client.
When we use queries like group by month, year, quarter and perform aggregations etc.., we need to convert to client timezone and we use CONVERT_TZ to convert and we see huge performance decrease.
SELECT
MONTH(CONVERT_TZ(Timestamp, '+00:00', '+03:00')) AS Month,
Asset,
SUM(Profit) AS Profit,
SUM(Margin) AS Margin
FROM Order
LEFT JOIN DimAsset ON Order.DimAssetKey = DimAsset.DimAssetKey
WHERE
(
Order.Timestamp >= CONVERT_TZ("2023-04-01T21:00:00", '+00:00', '+02:00')
and Order.Timestamp <= CONVERT_TZ("2023-04-05T20:59:59", '+00:00', '+02:00')
)
GROUP BY Month, Asset
LIMIT 51 OFFSET 0
Is there any way to optimize the above?