forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit45639a0
committed
Avoid invalidating all foreign-join cached plans when user mappings change.
We must not push down a foreign join when the foreign tables involvedshould be accessed under different user mappings. Previously we triedto enforce that rule literally during planning, but that meant that theresulting plans were dependent on the current contents of thepg_user_mapping catalog, and we had to blow away all cached planscontaining any remote join when anything at all changed in pg_user_mapping.This could have been improved somewhat, but the fact that a syscache invalcallback has very limited info about what changed made it hard to do betterwithin that design. Instead, let's change the planner to not consider usermappings per se, but to allow a foreign join if both RTEs have the samecheckAsUser value. If they do, then they necessarily will use the sameuser mapping at runtime, and we don't need to know specifically which onethat is. Post-plan-time changes in pg_user_mapping no longer require anyplan invalidation.This rule does give up some optimization ability, to wit where two foreigntable references come from views with different owners or one's from a viewand one's directly in the query, but nonetheless the same user mappingwould have applied. We'll sacrifice the first case, but to not regressmore than we have to in the second case, allow a foreign join involvingboth zero and nonzero checkAsUser values if the nonzero one is the same asthe prevailing effective userID. In that case, mark the plan as onlyrunnable by that userID.The plancache code already had a notion of plans being userID-specific,in order to support RLS. It was a little confused though, in particularlacking clarity of thought as to whether it was the rewritten query or justthe finished plan that's dependent on the userID. Rearrange that code sothat it's clearer what depends on which, and so that the same logic appliesto both RLS-injected role dependency and foreign-join-injected roledependency.Note that this patch doesn't remove the other issue mentioned in theoriginal complaint, which is that while we'll reliably stop using a foreignjoin if it's disallowed in a new context, we might fail to start using aforeign join if it's now allowed, but we previously created a genericcached plan that didn't use one. It was agreed that the chance of winningthat way was not high enough to justify the much larger number of planinvalidations that would have to occur if we tried to cause it to happen.In passing, clean up randomly-varying spelling of EXPLAIN commands inpostgres_fdw.sql, and fix a COSTS ON example that had been allowed toleak into the committed tests.This reverts most of commitsfbe5a3f and5d4171d, which were theprevious attempt at ensuring we wouldn't push down foreign joins thatspan permissions contexts.Etsuro Fujita and Tom LaneDiscussion: <d49c1e5b-f059-20f4-c132-e9752ee0113e@lab.ntt.co.jp>1 parent533e9c6 commit45639a0
File tree
19 files changed
+579
-716
lines changed- contrib/postgres_fdw
- expected
- sql
- src
- backend
- executor
- foreign
- nodes
- optimizer
- path
- plan
- util
- utils/cache
- include
- foreign
- nodes
- utils
19 files changed
+579
-716
lines changedLines changed: 240 additions & 252 deletions
Large diffs are not rendered by default.
Lines changed: 39 additions & 56 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
67 | 67 |
| |
68 | 68 |
| |
69 | 69 |
| |
70 |
| - | |
71 |
| - | |
72 | 70 |
| |
73 | 71 |
| |
74 | 72 |
| |
| |||
1226 | 1224 |
| |
1227 | 1225 |
| |
1228 | 1226 |
| |
1229 |
| - | |
| 1227 | + | |
1230 | 1228 |
| |
1231 | 1229 |
| |
1232 |
| - | |
1233 |
| - | |
| 1230 | + | |
1234 | 1231 |
| |
1235 | 1232 |
| |
1236 | 1233 |
| |
| |||
1262 | 1259 |
| |
1263 | 1260 |
| |
1264 | 1261 |
| |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
1265 | 1265 |
| |
| 1266 | + | |
1266 | 1267 |
| |
1267 | 1268 |
| |
1268 | 1269 |
| |
| |||
1278 | 1279 |
| |
1279 | 1280 |
| |
1280 | 1281 |
| |
1281 |
| - | |
1282 |
| - | |
1283 |
| - | |
1284 |
| - | |
1285 |
| - | |
1286 |
| - | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
1287 | 1285 |
| |
1288 | 1286 |
| |
1289 |
| - | |
1290 |
| - | |
1291 |
| - | |
1292 |
| - | |
1293 |
| - | |
1294 |
| - | |
1295 |
| - | |
1296 |
| - | |
1297 |
| - | |
1298 |
| - | |
1299 |
| - | |
1300 |
| - | |
1301 |
| - | |
1302 |
| - | |
1303 |
| - | |
| 1287 | + | |
1304 | 1288 |
| |
1305 |
| - | |
1306 |
| - | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
1307 | 1292 |
| |
1308 |
| - | |
1309 |
| - | |
1310 |
| - | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
1311 | 1296 |
| |
1312 | 1297 |
| |
1313 | 1298 |
| |
| |||
1344 | 1329 |
| |
1345 | 1330 |
| |
1346 | 1331 |
| |
| 1332 | + | |
| 1333 | + | |
1347 | 1334 |
| |
| 1335 | + | |
1348 | 1336 |
| |
| 1337 | + | |
| 1338 | + | |
1349 | 1339 |
| |
| 1340 | + | |
1350 | 1341 |
| |
1351 | 1342 |
| |
1352 | 1343 |
| |
| |||
3965 | 3956 |
| |
3966 | 3957 |
| |
3967 | 3958 |
| |
3968 |
| - | |
3969 |
| - | |
3970 |
| - | |
3971 |
| - | |
3972 |
| - | |
3973 |
| - | |
3974 |
| - | |
3975 |
| - | |
3976 |
| - | |
3977 |
| - | |
3978 | 3959 |
| |
3979 | 3960 |
| |
3980 | 3961 |
| |
| |||
4151 | 4132 |
| |
4152 | 4133 |
| |
4153 | 4134 |
| |
| 4135 | + | |
| 4136 | + | |
| 4137 | + | |
| 4138 | + | |
| 4139 | + | |
| 4140 | + | |
| 4141 | + | |
| 4142 | + | |
| 4143 | + | |
| 4144 | + | |
| 4145 | + | |
| 4146 | + | |
| 4147 | + | |
| 4148 | + | |
4154 | 4149 |
| |
4155 | 4150 |
| |
4156 | 4151 |
| |
| |||
4312 | 4307 |
| |
4313 | 4308 |
| |
4314 | 4309 |
| |
4315 |
| - | |
4316 |
| - | |
| 4310 | + | |
| 4311 | + | |
4317 | 4312 |
| |
4318 |
| - | |
4319 |
| - | |
4320 |
| - | |
4321 |
| - | |
4322 |
| - | |
4323 |
| - | |
4324 |
| - | |
4325 |
| - | |
4326 |
| - | |
4327 |
| - | |
| 4313 | + | |
4328 | 4314 |
| |
4329 | 4315 |
| |
4330 | 4316 |
| |
4331 | 4317 |
| |
4332 |
| - | |
4333 |
| - | |
4334 |
| - | |
4335 | 4318 |
| |
4336 | 4319 |
| |
4337 | 4320 |
| |
|
0 commit comments
Comments
(0)