forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitd8b2fcc
committed
Avoid unnecessary plancache revalidation of utility statements.
Revalidation of a plancache entry (after a cache invalidation event)requires acquiring a snapshot. Normally that is harmless, but notif the cached statement is one that needs to run without acquiring asnapshot. We were already aware of that for TransactionStmts,but for some reason hadn't extrapolated to the other statements thatPlannedStmtRequiresSnapshot() knows mustn't set a snapshot. This canlead to unexpected failures of commands such as SET TRANSACTIONISOLATION LEVEL. We can fix it in the same way, by excluding thosecommand types from revalidation.However, we can do even better than that: there is no need torevalidate for any statement type for which parse analysis, rewrite,and plan steps do nothing interesting, which is nearly all utilitycommands. To mechanize this, invent a parser functionstmt_requires_parse_analysis() that tells whether parse analysis doesanything beyond wrapping a CMD_UTILITY Query around the raw parsetree. If that's what it does, then rewrite and plan will justskip the Query, so that it is not possible for the same raw parsetree to produce a different plan tree after cache invalidation.stmt_requires_parse_analysis() is basically equivalent to theexisting function analyze_requires_snapshot(), except that forobscure reasons that function omits ReturnStmt and CallStmt.It is unclear whether those were oversights or intentional.I have not been able to demonstrate a bug from not acquiring asnapshot while analyzing these commands, but at best it seems mightyfragile. It seems safer to acquire a snapshot for parse analysis ofthese commands too, which allows making stmt_requires_parse_analysisand analyze_requires_snapshot equivalent.In passing this fixes a second bug, which is that ResetPlanCachewould exclude ReturnStmts and CallStmts from revalidation.That's surely *not* safe, since they contain parsable expressions.Per bug #18059 from Pavel Kulakov. Back-patch to all supportedbranches.Discussion:https://postgr.es/m/18059-79c692f036b25346@postgresql.org1 parent3da13a6 commitd8b2fcc
File tree
5 files changed
+108
-49
lines changed- src
- backend
- parser
- utils/cache
- include/parser
- pl/plpgsql/src
- expected
- sql
5 files changed
+108
-49
lines changedLines changed: 45 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
335 | 335 |
| |
336 | 336 |
| |
337 | 337 |
| |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
338 | 343 |
| |
339 | 344 |
| |
340 | 345 |
| |
| |||
421 | 426 |
| |
422 | 427 |
| |
423 | 428 |
| |
424 |
| - | |
425 |
| - | |
426 |
| - | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
427 | 437 |
| |
428 |
| - | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
429 | 442 |
| |
430 | 443 |
| |
431 |
| - | |
| 444 | + | |
432 | 445 |
| |
433 | 446 |
| |
434 | 447 |
| |
| |||
442 | 455 |
| |
443 | 456 |
| |
444 | 457 |
| |
| 458 | + | |
445 | 459 |
| |
446 | 460 |
| |
447 | 461 |
| |
| |||
452 | 466 |
| |
453 | 467 |
| |
454 | 468 |
| |
455 |
| - | |
| 469 | + | |
456 | 470 |
| |
457 | 471 |
| |
458 | 472 |
| |
459 | 473 |
| |
460 |
| - | |
| 474 | + | |
461 | 475 |
| |
462 | 476 |
| |
463 | 477 |
| |
464 | 478 |
| |
465 | 479 |
| |
466 | 480 |
| |
467 | 481 |
| |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
468 | 506 |
| |
469 | 507 |
| |
470 | 508 |
| |
|
Lines changed: 27 additions & 42 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
77 | 77 |
| |
78 | 78 |
| |
79 | 79 |
| |
80 |
| - | |
81 |
| - | |
82 |
| - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
83 | 85 |
| |
84 |
| - | |
85 |
| - | |
86 |
| - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
87 | 89 |
| |
88 | 90 |
| |
89 | 91 |
| |
| |||
383 | 385 |
| |
384 | 386 |
| |
385 | 387 |
| |
386 |
| - | |
| 388 | + | |
387 | 389 |
| |
388 | 390 |
| |
389 | 391 |
| |
390 | 392 |
| |
391 | 393 |
| |
392 |
| - | |
| 394 | + | |
393 | 395 |
| |
394 | 396 |
| |
395 | 397 |
| |
| |||
568 | 570 |
| |
569 | 571 |
| |
570 | 572 |
| |
571 |
| - | |
572 |
| - | |
573 |
| - | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
574 | 576 |
| |
575 |
| - | |
| 577 | + | |
576 | 578 |
| |
577 | 579 |
| |
578 | 580 |
| |
| |||
1029 | 1031 |
| |
1030 | 1032 |
| |
1031 | 1033 |
| |
1032 |
| - | |
1033 |
| - | |
| 1034 | + | |
| 1035 | + | |
1034 | 1036 |
| |
1035 | 1037 |
| |
1036 | 1038 |
| |
| |||
1972 | 1974 |
| |
1973 | 1975 |
| |
1974 | 1976 |
| |
1975 |
| - | |
1976 |
| - | |
| 1977 | + | |
| 1978 | + | |
1977 | 1979 |
| |
1978 | 1980 |
| |
1979 | 1981 |
| |
| |||
2057 | 2059 |
| |
2058 | 2060 |
| |
2059 | 2061 |
| |
2060 |
| - | |
2061 |
| - | |
| 2062 | + | |
| 2063 | + | |
2062 | 2064 |
| |
2063 | 2065 |
| |
2064 | 2066 |
| |
| |||
2167 | 2169 |
| |
2168 | 2170 |
| |
2169 | 2171 |
| |
2170 |
| - | |
2171 | 2172 |
| |
2172 | 2173 |
| |
2173 | 2174 |
| |
| |||
2179 | 2180 |
| |
2180 | 2181 |
| |
2181 | 2182 |
| |
| 2183 | + | |
| 2184 | + | |
| 2185 | + | |
2182 | 2186 |
| |
2183 |
| - | |
| 2187 | + | |
2184 | 2188 |
| |
2185 | 2189 |
| |
2186 |
| - | |
2187 |
| - | |
2188 |
| - | |
2189 |
| - | |
2190 |
| - | |
2191 |
| - | |
2192 |
| - | |
2193 |
| - | |
2194 |
| - | |
2195 |
| - | |
2196 |
| - | |
2197 |
| - | |
2198 |
| - | |
2199 |
| - | |
2200 |
| - | |
2201 |
| - | |
2202 |
| - | |
2203 |
| - | |
2204 |
| - | |
2205 |
| - | |
2206 |
| - | |
2207 |
| - | |
| 2190 | + | |
| 2191 | + | |
| 2192 | + | |
2208 | 2193 |
| |
2209 | 2194 |
| |
2210 | 2195 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
47 | 47 |
| |
48 | 48 |
| |
49 | 49 |
| |
| 50 | + | |
50 | 51 |
| |
51 | 52 |
| |
52 | 53 |
| |
|
Lines changed: 17 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
35 | 35 |
| |
36 | 36 |
| |
37 | 37 |
| |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
38 | 55 |
| |
39 | 56 |
| |
40 | 57 |
| |
|
Lines changed: 18 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
38 | 38 |
| |
39 | 39 |
| |
40 | 40 |
| |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
41 | 59 |
| |
42 | 60 |
| |
43 | 61 |
| |
|
0 commit comments
Comments
(0)