Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hvxi5-0006Te-Lf for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Aug 2019 05:45:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hvxi4-00084g-Hp for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Aug 2019 05:45:04 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hvxi4-00084Z-7R for pgsql-hackers@lists.postgresql.org; Fri, 09 Aug 2019 05:45:04 +0000 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hvxi1-0001Wq-S8 for pgsql-hackers@lists.postgresql.org; Fri, 09 Aug 2019 05:45:03 +0000 Received: by mail-pf1-x432.google.com with SMTP id r7so45425996pfl.3 for ; Thu, 08 Aug 2019 22:45:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:to:cc:subject:from:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=6P8aFiG7K+lwt3bw05PSfoKXAr9os+7PmWb6muScRxE=; b=YnOhKNFIJx4ouFcCPKdiA81Nadgz1CktR6KkCw8EKPpDLowrK/N5ThGDl74DG+z7K0 pMmohGVl8X3gBhCzLrsr2OrzMW5zzbcOHucejqlIvMGowEnSejskjlubQIhTe26wdc6F wSk2sMSCltf64BqpeYwyMFn+tOKuZn4VQp5mvYHupTI81WOezB3DpAWSe8w6mBbP6LB6 UhDlLBvhEWSPyLDyEl1tUJ3xK7ReLrN+LGrEs7o9005bViSeIEX56NVxCiXZgGPW8QMM YVhJh1kzuV+r5pyjZ1WR96iFGeNUcHUo3BeJWZlutj6lYLl0mBregelSHm24Ow5P59PI MkKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:to:cc:subject:from:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=6P8aFiG7K+lwt3bw05PSfoKXAr9os+7PmWb6muScRxE=; b=dNfnAq4jI83JwU92VP7I04MItBCtvSDhHd2MK8hO2NGMd3niRkVT/VLywc4tOrHt9W xQjm5o/rryOd88+5e62mHQQALbw9tmTKjuJvFMHELhUo7roTld7RLwop8esMUL1RYANf 1QpNHu1AMpXdgRYrJV5zLfMTGRBRrShlLuHQ+4Z5QzrDDQu0LVZOKNuSQFULWv9cCnHV TJRlCC4o+rKQYp4HFpO6iu1JRrcUGUFneCHjxTzgi3hepVDPcNvEALyA/NZp3e1ZTqIu EwB7NVzPt2HnQ8dLD/95QQBEIVkwsSGXMCnbckoeP3USRC3jRzZ2qx/iolQN6Ry1AHw+ /UvQ== X-Gm-Message-State: APjAAAX9hQaSnRFS0DWhZ65UxJ2/fK+/6VpGa4iH5eiOYuHZavz3LHkk bMyWtL1TScdXxgySLMkLlyk= X-Google-Smtp-Source: APXvYqxnZaQpI0kmp0xxwAuGbtp8uyE62ZgaE6V1szcf1ibbovgazRACxIo3NpKwxPBV3+td8n95dA== X-Received: by 2002:a63:cb4f:: with SMTP id m15mr15912509pgi.100.1565329499162; Thu, 08 Aug 2019 22:44:59 -0700 (PDT) Received: from localhost (w204177.dynamic.ppp.asahi-net.or.jp. [121.1.204.177]) by smtp.gmail.com with ESMTPSA id z13sm98661837pfa.94.2019.08.08.22.44.55 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 08 Aug 2019 22:44:58 -0700 (PDT) Date: Fri, 09 Aug 2019 14:44:38 +0900 (Tokyo Standard Time) Message-Id: <20190809.144438.221700512.horikyota.ntt@gmail.com> To: amitlangote09@gmail.com Cc: alvherre@2ndquadrant.com, simon@2ndquadrant.com, yuzukohosoya@gmail.com, shawn.wang.pg@gmail.com, shawn.wang@highgo.ca, pgsql-hackers@lists.postgresql.org Subject: Re: Problem with default partition pruning From: Kyotaro Horiguchi In-Reply-To: References: <20190809.120920.64991939.horikyota.ntt@gmail.com> User-Agent: Mew version 6.5 on Emacs 22.2 / Mule 5.0 =?iso-2022-jp?B?KBskQjpnGyhCKQ==?= / Meadow-3.01-dev (TSUBO-SUMIRE) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk At Fri, 9 Aug 2019 14:02:36 +0900, Amit Langote wrote in > On Fri, Aug 9, 2019 at 1:17 PM Amit Langote wrote: > > On Fri, Aug 9, 2019 at 12:09 PM Kyotaro Horiguchi > > wrote: > > > At Thu, 8 Aug 2019 14:50:54 +0900, Amit Langote wrote: > > > > When working on it, I realized > > > > that the way RelOptInfo.partition_qual is processed is a bit > > > > duplicative, so I created a separate patch to make that a bit more > > > > consistent. > > > > > > 0001 seems reasonable. By the way, the patch doesn't touch > > > get_relation_constraints(), but I suppose it can use the modified > > > partition constraint qual already stored in rel->partition_qual > > > in set_relation_partition_info. And we could move constifying to > > > set_rlation_partition_info? > > > > Ah, good advice. This make partition constraint usage within the > > planner quite a bit more consistent. > > Hmm, oops. I think that judgement was a bit too rushed on my part. I > unintentionally ended up making the partition constraint to *always* > be fetched, whereas we don't need it in most cases. I've reverted (v2 has been withdrawn before I see it:p) Yeah, I agreed. It is needed only by (sub)partition parents. > that change. RelOptInfo.partition_qual is poorly named in retrospect. > :( It's not set for all partitions, only those that are partitioned > themselves. > > Attached updated patches. +++ b/src/backend/optimizer/util/plancat.c @@ -1267,10 +1267,14 @@ get_relation_constraints(PlannerInfo *root, */ if (include_partition && relation->rd_rel->relispartition) { ... + else { + /* Nope, fetch from the relcache. */ I seems to me that include_partition is true both and only for modern and old-fasheoned partition parents. set_relation_partition_info() is currently called only for modern partition parents. If we need that at the place above, set_relation_partition_info can be called also for old-fashioned partition parent, and get_relation_constraints may forget the else case in a broad way. + /* Nope, fetch from the relcache. */ + List *pcqual = RelationGetPartitionQual(relation); If the comment above is right, This would be duplicate. What we should do instaed is only eval_const_expression. And we could move it to set_relation_partition_info completely. Consitify must be useful in both cases. regards. -- Kyotaro Horiguchi NTT Open Source Software Center