forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit908a968
committed
Optimize WindowAgg's use of tuplestores
When WindowAgg finished one partition of a PARTITION BY, it previouslywould call tuplestore_end() to purge all the stored tuples before againcalling tuplestore_begin_heap() and carefully setting up all of thetuplestore read pointers exactly as required for the given frameOptions.Since the frameOptions don't change between partitions, this part doesnot make much sense. For queries that had very few rows per partition,the overhead of this was very large.It seems much better to create the tuplestore and the read pointers onceand simply call tuplestore_clear() at the end of each partition.tuplestore_clear() moves all of the read pointers back to the startposition and deletes all the previously stored tuples.A simple test query with 1 million partitions and 1 tuple per partitionhas been shown to run around 40% faster than without this change. Theadditional effort seems to have mostly been spent in malloc/free.Making this work required adding a new bool field to WindowAggStatewhich had the unfortunate effect of being the 9th bool field in a groupresulting in the struct being enlarged. Here we shuffle the fieldsaround a little so that the two bool fields for runcondition relatingstuff fit into existing padding. Also, move the "runcondition" field tobe near those. This frees up enough space with the other bool fields sothat the newly added one fits into the padding bytes. This was done toaddress a very small but apparent performance regression with queriescontaining a large number of rows per partition.Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>Reviewed-by: Tatsuo Ishii <ishii@postgresql.org>Discussion:https://postgr.es/m/CAHoyFK9n-QCXKTUWT_xxtXninSMEv%2BgbJN66-y6prM3f4WkEHw%40mail.gmail.com1 parent19b861f commit908a968
File tree
2 files changed
+118
-66
lines changed- src
- backend/executor
- include/nodes
2 files changed
+118
-66
lines changedLines changed: 106 additions & 56 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1074 | 1074 |
| |
1075 | 1075 |
| |
1076 | 1076 |
| |
1077 |
| - | |
1078 |
| - | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
1079 | 1083 |
| |
1080 |
| - | |
1081 |
| - | |
| 1084 | + | |
| 1085 | + | |
1082 | 1086 |
| |
1083 | 1087 |
| |
1084 |
| - | |
1085 | 1088 |
| |
1086 | 1089 |
| |
1087 |
| - | |
1088 |
| - | |
1089 |
| - | |
1090 |
| - | |
1091 |
| - | |
1092 |
| - | |
1093 |
| - | |
1094 |
| - | |
1095 |
| - | |
1096 |
| - | |
1097 |
| - | |
1098 |
| - | |
1099 |
| - | |
1100 |
| - | |
1101 |
| - | |
1102 |
| - | |
1103 |
| - | |
1104 |
| - | |
1105 |
| - | |
1106 |
| - | |
1107 |
| - | |
1108 |
| - | |
1109 |
| - | |
1110 |
| - | |
1111 |
| - | |
1112 |
| - | |
1113 |
| - | |
1114 |
| - | |
1115 | 1090 |
| |
1116 |
| - | |
1117 |
| - | |
1118 |
| - | |
1119 |
| - | |
1120 |
| - | |
1121 |
| - | |
1122 |
| - | |
1123 |
| - | |
1124 |
| - | |
1125 |
| - | |
| 1091 | + | |
| 1092 | + | |
1126 | 1093 |
| |
1127 |
| - | |
| 1094 | + | |
1128 | 1095 |
| |
1129 | 1096 |
| |
1130 | 1097 |
| |
| |||
1158 | 1125 |
| |
1159 | 1126 |
| |
1160 | 1127 |
| |
1161 |
| - | |
1162 |
| - | |
1163 |
| - | |
1164 |
| - | |
1165 |
| - | |
1166 |
| - | |
1167 | 1128 |
| |
1168 | 1129 |
| |
1169 | 1130 |
| |
1170 |
| - | |
| 1131 | + | |
1171 | 1132 |
| |
1172 | 1133 |
| |
1173 | 1134 |
| |
| |||
1179 | 1140 |
| |
1180 | 1141 |
| |
1181 | 1142 |
| |
1182 |
| - | |
1183 |
| - | |
1184 | 1143 |
| |
1185 | 1144 |
| |
1186 | 1145 |
| |
| |||
1224 | 1183 |
| |
1225 | 1184 |
| |
1226 | 1185 |
| |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
1227 | 1268 |
| |
1228 | 1269 |
| |
1229 | 1270 |
| |
| |||
1360 | 1401 |
| |
1361 | 1402 |
| |
1362 | 1403 |
| |
1363 |
| - | |
1364 |
| - | |
| 1404 | + | |
1365 | 1405 |
| |
| 1406 | + | |
1366 | 1407 |
| |
1367 | 1408 |
| |
1368 | 1409 |
| |
| |||
2143 | 2184 |
| |
2144 | 2185 |
| |
2145 | 2186 |
| |
2146 |
| - | |
| 2187 | + | |
2147 | 2188 |
| |
2148 | 2189 |
| |
2149 | 2190 |
| |
| |||
2686 | 2727 |
| |
2687 | 2728 |
| |
2688 | 2729 |
| |
| 2730 | + | |
2689 | 2731 |
| |
2690 | 2732 |
| |
2691 | 2733 |
| |
| |||
2700 | 2742 |
| |
2701 | 2743 |
| |
2702 | 2744 |
| |
| 2745 | + | |
| 2746 | + | |
| 2747 | + | |
| 2748 | + | |
| 2749 | + | |
| 2750 | + | |
| 2751 | + | |
| 2752 | + | |
2703 | 2753 |
| |
2704 | 2754 |
| |
2705 | 2755 |
| |
|
Lines changed: 12 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2619 | 2619 |
| |
2620 | 2620 |
| |
2621 | 2621 |
| |
| 2622 | + | |
| 2623 | + | |
| 2624 | + | |
| 2625 | + | |
| 2626 | + | |
| 2627 | + | |
| 2628 | + | |
| 2629 | + | |
| 2630 | + | |
| 2631 | + | |
| 2632 | + | |
2622 | 2633 |
| |
2623 | 2634 |
| |
2624 | 2635 |
| |
| |||
2631 | 2642 |
| |
2632 | 2643 |
| |
2633 | 2644 |
| |
2634 |
| - | |
2635 |
| - | |
2636 |
| - | |
2637 |
| - | |
2638 |
| - | |
2639 |
| - | |
2640 |
| - | |
2641 |
| - | |
2642 |
| - | |
2643 |
| - | |
2644 | 2645 |
| |
2645 | 2646 |
| |
2646 | 2647 |
| |
| 2648 | + | |
2647 | 2649 |
| |
2648 | 2650 |
| |
2649 | 2651 |
| |
|
0 commit comments
Comments
(0)