From: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
To: 高增琦 <pgf00a@gmail.com>
To: Rajkumar Raghuwanshi <rajkumar.raghuwanshi@enterprisedb.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Amit Langote <amitlangote09@gmail.com>
Cc: Dmitry Ivanov <d.ivanov@postgrespro.ru>
Cc: Michael Paquier <michael.paquier@gmail.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Erik Rijkers <er@xs4all.nl>
Cc: Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>
Cc: Pg Hackers <pgsql-hackers@postgresql.org>
Cc: pgsql-hackers-owner@postgresql.org
Subject: Re: Declarative partitioning - another take
Date: Wed, 28 Dec 2016 10:41:17 +0900
Message-ID: <a2b7dd91-c1ae-72fc-1451-0f62d3298c4e@lab.ntt.co.jp> (raw)
In-Reply-To: <101e2c2d-45d6-fb1a-468c-d3f67572a2f3@lab.ntt.co.jp>
References: <890ce68d-2cff-ccf3-67f7-6f5d3264dbfc@lab.ntt.co.jp>
<c820c0eb-6935-6f84-8c6a-785fdff130c1@lab.ntt.co.jp>
<CA+TgmoanL20C2ZHrXZBEhMnAqebHv+0P5KmYZtNJw=vz3FHExA@mail.gmail.com>
<CA+HiwqGBKkfo6K=gcrRX9D9t_U4=-2GtjVRCMsupXRLtDzydJw@mail.gmail.com>
<262107e8-c506-6b34-f38a-2e5a1710a48e@lab.ntt.co.jp>
<CA+TgmoZPTWSfnQ5VTeYBXTRHAeKixAt_+F7dc=CkSiGCtfwMEw@mail.gmail.com>
<CA+TgmoaXiCBTCQsUSpQJP9JsXHt7kj7m+oS+tQLKMChHCX7zpQ@mail.gmail.com>
<d466b1e2-19e7-bd99-20f2-1ca26e5eb228@lab.ntt.co.jp>
<CA+TgmoY741D4MHhzSDgqc1=Jb2EF0sWba1Rqv2Rmo0-V9iSZQw@mail.gmail.com>
<95da7016-2757-9b11-74f5-ad4c6f647dfb@lab.ntt.co.jp>
<CA+TgmoYUfs8peo-p+Stw7afTdXqNWv_S4dx_6AWc-Y_ZrGWZbQ@mail.gmail.com>
<1bd459d9-4c0c-197a-346e-e5e59e217d97@lab.ntt.co.jp>
<f6f3a214-5bb5-aa8c-f82c-c720348cf086@lab.ntt.co.jp>
<CAKcux6=m1qyqB2k6cjniuMMrYXb75O-MB4qGQMu8zg-iGGLjDw@mail.gmail.com>
<CAFmBtr32FDOqofo8yG-4mjzL1HnYHxXK5S9OGFJ==cJpgEW4vA@mail.gmail.com>
<101e2c2d-45d6-fb1a-468c-d3f67572a2f3@lab.ntt.co.jp>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
On 2016/12/27 19:07, Amit Langote wrote:
> Attached should fix that.
Here are the last two patches with additional information like other
patches. Forgot to do that yesterday.
Thanks,
Amit
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackersAttachments:
[text/x-diff] 0001-Set-ecxt_scantuple-correctly-for-tuple-routing.patch (3.5K, ../a2b7dd91-c1ae-72fc-1451-0f62d3298c4e@lab.ntt.co.jp/2-0001-Set-ecxt_scantuple-correctly-for-tuple-routing.patch)
download | inline diff:
From 5a82b4caa6cec7845eb48e0397fab49c74b8dd98 Mon Sep 17 00:00:00 2001
From: amit <amitlangote09@gmail.com>
Date: Wed, 28 Dec 2016 10:10:26 +0900
Subject: [PATCH 1/2] Set ecxt_scantuple correctly for tuple-routing
In 2ac3ef7a01df859c62d0a02333b646d65eaec5ff, we changed things so that
it's possible for a different TupleTableSlot to be used for partitioned
tables at successive levels. If we do end up changing the slot from
the original, we must update ecxt_scantuple to point to the new one for
partition key expressions to be computed correctly.
Also update the regression tests so that the code manipulating
ecxt_scantuple is covered.
Reported by: Rajkumar Raghuwanshi
Patch by: Amit Langote
Reports: https://www.postgresql.org/message-id/CAKcux6%3Dm1qyqB2k6cjniuMMrYXb75O-MB4qGQMu8zg-iGGLjDw%40mail.gmail.com
---
src/backend/catalog/partition.c | 2 ++
src/backend/executor/execMain.c | 2 --
src/test/regress/expected/insert.out | 2 +-
src/test/regress/sql/insert.sql | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/backend/catalog/partition.c b/src/backend/catalog/partition.cindex fca874752f..f9daf8052d 100644--- a/src/backend/catalog/partition.c+++ b/src/backend/catalog/partition.c@@ -1647,6 +1647,7 @@ get_partition_for_tuple(PartitionDispatch *pd,
PartitionDesc partdesc = parent->partdesc;
TupleTableSlot *myslot = parent->tupslot;
TupleConversionMap *map = parent->tupmap;
+ ExprContext *econtext = GetPerTupleExprContext(estate);
/* Quick exit */
if (partdesc->nparts == 0)
@@ -1667,6 +1668,7 @@ get_partition_for_tuple(PartitionDispatch *pd,
}
/* Extract partition key from tuple */
+ econtext->ecxt_scantuple = slot;
FormPartitionKeyDatum(parent, slot, estate, values, isnull);
if (key->strategy == PARTITION_STRATEGY_RANGE)
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.cindex bca34a509c..1d699c1dab 100644--- a/src/backend/executor/execMain.c+++ b/src/backend/executor/execMain.c@@ -3107,9 +3107,7 @@ ExecFindPartition(ResultRelInfo *resultRelInfo, PartitionDispatch *pd,
{
int result;
Oid failed_at;
- ExprContext *econtext = GetPerTupleExprContext(estate);- econtext->ecxt_scantuple = slot;
result = get_partition_for_tuple(pd, slot, estate, &failed_at);
if (result < 0)
{
diff --git a/src/test/regress/expected/insert.out b/src/test/regress/expected/insert.outindex 49f667b119..ae54625034 100644--- a/src/test/regress/expected/insert.out+++ b/src/test/regress/expected/insert.out@@ -302,7 +302,7 @@ drop cascades to table part_ee_ff1
drop cascades to table part_ee_ff2
-- more tests for certain multi-level partitioning scenarios
create table p (a int, b int) partition by range (a, b);
-create table p1 (b int, a int not null) partition by range (b);+create table p1 (b int not null, a int not null) partition by range ((b+0));
create table p11 (like p1);
alter table p11 drop a;
alter table p11 add a int;
diff --git a/src/test/regress/sql/insert.sql b/src/test/regress/sql/insert.sqlindex 08dc068de8..9d3a34073c 100644--- a/src/test/regress/sql/insert.sql+++ b/src/test/regress/sql/insert.sql@@ -173,7 +173,7 @@ drop table list_parted cascade;
-- more tests for certain multi-level partitioning scenarios
create table p (a int, b int) partition by range (a, b);
-create table p1 (b int, a int not null) partition by range (b);+create table p1 (b int not null, a int not null) partition by range ((b+0));
create table p11 (like p1);
alter table p11 drop a;
alter table p11 add a int;
--
2.11.0
[text/x-diff] 0002-No-BulkInsertState-when-tuple-routing-is-in-action.patch (1.8K, ../a2b7dd91-c1ae-72fc-1451-0f62d3298c4e@lab.ntt.co.jp/3-0002-No-BulkInsertState-when-tuple-routing-is-in-action.patch)
download | inline diff:
From 798c51254563735dff843c71f1bbf34b969d8162 Mon Sep 17 00:00:00 2001
From: amit <amitlangote09@gmail.com>
Date: Wed, 28 Dec 2016 10:28:37 +0900
Subject: [PATCH 2/2] No BulkInsertState when tuple-routing is in action
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
In future, we might consider alleviating this restriction by
allocating a BulkInsertState per partition.
Reported by: 高增琦 <pgf00a(at)gmail(dot)com>
Patch by: Amit Langote (with pointers from 高增琦)
Reports: https://www.postgresql.org/message-id/CAFmBtr32FDOqofo8yG-4mjzL1HnYHxXK5S9OGFJ%3D%3DcJpgEW4vA%40mail.gmail.com
---
src/backend/commands/copy.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.cindex aa25a23336..e9bf4afa44 100644--- a/src/backend/commands/copy.c+++ b/src/backend/commands/copy.c@@ -2290,7 +2290,7 @@ CopyFrom(CopyState cstate)
ErrorContextCallback errcallback;
CommandId mycid = GetCurrentCommandId(true);
int hi_options = 0; /* start with default heap_insert options */
- BulkInsertState bistate;+ BulkInsertState bistate = NULL;
uint64 processed = 0;
bool useHeapMultiInsert;
int nBufferedTuples = 0;
@@ -2482,7 +2482,8 @@ CopyFrom(CopyState cstate)
values = (Datum *) palloc(tupDesc->natts * sizeof(Datum));
nulls = (bool *) palloc(tupDesc->natts * sizeof(bool));
- bistate = GetBulkInsertState();+ if (useHeapMultiInsert)+ bistate = GetBulkInsertState();
econtext = GetPerTupleExprContext(estate);
/* Set up callback to identify error line number */
@@ -2707,7 +2708,8 @@ CopyFrom(CopyState cstate)
/* Done, clean up */
error_context_stack = errcallback.previous;
- FreeBulkInsertState(bistate);+ if (bistate != NULL)+ FreeBulkInsertState(bistate);
MemoryContextSwitchTo(oldcontext);
--
2.11.0
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: Langote_Amit_f8@lab.ntt.co.jp, pgf00a@gmail.com, rajkumar.raghuwanshi@enterprisedb.com, robertmhaas@gmail.com, amitlangote09@gmail.com, d.ivanov@postgrespro.ru, michael.paquier@gmail.com, andres@anarazel.de, er@xs4all.nl, ashutosh.bapat@enterprisedb.com, pgsql-hackers-owner@postgresql.org
Subject: Re: Declarative partitioning - another take
In-Reply-To: <a2b7dd91-c1ae-72fc-1451-0f62d3298c4e@lab.ntt.co.jp>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox