Commit b5810de
committed
Reduce memory consumption for multi-statement query strings.
Previously, exec_simple_query always ran parse analysis, rewrite, and
planning in MessageContext, allowing all the data generated thereby
to persist until the end of processing of the whole query string.
That's fine for single-command strings, but if a client sends many
commands in a single simple-Query message, this strategy could result
in annoying memory bloat, as complained of by Andreas Seltenreich.
To fix, create a child context to do this work in, and reclaim it
after each command. But we only do so for parsetrees that are not
last in their query string. That avoids adding any memory management
overhead for the typical case of a single-command string. Memory
allocated for the last parsetree would be freed immediately after
finishing the command string anyway.
Similarly, adjust extension.c's execute_sql_string() to reclaim memory
after each command. In that usage, multi-command strings are the norm,
so it's a bit surprising that no one has yet complained of bloat ---
especially since the bloat extended to whatever data ProcessUtility
execution might leak.
Amit Langote, reviewed by Julien Rouhaud
Discussion: https://postgr.es/m/87ftp6l2qr.fsf@credativ.de1 parent 909a7b6 commit b5810de
2 files changed
+41
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
717 | 717 | | |
718 | 718 | | |
719 | 719 | | |
| 720 | + | |
| 721 | + | |
720 | 722 | | |
721 | 723 | | |
722 | 724 | | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
723 | 735 | | |
724 | 736 | | |
725 | 737 | | |
| |||
772 | 784 | | |
773 | 785 | | |
774 | 786 | | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
775 | 791 | | |
776 | 792 | | |
777 | 793 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1070 | 1070 | | |
1071 | 1071 | | |
1072 | 1072 | | |
| 1073 | + | |
1073 | 1074 | | |
1074 | 1075 | | |
1075 | 1076 | | |
| |||
1132 | 1133 | | |
1133 | 1134 | | |
1134 | 1135 | | |
1135 | | - | |
1136 | | - | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
1137 | 1144 | | |
1138 | | - | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
1139 | 1155 | | |
1140 | 1156 | | |
1141 | 1157 | | |
| |||
1160 | 1176 | | |
1161 | 1177 | | |
1162 | 1178 | | |
1163 | | - | |
1164 | | - | |
| 1179 | + | |
| 1180 | + | |
1165 | 1181 | | |
1166 | 1182 | | |
1167 | 1183 | | |
| |||
1263 | 1279 | | |
1264 | 1280 | | |
1265 | 1281 | | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
1266 | 1286 | | |
1267 | 1287 | | |
1268 | 1288 | | |
| |||
0 commit comments