mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +03:00
Check parallel safety in generate_useful_gather_paths
Commit ebb7ae839d ensured we ignore pathkeys with volatile expressions
when considering adding a sort below a Gather Merge. Turns out we need
to care about parallel safety of the pathkeys too, otherwise we might
try sorting e.g. on results of a correlated subquery (as demonstrated
by a report from Luis Roberto).
Initial investigation by Tom Lane, patch by James Coleman. Backpatch
to 13, where the code was instroduced (as part of Incremental Sort).
Reported-by: Luis Roberto
Author: James Coleman
Reviewed-by: Tomas Vondra
Backpatch-through: 13
Discussion: https://postgr.es/m/622580997.37108180.1604080457319.JavaMail.zimbra%40siscobra.com.br
Discussion: https://postgr.es/m/CAAaqYe8cK3g5CfLC4w7bs=hC0mSksZC=H5M8LSchj5e5OxpTAg@mail.gmail.com
This commit is contained in:
@@ -803,7 +803,8 @@ find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel)
|
||||
* applied in prepare_sort_from_pathkeys.
|
||||
*/
|
||||
Expr *
|
||||
find_em_expr_usable_for_sorting_rel(EquivalenceClass *ec, RelOptInfo *rel)
|
||||
find_em_expr_usable_for_sorting_rel(PlannerInfo *root, EquivalenceClass *ec,
|
||||
RelOptInfo *rel, bool require_parallel_safe)
|
||||
{
|
||||
ListCell *lc_em;
|
||||
|
||||
@@ -833,6 +834,12 @@ find_em_expr_usable_for_sorting_rel(EquivalenceClass *ec, RelOptInfo *rel)
|
||||
if (!bms_is_subset(em->em_relids, rel->relids))
|
||||
continue;
|
||||
|
||||
/*
|
||||
* If requested, reject expressions that are not parallel-safe.
|
||||
*/
|
||||
if (require_parallel_safe && !is_parallel_safe(root, (Node *) em_expr))
|
||||
continue;
|
||||
|
||||
/*
|
||||
* As long as the expression isn't volatile then
|
||||
* prepare_sort_from_pathkeys is able to generate a new target entry,
|
||||
|
||||
Reference in New Issue
Block a user