RE: Parallel INSERT (INTO ... SELECT ...)

From: "Hou, Zhijie" <houzj(dot)fnst(at)cn(dot)fujitsu(dot)com>
To: Greg Nancarrow <gregn4422(at)gmail(dot)com>
Cc: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, vignesh C <vignesh21(at)gmail(dot)com>, "Amit Langote" <amitlangote09(at)gmail(dot)com>, David Rowley <dgrowleyml(at)gmail(dot)com>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Tsunakawa, Takayuki" <tsunakawa(dot)takay(at)fujitsu(dot)com>, "Tang, Haiying" <tanghy(dot)fnst(at)cn(dot)fujitsu(dot)com>
Subject: RE: Parallel INSERT (INTO ... SELECT ...)
Date: 2021-02-01 09:18:39
Message-ID: 5276d7272635453eb44900d769994779@G08CNEXMBPEKD05.g08.fujitsu.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

When developing the reloption patch, I noticed some issues in the patch.

1).
> - Reduce Insert parallel-safety checks required for some SQL, by noting
> that the subquery must operate on a relation (check for RTE_RELATION in
> subquery range-table)

+ foreach(lcSub, rte->subquery->rtable)
+ {
+ rteSub = lfirst_node(RangeTblEntry, lcSub);
+ if (rteSub->rtekind == RTE_RELATION)
+ {
+ hasSubQueryOnRelation = true;
+ break;
+ }
+ }
It seems we can not only search RTE_RELATION in rtable,
because RTE_RELATION may exist in other place like:

---
--** explain insert into target select (select * from test);
Subplan's subplan

--** with cte as (select * from test) insert into target select * from cte;
In query's ctelist.
---

May be we should use a walker function [1] to
search the subquery and ctelist.

2).

+--
+-- Test INSERT into temporary table with underlying query.
+-- (should not use a parallel plan)
+--

May be the comment here need some change since
we currently support parallel plan for temp table.

3)
Do you think we can add a testcase for foreign-table ?
To test parallel query with serial insert on foreign table.

[1]
static bool
relation_walker(Node *node)
{
if (node == NULL)
return false;

else if (IsA(node, RangeTblEntry))
{
RangeTblEntry *rte = (RangeTblEntry *) node;
if (rte->rtekind == RTE_RELATION)
return true;

return false;
}

else if (IsA(node, Query))
{
Query *query = (Query *) node;

/* Recurse into subselects */
return query_tree_walker(query, relation_walker,
NULL, QTW_EXAMINE_RTES_BEFORE);
}

/* Recurse to check arguments */
return expression_tree_walker(node,
relation_walker,
NULL);
}

Best regards,
houzj

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dilip Kumar 2021-02-01 09:32:56 Re: Printing backtrace of postgres processes
Previous Message japin 2021-02-01 09:11:33 Re: row filtering for logical replication