forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit939f0fb
committed
Improve performance of EXPLAIN with large range tables.
As of 9.3, ruleutils.c goes to some lengths to ensure that table and columnaliases used in its output are unique. Of course this takes more time thanwas required before, which in itself isn't fatal. However, EXPLAIN was setup so that recalculation of the unique aliases was repeated for eachsubexpression printed in a plan. That results in O(N^2) time and memoryconsumption for large plan trees, which did not happen in older branches.Fortunately, the expensive work is the same across a whole plan tree,so there is no need to repeat it; we can do most of the initializationjust once per query and re-use it for each subexpression. This buysback most (not all) of the performance loss since 9.2.We need an extra ExplainState field to hold the precalculated deparsecontext. That's no problem in HEAD, but in the back branches, expandingsizeof(ExplainState) seems risky because third-party extensions mighthave local variables of that struct type. So, in 9.4 and 9.3, introducean auxiliary struct to keep sizeof(ExplainState) the same. We shouldrefactor the APIs to avoid such local variables in future, but that'smaterial for a separate HEAD-only commit.Per gripe from Alexey Bashtanov. Back-patch to 9.3 where the issuewas introduced.1 parentebbef4f commit939f0fb
File tree
4 files changed
+77
-37
lines changed- src
- backend
- commands
- utils/adt
- include
- commands
- utils
4 files changed
+77
-37
lines changedLines changed: 17 additions & 12 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
33 | 33 |
| |
34 | 34 |
| |
35 | 35 |
| |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
36 | 40 |
| |
37 | 41 |
| |
38 | 42 |
| |
| |||
253 | 257 |
| |
254 | 258 |
| |
255 | 259 |
| |
| 260 | + | |
| 261 | + | |
256 | 262 |
| |
257 | 263 |
| |
258 | 264 |
| |
| |||
555 | 561 |
| |
556 | 562 |
| |
557 | 563 |
| |
| 564 | + | |
| 565 | + | |
558 | 566 |
| |
559 | 567 |
| |
560 | 568 |
| |
| |||
1585 | 1593 |
| |
1586 | 1594 |
| |
1587 | 1595 |
| |
1588 |
| - | |
1589 |
| - | |
1590 |
| - | |
1591 |
| - | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
1592 | 1599 |
| |
1593 | 1600 |
| |
1594 | 1601 |
| |
| |||
1617 | 1624 |
| |
1618 | 1625 |
| |
1619 | 1626 |
| |
1620 |
| - | |
1621 |
| - | |
1622 |
| - | |
1623 |
| - | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
1624 | 1630 |
| |
1625 | 1631 |
| |
1626 | 1632 |
| |
| |||
1720 | 1726 |
| |
1721 | 1727 |
| |
1722 | 1728 |
| |
1723 |
| - | |
1724 |
| - | |
1725 |
| - | |
1726 |
| - | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
1727 | 1732 |
| |
1728 | 1733 |
| |
1729 | 1734 |
| |
|
Lines changed: 49 additions & 22 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2370 | 2370 |
| |
2371 | 2371 |
| |
2372 | 2372 |
| |
2373 |
| - | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
| 2380 | + | |
| 2381 | + | |
| 2382 | + | |
| 2383 | + | |
| 2384 | + | |
| 2385 | + | |
| 2386 | + | |
| 2387 | + | |
| 2388 | + | |
| 2389 | + | |
| 2390 | + | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
| 2396 | + | |
| 2397 | + | |
| 2398 | + | |
| 2399 | + | |
| 2400 | + | |
| 2401 | + | |
| 2402 | + | |
| 2403 | + | |
| 2404 | + | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
| 2409 | + | |
2374 | 2410 |
| |
2375 | 2411 |
| |
2376 | 2412 |
| |
| |||
2389 | 2425 |
| |
2390 | 2426 |
| |
2391 | 2427 |
| |
2392 |
| - | |
2393 |
| - | |
2394 |
| - | |
2395 |
| - | |
| 2428 | + | |
| 2429 | + | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
2396 | 2434 |
| |
2397 | 2435 |
| |
2398 |
| - | |
2399 |
| - | |
| 2436 | + | |
| 2437 | + | |
2400 | 2438 |
| |
2401 | 2439 |
| |
2402 | 2440 |
| |
2403 |
| - | |
2404 |
| - | |
2405 |
| - | |
2406 |
| - | |
2407 |
| - | |
2408 |
| - | |
2409 |
| - | |
2410 |
| - | |
2411 |
| - | |
2412 |
| - | |
2413 |
| - | |
2414 |
| - | |
2415 |
| - | |
| 2441 | + | |
| 2442 | + | |
| 2443 | + | |
2416 | 2444 |
| |
2417 | 2445 |
| |
2418 | 2446 |
| |
2419 | 2447 |
| |
2420 | 2448 |
| |
2421 |
| - | |
2422 |
| - | |
| 2449 | + | |
2423 | 2450 |
| |
2424 | 2451 |
| |
2425 | 2452 |
| |
|
Lines changed: 8 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
24 | 24 |
| |
25 | 25 |
| |
26 | 26 |
| |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
27 | 34 |
| |
28 | 35 |
| |
29 | 36 |
| |
| |||
39 | 46 |
| |
40 | 47 |
| |
41 | 48 |
| |
42 |
| - | |
| 49 | + | |
43 | 50 |
| |
44 | 51 |
| |
45 | 52 |
| |
|
Lines changed: 3 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
660 | 660 |
| |
661 | 661 |
| |
662 | 662 |
| |
663 |
| - | |
664 |
| - | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
665 | 666 |
| |
666 | 667 |
| |
667 | 668 |
| |
|
0 commit comments
Comments
(0)