#1: Those MAX/MIN queries can usually be rewritten using RANK/ROW_NUMBER:
SELECT *
FROM _person
QUALIFY
RANK()
OVER (PARTITION BY person_id, person_key
ORDER BY date_time DESC) = 1
In most cases this is (much) faster, only in some specific cases when the GROUP BY/JOIN is the PI and you rewrite it as a Correlated Subquery it might be a bit worse. I always prefer the OLAP version as it's also much easier to write.
#2: You can't create a Volatile Table within a View. You could something similar in a MACRO: INSERT/SELECT into a Global Temporary Table and then use it.
#3: See Explain. It's materializing the result of the Derived Table. This is similar to a CREATE VOLATILE TABLE, that's why you usually don't care about it. Just let the optimizer do it's work.
Dieter
#1: Those MAX/MIN queries can usually be rewritten using RANK/ROW_NUMBER:
In most cases this is (much) faster, only in some specific cases when the GROUP BY/JOIN is the PI and you rewrite it as a Correlated Subquery it might be a bit worse. I always prefer the OLAP version as it's also much easier to write.
#2: You can't create a Volatile Table within a View. You could something similar in a MACRO: INSERT/SELECT into a Global Temporary Table and then use it.
#3: See Explain. It's materializing the result of the Derived Table. This is similar to a CREATE VOLATILE TABLE, that's why you usually don't care about it. Just let the optimizer do it's work.
Dieter