forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit2ed8f9a
committed
Fix type-checking of RECORD-returning functions in FROM.
In the corner case where a function returning RECORD has beensimplified to a RECORD constant or an inlined ROW() expression,ExecInitFunctionScan failed to cross-check the function's resultrowtype against the coldeflist provided by the calling query.That happened because get_expr_result_type is able to extract atupdesc from such expressions, which led ExecInitFunctionScan toignore the coldeflist. (Instead, it used the extracted tupdescto check the function's output, which of course always succeeds.)I have not been able to demonstrate any really serious consequencesfrom this, because if some column of the result is of the wrongtype and is directly referenced by a Var of the calling query,CheckVarSlotCompatibility will catch it. However, we definitely dofail to report the case where the function returns more columns thanthe coldeflist expects, and in the converse case where it returnsfewer columns, we get an assert failure (but, seemingly, no worseresults in non-assert builds).To fix, always build the expected tupdesc from the coldeflist if thereis one, and consult get_expr_result_type only when there isn't one.Also remove the failing Assert, even though it is no longer reachedafter this fix. It doesn't seem to be adding anything useful, sincelater checking will deal with cases with the wrong number of columns.The only other place I could find that is doing something similaris inline_set_returning_function. There's no live bug there becausewe cannot be looking at a Const or RowExpr, but for consistencychange that code to agree with ExecInitFunctionScan.Per report from PetSerAl. After some debate I've concluded thatthis should be back-patched. There is a small risk that somebodyhas been relying on such a case not throwing an error, but I judgethis outweighed by the risk that I've missed some way in which thefailure to cross-check has worse consequences than sketched above.Discussion:https://postgr.es/m/CAKygsHSerA1eXsJHR9wft3Gn3wfHQ5RfP8XHBzF70_qcrrRvEg@mail.gmail.com1 parentde7c6fe commit2ed8f9a
File tree
4 files changed
+76
-41
lines changed- src
- backend
- executor
- optimizer/util
- test/regress
- expected
- sql
4 files changed
+76
-41
lines changedLines changed: 45 additions & 36 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
343 | 343 |
| |
344 | 344 |
| |
345 | 345 |
| |
346 |
| - | |
347 |
| - | |
348 | 346 |
| |
349 | 347 |
| |
350 | 348 |
| |
| |||
361 | 359 |
| |
362 | 360 |
| |
363 | 361 |
| |
364 |
| - | |
365 |
| - | |
366 |
| - | |
367 |
| - | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
368 | 372 |
| |
369 |
| - | |
370 |
| - | |
371 |
| - | |
372 |
| - | |
373 |
| - | |
374 |
| - | |
375 |
| - | |
376 |
| - | |
377 |
| - | |
378 |
| - | |
379 |
| - | |
380 |
| - | |
381 |
| - | |
382 |
| - | |
383 |
| - | |
384 |
| - | |
385 |
| - | |
386 |
| - | |
387 |
| - | |
388 |
| - | |
389 |
| - | |
390 |
| - | |
391 |
| - | |
392 |
| - | |
393 |
| - | |
394 |
| - | |
395 |
| - | |
396 |
| - | |
| 373 | + | |
397 | 374 |
| |
398 | 375 |
| |
399 | 376 |
| |
| |||
409 | 386 |
| |
410 | 387 |
| |
411 | 388 |
| |
412 |
| - | |
413 |
| - | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
414 | 423 |
| |
415 | 424 |
| |
416 | 425 |
| |
|
Lines changed: 9 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5216 | 5216 |
| |
5217 | 5217 |
| |
5218 | 5218 |
| |
5219 |
| - | |
5220 |
| - | |
5221 |
| - | |
| 5219 | + | |
| 5220 | + | |
| 5221 | + | |
5222 | 5222 |
| |
5223 |
| - | |
5224 |
| - | |
| 5223 | + | |
| 5224 | + | |
| 5225 | + | |
5225 | 5226 |
| |
5226 | 5227 |
| |
5227 | 5228 |
| |
5228 | 5229 |
| |
| 5230 | + | |
| 5231 | + | |
| 5232 | + | |
5229 | 5233 |
| |
5230 | 5234 |
| |
5231 | 5235 |
| |
|
Lines changed: 13 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2485 | 2485 |
| |
2486 | 2486 |
| |
2487 | 2487 |
| |
| 2488 | + | |
| 2489 | + | |
| 2490 | + | |
| 2491 | + | |
| 2492 | + | |
| 2493 | + | |
| 2494 | + | |
| 2495 | + | |
| 2496 | + | |
| 2497 | + | |
| 2498 | + | |
| 2499 | + | |
| 2500 | + |
Lines changed: 9 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
815 | 815 |
| |
816 | 816 |
| |
817 | 817 |
| |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + |
0 commit comments
Comments
(0)