Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

Volatile Table In View ?? - response (1) by dnoeth

$
0
0

#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


Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>