forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit244407a
committed
Fix efficiency problems in tuplestore_trim().
The original coding in tuplestore_trim() was only meant to work efficientlyin cases where each trim call deleted most of the tuples in the store.Which, in fact, was the pattern of the original usage with a Material nodesupporting mark/restore operations underneath a MergeJoin. However,WindowAgg now uses tuplestores and it has considerably less friendlytrimming behavior. In particular it can attempt to trim one tuple at atime off a large tuplestore. tuplestore_trim() had O(N^2) runtime in thissituation because of repeatedly shifting its tuple pointer array. Fix byavoiding shifting the array until a reasonably large number of tuples havebeen deleted. This can waste some pointer space, but we do still reclaimthe tuples themselves, so the percentage wastage should be pretty small.Per Jie Li's report of slow percent_rank() evaluation. cume_dist() andntile() would certainly be affected as well, along with any other windowfunction that has a moving frame start and requires reading substantiallyahead of the current row.Back-patch to 8.4, where window functions were introduced. There's noneed to tweak it before that.1 parent663fc32 commit244407a
1 file changed
+36
-16
lines changedLines changed: 36 additions & 16 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
145 | 145 |
| |
146 | 146 |
| |
147 | 147 |
| |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
148 | 154 |
| |
149 | 155 |
| |
| 156 | + | |
150 | 157 |
| |
151 | 158 |
| |
152 | 159 |
| |
| |||
252 | 259 |
| |
253 | 260 |
| |
254 | 261 |
| |
| 262 | + | |
255 | 263 |
| |
256 | 264 |
| |
257 | 265 |
| |
| |||
401 | 409 |
| |
402 | 410 |
| |
403 | 411 |
| |
404 |
| - | |
| 412 | + | |
405 | 413 |
| |
406 | 414 |
| |
407 | 415 |
| |
408 | 416 |
| |
409 | 417 |
| |
410 | 418 |
| |
411 | 419 |
| |
| 420 | + | |
412 | 421 |
| |
413 | 422 |
| |
414 | 423 |
| |
| |||
432 | 441 |
| |
433 | 442 |
| |
434 | 443 |
| |
435 |
| - | |
| 444 | + | |
436 | 445 |
| |
437 | 446 |
| |
438 | 447 |
| |
| |||
774 | 783 |
| |
775 | 784 |
| |
776 | 785 |
| |
777 |
| - | |
| 786 | + | |
778 | 787 |
| |
779 | 788 |
| |
780 | 789 |
| |
781 | 790 |
| |
782 | 791 |
| |
783 | 792 |
| |
784 |
| - | |
| 793 | + | |
785 | 794 |
| |
786 | 795 |
| |
787 | 796 |
| |
| |||
969 | 978 |
| |
970 | 979 |
| |
971 | 980 |
| |
972 |
| - | |
| 981 | + | |
973 | 982 |
| |
974 | 983 |
| |
975 | 984 |
| |
| |||
984 | 993 |
| |
985 | 994 |
| |
986 | 995 |
| |
| 996 | + | |
987 | 997 |
| |
988 | 998 |
| |
989 | 999 |
| |
| |||
1153 | 1163 |
| |
1154 | 1164 |
| |
1155 | 1165 |
| |
| 1166 | + | |
| 1167 | + | |
1156 | 1168 |
| |
1157 | 1169 |
| |
1158 | 1170 |
| |
1159 |
| - | |
| 1171 | + | |
1160 | 1172 |
| |
1161 | 1173 |
| |
1162 | 1174 |
| |
| 1175 | + | |
1163 | 1176 |
| |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
1164 | 1190 |
| |
1165 | 1191 |
| |
1166 |
| - | |
1167 |
| - | |
1168 |
| - | |
1169 |
| - | |
| 1192 | + | |
1170 | 1193 |
| |
1171 |
| - | |
1172 |
| - | |
1173 |
| - | |
| 1194 | + | |
| 1195 | + | |
1174 | 1196 |
| |
1175 | 1197 |
| |
1176 | 1198 |
| |
1177 | 1199 |
| |
1178 | 1200 |
| |
1179 | 1201 |
| |
1180 | 1202 |
| |
| 1203 | + | |
1181 | 1204 |
| |
1182 | 1205 |
| |
1183 | 1206 |
| |
1184 | 1207 |
| |
1185 | 1208 |
| |
1186 | 1209 |
| |
1187 |
| - | |
1188 |
| - | |
1189 |
| - | |
1190 | 1210 |
| |
1191 | 1211 |
| |
1192 | 1212 |
| |
|
0 commit comments
Comments
(0)