Commit 48a39f1
authored
[OSS-ONLY]Revert Output clause changes in Executor to match with PG Returning (babelfish-for-postgresql#668)
We are dealing with a critical crash bug in Babelfish's EPQ (EvalPlanQual) handling during concurrent UPDATE operations with OUTPUT clauses. The crash occurs when two sessions simultaneously modify the same row, where the column is of type "varchar" causing tuple alignment problems during EPQ re-evaluation. This is a memory corruption issue where PostgreSQL's EPQ mechanism fails to properly handle tuple structure changes when Babelfish processes OUTPUT clauses, leading to segmentation faults or assertion failures.
### The Problem
Babelfish was processing the OUTPUT clause (RETURNING clause) BEFORE EPQ evaluation, which created a race condition crash because:
1. Original Design Rationale: OUTPUT clause was moved before EPQ to ensure it executed before triggers
2. Race Condition: When EPQ re-evaluation occurred, the OUTPUT clause had already processed using stale tuple data
3. Crash Point: EPQ tried to re-evaluate with changed tuple structure, but OUTPUT processing was already complete with wrong memory references
### The Solution
Align Babelfish OUTPUT clause execution with PostgreSQL's native RETURNING clause flow:
### Key Insights from Fix
- [ ] Trigger Execution Order: Analysis revealed that OUTPUT clause doesn't actually need to run before triggers in Babelfish context
- [ ] PostgreSQL Alignment: Following PostgreSQL's native RETURNING execution flow eliminates the race condition
- [ ] EPQ Compatibility: Processing OUTPUT after EPQ ensures it always works with the correct, final tuple data
- [ ] Memory Safety: Eliminates tuple alignment crashes by ensuring OUTPUT clause processes current data structure
### Related PR -
Extension PR - babelfish-for-postgresql/babelfish_extensions#4347
Task: BABEL-4880
Signed-off-by: Herambh Shah <herambhs@amazon.com>1 parent b90bc07 commit 48a39f1
1 file changed
+3
-56
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
827 | 827 | | |
828 | 828 | | |
829 | 829 | | |
830 | | - | |
831 | | - | |
832 | | - | |
833 | | - | |
834 | 830 | | |
835 | 831 | | |
836 | 832 | | |
| |||
1220 | 1216 | | |
1221 | 1217 | | |
1222 | 1218 | | |
1223 | | - | |
| 1219 | + | |
1224 | 1220 | | |
1225 | 1221 | | |
1226 | 1222 | | |
| |||
1459 | 1455 | | |
1460 | 1456 | | |
1461 | 1457 | | |
1462 | | - | |
1463 | 1458 | | |
1464 | 1459 | | |
1465 | 1460 | | |
| |||
1472 | 1467 | | |
1473 | 1468 | | |
1474 | 1469 | | |
1475 | | - | |
1476 | | - | |
1477 | | - | |
1478 | | - | |
1479 | | - | |
1480 | | - | |
1481 | | - | |
1482 | | - | |
1483 | | - | |
1484 | | - | |
1485 | | - | |
1486 | | - | |
1487 | | - | |
1488 | | - | |
1489 | | - | |
1490 | | - | |
1491 | | - | |
1492 | | - | |
1493 | | - | |
1494 | | - | |
1495 | | - | |
1496 | | - | |
1497 | | - | |
1498 | | - | |
1499 | | - | |
1500 | | - | |
1501 | | - | |
1502 | | - | |
1503 | | - | |
1504 | | - | |
1505 | | - | |
1506 | | - | |
1507 | | - | |
1508 | | - | |
1509 | | - | |
1510 | | - | |
1511 | | - | |
1512 | 1470 | | |
1513 | 1471 | | |
1514 | 1472 | | |
| |||
1744 | 1702 | | |
1745 | 1703 | | |
1746 | 1704 | | |
1747 | | - | |
| 1705 | + | |
1748 | 1706 | | |
1749 | 1707 | | |
1750 | 1708 | | |
| |||
1785 | 1743 | | |
1786 | 1744 | | |
1787 | 1745 | | |
1788 | | - | |
1789 | | - | |
1790 | | - | |
1791 | 1746 | | |
1792 | 1747 | | |
1793 | 1748 | | |
| |||
2352 | 2307 | | |
2353 | 2308 | | |
2354 | 2309 | | |
2355 | | - | |
2356 | 2310 | | |
2357 | 2311 | | |
2358 | 2312 | | |
| |||
2367 | 2321 | | |
2368 | 2322 | | |
2369 | 2323 | | |
2370 | | - | |
2371 | | - | |
2372 | | - | |
2373 | | - | |
2374 | 2324 | | |
2375 | 2325 | | |
2376 | 2326 | | |
| |||
2594 | 2544 | | |
2595 | 2545 | | |
2596 | 2546 | | |
2597 | | - | |
2598 | | - | |
2599 | | - | |
2600 | 2547 | | |
2601 | | - | |
| 2548 | + | |
2602 | 2549 | | |
2603 | 2550 | | |
2604 | 2551 | | |
| |||
0 commit comments