@@ -1623,3 +1623,113 @@ Source materialize.public.t6
16231623Target cluster: no_replicas
16241624
16251625EOF
1626+
1627+ # `count(*)` is planned as `count(true)`. We take care in EXPLAIN to show `count(true)` as `count(*)` to avoid confusing
1628+ # users.
1629+ query T multiline
1630+ EXPLAIN OPTIMIZED PLAN AS TEXT FOR
1631+ SELECT count(*)
1632+ FROM t5;
1633+ ----
1634+ Explained Query:
1635+ With
1636+ cte l0 =
1637+ Reduce aggregates=[count(*)]
1638+ Project ()
1639+ ReadStorage materialize.public.t5
1640+ Return
1641+ Union
1642+ Get l0
1643+ Map (0)
1644+ Union
1645+ Negate
1646+ Project ()
1647+ Get l0
1648+ Constant
1649+ - ()
1650+
1651+ Source materialize.public.t5
1652+
1653+ Target cluster: no_replicas
1654+
1655+ EOF
1656+
1657+ query error DISTINCT \* not supported as function args
1658+ EXPLAIN OPTIMIZED PLAN AS TEXT FOR
1659+ SELECT count(distinct *)
1660+ FROM t5;
1661+
1662+ # `count(true)` is currently also printed as `count(*)` in EXPLAIN, which I'd say is fine.
1663+ query T multiline
1664+ EXPLAIN OPTIMIZED PLAN AS TEXT FOR
1665+ SELECT count(true)
1666+ FROM t5;
1667+ ----
1668+ Explained Query:
1669+ With
1670+ cte l0 =
1671+ Reduce aggregates=[count(*)]
1672+ Project ()
1673+ ReadStorage materialize.public.t5
1674+ Return
1675+ Union
1676+ Get l0
1677+ Map (0)
1678+ Union
1679+ Negate
1680+ Project ()
1681+ Get l0
1682+ Constant
1683+ - ()
1684+
1685+ Source materialize.public.t5
1686+
1687+ Target cluster: no_replicas
1688+
1689+ EOF
1690+
1691+ # But `count(DISTINCT true)` means an entirely different thing, so EXPLAIN shouldn't conflate it with `count(*)`.
1692+ query T multiline
1693+ EXPLAIN OPTIMIZED PLAN AS TEXT FOR
1694+ SELECT count(DISTINCT true)
1695+ FROM t5;
1696+ ----
1697+ Explained Query:
1698+ With
1699+ cte l0 =
1700+ Reduce aggregates=[count(distinct true)]
1701+ Project ()
1702+ ReadStorage materialize.public.t5
1703+ Return
1704+ Union
1705+ Get l0
1706+ Map (0)
1707+ Union
1708+ Negate
1709+ Project ()
1710+ Get l0
1711+ Constant
1712+ - ()
1713+
1714+ Source materialize.public.t5
1715+
1716+ Target cluster: no_replicas
1717+
1718+ EOF
1719+
1720+ # EXPLAIN statement without an explicit stage or format, so that we test the default
1721+ # (Currently defaults to `EXPLAIN OPTIMIZED PLAN AS TEXT FOR`.)
1722+ query T multiline
1723+ EXPLAIN
1724+ SELECT a+b FROM t4;
1725+ ----
1726+ Explained Query:
1727+ Project (#3)
1728+ Map ((#0 + #1))
1729+ ReadStorage materialize.public.t4
1730+
1731+ Source materialize.public.t4
1732+
1733+ Target cluster: no_replicas
1734+
1735+ EOF
0 commit comments