- Notifications
You must be signed in to change notification settings - Fork5
Commit94afbd5
committed
Invent a "one-shot" variant of CachedPlans for better performance.
SPI_execute() and related functions create a CachedPlan, execute it once,and immediately discard it, so that the functionality offered byplancache.c is of no value in this code path. And performance measurementsshow that the extra data copying and invalidation checking done byplancache.c slows down simple queries by 10% or more compared to 9.1.However, enough of the SPI code is shared with functions that do need plancaching that it seems impractical to bypass plancache.c altogether.Instead, let's invent a variant version of cached plans that preserves99% of the API but doesn't offer any of the actual functionality, nor theoverhead. This puts SPI_execute() performance back on par, or maybe evenslightly better, than it was before. This change should resolve recentcomplaints of performance degradation from Dong Ye, Pavel Stehule, andothers.By avoiding data copying, this change also reduces the amount of memoryneeded to execute many-statement SPI_execute() strings, as for instance ina recent complaint from Tomas Vondra.An additional benefit of this change is that multi-statement SPI_execute()query strings are now processed fully serially, that is we completeexecution of earlier statements before running parse analysis and planningon following ones. This eliminates a long-standing POLA violation, in thatDDL that affects the behavior of a later statement will now behave asexpected.Back-patch to 9.2, since this was a performance regression compared to 9.1.(In 9.2, place the added struct fields so as to avoid changing the offsetsof existing fields.)Heikki Linnakangas and Tom Lane1 parent78a5e73 commit94afbd5
File tree
5 files changed
+329
-57
lines changed- doc/src/sgml
- src
- backend
- executor
- utils/cache
- include
- executor
- utils
5 files changed
+329
-57
lines changedLines changed: 15 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
326 | 326 |
| |
327 | 327 |
| |
328 | 328 |
| |
329 |
| - | |
330 |
| - | |
331 |
| - | |
| 329 | + | |
332 | 330 |
| |
333 | 331 |
| |
334 | 332 |
| |
| |||
395 | 393 |
| |
396 | 394 |
| |
397 | 395 |
| |
398 |
| - | |
| 396 | + | |
| 397 | + | |
399 | 398 |
| |
400 | 399 |
| |
401 | 400 |
| |
| |||
435 | 434 |
| |
436 | 435 |
| |
437 | 436 |
| |
438 |
| - | |
| 437 | + | |
| 438 | + | |
439 | 439 |
| |
440 | 440 |
| |
441 | 441 |
| |
| |||
674 | 674 |
| |
675 | 675 |
| |
676 | 676 |
| |
677 |
| - | |
| 677 | + | |
| 678 | + | |
678 | 679 |
| |
679 | 680 |
| |
680 | 681 |
| |
| |||
812 | 813 |
| |
813 | 814 |
| |
814 | 815 |
| |
815 |
| - | |
| 816 | + | |
| 817 | + | |
816 | 818 |
| |
817 | 819 |
| |
818 | 820 |
| |
| |||
1455 | 1457 |
| |
1456 | 1458 |
| |
1457 | 1459 |
| |
1458 |
| - | |
| 1460 | + | |
| 1461 | + | |
1459 | 1462 |
| |
1460 | 1463 |
| |
1461 | 1464 |
| |
| |||
1572 | 1575 |
| |
1573 | 1576 |
| |
1574 | 1577 |
| |
1575 |
| - | |
| 1578 | + | |
| 1579 | + | |
1576 | 1580 |
| |
1577 | 1581 |
| |
1578 | 1582 |
| |
| |||
1672 | 1676 |
| |
1673 | 1677 |
| |
1674 | 1678 |
| |
1675 |
| - | |
| 1679 | + | |
| 1680 | + | |
1676 | 1681 |
| |
1677 | 1682 |
| |
1678 | 1683 |
| |
|
Lines changed: 128 additions & 16 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
49 | 49 |
| |
50 | 50 |
| |
51 | 51 |
| |
52 |
| - | |
53 |
| - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
54 | 55 |
| |
55 | 56 |
| |
56 | 57 |
| |
| |||
355 | 356 |
| |
356 | 357 |
| |
357 | 358 |
| |
358 |
| - | |
| 359 | + | |
359 | 360 |
| |
360 | 361 |
| |
361 | 362 |
| |
| |||
506 | 507 |
| |
507 | 508 |
| |
508 | 509 |
| |
509 |
| - | |
| 510 | + | |
510 | 511 |
| |
511 | 512 |
| |
512 | 513 |
| |
| |||
547 | 548 |
| |
548 | 549 |
| |
549 | 550 |
| |
550 |
| - | |
| 551 | + | |
551 | 552 |
| |
552 | 553 |
| |
553 | 554 |
| |
| |||
584 | 585 |
| |
585 | 586 |
| |
586 | 587 |
| |
587 |
| - | |
| 588 | + | |
588 | 589 |
| |
589 | 590 |
| |
590 | 591 |
| |
| |||
599 | 600 |
| |
600 | 601 |
| |
601 | 602 |
| |
602 |
| - | |
| 603 | + | |
| 604 | + | |
603 | 605 |
| |
604 | 606 |
| |
605 | 607 |
| |
| |||
1083 | 1085 |
| |
1084 | 1086 |
| |
1085 | 1087 |
| |
1086 |
| - | |
| 1088 | + | |
1087 | 1089 |
| |
1088 | 1090 |
| |
1089 | 1091 |
| |
| |||
1645 | 1647 |
| |
1646 | 1648 |
| |
1647 | 1649 |
| |
1648 |
| - | |
1649 |
| - | |
1650 |
| - | |
1651 |
| - | |
1652 | 1650 |
| |
1653 | 1651 |
| |
1654 | 1652 |
| |
| |||
1657 | 1655 |
| |
1658 | 1656 |
| |
1659 | 1657 |
| |
1660 |
| - | |
| 1658 | + | |
1661 | 1659 |
| |
1662 | 1660 |
| |
1663 | 1661 |
| |
1664 | 1662 |
| |
1665 | 1663 |
| |
1666 |
| - | |
1667 | 1664 |
| |
1668 | 1665 |
| |
1669 | 1666 |
| |
| |||
1726 | 1723 |
| |
1727 | 1724 |
| |
1728 | 1725 |
| |
1729 |
| - | |
| 1726 | + | |
1730 | 1727 |
| |
1731 | 1728 |
| |
1732 | 1729 |
| |
1733 | 1730 |
| |
1734 | 1731 |
| |
1735 | 1732 |
| |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
1736 | 1800 |
| |
1737 | 1801 |
| |
1738 | 1802 |
| |
| |||
1770 | 1834 |
| |
1771 | 1835 |
| |
1772 | 1836 |
| |
1773 |
| - | |
| 1837 | + | |
1774 | 1838 |
| |
1775 | 1839 |
| |
1776 | 1840 |
| |
| |||
1816 | 1880 |
| |
1817 | 1881 |
| |
1818 | 1882 |
| |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
| 1900 | + | |
| 1901 | + | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
| 1905 | + | |
| 1906 | + | |
| 1907 | + | |
| 1908 | + | |
| 1909 | + | |
| 1910 | + | |
| 1911 | + | |
| 1912 | + | |
| 1913 | + | |
| 1914 | + | |
| 1915 | + | |
| 1916 | + | |
| 1917 | + | |
| 1918 | + | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
| 1922 | + | |
| 1923 | + | |
1819 | 1924 |
| |
1820 | 1925 |
| |
1821 | 1926 |
| |
| |||
2313 | 2418 |
| |
2314 | 2419 |
| |
2315 | 2420 |
| |
| 2421 | + | |
| 2422 | + | |
2316 | 2423 |
| |
2317 | 2424 |
| |
2318 | 2425 |
| |
| |||
2330 | 2437 |
| |
2331 | 2438 |
| |
2332 | 2439 |
| |
| 2440 | + | |
2333 | 2441 |
| |
2334 | 2442 |
| |
2335 | 2443 |
| |
| |||
2379 | 2487 |
| |
2380 | 2488 |
| |
2381 | 2489 |
| |
| 2490 | + | |
| 2491 | + | |
| 2492 | + | |
2382 | 2493 |
| |
2383 | 2494 |
| |
2384 | 2495 |
| |
| |||
2395 | 2506 |
| |
2396 | 2507 |
| |
2397 | 2508 |
| |
| 2509 | + | |
2398 | 2510 |
| |
2399 | 2511 |
| |
2400 | 2512 |
| |
|
0 commit comments
Comments
(0)