Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1faHFx-00071G-7Y for pgsql-committers@arkaria.postgresql.org; Tue, 03 Jul 2018 09:05:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1faHFv-00025x-0S for pgsql-committers@arkaria.postgresql.org; Tue, 03 Jul 2018 09:05:51 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1faHFu-00025q-OF for pgsql-committers@lists.postgresql.org; Tue, 03 Jul 2018 09:05:50 +0000 Received: from mail-it0-x241.google.com ([2607:f8b0:4001:c0b::241]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1faHFn-0003Zz-9Z for pgsql-committers@postgresql.org; Tue, 03 Jul 2018 09:05:49 +0000 Received: by mail-it0-x241.google.com with SMTP id j185-v6so1805247ite.1 for ; Tue, 03 Jul 2018 02:05:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=sfNn5sXplGWi1n6FuUD4wySs+YTBDwpXvQMFEWvNnTE=; b=Mey6OeYSQhbNrzGNfy/BGqb0GCrHZSMgk2y9M09cTsMTxaxgiU6W2Lar4kdsfvtSs7 eah6PCHG6he1U8DmG0b1APxWXLFVyeS7vFDinUl94wqFavMq1YpehGJMcRXX+ILsfjec SQb/0vLQR/Ks7RV9h2GPVy88WdB3PwBMaplvozMDUQMObmGbuS32dUJx+/V7FVDegZQl EkSgnPRj7xmdSPknVYF39WMns/PP/X/vNR9Oc5K55dAHDTNoPzN7IXTKzZzrKW0iV4y/ Lnk56pGQmHHhgXVTP/+B0YXicttuGeyjSrW/JjrIZdarfdBOWgfxic6dIplmWsyl08gn tpmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=sfNn5sXplGWi1n6FuUD4wySs+YTBDwpXvQMFEWvNnTE=; b=f0WyikRDtjOtSTcmNvTNU0cxtlVzGYEE6CBepyTMSpSAVP+377PKKSczYQoI8VEo89 71q1C36i/zfmfkTcw3Emt4x5C/n98jqlO7ZhuQEEVm2ntG597TlxAkyYrXu63Rcj4SoQ XiWv2gyfQTrcj8N8C+IpjePIUoRiLvBRyVoO5TivmGg21+DNf/2Osrji/HPP3MA+UxXj ut2rwQ0dPWThhuwXLK9c1TeAx3/0Vy9sADsuR8FrgS42RwF6DQNvryYDA+wPKu0lkN7F uxbHvJZioL+eZDhtJgbYEGAXQh8QNxKS4DFL3AD+x8OROOkd33fGy7aMmpujAQLDSXE0 55ig== X-Gm-Message-State: APt69E0ECK0sJx8ZpUrp7TX28wWuF4lrPGRgZl3IaY93eEguQo3M24Qp bZyKMGKPXVtQuagDaRTERjhITN4IA5CB9LUBzDljtw== X-Google-Smtp-Source: AAOMgpeGn0ODQM4dgbDfpQZfme4Hewo5y2zxW2BLhr2s2YV1dk/nrT12GgQHnkb/WP/JZSY1XkkzMGRBFjjLxxtw10A= X-Received: by 2002:a02:8895:: with SMTP id n21-v6mr23434718jaj.21.1530608742009; Tue, 03 Jul 2018 02:05:42 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a02:241f:0:0:0:0:0 with HTTP; Tue, 3 Jul 2018 02:05:41 -0700 (PDT) In-Reply-To: References: <20180702221650.GA2159@paquier.xyz> <20180703045502.GA26236@paquier.xyz> <20180703061119.GA11732@paquier.xyz> <5db5fe6e-4a73-6a24-09e4-060b9f132ea9@lab.ntt.co.jp> <20180703070551.GC11732@paquier.xyz> From: David Rowley Date: Tue, 3 Jul 2018 21:05:41 +1200 Message-ID: Subject: Re: pgsql: Clarify use of temporary tables within partition trees To: Amit Langote Cc: Michael Paquier , Robert Haas , Ashutosh Bapat , pgsql-committers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk (re-adding committers list) On 3 July 2018 at 20:31, Amit Langote wrote: > 1. I still insist that it's better for the newly added code to be near the > top of the function body than in the middle, which brings me to... That will cause the AppendRelInfo not to be built for a partitioned table with no partitions. I'm not personally certain that doing that comes without consequence. Are you certain of that? If not 100%, then I think that's more of a task for PG12. I'm trying to propose removing dead code for PG11 and on. My current thoughts are that moving this test up a few lines is unlikely to improve performance in a real-world situation, so it does not seem worth the risk for a backpatch to me. > 2. While we're at fixing the code around here, I think we should think > about trying to get rid of the *non-dead* code that produces a structure > that isn't used anywhere, which I was under the impression, 0a480502b09 > [1] already did (cc'ing Ashutosh). To clarify, we still unnecessarily > create a "duplicate" RTE for partitioned tables in a partition tree > (non-leaf tables) in its role as a child. So, for the above query, there > end up being created 4 entries in the query's range table (2 for 'p' and 2 > for 'pd'). That makes sense for plain inheritance, because even the root > parent table in a plain inheritance tree is a regular table containing > data. That's not true for partition inheritance trees, where non-leaf > tables contain no data, so we don't create a plan to scan them (see > d3cc37f1d80 [2]), which in turn means we don't need to create the > redundant "duplicate" child RTEs for them either. > > See attached my delta patch to address both 1 and 2. I recently saw this too and wondered about it. I then wrote a patch to just have it create a single RangeTblEntry for each partitioned table. The tests all passed. I'd categorise this one the same as I have #1 above, i.e. not backpatch material. It seems like something useful to look into for v12 though. I assumed this was done for a reason and that I just didn't understand what that reason was. I don't recall any comments to explain the reason why we build two RangeTblEntrys for each partitioned table. In light of what Amit has highlighted, I'm still standing by the v3 patch assuming the typo is fixed. -- David Rowley http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services