- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit8d83a5d
committed
Remove redundant grouping and DISTINCT columns.
Avoid explicitly grouping by columns that we know are redundantfor sorting, for example we need group by only one of x and y inSELECT ... WHERE x = y GROUP BY x, yThis comes up more often than you might think, as shown by thechanges in the regression tests. It's nearly free to detect too,since we are just piggybacking on the existing logic that detectsredundant pathkeys. (In some of the existing plans that change,it's visible that a sort step preceding the grouping step alreadydidn't bother to sort by the redundant column, making the old plana bit silly-looking.)To do this, build processed_groupClause and processed_distinctClauselists that omit any provably-redundant sort items, and consult thosenot the originals where relevant. This means that within theplanner, one should usually consult root->processed_groupClause orroot->processed_distinctClause if one wants to know which columnsare to be grouped on; but to check whether grouping or distinct-ingis happening at all, check non-NIL-ness of parse->groupClause orparse->distinctClause. This is comparable to longstanding rulesabout handling the HAVING clause, so I don't think it'll be a hugemaintenance problem.nodeAgg.c also needs minor mods, because it's now possible to generateAGG_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.us1 parentd540a02 commit8d83a5d
File tree
16 files changed
+303
-171
lines changed- contrib
- pg_trgm/expected
- postgres_fdw
- expected
- src
- backend
- executor
- optimizer
- path
- plan
- prep
- include
- nodes
- optimizer
- test/regress/expected
16 files changed
+303
-171
lines changedLines changed: 3 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5366 | 5366 |
| |
5367 | 5367 |
| |
5368 | 5368 |
| |
5369 |
| - | |
5370 |
| - | |
| 5369 | + | |
| 5370 | + | |
5371 | 5371 |
| |
5372 |
| - | |
| 5372 | + | |
5373 | 5373 |
| |
5374 | 5374 |
| |
5375 | 5375 |
| |
|
Lines changed: 7 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3736 | 3736 |
| |
3737 | 3737 |
| |
3738 | 3738 |
| |
| 3739 | + | |
| 3740 | + | |
| 3741 | + | |
| 3742 | + | |
| 3743 | + | |
| 3744 | + | |
| 3745 | + | |
3739 | 3746 |
| |
3740 | 3747 |
| |
3741 | 3748 |
| |
|
Lines changed: 16 additions & 22 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2293 | 2293 |
| |
2294 | 2294 |
| |
2295 | 2295 |
| |
2296 |
| - | |
| 2296 | + | |
2297 | 2297 |
| |
2298 | 2298 |
| |
2299 | 2299 |
| |
| |||
2864 | 2864 |
| |
2865 | 2865 |
| |
2866 | 2866 |
| |
2867 |
| - | |
2868 |
| - | |
2869 |
| - | |
| 2867 | + | |
| 2868 | + | |
| 2869 | + | |
2870 | 2870 |
| |
2871 |
| - | |
2872 |
| - | |
2873 |
| - | |
2874 |
| - | |
2875 |
| - | |
2876 |
| - | |
| 2871 | + | |
| 2872 | + | |
| 2873 | + | |
2877 | 2874 |
| |
2878 | 2875 |
| |
2879 | 2876 |
| |
| |||
2990 | 2987 |
| |
2991 | 2988 |
| |
2992 | 2989 |
| |
2993 |
| - | |
2994 |
| - | |
| 2990 | + | |
2995 | 2991 |
| |
2996 | 2992 |
| |
2997 | 2993 |
| |
2998 |
| - | |
| 2994 | + | |
2999 | 2995 |
| |
3000 |
| - | |
| 2996 | + | |
3001 | 2997 |
| |
3002 | 2998 |
| |
3003 | 2999 |
| |
| |||
3382 | 3378 |
| |
3383 | 3379 |
| |
3384 | 3380 |
| |
3385 |
| - | |
3386 | 3381 |
| |
3387 |
| - | |
| 3382 | + | |
3388 | 3383 |
| |
3389 | 3384 |
| |
3390 |
| - | |
| 3385 | + | |
3391 | 3386 |
| |
3392 |
| - | |
| 3387 | + | |
3393 | 3388 |
| |
3394 | 3389 |
| |
3395 | 3390 |
| |
| |||
3458 | 3453 |
| |
3459 | 3454 |
| |
3460 | 3455 |
| |
3461 |
| - | |
3462 | 3456 |
| |
3463 |
| - | |
| 3457 | + | |
3464 | 3458 |
| |
3465 | 3459 |
| |
3466 |
| - | |
| 3460 | + | |
3467 | 3461 |
| |
3468 |
| - | |
| 3462 | + | |
3469 | 3463 |
| |
3470 | 3464 |
| |
3471 | 3465 |
| |
|
Lines changed: 8 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3345 | 3345 |
| |
3346 | 3346 |
| |
3347 | 3347 |
| |
3348 |
| - | |
| 3348 | + | |
3349 | 3349 |
| |
3350 |
| - | |
| 3350 | + | |
3351 | 3351 |
| |
3352 | 3352 |
| |
3353 | 3353 |
| |
| |||
3636 | 3636 |
| |
3637 | 3637 |
| |
3638 | 3638 |
| |
3639 |
| - | |
| 3639 | + | |
3640 | 3640 |
| |
3641 | 3641 |
| |
3642 | 3642 |
| |
| |||
6415 | 6415 |
| |
6416 | 6416 |
| |
6417 | 6417 |
| |
6418 |
| - | |
| 6418 | + | |
| 6419 | + | |
| 6420 | + | |
| 6421 | + | |
| 6422 | + | |
6419 | 6423 |
| |
6420 | 6424 |
| |
6421 | 6425 |
| |
|
Lines changed: 3 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2476 | 2476 |
| |
2477 | 2477 |
| |
2478 | 2478 |
| |
2479 |
| - | |
| 2479 | + | |
2480 | 2480 |
| |
2481 | 2481 |
| |
2482 | 2482 |
| |
| |||
3480 | 3480 |
| |
3481 | 3481 |
| |
3482 | 3482 |
| |
3483 |
| - | |
3484 |
| - | |
3485 | 3483 |
| |
3486 | 3484 |
| |
3487 | 3485 |
| |
| |||
3512 | 3510 |
| |
3513 | 3511 |
| |
3514 | 3512 |
| |
3515 |
| - | |
| 3513 | + | |
| 3514 | + | |
3516 | 3515 |
| |
3517 | 3516 |
| |
3518 | 3517 |
| |
|
Lines changed: 48 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1152 | 1152 |
| |
1153 | 1153 |
| |
1154 | 1154 |
| |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
1155 | 1194 |
| |
1156 | 1195 |
| |
1157 | 1196 |
| |
1158 | 1197 |
| |
1159 |
| - | |
| 1198 | + | |
| 1199 | + | |
1160 | 1200 |
| |
1161 | 1201 |
| |
1162 | 1202 |
| |
1163 | 1203 |
| |
1164 | 1204 |
| |
1165 | 1205 |
| |
1166 |
| - | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
1167 | 1211 |
| |
1168 | 1212 |
| |
1169 | 1213 |
| |
| |||
1175 | 1219 |
| |
1176 | 1220 |
| |
1177 | 1221 |
| |
| 1222 | + | |
| 1223 | + | |
1178 | 1224 |
| |
1179 | 1225 |
| |
1180 | 1226 |
| |
|
Lines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2404 | 2404 |
| |
2405 | 2405 |
| |
2406 | 2406 |
| |
2407 |
| - | |
| 2407 | + | |
2408 | 2408 |
| |
2409 | 2409 |
| |
2410 | 2410 |
| |
| |||
2415 | 2415 |
| |
2416 | 2416 |
| |
2417 | 2417 |
| |
2418 |
| - | |
| 2418 | + | |
2419 | 2419 |
| |
2420 | 2420 |
| |
2421 | 2421 |
| |
|
0 commit comments
Comments
(0)