- Notifications
You must be signed in to change notification settings - Fork4.9k
Commitcbc1279
committed
Track unpruned relids to avoid processing pruned relations
This commit introduces changes to track unpruned relations explicitly,making it possible for top-level plan nodes, such as ModifyTable andLockRows, to avoid processing partitions pruned during initialpruning. Scan-level nodes, such as Append and MergeAppend, alreadyavoid the unnecessary processing by accessing partition pruningresults directly via part_prune_index. In contrast, top-level nodescannot access pruning results directly and need to determine whichpartitions remain unpruned.To address this, this commit introduces a new bitmapset field,es_unpruned_relids, which the executor uses to track the set ofunpruned relations. This field is referenced during planinitialization to skip initializing certain nodes for prunedpartitions. It is initialized with PlannedStmt.unprunableRelids,a new field that the planner populates with RT indexes of relationsthat cannot be pruned during runtime pruning. These include relationsnot subject to partition pruning and those required for executionregardless of pruning.PlannedStmt.unprunableRelids is computed during set_plan_refs() byremoving the RT indexes of runtime-prunable relations, identifiedfrom PartitionPruneInfos, from the full set of relation RT indexes.ExecDoInitialPruning() then updates es_unpruned_relids by addingpartitions that survive initial pruning.To support this, PartitionedRelPruneInfo and PartitionedRelPruningDatanow include a leafpart_rti_map[] array that maps partition indexes totheir corresponding RT indexes. The former is used in set_plan_refs()when constructing unprunableRelids, while the latter is used inExecDoInitialPruning() to convert partition indexes returned byget_matching_partitions() into RT indexes, which are then added toes_unpruned_relids.These changes make it possible for ModifyTable and LockRows nodes toprocess only relations that remain unpruned after initial pruning.ExecInitModifyTable() trims lists, such as resultRelations,withCheckOptionLists, returningLists, and updateColnosLists, toconsider only unpruned partitions. It also creates ResultRelInfostructs only for these partitions. Similarly, child RowMarks forpruned relations are skipped.By avoiding unnecessary initialization of structures for prunedpartitions, these changes improve the performance of updates anddeletes on partitioned tables during initial runtime pruning.Due to ExecInitModifyTable() changes as described above, EXPLAIN on aplan for UPDATE and DELETE that uses runtime initial pruning no longerlists partitions pruned during initial pruning.Reviewed-by: Robert Haas <robertmhaas@gmail.com> (earlier versions)Reviewed-by: Tomas Vondra <tomas@vondra.me>Discussion:https://postgr.es/m/CA+HiwqFGkMSge6TgC9KQzde0ohpAycLQuV7ooitEEpbKB0O_mg@mail.gmail.com1 parent926c7fc commitcbc1279
File tree
21 files changed
+340
-51
lines changed- src
- backend
- commands
- executor
- optimizer/plan
- partitioning
- replication
- logical
- pgoutput
- include
- executor
- nodes
- test/regress
- expected
- sql
21 files changed
+340
-51
lines changedLines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
774 | 774 |
| |
775 | 775 |
| |
776 | 776 |
| |
777 |
| - | |
| 777 | + | |
| 778 | + | |
778 | 779 |
| |
779 | 780 |
| |
780 | 781 |
| |
|
Lines changed: 16 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
851 | 851 |
| |
852 | 852 |
| |
853 | 853 |
| |
854 |
| - | |
| 854 | + | |
| 855 | + | |
855 | 856 |
| |
856 | 857 |
| |
857 | 858 |
| |
| |||
881 | 882 |
| |
882 | 883 |
| |
883 | 884 |
| |
884 |
| - | |
885 |
| - | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
886 | 892 |
| |
887 | 893 |
| |
888 | 894 |
| |
| |||
2933 | 2939 |
| |
2934 | 2940 |
| |
2935 | 2941 |
| |
| 2942 | + | |
| 2943 | + | |
| 2944 | + | |
| 2945 | + | |
| 2946 | + | |
| 2947 | + | |
| 2948 | + | |
2936 | 2949 |
| |
2937 | 2950 |
| |
2938 | 2951 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
183 | 183 |
| |
184 | 184 |
| |
185 | 185 |
| |
| 186 | + | |
186 | 187 |
| |
187 | 188 |
| |
188 | 189 |
| |
|
Lines changed: 71 additions & 12 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
182 | 182 |
| |
183 | 183 |
| |
184 | 184 |
| |
185 |
| - | |
| 185 | + | |
| 186 | + | |
186 | 187 |
| |
187 | 188 |
| |
188 | 189 |
| |
| |||
196 | 197 |
| |
197 | 198 |
| |
198 | 199 |
| |
199 |
| - | |
| 200 | + | |
| 201 | + | |
200 | 202 |
| |
201 | 203 |
| |
202 | 204 |
| |
| |||
1820 | 1822 |
| |
1821 | 1823 |
| |
1822 | 1824 |
| |
| 1825 | + | |
| 1826 | + | |
1823 | 1827 |
| |
1824 | 1828 |
| |
1825 |
| - | |
| 1829 | + | |
| 1830 | + | |
1826 | 1831 |
| |
1827 | 1832 |
| |
1828 | 1833 |
| |
| |||
1831 | 1836 |
| |
1832 | 1837 |
| |
1833 | 1838 |
| |
1834 |
| - | |
| 1839 | + | |
| 1840 | + | |
| 1841 | + | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
1835 | 1846 |
| |
1836 | 1847 |
| |
1837 | 1848 |
| |
| |||
1944 | 1955 |
| |
1945 | 1956 |
| |
1946 | 1957 |
| |
| 1958 | + | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
| 1963 | + | |
1947 | 1964 |
| |
1948 | 1965 |
| |
1949 |
| - | |
| 1966 | + | |
| 1967 | + | |
1950 | 1968 |
| |
1951 | 1969 |
| |
1952 | 1970 |
| |
| |||
2039 | 2057 |
| |
2040 | 2058 |
| |
2041 | 2059 |
| |
2042 |
| - | |
2043 |
| - | |
| 2060 | + | |
| 2061 | + | |
2044 | 2062 |
| |
2045 | 2063 |
| |
2046 | 2064 |
| |
| |||
2059 | 2077 |
| |
2060 | 2078 |
| |
2061 | 2079 |
| |
| 2080 | + | |
2062 | 2081 |
| |
2063 | 2082 |
| |
2064 | 2083 |
| |
| |||
2079 | 2098 |
| |
2080 | 2099 |
| |
2081 | 2100 |
| |
| 2101 | + | |
2082 | 2102 |
| |
2083 | 2103 |
| |
2084 | 2104 |
| |
| |||
2096 | 2116 |
| |
2097 | 2117 |
| |
2098 | 2118 |
| |
| 2119 | + | |
| 2120 | + | |
2099 | 2121 |
| |
2100 | 2122 |
| |
2101 | 2123 |
| |
| |||
2133 | 2155 |
| |
2134 | 2156 |
| |
2135 | 2157 |
| |
| 2158 | + | |
2136 | 2159 |
| |
2137 | 2160 |
| |
2138 | 2161 |
| |
| |||
2174 | 2197 |
| |
2175 | 2198 |
| |
2176 | 2199 |
| |
| 2200 | + | |
| 2201 | + | |
| 2202 | + | |
| 2203 | + | |
| 2204 | + | |
| 2205 | + | |
| 2206 | + | |
| 2207 | + | |
| 2208 | + | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
| 2212 | + | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
| 2216 | + | |
| 2217 | + | |
| 2218 | + | |
2177 | 2219 |
| |
2178 | 2220 |
| |
2179 | 2221 |
| |
| |||
2439 | 2481 |
| |
2440 | 2482 |
| |
2441 | 2483 |
| |
| 2484 | + | |
| 2485 | + | |
| 2486 | + | |
| 2487 | + | |
2442 | 2488 |
| |
2443 | 2489 |
| |
2444 | 2490 |
| |
2445 |
| - | |
| 2491 | + | |
| 2492 | + | |
2446 | 2493 |
| |
2447 | 2494 |
| |
2448 | 2495 |
| |
| |||
2454 | 2501 |
| |
2455 | 2502 |
| |
2456 | 2503 |
| |
| 2504 | + | |
2457 | 2505 |
| |
2458 | 2506 |
| |
2459 | 2507 |
| |
| |||
2477 | 2525 |
| |
2478 | 2526 |
| |
2479 | 2527 |
| |
2480 |
| - | |
| 2528 | + | |
2481 | 2529 |
| |
2482 | 2530 |
| |
2483 | 2531 |
| |
| |||
2495 | 2543 |
| |
2496 | 2544 |
| |
2497 | 2545 |
| |
| 2546 | + | |
| 2547 | + | |
2498 | 2548 |
| |
2499 | 2549 |
| |
2500 | 2550 |
| |
| |||
2505 | 2555 |
| |
2506 | 2556 |
| |
2507 | 2557 |
| |
2508 |
| - | |
| 2558 | + | |
| 2559 | + | |
| 2560 | + | |
2509 | 2561 |
| |
2510 | 2562 |
| |
2511 | 2563 |
| |
2512 | 2564 |
| |
2513 | 2565 |
| |
2514 |
| - | |
| 2566 | + | |
| 2567 | + | |
2515 | 2568 |
| |
2516 | 2569 |
| |
2517 | 2570 |
| |
| |||
2538 | 2591 |
| |
2539 | 2592 |
| |
2540 | 2593 |
| |
| 2594 | + | |
2541 | 2595 |
| |
2542 | 2596 |
| |
| 2597 | + | |
| 2598 | + | |
| 2599 | + | |
| 2600 | + | |
2543 | 2601 |
| |
2544 | 2602 |
| |
2545 | 2603 |
| |
2546 | 2604 |
| |
2547 | 2605 |
| |
2548 | 2606 |
| |
2549 | 2607 |
| |
2550 |
| - | |
| 2608 | + | |
| 2609 | + | |
2551 | 2610 |
| |
2552 | 2611 |
| |
2553 | 2612 |
| |
|
Lines changed: 11 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
771 | 771 |
| |
772 | 772 |
| |
773 | 773 |
| |
774 |
| - | |
| 774 | + | |
| 775 | + | |
775 | 776 |
| |
776 | 777 |
| |
777 | 778 |
| |
| |||
782 | 783 |
| |
783 | 784 |
| |
784 | 785 |
| |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
785 | 795 |
| |
786 | 796 |
| |
787 | 797 |
| |
|
Lines changed: 4 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
595 | 595 |
| |
596 | 596 |
| |
597 | 597 |
| |
598 |
| - | |
| 598 | + | |
599 | 599 |
| |
600 | 600 |
| |
601 | 601 |
| |
| |||
662 | 662 |
| |
663 | 663 |
| |
664 | 664 |
| |
665 |
| - | |
| 665 | + | |
666 | 666 |
| |
667 | 667 |
| |
668 | 668 |
| |
| |||
738 | 738 |
| |
739 | 739 |
| |
740 | 740 |
| |
741 |
| - | |
| 741 | + | |
742 | 742 |
| |
743 | 743 |
| |
744 | 744 |
| |
| |||
891 | 891 |
| |
892 | 892 |
| |
893 | 893 |
| |
894 |
| - | |
| 894 | + | |
895 | 895 |
| |
896 | 896 |
| |
897 | 897 |
| |
|
Lines changed: 7 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
347 | 347 |
| |
348 | 348 |
| |
349 | 349 |
| |
350 |
| - | |
351 |
| - | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
352 | 357 |
| |
353 | 358 |
| |
354 | 359 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
233 | 233 |
| |
234 | 234 |
| |
235 | 235 |
| |
236 |
| - | |
| 236 | + | |
237 | 237 |
| |
238 | 238 |
| |
239 | 239 |
| |
|
0 commit comments
Comments
(0)