forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit86dc900
committed
Rework planning and execution of UPDATE and DELETE.
This patch makes two closely related sets of changes:1. For UPDATE, the subplan of the ModifyTable node now only deliversthe new values of the changed columns (i.e., the expressions computedin the query's SET clause) plus row identity information such as CTID.ModifyTable must re-fetch the original tuple to merge in the oldvalues of any unchanged columns. The core advantage of this is thatthe changed columns are uniform across all tables of an inherited orpartitioned target relation, whereas the other columns might not be.A secondary advantage, when the UPDATE involves joins, is that lessdata needs to pass through the plan tree. The disadvantage of courseis an extra fetch of each tuple to be updated. However, that seems tobe very nearly free in context; even worst-case tests don't show it toadd more than a couple percent to the total query cost. At some pointit might be interesting to combine the re-fetch with the tuple accessthat ModifyTable must do anyway to mark the old tuple dead; but thatwould require a good deal of refactoring and it seems it wouldn't buyall that much, so this patch doesn't attempt it.2. For inherited UPDATE/DELETE, instead of generating a separatesubplan for each target relation, we now generate a single subplanthat is just exactly like a SELECT's plan, then stick ModifyTableon top of that. To let ModifyTable know which target relation agiven incoming row refers to, a tableoid junk column is added tothe row identity information. This gets rid of the horrid hackthat was inheritance_planner(), eliminating O(N^2) planning costand memory consumption in cases where there were many unprunabletarget relations.Point 2 of course requires point 1, so that there is a uniformdefinition of the non-junk columns to be returned by the subplan.We can't insist on uniform definition of the row identity junkcolumns however, if we want to keep the ability to have bothplain and foreign tables in a partitioning hierarchy. Sinceit wouldn't scale very far to have every child table have itsown row identity column, this patch includes provisions to mergesimilar row identity columns into one column of the subplan result.In particular, we can merge the whole-row Vars typically used asrow identity by FDWs into one column by pretending they are typeRECORD. (It's still okay for the actual composite Datums to belabeled with the table's rowtype OID, though.)There is more that can be done to file down residual inefficienciesin this patch, but it seems to be committable now.FDW authors should note several API changes:* The argument list for AddForeignUpdateTargets() has changed, and sohas the method it must use for adding junk columns to the query. Calladd_row_identity_var() instead of manipulating the parse tree directly.You might want to reconsider exactly what you're adding, too.* PlanDirectModify() must now work a little harder to find theForeignScan plan node; if the foreign table is part of a partitioninghierarchy then the ForeignScan might not be the direct child ofModifyTable. See postgres_fdw for sample code.* To check whether a relation is a target relation, it's nolonger sufficient to compare its relid to root->parse->resultRelation.Instead, check it against all_result_relids or leaf_result_relids,as appropriate.Amit Langote and Tom LaneDiscussion:https://postgr.es/m/CA+HiwqHpHdqdDn48yCEhynnniahH78rwcrv1rEX65-fsZGBOLQ@mail.gmail.com1 parent055fee7 commit86dc900
File tree
55 files changed
+2352
-2198
lines changed- contrib/postgres_fdw
- expected
- doc/src/sgml
- src
- backend
- commands
- executor
- nodes
- optimizer
- path
- plan
- prep
- util
- rewrite
- utils/adt
- include
- executor
- foreign
- nodes
- optimizer
- rewrite
- test/regress/expected
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
55 files changed
+2352
-2198
lines changedLines changed: 9 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1275 | 1275 |
| |
1276 | 1276 |
| |
1277 | 1277 |
| |
1278 |
| - | |
| 1278 | + | |
1279 | 1279 |
| |
1280 | 1280 |
| |
1281 | 1281 |
| |
| |||
1867 | 1867 |
| |
1868 | 1868 |
| |
1869 | 1869 |
| |
| 1870 | + | |
1870 | 1871 |
| |
1871 | 1872 |
| |
1872 | 1873 |
| |
| |||
1888 | 1889 |
| |
1889 | 1890 |
| |
1890 | 1891 |
| |
1891 |
| - | |
1892 | 1892 |
| |
| 1893 | + | |
| 1894 | + | |
1893 | 1895 |
| |
1894 | 1896 |
| |
1895 | 1897 |
| |
| |||
1908 | 1910 |
| |
1909 | 1911 |
| |
1910 | 1912 |
| |
1911 |
| - | |
| 1913 | + | |
1912 | 1914 |
| |
1913 |
| - | |
1914 |
| - | |
| 1915 | + | |
| 1916 | + | |
1915 | 1917 |
| |
1916 |
| - | |
1917 |
| - | |
1918 |
| - | |
| 1918 | + | |
| 1919 | + | |
1919 | 1920 |
| |
1920 | 1921 |
| |
1921 | 1922 |
| |
|
Lines changed: 193 additions & 230 deletions
Large diffs are not rendered by default.
Lines changed: 87 additions & 42 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
27 | 27 |
| |
28 | 28 |
| |
29 | 29 |
| |
| 30 | + | |
30 | 31 |
| |
31 | 32 |
| |
32 | 33 |
| |
| |||
345 | 346 |
| |
346 | 347 |
| |
347 | 348 |
| |
348 |
| - | |
| 349 | + | |
| 350 | + | |
349 | 351 |
| |
350 | 352 |
| |
351 | 353 |
| |
| |||
1669 | 1671 |
| |
1670 | 1672 |
| |
1671 | 1673 |
| |
1672 |
| - | |
| 1674 | + | |
| 1675 | + | |
1673 | 1676 |
| |
1674 | 1677 |
| |
1675 | 1678 |
| |
1676 | 1679 |
| |
1677 |
| - | |
1678 |
| - | |
1679 | 1680 |
| |
1680 | 1681 |
| |
1681 | 1682 |
| |
1682 | 1683 |
| |
1683 | 1684 |
| |
1684 | 1685 |
| |
1685 |
| - | |
| 1686 | + | |
1686 | 1687 |
| |
1687 | 1688 |
| |
1688 | 1689 |
| |
1689 | 1690 |
| |
1690 | 1691 |
| |
1691 | 1692 |
| |
1692 |
| - | |
1693 |
| - | |
1694 |
| - | |
1695 |
| - | |
1696 |
| - | |
1697 |
| - | |
1698 |
| - | |
1699 |
| - | |
1700 |
| - | |
1701 |
| - | |
| 1693 | + | |
| 1694 | + | |
1702 | 1695 |
| |
1703 | 1696 |
| |
1704 | 1697 |
| |
| |||
1886 | 1879 |
| |
1887 | 1880 |
| |
1888 | 1881 |
| |
1889 |
| - | |
| 1882 | + | |
1890 | 1883 |
| |
1891 | 1884 |
| |
1892 | 1885 |
| |
| |||
2086 | 2079 |
| |
2087 | 2080 |
| |
2088 | 2081 |
| |
2089 |
| - | |
2090 |
| - | |
| 2082 | + | |
2091 | 2083 |
| |
2092 | 2084 |
| |
2093 | 2085 |
| |
| |||
2283 | 2275 |
| |
2284 | 2276 |
| |
2285 | 2277 |
| |
| 2278 | + | |
| 2279 | + | |
| 2280 | + | |
| 2281 | + | |
| 2282 | + | |
| 2283 | + | |
| 2284 | + | |
| 2285 | + | |
| 2286 | + | |
| 2287 | + | |
| 2288 | + | |
| 2289 | + | |
| 2290 | + | |
| 2291 | + | |
| 2292 | + | |
| 2293 | + | |
| 2294 | + | |
| 2295 | + | |
| 2296 | + | |
| 2297 | + | |
| 2298 | + | |
| 2299 | + | |
| 2300 | + | |
| 2301 | + | |
| 2302 | + | |
| 2303 | + | |
| 2304 | + | |
| 2305 | + | |
| 2306 | + | |
| 2307 | + | |
| 2308 | + | |
| 2309 | + | |
| 2310 | + | |
| 2311 | + | |
| 2312 | + | |
| 2313 | + | |
| 2314 | + | |
| 2315 | + | |
| 2316 | + | |
| 2317 | + | |
| 2318 | + | |
| 2319 | + | |
| 2320 | + | |
| 2321 | + | |
| 2322 | + | |
| 2323 | + | |
| 2324 | + | |
| 2325 | + | |
| 2326 | + | |
| 2327 | + | |
| 2328 | + | |
| 2329 | + | |
| 2330 | + | |
| 2331 | + | |
| 2332 | + | |
| 2333 | + | |
| 2334 | + | |
| 2335 | + | |
| 2336 | + | |
2286 | 2337 |
| |
2287 | 2338 |
| |
2288 | 2339 |
| |
| |||
2297 | 2348 |
| |
2298 | 2349 |
| |
2299 | 2350 |
| |
2300 |
| - | |
2301 | 2351 |
| |
2302 | 2352 |
| |
2303 | 2353 |
| |
2304 | 2354 |
| |
2305 | 2355 |
| |
2306 | 2356 |
| |
| 2357 | + | |
2307 | 2358 |
| |
2308 | 2359 |
| |
2309 | 2360 |
| |
| |||
2321 | 2372 |
| |
2322 | 2373 |
| |
2323 | 2374 |
| |
2324 |
| - | |
2325 |
| - | |
| 2375 | + | |
2326 | 2376 |
| |
2327 |
| - | |
2328 |
| - | |
| 2377 | + | |
| 2378 | + | |
2329 | 2379 |
| |
2330 |
| - | |
2331 | 2380 |
| |
2332 | 2381 |
| |
2333 | 2382 |
| |
2334 | 2383 |
| |
2335 | 2384 |
| |
2336 |
| - | |
| 2385 | + | |
2337 | 2386 |
| |
2338 | 2387 |
| |
2339 | 2388 |
| |
| |||
2354 | 2403 |
| |
2355 | 2404 |
| |
2356 | 2405 |
| |
2357 |
| - | |
| 2406 | + | |
| 2407 | + | |
2358 | 2408 |
| |
2359 | 2409 |
| |
2360 |
| - | |
2361 |
| - | |
| 2410 | + | |
| 2411 | + | |
2362 | 2412 |
| |
2363 |
| - | |
2364 |
| - | |
| 2413 | + | |
| 2414 | + | |
| 2415 | + | |
2365 | 2416 |
| |
2366 |
| - | |
2367 |
| - | |
2368 |
| - | |
| 2417 | + | |
| 2418 | + | |
| 2419 | + | |
| 2420 | + | |
| 2421 | + | |
2369 | 2422 |
| |
2370 | 2423 |
| |
2371 | 2424 |
| |
2372 | 2425 |
| |
2373 |
| - | |
2374 |
| - | |
2375 |
| - | |
2376 |
| - | |
2377 |
| - | |
2378 |
| - | |
2379 | 2426 |
| |
2380 | 2427 |
| |
2381 |
| - | |
2382 |
| - | |
2383 | 2428 |
| |
2384 | 2429 |
| |
2385 | 2430 |
| |
| |||
2430 | 2475 |
| |
2431 | 2476 |
| |
2432 | 2477 |
| |
2433 |
| - | |
| 2478 | + | |
2434 | 2479 |
| |
2435 | 2480 |
| |
2436 | 2481 |
| |
|
Lines changed: 1 addition & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4823 | 4823 |
| |
4824 | 4824 |
| |
4825 | 4825 |
| |
4826 |
| - | |
4827 |
| - | |
| 4826 | + | |
4828 | 4827 |
| |
4829 | 4828 |
| |
4830 | 4829 |
| |
|
Lines changed: 37 additions & 28 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
424 | 424 |
| |
425 | 425 |
| |
426 | 426 |
| |
427 |
| - | |
| 427 | + | |
| 428 | + | |
428 | 429 |
| |
429 | 430 |
| |
430 | 431 |
| |
| |||
440 | 441 |
| |
441 | 442 |
| |
442 | 443 |
| |
443 |
| - | |
444 |
| - | |
445 |
| - | |
446 |
| - | |
447 |
| - | |
448 |
| - | |
449 |
| - | |
450 |
| - | |
451 |
| - | |
452 |
| - | |
453 |
| - | |
454 |
| - | |
455 |
| - | |
456 |
| - | |
457 |
| - | |
458 |
| - | |
459 |
| - | |
460 |
| - | |
461 |
| - | |
462 |
| - | |
463 |
| - | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
464 | 469 |
| |
465 | 470 |
| |
466 | 471 |
| |
| |||
495 | 500 |
| |
496 | 501 |
| |
497 | 502 |
| |
498 |
| - | |
499 |
| - | |
| 503 | + | |
| 504 | + | |
500 | 505 |
| |
501 | 506 |
| |
502 | 507 |
| |
| |||
703 | 708 |
| |
704 | 709 |
| |
705 | 710 |
| |
706 |
| - | |
707 |
| - | |
708 |
| - | |
709 |
| - | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
710 | 719 |
| |
711 | 720 |
| |
712 | 721 |
| |
|
0 commit comments
Comments
(0)