forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitb262ad4
committed
Add better handling of redundant IS [NOT] NULL quals
Until now PostgreSQL has not been very smart about optimizing away ISNOT NULL base quals on columns defined as NOT NULL. The evaluation ofthese needless quals adds overhead. Ordinarily, anyone who camecomplaining about that would likely just have been told to not includethe qual in their query if it's not required. However, a recent bugreport indicates this might not always be possible.Bug 17540 highlighted that when we optimize Min/Max aggregates the IS NOTNULL qual that the planner adds to make the rewritten plan ignore NULLscan cause issues with poor index choice. That particular casedemonstrated that other quals, especially ones where no statistics areavailable to allow the planner a chance at estimating an approximateselectivity for can result in poor index choice due to cheap startup pathsbeing prefered with LIMIT 1.Here we take generic approach to fixing this by having the planner checkfor NOT NULL columns and just have the planner remove these quals (whenthey're not needed) for all queries, not just when optimizing Min/Maxaggregates.Additionally, here we also detect IS NULL quals on a NOT NULL column andtransform that into a gating qual so that we don't have to perform thescan at all. This also works for join relations when the Var is notnullable by any outer join.This also helps with the self-join removal work as it must replacestrict join quals with IS NOT NULL quals to ensure equivalence with theoriginal query.Author: David Rowley, Richard Guo, Andy FanReviewed-by: Richard Guo, David RowleyDiscussion:https://postgr.es/m/CAApHDvqg6XZDhYRPz0zgOcevSMo0d3vxA9DvHrZtKfqO30WTnw@mail.gmail.comDiscussion:https://postgr.es/m/17540-7aa1855ad5ec18b4%40postgresql.org1 parent183b6f7 commitb262ad4
File tree
13 files changed
+664
-67
lines changed- contrib/postgres_fdw
- expected
- sql
- src
- backend/optimizer
- plan
- util
- include
- nodes
- optimizer
- test/regress
- expected
- sql
13 files changed
+664
-67
lines changedLines changed: 8 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
656 | 656 |
| |
657 | 657 |
| |
658 | 658 |
| |
659 |
| - | |
660 |
| - | |
661 |
| - | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
662 | 662 |
| |
663 | 663 |
| |
664 |
| - | |
| 664 | + | |
665 | 665 |
| |
666 | 666 |
| |
667 |
| - | |
668 |
| - | |
669 |
| - | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
670 | 670 |
| |
671 | 671 |
| |
672 |
| - | |
| 672 | + | |
673 | 673 |
| |
674 | 674 |
| |
675 | 675 |
| |
|
Lines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
332 | 332 |
| |
333 | 333 |
| |
334 | 334 |
| |
335 |
| - | |
336 |
| - | |
| 335 | + | |
| 336 | + | |
337 | 337 |
| |
338 | 338 |
| |
339 | 339 |
| |
|
Lines changed: 188 additions & 9 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2618 | 2618 |
| |
2619 | 2619 |
| |
2620 | 2620 |
| |
| 2621 | + | |
| 2622 | + | |
| 2623 | + | |
| 2624 | + | |
| 2625 | + | |
| 2626 | + | |
| 2627 | + | |
| 2628 | + | |
| 2629 | + | |
| 2630 | + | |
| 2631 | + | |
| 2632 | + | |
| 2633 | + | |
| 2634 | + | |
| 2635 | + | |
| 2636 | + | |
| 2637 | + | |
| 2638 | + | |
| 2639 | + | |
| 2640 | + | |
| 2641 | + | |
| 2642 | + | |
| 2643 | + | |
| 2644 | + | |
| 2645 | + | |
| 2646 | + | |
| 2647 | + | |
| 2648 | + | |
| 2649 | + | |
| 2650 | + | |
| 2651 | + | |
| 2652 | + | |
| 2653 | + | |
| 2654 | + | |
| 2655 | + | |
| 2656 | + | |
| 2657 | + | |
| 2658 | + | |
| 2659 | + | |
| 2660 | + | |
| 2661 | + | |
| 2662 | + | |
| 2663 | + | |
| 2664 | + | |
| 2665 | + | |
| 2666 | + | |
| 2667 | + | |
| 2668 | + | |
| 2669 | + | |
| 2670 | + | |
| 2671 | + | |
| 2672 | + | |
| 2673 | + | |
| 2674 | + | |
| 2675 | + | |
| 2676 | + | |
| 2677 | + | |
| 2678 | + | |
| 2679 | + | |
| 2680 | + | |
| 2681 | + | |
| 2682 | + | |
| 2683 | + | |
| 2684 | + | |
| 2685 | + | |
| 2686 | + | |
| 2687 | + | |
| 2688 | + | |
| 2689 | + | |
| 2690 | + | |
| 2691 | + | |
| 2692 | + | |
| 2693 | + | |
| 2694 | + | |
| 2695 | + | |
| 2696 | + | |
| 2697 | + | |
| 2698 | + | |
| 2699 | + | |
| 2700 | + | |
| 2701 | + | |
| 2702 | + | |
| 2703 | + | |
| 2704 | + | |
| 2705 | + | |
| 2706 | + | |
| 2707 | + | |
| 2708 | + | |
| 2709 | + | |
| 2710 | + | |
| 2711 | + | |
| 2712 | + | |
| 2713 | + | |
| 2714 | + | |
| 2715 | + | |
| 2716 | + | |
| 2717 | + | |
| 2718 | + | |
| 2719 | + | |
| 2720 | + | |
| 2721 | + | |
| 2722 | + | |
| 2723 | + | |
| 2724 | + | |
| 2725 | + | |
| 2726 | + | |
| 2727 | + | |
| 2728 | + | |
| 2729 | + | |
| 2730 | + | |
| 2731 | + | |
| 2732 | + | |
| 2733 | + | |
| 2734 | + | |
| 2735 | + | |
| 2736 | + | |
| 2737 | + | |
| 2738 | + | |
| 2739 | + | |
| 2740 | + | |
| 2741 | + | |
| 2742 | + | |
| 2743 | + | |
| 2744 | + | |
| 2745 | + | |
| 2746 | + | |
| 2747 | + | |
| 2748 | + | |
| 2749 | + | |
| 2750 | + | |
| 2751 | + | |
| 2752 | + | |
| 2753 | + | |
| 2754 | + | |
| 2755 | + | |
| 2756 | + | |
| 2757 | + | |
| 2758 | + | |
| 2759 | + | |
| 2760 | + | |
| 2761 | + | |
| 2762 | + | |
| 2763 | + | |
| 2764 | + | |
| 2765 | + | |
| 2766 | + | |
| 2767 | + | |
| 2768 | + | |
| 2769 | + | |
| 2770 | + | |
| 2771 | + | |
| 2772 | + | |
| 2773 | + | |
| 2774 | + | |
| 2775 | + | |
| 2776 | + | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
| 2793 | + | |
| 2794 | + | |
| 2795 | + | |
| 2796 | + | |
| 2797 | + | |
| 2798 | + | |
| 2799 | + | |
| 2800 | + | |
| 2801 | + | |
| 2802 | + | |
| 2803 | + | |
| 2804 | + | |
| 2805 | + | |
| 2806 | + | |
| 2807 | + | |
2621 | 2808 |
| |
2622 | 2809 |
| |
2623 | 2810 |
| |
| |||
2632 | 2819 |
| |
2633 | 2820 |
| |
2634 | 2821 |
| |
2635 |
| - | |
2636 | 2822 |
| |
2637 | 2823 |
| |
2638 | 2824 |
| |
| |||
2644 | 2830 |
| |
2645 | 2831 |
| |
2646 | 2832 |
| |
2647 |
| - | |
2648 |
| - | |
2649 |
| - | |
2650 |
| - | |
2651 |
| - | |
2652 |
| - | |
2653 |
| - | |
2654 |
| - | |
| 2833 | + | |
2655 | 2834 |
| |
2656 | 2835 |
| |
2657 | 2836 |
| |
|
Lines changed: 28 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
14 | 14 |
| |
15 | 15 |
| |
16 | 16 |
| |
| 17 | + | |
17 | 18 |
| |
18 | 19 |
| |
19 | 20 |
| |
| 21 | + | |
| 22 | + | |
20 | 23 |
| |
21 | 24 |
| |
22 | 25 |
| |
| |||
98 | 101 |
| |
99 | 102 |
| |
100 | 103 |
| |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
101 | 129 |
| |
102 | 130 |
| |
103 | 131 |
| |
|
Lines changed: 19 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
163 | 163 |
| |
164 | 164 |
| |
165 | 165 |
| |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
166 | 185 |
| |
167 | 186 |
| |
168 | 187 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
222 | 222 |
| |
223 | 223 |
| |
224 | 224 |
| |
| 225 | + | |
225 | 226 |
| |
226 | 227 |
| |
227 | 228 |
| |
| |||
719 | 720 |
| |
720 | 721 |
| |
721 | 722 |
| |
| 723 | + | |
722 | 724 |
| |
723 | 725 |
| |
724 | 726 |
| |
| |||
917 | 919 |
| |
918 | 920 |
| |
919 | 921 |
| |
| 922 | + | |
920 | 923 |
| |
921 | 924 |
| |
922 | 925 |
| |
|
Lines changed: 6 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
913 | 913 |
| |
914 | 914 |
| |
915 | 915 |
| |
| 916 | + | |
| 917 | + | |
916 | 918 |
| |
917 | 919 |
| |
918 | 920 |
| |
| |||
2598 | 2600 |
| |
2599 | 2601 |
| |
2600 | 2602 |
| |
2601 |
| - | |
| 2603 | + | |
| 2604 | + | |
| 2605 | + | |
| 2606 | + | |
2602 | 2607 |
| |
2603 | 2608 |
| |
2604 | 2609 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
76 | 76 |
| |
77 | 77 |
| |
78 | 78 |
| |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
79 | 83 |
| |
80 | 84 |
| |
81 | 85 |
| |
|
0 commit comments
Comments
(0)