Re: Internal error XX000 with enable_partition_pruning=on, pg 11beta1 on Debian - Mailing list pgsql-hackers

From Rushabh Lathia
Subject Re: Internal error XX000 with enable_partition_pruning=on, pg 11beta1 on Debian
Date
Msg-id CAGPqQf3anJGj65bqAQ9edDr8gF7qig6_avRgwMT9MsZ19COUPw@mail.gmail.com
Whole thread Raw
In response to Re: Internal error XX000 with enable_partition_pruning=on, pg 11beta1 on Debian  (Alvaro Herrera <alvherre@2ndquadrant.com>)
Responses Re: Internal error XX000 with enable_partition_pruning=on, pg 11 beta1 on Debian
List pgsql-hackers
Hi,

Consider the below case:

CREATE TABLE pt (a INT, b INT, c INT) PARTITION BY RANGE(a);
CREATE TABLE pt_p1 PARTITION OF pt FOR VALUES FROM (1) to (6) PARTITION BY RANGE (b);
CREATE TABLE pt_p1_p1 PARTITION OF pt_p1 FOR VALUES FROM (11) to (44);
CREATE TABLE pt_p1_p2 PARTITION OF pt_p1 FOR VALUES FROM (44) to (66);
INSERT INTO pt (a,b,c) VALUES (1,11,111),(2,22,222),(3,33,333),(4,44,444),(5,55,555);

-- rule on root partition to first level child,
CREATE RULE pt_rule_ptp1 AS ON UPDATE TO pt DO INSTEAD UPDATE pt_p1 SET a = new.a WHERE a = old.a;

-- Below command end up with error
UPDATE pt SET a = 3 WHERE a = 2;
ERROR:  child rel 1 not found in append_rel_array

Here update on the partition table fail, if it has rule which is define on
partition table - to redirect record on the child table.

While looking further, I found the test started failing with below commit:

commit 1b54e91faabf3764b6786915881e514e42dccf89
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date:   Wed Aug 1 19:42:46 2018 -0400

    Fix run-time partition pruning for appends with multiple source rels.


Error coming from below code, where its try to adjust the appendrel
attribute and end up with error from find_appinfos_by_relids().

            /*
             * The prunequal is presented to us as a qual for 'parentrel'.
             * Frequently this rel is the same as targetpart, so we can skip
             * an adjust_appendrel_attrs step.  But it might not be, and then
             * we have to translate.  We update the prunequal parameter here,
             * because in later iterations of the loop for child partitions,
             * we want to translate from parent to child variables.
             */
            if (parentrel != subpart)
            {
                int            nappinfos;
                AppendRelInfo **appinfos = find_appinfos_by_relids(root,
                                                                   subpart->relids,
                                                                   &nappinfos);

                prunequal = (List *) adjust_appendrel_attrs(root, (Node *)
                                                            prunequal,
                                                            nappinfos,
                                                            appinfos);

                pfree(appinfos);
            }


Regards,

On Thu, Aug 2, 2018 at 8:36 PM, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
On 2018-Aug-01, Tom Lane wrote:

> David Rowley <david.rowley@2ndquadrant.com> writes:
> > On 20 July 2018 at 01:03, David Rowley <david.rowley@2ndquadrant.com> wrote:
> >> I've attached a patch intended for master which is just v2 based on
> >> post 5220bb7533.
>
> I've pushed the v3 patch with a lot of editorial work (e.g. cleaning
> up comments you hadn't).

Thanks Tom, much appreciated.

--
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services




--
Rushabh Lathia

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [PATCH] Include application_name in "connection authorized" log message
Next
From: Don Seiler
Date:
Subject: Re: [PATCH] Include application_name in "connection authorized" log message