“Cached”指的是在每次获取行时是否会对子查询进行调用?
以下是几个示例:
-- Simple query
SELECT * FROM (
SELECT * FROM accounts
) AS subquery;
-- Subquery with function
SELECT * FROM (
SELECT AVG(id_groups) FROM accounts
) AS subquery;
-- More messy queries
SELECT * FROM (
SELECT id_groups, AVG(id_accounts) OVER (PARTITION BY id_groups)
FROM accounts
) AS subquery
GROUP BY subquery.id_groups, subquery.avg;
此外,
两者有何不同?
SELECT * FROM (
SELECT * FROM accounts
) AS subquery;
并且
WITH everything_about_accounts AS (
SELECT * FROM accounts
)
SELECT * FROM everything_about_accounts;