Commit 7bb47fa
committed
optbuilder: preserve ORDER BY in set-returning UDFs with OUT parameters
When set-returning UDFs with OUT parameters are called directly in a
SELECT list (e.g., SELECT f()), CockroachDB wraps multiple result
columns into a single tuple column. During this transformation, two
functions created new scopes without preserving ordering information,
causing ORDER BY clauses in the UDF body to be ignored.
This commit fixes the issue by calling copyOrdering() in two places:
1. combineRoutineColsIntoTuple - when wrapping columns into a tuple
2. maybeAddRoutineAssignmentCasts - when adding type casts
The copyOrdering() method not only copies the ordering metadata but
also adds the columns referenced by the ordering to extraCols, ensuring
they remain available for the optimizer to enforce the ordering.
Fixes #144013
Release note (bug fix): Fixed a bug where ORDER BY clauses in
set-returning SQL user-defined functions with OUT parameters were
ignored when the function was called directly in a SELECT list
(e.g., SELECT f()). The ordering is now properly preserved and
enforced.
Epic: None1 parent ae0b3d7 commit 7bb47fa
File tree
2 files changed
+62
-0
lines changed- pkg/sql
- logictest/testdata/logic_test
- opt/optbuilder
2 files changed
+62
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
325 | 325 | | |
326 | 326 | | |
327 | 327 | | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
653 | 653 | | |
654 | 654 | | |
655 | 655 | | |
| 656 | + | |
656 | 657 | | |
657 | 658 | | |
658 | 659 | | |
| |||
721 | 722 | | |
722 | 723 | | |
723 | 724 | | |
| 725 | + | |
724 | 726 | | |
725 | 727 | | |
726 | 728 | | |
| |||
0 commit comments