8000 Restore the ability to run pl/pgsql expression queries in parallel. · postgres/postgres@3bbc1c4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3bbc1c4

Browse files
committed
Restore the ability to run pl/pgsql expression queries in parallel.
pl/pgsql's notion of an "expression" is very broad, encompassing any SQL SELECT query that returns a single column and no more than one row. So there are cases, for example evaluation of an aggregate function, where the query involves significant work and it'd be useful to run it with parallel workers. This used to be possible, but commits 3eea7a0 et al unintentionally disabled it. The simplest fix is to make exec_eval_expr() pass maxtuples = 0 rather than 2 to exec_run_select(). This avoids the new rule that we will never use parallelism when a nonzero "count" limit is passed to ExecutorRun(). (Note that the pre-3eea7a0c9 behavior was indeed unsafe, so reverting that rule is not in the cards.) The reason for passing 2 before was that exec_eval_expr() will throw an error if it gets more than one returned row, so we figured that as soon as we have two rows we know that will happen and we might as well stop running the query. That choice was cost-free when it was made; but disabling parallelism is far from cost-free, so now passing 2 amounts to optimizing a failure case at the expense of useful cases. An expression query that can return more than one row is certainly broken. People might now need to wait a bit longer to discover such breakage; but hopefully few will use enormously expensive cases as their first test of new pl/pgsql logic. Author: Dipesh Dhameliya <dipeshdhameliya125@gmail.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/CABgZEgdfbnq9t6xXJnmXbChNTcWFjeM_6nuig41tm327gYi2ig@mail.gmail.com Backpatch-through: 13
1 parent d24a96c commit 3bbc1c4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/pl/plpgsql/src/pl_exec.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5709,7 +5709,7 @@ exec_eval_expr(PLpgSQL_execstate *estate,
57095709
/*
57105710
* Else do it the hard way via exec_run_select
57115711
*/
5712-
rc = exec_run_select(estate, expr, 2, NULL);
5712+
rc = exec_run_select(estate, expr, 0, NULL);
57135713
if (rc != SPI_OK_SELECT)
57145714
ereport(ERROR,
57155715
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
@@ -5763,6 +5763,10 @@ exec_eval_expr(PLpgSQL_execstate *estate,
57635763

57645764
/* ----------
57655765
* exec_run_select Execute a select query
5766+
*
5767+
* Note: passing maxtuples different from 0 ("return all tuples") is
5768+
* deprecated because it will prevent parallel execution of the query.
5769+
* However, we retain the parameter in case we need it someday.
57665770
* ----------
57675771
*/
57685772
static int

0 commit comments

Comments
 (0)
0