forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitc8c74ad
committed
Get rid of O(N^2) script-parsing overhead in pgbench.
pgbench wants to record the starting line number of each commandin its scripts. It was computing that by scanning from the scriptstart and counting newlines, so that O(N^2) work had to be donefor an N-command script. In a script with 50K lines, this addsup to about 10 seconds on my machine.To add insult to injury, the results were subtly wrong, becauseexpr_scanner_offset() scanned to find the NUL that flex insertsat the end of the current token --- and before the first yylexcall, no such NUL has been inserted. So we ended by computing thescript's last line number not its first one. This was visible onlyin case of \gset at the start of a script, which perhaps accountsfor the lack of complaints.To fix, steal an idea from plpgsql and track the current lexerending position and line count as we advance through the script.(It's a bit simpler than plpgsql since we can't need to back up.)Also adjust a couple of other places that were invoking scansfrom script start when they didn't really need to. I made a newpsqlscan function psql_scan_get_location() that replaces bothexpr_scanner_offset() and expr_scanner_get_lineno(), since inpractice expr_scanner_get_lineno() was only being invoked to findthe line number of the current lexer end position.Reported-by: Daniel Vérité <daniel@manitou-mail.org>Author: Tom Lane <tgl@sss.pgh.pa.us>Discussion:https://postgr.es/m/84a8a89e-adb8-47a9-9d34-c13f7150ee45@manitou-mail.org1 parente167191 commitc8c74ad
File tree
6 files changed
+89
-55
lines changed- src
- bin/pgbench
- fe_utils
- include/fe_utils
6 files changed
+89
-55
lines changedLines changed: 21 additions & 44 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
271 | 271 |
| |
272 | 272 |
| |
273 | 273 |
| |
274 |
| - | |
| 274 | + | |
| 275 | + | |
275 | 276 |
| |
276 | 277 |
| |
277 | 278 |
| |
| 279 | + | |
| 280 | + | |
| 281 | + | |
278 | 282 |
| |
279 | 283 |
| |
280 | 284 |
| |
| |||
289 | 293 |
| |
290 | 294 |
| |
291 | 295 |
| |
292 |
| - | |
293 | 296 |
| |
294 | 297 |
| |
295 | 298 |
| |
| |||
336 | 339 |
| |
337 | 340 |
| |
338 | 341 |
| |
339 |
| - | |
340 |
| - | |
341 |
| - | |
342 |
| - | |
| 342 | + | |
343 | 343 |
| |
344 |
| - | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
345 | 351 |
| |
346 | 352 |
| |
347 | 353 |
| |
| |||
404 | 410 |
| |
405 | 411 |
| |
406 | 412 |
| |
407 |
| - | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
408 | 416 |
| |
409 | 417 |
| |
410 | 418 |
| |
411 | 419 |
| |
412 |
| - | |
413 |
| - | |
414 |
| - | |
415 |
| - | |
416 |
| - | |
417 |
| - | |
418 |
| - | |
419 |
| - | |
420 |
| - | |
421 |
| - | |
422 |
| - | |
423 |
| - | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
424 | 423 |
| |
425 | 424 |
| |
426 | 425 |
| |
427 |
| - | |
| 426 | + | |
428 | 427 |
| |
429 | 428 |
| |
430 | 429 |
| |
431 | 430 |
| |
432 |
| - | |
433 |
| - | |
434 |
| - | |
435 |
| - | |
| 431 | + | |
436 | 432 |
| |
437 | 433 |
| |
438 | 434 |
| |
| |||
447 | 443 |
| |
448 | 444 |
| |
449 | 445 |
| |
450 |
| - | |
451 |
| - | |
452 |
| - | |
453 |
| - | |
454 |
| - | |
455 |
| - | |
456 |
| - | |
457 |
| - | |
458 |
| - | |
459 |
| - | |
460 |
| - | |
461 |
| - | |
462 |
| - | |
463 |
| - | |
464 |
| - | |
465 |
| - | |
466 |
| - | |
467 |
| - | |
468 |
| - |
Lines changed: 6 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5690 | 5690 |
| |
5691 | 5691 |
| |
5692 | 5692 |
| |
5693 |
| - | |
5694 |
| - | |
| 5693 | + | |
| 5694 | + | |
5695 | 5695 |
| |
5696 | 5696 |
| |
5697 | 5697 |
| |
| |||
5747 | 5747 |
| |
5748 | 5748 |
| |
5749 | 5749 |
| |
5750 |
| - | |
5751 | 5750 |
| |
5752 | 5751 |
| |
5753 | 5752 |
| |
| |||
5777 | 5776 |
| |
5778 | 5777 |
| |
5779 | 5778 |
| |
5780 |
| - | |
5781 | 5779 |
| |
5782 | 5780 |
| |
5783 | 5781 |
| |
| |||
5952 | 5950 |
| |
5953 | 5951 |
| |
5954 | 5952 |
| |
5955 |
| - | |
5956 |
| - | |
5957 | 5953 |
| |
5958 | 5954 |
| |
5959 | 5955 |
| |
| |||
5977 | 5973 |
| |
5978 | 5974 |
| |
5979 | 5975 |
| |
5980 |
| - | |
5981 | 5976 |
| |
5982 | 5977 |
| |
5983 | 5978 |
| |
5984 | 5979 |
| |
5985 | 5980 |
| |
5986 | 5981 |
| |
5987 | 5982 |
| |
| 5983 | + | |
| 5984 | + | |
5988 | 5985 |
| |
5989 | 5986 |
| |
5990 | 5987 |
| |
5991 | 5988 |
| |
5992 | 5989 |
| |
5993 |
| - | |
| 5990 | + | |
| 5991 | + | |
5994 | 5992 |
| |
5995 | 5993 |
| |
5996 | 5994 |
| |
|
Lines changed: 1 addition & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
149 | 149 |
| |
150 | 150 |
| |
151 | 151 |
| |
152 |
| - | |
153 | 152 |
| |
154 |
| - | |
| 153 | + | |
155 | 154 |
| |
156 |
| - | |
157 | 155 |
| |
158 | 156 |
| |
159 | 157 |
| |
|
Lines changed: 54 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1079 | 1079 |
| |
1080 | 1080 |
| |
1081 | 1081 |
| |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
1082 | 1086 |
| |
1083 | 1087 |
| |
1084 | 1088 |
| |
| |||
1136 | 1140 |
| |
1137 | 1141 |
| |
1138 | 1142 |
| |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
1139 | 1147 |
| |
1140 | 1148 |
| |
1141 | 1149 |
| |
| |||
1311 | 1319 |
| |
1312 | 1320 |
| |
1313 | 1321 |
| |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
1314 | 1368 |
| |
1315 | 1369 |
| |
1316 | 1370 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
87 | 87 |
| |
88 | 88 |
| |
89 | 89 |
| |
| 90 | + | |
| 91 | + | |
| 92 | + | |
90 | 93 |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
104 | 104 |
| |
105 | 105 |
| |
106 | 106 |
| |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
107 | 111 |
| |
108 | 112 |
| |
109 | 113 |
| |
|
0 commit comments
Comments
(0)