Skip to content

Commit 5b9968d

Browse files
authored
Merge pull request #14 from Algunenano/REL_10_CARTO_revert_parallel
Revert #10
2 parents 1f790d3 + 8ab56f7 commit 5b9968d

File tree

11 files changed

+35
-151
lines changed

11 files changed

+35
-151
lines changed

CHANGELOG.carto.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 10.1.2+carto-1
4+
5+
**Release data**: 2018-XX-XX
6+
7+
Changes
8+
- Revert [#10](https://github.com/CartoDB/postgres/pull/10) as the patch was incomplete and causing crashes
9+
310
## 10.1.1+carto-1
411

512
**Release date**: 2017-12-05

doc/src/sgml/parallel.sgml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,9 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
151151
<para>
152152
The query writes any data or locks any database rows. If a query
153153
contains a data-modifying operation either at the top level or within
154-
a CTE, no parallel plans for that query will be generated. As an
155-
exception, the commands <literal>CREATE TABLE</>, <literal>SELECT
156-
INTO</>, and <literal>CREATE MATERIALIZED VIEW</> which create a new
157-
table and populate it can use a parallel plan.
154+
a CTE, no parallel plans for that query will be generated. This is a
155+
limitation of the current implementation which could be lifted in a
156+
future release.
158157
</para>
159158
</listitem>
160159

@@ -242,6 +241,15 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
242241
</para>
243242
</listitem>
244243

244+
<listitem>
245+
<para>
246+
A prepared statement is executed using a <literal>CREATE TABLE .. AS
247+
EXECUTE ..</literal> statement. This construct converts what otherwise
248+
would have been a read-only operation into a read-write operation,
249+
making it ineligible for parallel query.
250+
</para>
251+
</listitem>
252+
245253
<listitem>
246254
<para>
247255
The transaction isolation level is serializable. This situation

src/backend/access/heap/heapam.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,17 +2581,15 @@ heap_prepare_insert(Relation relation, HeapTuple tup, TransactionId xid,
25812581
CommandId cid, int options)
25822582
{
25832583
/*
2584-
* Parallel operations are required to be strictly read-only in a parallel
2585-
* worker. Parallel inserts are not safe even in the leader in the
2586-
* general case, because group locking means that heavyweight locks for
2587-
* relation extension or GIN page locks will not conflict between members
2588-
* of a lock group, but we don't prohibit that case here because there are
2589-
* useful special cases that we can safely allow, such as CREATE TABLE AS.
2590-
*/
2591-
if (IsParallelWorker())
2584+
* For now, parallel operations are required to be strictly read-only.
2585+
* Unlike heap_update() and heap_delete(), an insert should never create a
2586+
* combo CID, so it might be possible to relax this restriction, but not
2587+
* without more thought and testing.
2588+
*/
2589+
if (IsInParallelMode())
25922590
ereport(ERROR,
25932591
(errcode(ERRCODE_INVALID_TRANSACTION_STATE),
2594-
errmsg("cannot insert tuples in a parallel worker")));
2592+
errmsg("cannot insert tuples during a parallel operation")));
25952593

25962594
if (relation->rd_rel->relhasoids)
25972595
{

src/backend/commands/createas.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
326326
query = linitial_node(Query, rewritten);
327327
Assert(query->commandType == CMD_SELECT);
328328

329-
/* plan the query */
330-
plan = pg_plan_query(query, CURSOR_OPT_PARALLEL_OK, params);
329+
/* plan the query --- note we disallow parallelism */
330+
plan = pg_plan_query(query, 0, params);
331331

332332
/*
333333
* Use a snapshot with an updated command ID to ensure this query sees

src/backend/commands/explain.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,14 +400,16 @@ ExplainOneUtility(Node *utilityStmt, IntoClause *into, ExplainState *es,
400400
* We have to rewrite the contained SELECT and then pass it back to
401401
* ExplainOneQuery. It's probably not really necessary to copy the
402402
* contained parsetree another time, but let's be safe.
403+
*
404+
* Like ExecCreateTableAs, disallow parallelism in the plan.
403405
*/
404406
CreateTableAsStmt *ctas = (CreateTableAsStmt *) utilityStmt;
405407
List *rewritten;
406408

407409
rewritten = QueryRewrite(castNode(Query, copyObject(ctas->query)));
408410
Assert(list_length(rewritten) == 1);
409411
ExplainOneQuery(linitial_node(Query, rewritten),
410-
CURSOR_OPT_PARALLEL_OK, ctas->into, es,
412+
0, ctas->into, es,
411413
queryString, params, queryEnv);
412414
}
413415
else if (IsA(utilityStmt, DeclareCursorStmt))

src/backend/executor/execMain.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,9 +1697,11 @@ ExecutePlan(EState *estate,
16971697

16981698
/*
16991699
* If the plan might potentially be executed multiple times, we must force
1700-
* it to run without parallelism, because we might exit early.
1700+
* it to run without parallelism, because we might exit early. Also
1701+
* disable parallelism when writing into a relation, because no database
1702+
* changes are allowed in parallel mode.
17011703
*/
1702-
if (!execute_once)
1704+
if (!execute_once || dest->mydest == DestIntoRel)
17031705
use_parallel_mode = false;
17041706

17051707
estate->es_use_parallel_mode = use_parallel_mode;

src/backend/optimizer/plan/planner.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,6 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
257257
* to values that don't permit parallelism, or if parallel-unsafe
258258
* functions are present in the query tree.
259259
*
260-
* (Note that we do allow CREATE TABLE AS, SELECT INTO, and CREATE
261-
* MATERIALIZED VIEW to use parallel plans, but this is safe only because
262-
* the command is writing into a completely new table which workers won't
263-
* be able to see. If the workers could see the table, the fact that
264-
* group locking would cause them to ignore the leader's heavyweight
265-
* relation extension lock and GIN page locks would make this unsafe.
266-
* We'll have to fix that somehow if we want to allow parallel inserts in
267-
* general; updates and deletes have additional problems especially around
268-
* combo CIDs.)
269-
*
270260
* For now, we don't try to use parallel mode if we're running inside a
271261
* parallel worker. We might eventually be able to relax this
272262
* restriction, but for now it seems best not to have parallel workers

src/test/regress/expected/write_parallel.out

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/test/regress/parallel_schedule

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ test: rules psql_crosstab amutils
9696

9797
# run by itself so it can run parallel workers
9898
test: select_parallel
99-
test: write_parallel
10099

101100
# no relation related tests can be put in this group
102101
test: publication subscription

src/test/regress/serial_schedule

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ test: stats_ext
134134
test: rules
135135
test: psql_crosstab
136136
test: select_parallel
137-
test: write_parallel
138137
test: publication
139138
test: subscription
140139
test: amutils

src/test/regress/sql/write_parallel.sql

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)