Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
None
-
None
-
None
-
None
Description
The WinMagic paper describes how to convert sub-queries into windowed aggregate functions.
For example, TPC-H query
SELECT SUM(l_extendedprice) / 7.0 AS avg_yearly FROM tpcd.lineitem, tpcd.part WHERE p_partkey = l_partkey AND p_brand = 'Brand#23' AND p_container = 'MED BOX' AND l_quantity < ( SELECT 0.2 * avg(l_quantity) FROM tpcd.lineitem WHERE l_partkey = p_partkey)
becomes
WITH WinMagic AS ( SELECT l_extendedprice, l_quantity, avg(l_quantity) OVER (PARTITION BY p_partkey) AS avg_l_quantity FROM tpcd.lineitem, tpcd.part WHERE p_partkey = l_partkey AND p_brand = 'Brand#23' AND p_container = 'MED BOX') SELECT SUM(l_extendedprice) / 7.0 as avg_yearly FROM WinMagic WHERE l_quantity < 0.2 * avg_l_quantity;
It is applicable to several TPC-H and TPC-DS queries, and also helps with temporal database queries (e.g. effective dates).
Attachments
Issue Links
- is related to
-
CALCITE-1317 Rewrite "MAX" as "ORDER BY ... LIMIT ..."
- Open
- relates to
-
CALCITE-4210 Sub-query in ON clause is not correctly expanded by SqlToRelConverter
- Closed