- Notifications
You must be signed in to change notification settings - Fork28
Commit8f59f6b
committed
Improve performance of "simple expressions" in PL/pgSQL.
For relatively simple expressions (say, "x + 1" or "x > 0"), plpgsql'smanagement overhead exceeds the cost of evaluating the expression.This patch substantially improves that situation, providing roughly2X speedup for such trivial expressions.First, add infrastructure in the plancache to allow fast re-validationof cached plans that contain no table access, and hence need no locks.Teach plpgsql to use this infrastructure for expressions that it'salready deemed "simple" (which in particular will never contain tablereferences).The fast path still requires checking that search_path hasn't changed,so provide a fast path for OverrideSearchPathMatchesCurrent bycounting changes that have occurred to the active search path in thecurrent session. This is simplistic but seems enough for now, seeingthat PushOverrideSearchPath is not used in any performance-criticalcases.Second, manage the refcounts on simple expressions' cached plans usinga transaction-lifespan resource owner, so that we only need to takeand release an expression's refcount once per transaction not once perexpression evaluation. The management of this resource owner exactlyparallels the existing management of plpgsql's simple-expression EState.Add some regression tests covering this area, in particular verifyingthat expression caching doesn't break semantics for search_path changes.Patch by me, but it owes something to previous work by Amit Langote,who recognized that getting rid of plancache-related overhead wouldbe a useful thing to do here. Also thanks to Andres Freund for review.Discussion:https://postgr.es/m/CAFj8pRDRVfLdAxsWeVLzCAbkLFZhW549K+67tpOc-faC8uH8zw@mail.gmail.com1 parent86e5bad commit8f59f6b
File tree
12 files changed
+627
-74
lines changed- src
- backend
- catalog
- utils
- cache
- resowner
- include
- catalog
- utils
- pl/plpgsql/src
- expected
- sql
12 files changed
+627
-74
lines changedLines changed: 88 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
126 | 126 |
| |
127 | 127 |
| |
128 | 128 |
| |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
129 | 134 |
| |
130 | 135 |
| |
131 | 136 |
| |
| |||
138 | 143 |
| |
139 | 144 |
| |
140 | 145 |
| |
| 146 | + | |
| 147 | + | |
| 148 | + | |
141 | 149 |
| |
142 | 150 |
| |
143 | 151 |
| |
| |||
3373 | 3381 |
| |
3374 | 3382 |
| |
3375 | 3383 |
| |
| 3384 | + | |
3376 | 3385 |
| |
3377 | 3386 |
| |
3378 | 3387 |
| |
| |||
3393 | 3402 |
| |
3394 | 3403 |
| |
3395 | 3404 |
| |
| 3405 | + | |
3396 | 3406 |
| |
3397 | 3407 |
| |
3398 | 3408 |
| |
3399 | 3409 |
| |
3400 | 3410 |
| |
3401 | 3411 |
| |
| 3412 | + | |
| 3413 | + | |
| 3414 | + | |
| 3415 | + | |
| 3416 | + | |
3402 | 3417 |
| |
3403 | 3418 |
| |
3404 | 3419 |
| |
| |||
3408 | 3423 |
| |
3409 | 3424 |
| |
3410 | 3425 |
| |
| 3426 | + | |
| 3427 | + | |
| 3428 | + | |
| 3429 | + | |
3411 | 3430 |
| |
3412 | 3431 |
| |
3413 | 3432 |
| |
| |||
3440 | 3459 |
| |
3441 | 3460 |
| |
3442 | 3461 |
| |
| 3462 | + | |
| 3463 | + | |
| 3464 | + | |
| 3465 | + | |
| 3466 | + | |
| 3467 | + | |
| 3468 | + | |
3443 | 3469 |
| |
3444 | 3470 |
| |
3445 | 3471 |
| |
| |||
3510 | 3536 |
| |
3511 | 3537 |
| |
3512 | 3538 |
| |
| 3539 | + | |
| 3540 | + | |
| 3541 | + | |
| 3542 | + | |
| 3543 | + | |
| 3544 | + | |
| 3545 | + | |
| 3546 | + | |
3513 | 3547 |
| |
3514 | 3548 |
| |
3515 | 3549 |
| |
| |||
3551 | 3585 |
| |
3552 | 3586 |
| |
3553 | 3587 |
| |
| 3588 | + | |
| 3589 | + | |
| 3590 | + | |
3554 | 3591 |
| |
3555 | 3592 |
| |
3556 | 3593 |
| |
| |||
3707 | 3744 |
| |
3708 | 3745 |
| |
3709 | 3746 |
| |
| 3747 | + | |
3710 | 3748 |
| |
3711 | 3749 |
| |
3712 | 3750 |
| |
| |||
3814 | 3852 |
| |
3815 | 3853 |
| |
3816 | 3854 |
| |
3817 |
| - | |
3818 |
| - | |
| 3855 | + | |
| 3856 | + | |
| 3857 | + | |
3819 | 3858 |
| |
3820 |
| - | |
3821 |
| - | |
3822 |
| - | |
| 3859 | + | |
| 3860 | + | |
| 3861 | + | |
| 3862 | + | |
| 3863 | + | |
| 3864 | + | |
| 3865 | + | |
| 3866 | + | |
| 3867 | + | |
| 3868 | + | |
| 3869 | + | |
| 3870 | + | |
| 3871 | + | |
| 3872 | + | |
3823 | 3873 |
| |
3824 |
| - | |
3825 |
| - | |
3826 |
| - | |
3827 |
| - | |
3828 |
| - | |
| 3874 | + | |
| 3875 | + | |
| 3876 | + | |
| 3877 | + | |
| 3878 | + | |
| 3879 | + | |
3829 | 3880 |
| |
3830 | 3881 |
| |
3831 | 3882 |
| |
| |||
3836 | 3887 |
| |
3837 | 3888 |
| |
3838 | 3889 |
| |
| 3890 | + | |
| 3891 | + | |
| 3892 | + | |
| 3893 | + | |
| 3894 | + | |
| 3895 | + | |
| 3896 | + | |
| 3897 | + | |
| 3898 | + | |
| 3899 | + | |
3839 | 3900 |
| |
3840 | 3901 |
| |
3841 | 3902 |
| |
| |||
4054 | 4115 |
| |
4055 | 4116 |
| |
4056 | 4117 |
| |
| 4118 | + | |
| 4119 | + | |
4057 | 4120 |
| |
4058 | 4121 |
| |
4059 | 4122 |
| |
| |||
4109 | 4172 |
| |
4110 | 4173 |
| |
4111 | 4174 |
| |
| 4175 | + | |
| 4176 | + | |
4112 | 4177 |
| |
4113 | 4178 |
| |
4114 | 4179 |
| |
| |||
4118 | 4183 |
| |
4119 | 4184 |
| |
4120 | 4185 |
| |
| 4186 | + | |
| 4187 | + | |
| 4188 | + | |
| 4189 | + | |
| 4190 | + | |
| 4191 | + | |
4121 | 4192 |
| |
4122 | 4193 |
| |
4123 | 4194 |
| |
4124 | 4195 |
| |
4125 | 4196 |
| |
4126 | 4197 |
| |
4127 | 4198 |
| |
| 4199 | + | |
| 4200 | + | |
| 4201 | + | |
| 4202 | + | |
| 4203 | + | |
| 4204 | + | |
4128 | 4205 |
| |
4129 | 4206 |
| |
4130 | 4207 |
| |
| |||
4264 | 4341 |
| |
4265 | 4342 |
| |
4266 | 4343 |
| |
| 4344 | + | |
4267 | 4345 |
| |
4268 | 4346 |
| |
4269 | 4347 |
| |
|
Lines changed: 154 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1277 | 1277 |
| |
1278 | 1278 |
| |
1279 | 1279 |
| |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
1280 | 1434 |
| |
1281 | 1435 |
| |
1282 | 1436 |
| |
|
0 commit comments
Comments
(0)