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 1fQsNq-0007oK-Lh for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Jun 2018 10:43:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fQsNp-0000yZ-Ce for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Jun 2018 10:43:09 +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 1fQsNp-0000yJ-1e for pgsql-hackers@lists.postgresql.org; Thu, 07 Jun 2018 10:43:09 +0000 Received: from mail-pg0-x22b.google.com ([2607:f8b0:400e:c05::22b]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fQsNg-0007uo-PJ for pgsql-hackers@postgresql.org; Thu, 07 Jun 2018 10:43:07 +0000 Received: by mail-pg0-x22b.google.com with SMTP id l65-v6so4562641pgl.8 for ; Thu, 07 Jun 2018 03:43:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=DXOkD+gduxM/YdwT92/i1TULmdG8/7itrkUatyUSM8c=; b=S1yKGf3aoBoivOyby8D4P2VP9Y/ytvLRvlzI18nq5JzkUj2NliIuIl6YyrDGdrZHZo mqRAOAQYNy0nWPSWKuPxXXuIZ1YGl1d1voOYWhZAa9QBusVkTsiaGuI4VQ9lQfOGemUH E2RiNru9EwQfinTIxonqoRMi/R7vqqYnyvb9rLPTm8Nau1r/q5CeltV5XlDlTAFjwfm3 qvQqZSlcaD4nHa2kUVQUFqvqFjqMmY24pceFA0KSMuFnwUgka+k3q89HwC6Sl5A+i+I0 s41aIl4XO8VgikRy8m9qUqOA6NLTwadOZBykpdQfZD13OALzdAvu+uR6vcq6i/WrHKNL m04A== 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=DXOkD+gduxM/YdwT92/i1TULmdG8/7itrkUatyUSM8c=; b=S0rYdlvZ1EFF/zxXJEfNB/4mcJSk/3k6RWM8DUdWlIpRwS2QTWlpFGkImqjAWIEAcT bqS++Z+bSEdOTIWzXlbSq7z7nvChE5Z34kdl6j000NyFv5ckKbZ6Odza7wTdHiWbnqoY Jpan5ga03PXk8sTqYcb8bKv96xK2AAVdzjRmS5jCNvOOpVVeb6eAPcDwXysGrUZzCtoO YYcCaBpKEoeOvpdDdPufmUXPpIrjqWxedwaSd4yPtkB0hydRwLO1L6S86W7U//kPMjGE ckRJAxuAUqx0Vj1mv/JQBERxOMh9VNPkzT6LEgyH3yShQa928UxI8RvPWJMF3kYCHqyr ewlw== X-Gm-Message-State: APt69E2pvKRO67MEHz/Kc34cWSCdUo0FWUb8JkyTND8gSHsyvfhapmbD NHE2JcYo7mCWn5lGdMdHNNeR9ezSHfTtk0JTSh0PNw== X-Google-Smtp-Source: ADUXVKLcS+//Z/ljHr+MMqmWDMHXA2l0o98LECgM+GtKXoNs1ZZ3+GMH+iNJe5W1k09U8kPeprUxaxwRtdYymIbD9Zk= X-Received: by 2002:a62:d9c5:: with SMTP id b66-v6mr1302278pfl.41.1528368179167; Thu, 07 Jun 2018 03:42:59 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a17:90a:ac2:0:0:0:0 with HTTP; Thu, 7 Jun 2018 03:42:58 -0700 (PDT) In-Reply-To: <5B17C5EC.1090602@lab.ntt.co.jp> References: <5ADF12D1.1030406@lab.ntt.co.jp> <5AE1C0D3.5060009@lab.ntt.co.jp> <5AE84FBF.3040905@lab.ntt.co.jp> <5AF2E09F.9060208@lab.ntt.co.jp> <5AF440C2.3040805@lab.ntt.co.jp> <5AF59415.10309@lab.ntt.co.jp> <5AFC0865.8050802@lab.ntt.co.jp> <5AFD6580.5090308@lab.ntt.co.jp> <5AFE81CC.8000508@lab.ntt.co.jp> <5B17C5EC.1090602@lab.ntt.co.jp> From: Ashutosh Bapat Date: Thu, 7 Jun 2018 16:12:58 +0530 Message-ID: Subject: Re: Expression errors with "FOR UPDATE" and postgres_fdw with partition wise join enabled. To: Etsuro Fujita Cc: Rajkumar Raghuwanshi , pgsql-hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Jun 6, 2018 at 5:00 PM, Etsuro Fujita wrote: > (2018/05/18 16:33), Etsuro Fujita wrote: >> >> Other than pull_var_clause things, >> the updated version looks good to me, so I'll mark this as Ready for >> Committer. > > > Since I'm not 100% sure that that is the right way to go, I've been > rethinking how to fix this issue. Yet another idea I came up with to fix > this is to redesign the handling of the tlists for children in the > partitioning case. Currently, we build the reltarget for a child by > applying adjust_appendrel_attrs to the reltarget for its parent in > set_append_rel_size, which maps a wholerow Var referring to the parent rel > to a ConvertRowtypeExpr that translates a wholerow of the child rel into a > wholerow of the parent rel's rowtype. This works well for the > non-partitioned inheritance case, but makes complicated the code for > handling the partitioning case especially when planning partitionwise-joins. > And I think this would be the root cause of this issue. Although true, this is not only about targetlist. Even the whole-row expressions in the conditions, equivalence classes and other planner/optimizer data structures are translated to ConvertRowtypeExpr. > I don't think the > tlists for the children need to have their wholerows transformed into the > corresponding ConvertRowtypeExprs *at this point*, so what I'd like to > propose is to 1) map a parent wholerow Var simply to a child wholerow Var, > instead (otherwise, the same as adjust_appendrel_attrs), when building the > reltarget for a child in set_append_rel_size, 2) build the tlists for child > joins using those children's wholerow Vars at path creation time, and 3) > adjust those wholerow Vars in the tlists for subpaths in the chosen > AppendPath so that those are transformed into the corresponding > ConvertRowtypeExprs, at plan creation time (ie, in > create_append_plan/create_merge_append_plan). IIUC, this would not require > any changes to pull_var_clause as proposed by the patch. This would not > require any changes to postgres_fdw as proposed by the patch, either. In > addition, this would make unnecessary the code added to setrefs.c by the > partitionwise-join patch. Maybe I'm missing something though. Not translating whole-row expressions to ConvertRowtypeExpr before creating paths can lead to a number of anomalies. For example, 1. if there's an index on the whole-row expression of child, translating parent's whole-row expression to child's whole-row expression as is will lead to using that index, when in reality the it can not be used since the condition/ORDER BY clause (which originally referred the parent's whole-row expression) require the child's whole-row reassembled as parent's whole-row. 2. Constraints on child'd whole-row expression, will be used to prune a child when they can not be used since the original condition was on parent' whole-row expression and not that of the child. 3. Equivalence classes will think that a child whole-row expression (without ConvertRowtypeExpr) is equivalent to an expression which is part of the same equivalence class as the parent' whole-row expression. Given these serious problems, I don't think we could afford not to cover a child whole-row reference in ConvertRowtypeExpr. -- Best Wishes, Ashutosh Bapat EnterpriseDB Corporation The Postgres Database Company