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 1hsXev-00077R-8Z for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Jul 2019 19:19:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hsXeu-0000Ou-2P for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Jul 2019 19:19:40 +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 1hsXet-0000Ol-Ob for pgsql-hackers@lists.postgresql.org; Tue, 30 Jul 2019 19:19:39 +0000 Received: from mail-lj1-f194.google.com ([209.85.208.194]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hsXer-0008Br-Oo for pgsql-hackers@postgresql.org; Tue, 30 Jul 2019 19:19:39 +0000 Received: by mail-lj1-f194.google.com with SMTP id k18so63135587ljc.11 for ; Tue, 30 Jul 2019 12:19:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ZdJfx8LA9VjRbyXOEytUcKcu8j/bXdZ6iWklX84IYCQ=; b=GSk19gkbN2XXvGkkXBLg47ORTy9jDbMvf4SU2ocFC1EZaY4nCkxj4YQyQhMqPxz+C9 d1IzMorrr/3zt2Qnjyx5/20tXxnjvDEE5EQCuLGaDkrDRvUnBUe8qC8d/oj0/R+Lq9je Oh7eNjY4z921Ze0idtUOVTQ+e91KV+iwbRQjQBgE4kPs1n/vrpl9oGw8xaIjfZgskKpW d5aX/BU00FtW+PzVv5+A7OurKApOa+Lv1z49h6qmdWiO4EwZU6NMumg3I+LhiMXUs7Ym pHbEyy0t5hQAOGOI4JLKC5DGCbezKKmZSENmbMg+ybY5Q5VVPdTxIblQ4NS+D7YcTH+1 O+Iw== X-Gm-Message-State: APjAAAU37hyA25x2sRyRKyeDrS8b5XrvizmIIGxtp5kFgiL/HK89UhrX F0OvcSMAnQZjkQttLfw6wBrvMMfvTJI= X-Google-Smtp-Source: APXvYqwdYxmZ5GldXllkN0zL/knlKycbE84cLnmkIm7IJj4sdb+16UeO/gbdtGKmS9akFW7iUBBL2g== X-Received: by 2002:a2e:8681:: with SMTP id l1mr13849138lji.166.1564514376785; Tue, 30 Jul 2019 12:19:36 -0700 (PDT) Received: from ?IPv6:2a00:5500:80f5:1900::c32? ([2a00:5500:80f5:1900::c32]) by smtp.gmail.com with ESMTPSA id j23sm11423917lfb.93.2019.07.30.12.19.35 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Tue, 30 Jul 2019 12:19:36 -0700 (PDT) Subject: Re: Allow table AM's to cache stuff in relcache To: Julien Rouhaud Cc: Tom Lane , pgsql-hackers References: <28934.1560526836@sss.pgh.pa.us> From: Heikki Linnakangas Message-ID: Date: Tue, 30 Jul 2019 22:19:34 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 12/07/2019 16:07, Julien Rouhaud wrote: > On Fri, Jun 14, 2019 at 5:40 PM Tom Lane wrote: >> Heikki Linnakangas writes: >>> In the patch, I documented that rd_amcache must be allocated in >>> CacheMemoryContext, or in rd_indexcxt if it's an index. It works, but >>> it's a bit weird. >> >> Given the way the patch is implemented, it doesn't really matter which >> context it's in, does it? The retail pfree is inessential but also >> harmless, if rd_amcache is in rd_indexcxt. So we could take out the >> "must". I think it's slightly preferable to use rd_indexcxt if available, >> to reduce the amount of loose junk in CacheMemoryContext. > > I agree that for indexes the context used won't make much difference. > But IMHO avoiding some bloat in CacheMemoryContext is a good enough > reason to document using rd_indexcxt when available. Right, it doesn't really matter whether an index AM uses CacheMemoryContext or rd_indexctx, the code works either way. I think it's better to give clear advice though, one way or another. Otherwise, different index AM's can end up doing it differently for no particular reason, which seems confusing. >>> It would nice to have one memory context in every >>> relcache entry, to hold all the stuff related to it, including >>> rd_amcache. In other words, it would be nice if we had "rd_indexcxt" for >>> tables, too, not just indexes. That would allow tracking memory usage >>> more accurately, if you're debugging an out of memory situation for example. >> >> We had some discussion related to that in the "hyrax >> vs. RelationBuildPartitionDesc" thread. I'm not quite sure where >> we'll settle on that, but some redesign seems inevitable. > > There wasn't any progress on this since last month, and this patch > won't make the situation any worse. I'll mark this patch as ready for > committer, as it may save some time for people working on custom table > AM. Pushed, thanks for the review! As Tom noted, some redesign here seems inevitable, but this patch shouldn't get in the way of that, so no need to hold this back for the redesign. - Heikki