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 1hv35v-0002c5-Cp for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Aug 2019 17:17:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hv35u-0002Nw-4I for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Aug 2019 17:17:54 +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 1hv35t-0002Np-S3 for pgsql-hackers@lists.postgresql.org; Tue, 06 Aug 2019 17:17:53 +0000 Received: from mail-qk1-x743.google.com ([2607:f8b0:4864:20::743]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hv35m-00066x-I8 for pgsql-hackers@lists.postgresql.org; Tue, 06 Aug 2019 17:17:53 +0000 Received: by mail-qk1-x743.google.com with SMTP id r4so63389559qkm.13 for ; Tue, 06 Aug 2019 10:17:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=9r4PljWjZpiyP0Fdir/tEuwIU8AZzl3GWY0o9xR00Uk=; b=Ue+6d0BliUSSGyHLh2BIbwuu6QbHmXC/kaEea7WvLEIosVqvCCqYBrTeC6G2/qfOxf cHBHblLuiKE0VC+pvQckb8q5Dv+J1SN+hl3FWR4n842wwotxSP12NpXeGYtpgWHe903J jCjHqweyIVaDSsqY8LHBEFohqxUls5KcWb8eioQPt9l84rznl4YHvj5IaI8gId6PBDgC QNG+Mwa2/ToA+rn4c6WlpH71XkgOgTnl/jswxpsrrq1LaSXBkdFDKRme4wOHC6w4oXgj HU+ESDu8wRYbzqehZ5+jyifw++XmgYpr0a98eTRFiU5cDH80M+BB/i6vsuzieTlgo5Uk X5gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=9r4PljWjZpiyP0Fdir/tEuwIU8AZzl3GWY0o9xR00Uk=; b=drTGehg9an5SHmAEM2AEhKEJbTsOGNmmGVU0jAuS5+txQv82Stct+OupOUDo9Zn02v YM7V6e3YAHI/i4Lw+bNR157hXxLV1lT5HwoLp9d3hDWZeU5S4YaBi1sBQpfcqqj1SAOs kVJL2NmsJPFlTJVdyovTVMTk1532j5RbfTGsE09GX5pZtthSATBiM1xY2xEJ9ilko619 BBb3ZBqT8btZ/xNIAh2F2wQd6+vCPIKfNS2s1Yr8M9y5QT5oW1oZ0dYgowgzQBirayhT /ZO0x+JZJxRiwskip3uwIGm0OPpHW8bLGWU/eiv/yBGDtiZa4AX+neowPLooMyiIAh1G 043w== X-Gm-Message-State: APjAAAVWmtiFvUMdBdKZH8at4s7hfRG+qot6vB43hp6Sl+JNprtn8tsB qLrD1Sryx+jYVvpN5fDq4XlstA== X-Google-Smtp-Source: APXvYqygdTqvp2rJPaMrJIsSF3R8ni4nBcHj7RqSBDz+4VWw+O30HkE0Oll9TyW/vim2/BiX8L9JeQ== X-Received: by 2002:a37:a013:: with SMTP id j19mr4420170qke.401.1565111864302; Tue, 06 Aug 2019 10:17:44 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.13.189.98]) by smtp.gmail.com with ESMTPSA id c20sm31619231qkk.69.2019.08.06.10.17.43 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 06 Aug 2019 10:17:43 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id B66D5120CC4; Tue, 6 Aug 2019 13:17:40 -0400 (-04) Date: Tue, 6 Aug 2019 13:17:40 -0400 From: Alvaro Herrera To: Amit Langote Cc: yuzuko , shawn wang , Shawn Wang , PostgreSQL Hackers Subject: Re: Problem with default partition pruning Message-ID: <20190806171740.GA7610@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="/9DWx/yDrRhgMJTb" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --/9DWx/yDrRhgMJTb Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit Hello, On 2019-Aug-06, Amit Langote wrote: > On Mon, Aug 5, 2019 at 11:39 PM Alvaro Herrera wrote: > > I don't think that we care about what happens with constraint_exclusion > > is on. That's not the recommended value for that setting anyway. > > One issue I expressed with unconditionally applying constraint > exclusion in partprune.c the way the third patch proposes to do it is > that it means we end up performing the same processing twice for a > given relation in come cases. Specifically, when constraint_exclusion > is set to on, relation_excluded_by_constraints() that occurs when > set_rel_sizes() is applied to that relation would perform the same > proof. But maybe we shouldn't worry about the repetition too much, > because it's not likely to be very problematic in practice, > considering that setting constraint_exclusion to on is not > recommended. Well, if this is really all that duplicative, one thing we could do is run this check in get_partprune_steps_internal only if constraint_exclusion is a value other than on; we should achieve the same effect with no repetition. Patch for that is attached. However, if I run the server with constraint_exclusion=on, the regression test fail with the attached diff. I didn't look at what test is failing, but it seems to me that it's not really duplicative in all cases, only some. Therefore we can't do it. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --/9DWx/yDrRhgMJTb Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="no-dupe-check.patch" diff --git a/src/backend/partitioning/partprune.c b/src/backend/partitioning/partprune.c index 2ed1e44c18..2f84f30423 100644 --- a/src/backend/partitioning/partprune.c +++ b/src/backend/partitioning/partprune.c @@ -1023,8 +1023,12 @@ gen_partprune_steps_internal(GeneratePruningStepsContext *context, * If the clause contradicts the partition constraint, mark the clause * as contradictory and we're done. This is particularly helpful to * prune the default partition. + * + * However, we skip this if constraint_exclusion is set to ON, because + * this check will be done by set_rel_size later on anyway. */ - if (context->rel->partition_qual) + if (context->rel->partition_qual && + constraint_exclusion != CONSTRAINT_EXCLUSION_ON) { List *partconstr; --/9DWx/yDrRhgMJTb Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="regression.diffs" diff -U3 /pgsql/source/master/src/test/regress/expected/partition_prune.out /home/alvherre/Code/pgsql/build/master/src/test/regress/results/partition_prune.out --- /pgsql/source/master/src/test/regress/expected/partition_prune.out 2019-08-06 12:27:10.041137540 -0400 +++ /home/alvherre/Code/pgsql/build/master/src/test/regress/results/partition_prune.out 2019-08-06 13:12:20.367678444 -0400 @@ -529,6 +529,12 @@ Filter: ((a = 1) OR ((b)::text = 'ab'::text)) -> Seq Scan on rlp3abcd Filter: ((a = 1) OR ((b)::text = 'ab'::text)) + -> Seq Scan on rlp3efgh + Filter: ((a = 1) OR ((b)::text = 'ab'::text)) + -> Seq Scan on rlp3nullxy + Filter: ((a = 1) OR ((b)::text = 'ab'::text)) + -> Seq Scan on rlp3_default + Filter: ((a = 1) OR ((b)::text = 'ab'::text)) -> Seq Scan on rlp4_1 Filter: ((a = 1) OR ((b)::text = 'ab'::text)) -> Seq Scan on rlp4_2 @@ -547,7 +553,7 @@ Filter: ((a = 1) OR ((b)::text = 'ab'::text)) -> Seq Scan on rlp_default_default Filter: ((a = 1) OR ((b)::text = 'ab'::text)) -(25 rows) +(31 rows) explain (costs off) select * from rlp where a > 20 and a < 27; QUERY PLAN @@ -599,9 +605,11 @@ Append -> Seq Scan on rlp4_1 Filter: ((a = 20) OR (a = 40)) + -> Seq Scan on rlp4_default + Filter: ((a = 20) OR (a = 40)) -> Seq Scan on rlp5_default Filter: ((a = 20) OR (a = 40)) -(5 rows) +(7 rows) explain (costs off) select * from rlp3 where a = 20; /* empty */ QUERY PLAN --/9DWx/yDrRhgMJTb--