postgresql/contrib/pg_trgm
Tom Lane 8d83a5d0a2 Remove redundant grouping and DISTINCT columns.
Avoid explicitly grouping by columns that we know are redundant
for sorting, for example we need group by only one of x and y in
	SELECT ... WHERE x = y GROUP BY x, y
This comes up more often than you might think, as shown by the
changes in the regression tests.  It's nearly free to detect too,
since we are just piggybacking on the existing logic that detects
redundant pathkeys.  (In some of the existing plans that change,
it's visible that a sort step preceding the grouping step already
didn't bother to sort by the redundant column, making the old plan
a bit silly-looking.)

To do this, build processed_groupClause and processed_distinctClause
lists that omit any provably-redundant sort items, and consult those
not the originals where relevant.  This means that within the
planner, one should usually consult root->processed_groupClause or
root->processed_distinctClause if one wants to know which columns
are to be grouped on; but to check whether grouping or distinct-ing
is happening at all, check non-NIL-ness of parse->groupClause or
parse->distinctClause.  This is comparable to longstanding rules
about handling the HAVING clause, so I don't think it'll be a huge
maintenance problem.

nodeAgg.c also needs minor mods, because it's now possible to generate
AGG_PLAIN and AGG_SORTED Agg nodes with zero grouping columns.

Patch by me; thanks to Richard Guo and David Rowley for review.

Discussion: https://postgr.es/m/185315.1672179489@sss.pgh.pa.us
2023-01-18 12:37:57 -05:00
..
data
expected Remove redundant grouping and DISTINCT columns. 2023-01-18 12:37:57 -05:00
sql
.gitignore
Makefile
meson.build Update copyright for 2023 2023-01-02 15:00:37 -05:00
pg_trgm--1.0--1.1.sql
pg_trgm--1.1--1.2.sql
pg_trgm--1.2--1.3.sql
pg_trgm--1.3--1.4.sql
pg_trgm--1.3.sql
pg_trgm--1.4--1.5.sql
pg_trgm--1.5--1.6.sql
pg_trgm.control
trgm_gin.c New header varatt.h split off from postgres.h 2023-01-10 05:54:36 +01:00
trgm_gist.c New header varatt.h split off from postgres.h 2023-01-10 05:54:36 +01:00
trgm_op.c Clean up some inconsistencies with GUC declarations 2022-10-31 12:44:48 +09:00
trgm_regexp.c New header varatt.h split off from postgres.h 2023-01-10 05:54:36 +01:00
trgm.h Introduce t_isalnum() to replace t_isalpha() || t_isdigit() tests. 2022-10-06 11:08:56 -04:00