@@ -2076,19 +2076,81 @@ select i % 2, sum(abs(v - 500)), count(abs(v - 500)),
20762076 1 | 303822 | 741 | 320 | 320
20772077 $ | 1846700 | 4471 | 1484 | 742
20782078
2079- -- FILTER clause with hash grouping: FILTER aggregate excluded from CSE,
2080- -- other aggregates still share.
2079+ -- FILTER clause with hash grouping: FILTER aggregate excluded from CSE.
20812080select i % 2,
20822081 sum(abs(v - 500)) filter (where b),
20832082 count(abs(v - 500)),
20842083 sum(abs(v - 500))
2085- from aggexpr group by i % 2 order by 1;
2084+ from aggexpr group by i % 2 order by 1
2085+ ;
20862086 ?column? | sum | count | sum
20872087----------+--------+-------+---------
20882088 0 | 101274 | 3720 | 1533439
20892089 1 | 101436 | 741 | 303822
20902090 $ | 202226 | 4471 | 1846700
20912091
2092+ select x
2093+ , sum(abs(v - 500)) filter (where b)
2094+ , sum(abs(v - 500)) filter (where not b)
2095+ from aggexpr
2096+ group by 1 order by 1, 2, 3 limit 10
2097+ ;
2098+ x | sum | sum
2099+ --------+--------+--------
2100+ 0 | $ | $
2101+ 12 | $ | 612328
2102+ 13 | 101193 | 203371
2103+ 1410 | 490 | $
2104+ 14100 | 400 | $
2105+ 141000 | 500 | $
2106+ 141002 | $ | 502
2107+ 141004 | $ | 504
2108+ 141006 | 506 | $
2109+ 141008 | $ | 508
2110+
2111+ select x
2112+ , sum(abs(v - 500)) filter (where b)
2113+ , sum(abs(v - 500)) filter (where not b)
2114+ , sum(abs(v - 500))
2115+ , sum(abs(v - 500) + 1)
2116+ from aggexpr
2117+ group by 1 order by 1, 2, 3 limit 10
2118+ ;
2119+ x | sum | sum | sum | sum
2120+ --------+--------+--------+--------+--------
2121+ 0 | $ | $ | $ | $
2122+ 12 | $ | 612328 | 612328 | 613815
2123+ 13 | 101193 | 203371 | 304564 | 305306
2124+ 1410 | 490 | $ | 490 | 491
2125+ 14100 | 400 | $ | 400 | 401
2126+ 141000 | 500 | $ | 500 | 501
2127+ 141002 | $ | 502 | 502 | 503
2128+ 141004 | $ | 504 | 504 | 505
2129+ 141006 | 506 | $ | 506 | 507
2130+ 141008 | $ | 508 | 508 | 509
2131+
2132+ select x
2133+ , sum(abs(v - 500)) filter (where b)
2134+ , sum(v - 500) filter (where not b)
2135+ , sum(v - 500)
2136+ , sum(abs(v - 500))
2137+ , sum(abs(v - 500) + 1)
2138+ from aggexpr
2139+ group by 1 order by 1, 2, 3 limit 10
2140+ ;
2141+ x | sum | sum | sum | sum | sum
2142+ --------+--------+--------+--------+--------+--------
2143+ 0 | $ | $ | $ | $ | $
2144+ 12 | $ | 362828 | 362828 | 612328 | 613815
2145+ 13 | 101193 | 120037 | 179564 | 304564 | 305306
2146+ 1410 | 490 | $ | -490 | 490 | 491
2147+ 14100 | 400 | $ | -400 | 400 | 401
2148+ 141000 | 500 | $ | 500 | 500 | 501
2149+ 141002 | $ | 502 | 502 | 502 | 503
2150+ 141004 | $ | 504 | 504 | 504 | 505
2151+ 141006 | 506 | $ | 506 | 506 | 507
2152+ 141008 | $ | 508 | 508 | 508 | 509
2153+
20922154-- Two shared sibling subexpressions: abs(v - 500) and length(x) both appear
20932155-- in both aggregates. Tests that the refcount walker continues to sibling
20942156-- nodes after finding a shared subtree.
0 commit comments