Commit a5cd70d
committed
Improve performance of EXPLAIN with large range tables.
As of 9.3, ruleutils.c goes to some lengths to ensure that table and column
aliases used in its output are unique. Of course this takes more time than
was required before, which in itself isn't fatal. However, EXPLAIN was set
up so that recalculation of the unique aliases was repeated for each
subexpression printed in a plan. That results in O(N^2) time and memory
consumption 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 initialization
just once per query and re-use it for each subexpression. This buys
back most (not all) of the performance loss since 9.2.
We need an extra ExplainState field to hold the precalculated deparse
context. That's no problem in HEAD, but in the back branches, expanding
sizeof(ExplainState) seems risky because third-party extensions might
have local variables of that struct type. So, in 9.4 and 9.3, introduce
an auxiliary struct to keep sizeof(ExplainState) the same. We should
refactor the APIs to avoid such local variables in future, but that's
material for a separate HEAD-only commit.
Per gripe from Alexey Bashtanov. Back-patch to 9.3 where the issue
was introduced.1 parent 0b49642 commit a5cd70d
File tree
4 files changed
+66
-38
lines changed- src
- backend
- commands
- utils/adt
- include
- commands
- utils
4 files changed
+66
-38
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
563 | 563 | | |
564 | 564 | | |
565 | 565 | | |
| 566 | + | |
| 567 | + | |
566 | 568 | | |
567 | 569 | | |
568 | 570 | | |
| |||
1678 | 1680 | | |
1679 | 1681 | | |
1680 | 1682 | | |
1681 | | - | |
1682 | | - | |
1683 | | - | |
1684 | | - | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
1685 | 1686 | | |
1686 | 1687 | | |
1687 | 1688 | | |
| |||
1710 | 1711 | | |
1711 | 1712 | | |
1712 | 1713 | | |
1713 | | - | |
1714 | | - | |
1715 | | - | |
1716 | | - | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
1717 | 1717 | | |
1718 | 1718 | | |
1719 | 1719 | | |
| |||
1855 | 1855 | | |
1856 | 1856 | | |
1857 | 1857 | | |
1858 | | - | |
1859 | | - | |
1860 | | - | |
1861 | | - | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
1862 | 1861 | | |
1863 | 1862 | | |
1864 | 1863 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2520 | 2520 | | |
2521 | 2521 | | |
2522 | 2522 | | |
2523 | | - | |
| 2523 | + | |
| 2524 | + | |
| 2525 | + | |
| 2526 | + | |
| 2527 | + | |
| 2528 | + | |
| 2529 | + | |
| 2530 | + | |
| 2531 | + | |
| 2532 | + | |
| 2533 | + | |
| 2534 | + | |
| 2535 | + | |
| 2536 | + | |
| 2537 | + | |
| 2538 | + | |
| 2539 | + | |
| 2540 | + | |
| 2541 | + | |
| 2542 | + | |
| 2543 | + | |
| 2544 | + | |
| 2545 | + | |
| 2546 | + | |
| 2547 | + | |
| 2548 | + | |
| 2549 | + | |
| 2550 | + | |
| 2551 | + | |
| 2552 | + | |
| 2553 | + | |
| 2554 | + | |
| 2555 | + | |
| 2556 | + | |
| 2557 | + | |
| 2558 | + | |
| 2559 | + | |
2524 | 2560 | | |
2525 | 2561 | | |
2526 | 2562 | | |
| |||
2533 | 2569 | | |
2534 | 2570 | | |
2535 | 2571 | | |
2536 | | - | |
| 2572 | + | |
2537 | 2573 | | |
2538 | 2574 | | |
2539 | 2575 | | |
2540 | 2576 | | |
2541 | 2577 | | |
2542 | | - | |
2543 | | - | |
2544 | | - | |
2545 | | - | |
| 2578 | + | |
| 2579 | + | |
| 2580 | + | |
| 2581 | + | |
| 2582 | + | |
| 2583 | + | |
2546 | 2584 | | |
2547 | 2585 | | |
2548 | | - | |
2549 | | - | |
| 2586 | + | |
| 2587 | + | |
2550 | 2588 | | |
2551 | 2589 | | |
2552 | 2590 | | |
2553 | | - | |
2554 | | - | |
2555 | | - | |
2556 | | - | |
2557 | | - | |
2558 | | - | |
2559 | | - | |
2560 | | - | |
2561 | | - | |
2562 | | - | |
2563 | | - | |
2564 | | - | |
2565 | | - | |
| 2591 | + | |
| 2592 | + | |
| 2593 | + | |
2566 | 2594 | | |
2567 | 2595 | | |
2568 | 2596 | | |
2569 | 2597 | | |
2570 | 2598 | | |
2571 | | - | |
2572 | | - | |
| 2599 | + | |
2573 | 2600 | | |
2574 | 2601 | | |
2575 | 2602 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
0 commit comments