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 1flaO4-0003UJ-QF for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Aug 2018 13:45:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1flaO3-0007Ag-4O for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Aug 2018 13:44:59 +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_SHA384:256) (Exim 4.89) (envelope-from ) id 1flaO2-0007AY-Qw for pgsql-hackers@lists.postgresql.org; Fri, 03 Aug 2018 13:44:58 +0000 Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1flaNz-0005ax-Ac for pgsql-hackers@postgresql.org; Fri, 03 Aug 2018 13:44:58 +0000 Received: by mail-lj1-x242.google.com with SMTP id s12-v6so5016992ljj.0 for ; Fri, 03 Aug 2018 06:44:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=jvI1BTDetTG//qQxVG5he8ebaqPoEabadcKjmx2DalA=; b=cf9F5j0Jq+6Ft/WvlIEL+KCDIPv6uiJWxs9Au25Kf6kJsmxGLrl33qMRXoNKN2Fdhr 8rhc5mVVg05F2YBoKlkKivnIWF0WSxb8aT/fBtGZK8yx2iOzfs/JfplrRlKsOS6hdIWm 6q0gnldAtNrpCvDZsTyOFXapad44PbDDDJfECFTivcgKuw3TAYvndT/cFPd+HkrHuJ67 2gjuLjxNWj5jrP6q1dv9WulyApPCpUjj9XuKqTbQ+1RBgT6Xz5QrCsL9qqQhEZTeNaRU 3cqf1IHqKLW4/Pr0AAJmPgZFdPqm0SHyNXPRSa930xcXAQGTDQJZ2b47DY0SWUIcczaU OFhA== 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=jvI1BTDetTG//qQxVG5he8ebaqPoEabadcKjmx2DalA=; b=mdRNSVahyw4eQvbnJ+yMvEOUlL3GPDU120S8gCm7GfPX0tTTqzdogHONsMuPQtE3tG 7CoSxcNLBioIAegIYNLqq2W/mueYZzKZ6M6/SpaDRzRfzxU/X08R2Rg7t/4uz4CzxySZ InQ4KFH4VGlqTOxX4JOvyPqnXI1H8/GyGV3Gnq1SQdf9NZfQwqkbKsFgiMVEpizSy1N5 Hjmy0K0jggM6kFMJ6z+tn9Zs74Sp7kjjwqVs0LX75hwpVIztf1nr0ot6/gFSSAduxshn rBeYaaXQsvhXCMPnEVZrA8LUzRS/OdMjXXIEJ4k5a4tMs4TPa6MYk/j7+KIfEqNDQYgt B2Tg== X-Gm-Message-State: AOUpUlG+1azQ9jOBMRbT9IsJ4MM88S7K9slm6tmTL3Oi2OFDstk6yOqt U4ssqSP6aFtS0R2tr1knd836WrPzv8kW5/cyCBE= X-Google-Smtp-Source: AAOMgpdaqc3tLSgcOJcdcpjN9e25H1lUfFpS+M16xoIQJsviZNNQzf9DHHyqkETh8zKiD9A94PEaF56hPleC0VDgbFw= X-Received: by 2002:a2e:5bc8:: with SMTP id m69-v6mr5955510lje.115.1533303893334; Fri, 03 Aug 2018 06:44:53 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a19:e508:0:0:0:0:0 with HTTP; Fri, 3 Aug 2018 06:44:52 -0700 (PDT) In-Reply-To: <5358.1533241519@sss.pgh.pa.us> References: <5AFC0865.8050802@lab.ntt.co.jp> <5AFD6580.5090308@lab.ntt.co.jp> <5AFE81CC.8000508@lab.ntt.co.jp> <5B17C5EC.1090602@lab.ntt.co.jp> <5B1E5071.1000704@lab.ntt.co.jp> <5B23A964.9020800@lab.ntt.co.jp> <5B28FB19.3090809@lab.ntt.co.jp> <20180703163519.tsigyic5xefunv74@alap3.anarazel.de> <5B3C2A4E.5030901@lab.ntt.co.jp> <5B4F2BE9.3000304@lab.ntt.co.jp> <5B55886F.5090906@lab.ntt.co.jp> <5B5712C8.9030404@lab.ntt.co.jp> <5B59BA55.30200@lab.ntt.co.jp> <5B619D23.4010000@lab.ntt.co.jp> <5358.1533241519@sss.pgh.pa.us> From: Robert Haas Date: Fri, 3 Aug 2018 09:44:52 -0400 Message-ID: Subject: Re: Expression errors with "FOR UPDATE" and postgres_fdw with partition wise join enabled. To: Tom Lane Cc: Etsuro Fujita , Andres Freund , Ashutosh Bapat , 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 Thu, Aug 2, 2018 at 4:25 PM, Tom Lane wrote: > I do not trust Ashutosh's patch because of the point you noted that it > will kick in on ConvertRowtypeExprs that are not related to partitioning. I don't remember making that point -- can you clarify? > It's also got a rather fundamental conceptual (or at least documentation) > error in that it says it's making pull_var_clause do certain things to > all ConvertRowtypeExprs, but that's not what the code actually does. > I think the tension around that has a lot to do with the fact that the > patch went through so many revisions, and I don't have any faith that > it's right even yet. As you mentioned upthread, this might be insoluble > without some representational change for converted whole-row Vars. Insoluble is a strong word.... > What I'm thinking might be a more appropriate thing, at least for > getting v11 out the door, is to refuse to generate partitionwise > joins when any whole-row vars are involved. (Perhaps that's not > enough to dodge all the problems, though?) It's enough to dodge the problem being discussed on this thread. > Now, that's a bit of a problem for postgres_fdw, because it seems to > insist on injecting WRVs even when the query text does not require any. > Why is that, and can't we get rid of it? It's horrid for performance > even without any of these other considerations. But if we fail to get > rid of that in time for v11, it would mean that postgres_fdw can't > participate in PWJ, which isn't great but I think we could live with it > for now. I don't quite know what you mean here -- postgres_fdw does use whole-row vars for EPQ handling, which may be what you're thinking about. > BTW, what exactly do we think the production status of PWJ is, anyway? > I notice that upthread it was stated that enable_partitionwise_join > defaults to off, as indeed it still does, and we'd turn it on later > when we'd gotten rid of some memory-hogging problems. If that hasn't > happened yet (and I don't see any open item about considering enabling > PWJ by default for v11), then I have exactly no hesitation about > lobotomizing PWJ as hard as we need to to mask this problem for v11. > I'd certainly prefer a solution along those lines to either of these > patches. Yeah, that hasn't been done yet. Partition-wise join probably needs a good bit of work in a number of areas to do all the things that people will want it to do -- see the thread on advanced partition-matching, which is an improvement but still doesn't cover every case that could come up. In terms of memory usage, I think that we need some discussion of the approach that should be taken. I see a couple of possible things we could do, not necessarily mutually exclusive. 1. We could try to avoid translating all of the parent's data structures for every child RelOptInfo, either by rejiggering things so that the child doesn't need all of that data, or by making it able to use the parent's copy of the data. 2. We could try to recycle memory more quickly. For example, if we're planning a partition-wise join of A-B-C-D, first plan paths for A1-B1-C1-D1 (and all proper subsets of those rels), then throw away most of the memory, then plan paths for A2-B2-C2-D2, etc. 3. We could generate paths for on "representative" children (e.g. the biggest ones) and use that to estimate the cost of the partition-wise plan. If that plan is selected, then go back and figure out real paths for the other children. All of these things help in different ways, and Ashutosh had code for some version of all of them at various points, but the problem is quite difficult. If you have three tables with 1000 partitions each, then without partition-wise join you need 3000 (partitions) + 3 (baserels) + 3 (level-2 joinrels) + 1 (level-3 joinrel) RelOptInfos. If you do a partition-wise join, then you get 3000 level-2 child-joinrels and 1000 level-3 child joinrels. Those RelOptInfo structures, and the paths attached to them, cannot help but take up memory. Perhaps that's OK, and we ought to just say "well, if you want better plans, you're going to have to allow more memory for planning". If not, we have to decide how hard we want to work in which areas and how good the result needs to be in order to have this turned on by difficult. Honestly, I'm pretty impressed that we have added not one but two members to the RelOptKind enum without as little collateral damage as there has been. This issue is annoying and the discussion has gone on longer than anyone would probably prefer, but it's really pretty minor in the grand scheme of things, at least IMHO. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company