From 42473b3b31238b15cc3c030b4416b2ee79508d8c Mon Sep 17 00:00:00 2001 From: David Rowley Date: Thu, 27 Nov 2025 10:43:28 +1300 Subject: Have the planner replace COUNT(ANY) with COUNT(*), when possible This adds SupportRequestSimplifyAggref to allow pg_proc.prosupport functions to receive an Aggref and allow them to determine if there is a way that the Aggref call can be optimized. Also added is a support function to allow transformation of COUNT(ANY) into COUNT(*). This is possible to do when the given "ANY" cannot be NULL and also that there are no ORDER BY / DISTINCT clauses within the Aggref. This is a useful transformation to do as it is common that people write COUNT(1), which until now has added unneeded overhead. When counting a NOT NULL column. The overheads can be worse as that might mean deforming more of the tuple, which for large fact tables may be many columns in. It may be possible to add prosupport functions for other aggregates. We could consider if ORDER BY could be dropped for some calls, e.g. the ORDER BY is quite useless in MAX(c ORDER BY c). There is a little bit of passing fallout from adjusting expr_is_nonnullable() to handle Const which results in a plan change in the aggregates.out regression test. Previously, nothing was able to determine that "One-Time Filter: (100 IS NOT NULL)" was always true, therefore useless to include in the plan. Author: David Rowley Reviewed-by: Corey Huinker Reviewed-by: Matheus Alcantara Discussion: https://postgr.es/m/CAApHDvqGcPTagXpKfH=CrmHBqALpziThJEDs_MrPqjKVeDF9wA@mail.gmail.com --- src/tools/pgindent/typedefs.list | 1 + 1 file changed, 1 insertion(+) (limited to 'src/tools/pgindent') diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list index dfcd619bfee..e3c3523b5b2 100644 --- a/src/tools/pgindent/typedefs.list +++ b/src/tools/pgindent/typedefs.list @@ -2927,6 +2927,7 @@ SupportRequestOptimizeWindowClause SupportRequestRows SupportRequestSelectivity SupportRequestSimplify +SupportRequestSimplifyAggref SupportRequestWFuncMonotonic Syn SyncOps -- cgit v1.2.3