forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit4ace456
committed
Fix index-only scan plans when not all index columns can be returned.
If an index has both returnable and non-returnable columns, and one ofthe non-returnable columns is an expression using a Var that is in areturnable column, then a query returning that expression could resultin an index-only scan plan that attempts to read the non-returnablecolumn, instead of recomputing the expression from the returnablecolumn as intended.To fix, redefine the "indextlist" list of an IndexOnlyScan plan nodeas containing null Consts in place of any non-returnable columns.This solves the problem by preventing setrefs.c from falsely matchingto such entries. The executor is happy since it only cares about theexposed types of the entries, and ruleutils.c doesn't care because acorrect plan won't reference those entries. I considered some otherways to prevent setrefs.c from doing the wrong thing, but this wayseems good since (a) it allows a very localized fix, (b) it makesthe indextlist structure more compact in many cases, and (c) theindextlist is now a more faithful representation of what the index AMwill actually produce, viz. nulls for any non-returnable columns.This is easier to hit since we introduced included columns, but it'spossible to construct failing examples without that, as per theadded regression test. Hence, back-patch to all supported branches.Per bug #17350 from Louis Jachiet.Discussion:https://postgr.es/m/17350-b5bdcf476e5badbb@postgresql.org1 parent3e6e86a commit4ace456
File tree
4 files changed
+92
-3
lines changed- src
- backend/optimizer/plan
- include/nodes
- test/regress
- expected
- sql
4 files changed
+92
-3
lines changedLines changed: 51 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
20 | 20 |
| |
21 | 21 |
| |
22 | 22 |
| |
| 23 | + | |
23 | 24 |
| |
24 | 25 |
| |
25 | 26 |
| |
| |||
191 | 192 |
| |
192 | 193 |
| |
193 | 194 |
| |
| 195 | + | |
194 | 196 |
| |
195 | 197 |
| |
196 | 198 |
| |
| |||
621 | 623 |
| |
622 | 624 |
| |
623 | 625 |
| |
624 |
| - | |
| 626 | + | |
625 | 627 |
| |
626 | 628 |
| |
627 | 629 |
| |
| |||
3070 | 3072 |
| |
3071 | 3073 |
| |
3072 | 3074 |
| |
3073 |
| - | |
| 3075 | + | |
3074 | 3076 |
| |
3075 | 3077 |
| |
3076 | 3078 |
| |
| |||
5463 | 5465 |
| |
5464 | 5466 |
| |
5465 | 5467 |
| |
| 5468 | + | |
| 5469 | + | |
| 5470 | + | |
| 5471 | + | |
| 5472 | + | |
| 5473 | + | |
| 5474 | + | |
| 5475 | + | |
| 5476 | + | |
| 5477 | + | |
| 5478 | + | |
| 5479 | + | |
| 5480 | + | |
| 5481 | + | |
| 5482 | + | |
| 5483 | + | |
| 5484 | + | |
| 5485 | + | |
| 5486 | + | |
| 5487 | + | |
| 5488 | + | |
| 5489 | + | |
| 5490 | + | |
| 5491 | + | |
| 5492 | + | |
| 5493 | + | |
| 5494 | + | |
| 5495 | + | |
| 5496 | + | |
| 5497 | + | |
| 5498 | + | |
| 5499 | + | |
| 5500 | + | |
| 5501 | + | |
| 5502 | + | |
| 5503 | + | |
| 5504 | + | |
| 5505 | + | |
| 5506 | + | |
| 5507 | + | |
| 5508 | + | |
| 5509 | + | |
| 5510 | + | |
| 5511 | + | |
| 5512 | + | |
| 5513 | + | |
| 5514 | + | |
5466 | 5515 |
| |
5467 | 5516 |
| |
5468 | 5517 |
| |
|
Lines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
427 | 427 |
| |
428 | 428 |
| |
429 | 429 |
| |
430 |
| - | |
| 430 | + | |
| 431 | + | |
431 | 432 |
| |
432 | 433 |
| |
433 | 434 |
| |
|
Lines changed: 28 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
312 | 312 |
| |
313 | 313 |
| |
314 | 314 |
| |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
315 | 343 |
| |
316 | 344 |
| |
317 | 345 |
| |
|
Lines changed: 11 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
142 | 142 |
| |
143 | 143 |
| |
144 | 144 |
| |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
145 | 156 |
| |
146 | 157 |
| |
147 | 158 |
| |
|
0 commit comments
Comments
(0)