How can I speed up a query that's currently doing a full table scan to get the maximum value of a timestamp column?
I have a large table with a timestamp column. There is a TPump running all day with many sessions inserting and updating rows, serialized using the PI. I need to run the equivalent of:
SELECT MAX(ts) FROM TABLE1
many times a day, which does a full table scan. Is there any index that can be added or something that can be done to speed this up?
- A normal NUSI will not be used by Teradata because it is not ordered.
- A value-ordered NUSI cannot be created on a timestamp column.
- I cannot use an aggregate join index that precomputes the max because the AGI will have a different PI from the table, causing the different TPump sessions to block each other when updating the singe AGI value.
- I cannot reduce the number of TPump sessions to 1 to avoid the AGI blocking problem because the feed requires a high update rate.
The best solution I have up to now is to change the tpump to keep another table updated that keeps the max(ts) for large enough groups of rows, so that the number of groups is small enough to make the SELECT max(ts) run fast, but large enough to get enough parallelism in the TPump to not become a bottleneck for the TPump. The TPump would have to use a different serialization key appropriate for this table's PI.
I would prefer is something could be done inside Teradata without having to create more tables or change the Tpump.