Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nMxBB-0006ZW-Fo for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Feb 2022 19:20:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nMxBA-0001tg-AE for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Feb 2022 19:20:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nMxBA-0001tX-0s for pgsql-hackers@lists.postgresql.org; Wed, 23 Feb 2022 19:20:00 +0000 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nMxB6-0001ZQ-52 for pgsql-hackers@lists.postgresql.org; Wed, 23 Feb 2022 19:19:59 +0000 Received: by mail-ed1-x535.google.com with SMTP id m3so39812422eda.10 for ; Wed, 23 Feb 2022 11:19:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=Fb0/C6utv7BDOjOvpQ6sUw/qwU5uBUVNLhnk7GSMWI8=; b=FZcs9s53qsNzzy04m66U8eEu7M7tEpb98aLapzzRBEzvvKakOIPP299HEr9KCoB/ia Lly908ImAjmz+bZnL4Gp8nQi8sh5nIZB+j748pz1RKtsepAA3a08fow0PKJIeNyUNQPj WbzazaAfeWSiY3PYrHmqZM3tKPbmJQxIYEYTitR3rzQSSw7jmJfL+DCQJZ0VpHZM2VsC rWPnF4sXdHmw+RXMFE+X6A0jGXOVmXR2rneghFQOiw864d6LlT7Mp5MjLYkgFhgpygaf f9YI9rx5zp4KwfatLsUK425Q2Wsq6+KnQlBgf2U3hubrRGR3T3BYdtjTO2jtw+T1F/bf sJrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=Fb0/C6utv7BDOjOvpQ6sUw/qwU5uBUVNLhnk7GSMWI8=; b=ZKQsiPslVFnfRuLidasbN2a77WKizutK/CQNl+CEe0SLzSGVZ0o3mA7dwZKIQ0aI2o tefJNuy8txIOoZCCv97hEjnWf5oBp8BPrt4NYOqcSOzukBxjEbYuasPd1U979imGUNlU pdSm328Mgj9hMKSlKrC41zFhVz5cbp5ykPI/NhqaoTnYE891+/9sSlFK1qcT6tY3O6/z wEH9TxcpgP0Cgduu52gKU+y1uoGz3qVFg4MuFMgyfhyR9JiyNn4/BYeLM0swmNqjgrXi CcRmnpEtNbnHsLEYR9D6OykijeA3j8z2HHCLXNQK2ZElViCmXJ/tIAOpuoqQloQwhc6q UdBw== X-Gm-Message-State: AOAM531EJXslS8SHYh2t/IR3sHBfbhOT1NRbKqwxgtaDrXryEb0d3qX2 ZBja8bbx0vZovs8bx5cPe+suBdrKGjiIQF+3J9j+7pGiDM9R65RQl/yY7orAgvBMaAjrZ6pip7N +mvwrLqdZ7UcXtvAEyV8TvSmJczGIkBs6WX86O+EkZfTuj9bW0ny047+voPYgUZZcs6EaRSwNez rHVxI/na1eH5nv94ia7sCJyHH5MgqQg1GJyM+dezgy3khDU+qj59uH X-Google-Smtp-Source: ABdhPJx8gZGKOyD1j+K9Hl6OEqfndj6aqXGt0yuGkKT/vP1ya4VVTvYh2U3Eua4jbX8Hofrn8A4Y7A== X-Received: by 2002:a05:6402:349:b0:410:a0bd:35ad with SMTP id r9-20020a056402034900b00410a0bd35admr902255edw.12.1645643994325; Wed, 23 Feb 2022 11:19:54 -0800 (PST) Received: from [10.137.0.19] (ip-86-49-251-241.net.upcbroadband.cz. [86.49.251.241]) by smtp.gmail.com with ESMTPSA id fx4sm203087ejb.221.2022.02.23.11.19.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 23 Feb 2022 11:19:53 -0800 (PST) Message-ID: <6043f5db-d9b1-5fcd-a713-a7ac71fa6fe1@enterprisedb.com> Date: Wed, 23 Feb 2022 20:19:52 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: Use generation context to speed up tuplesorts Content-Language: en-US To: Andres Freund , David Rowley Cc: Ronan Dunklau , Julien Rouhaud , PostgreSQL Developers , Tomas Vondra References: <20220118064539.o3gc257z2vavb66e@jrouhaud> <4377612.LvFx2qVVIh@aivenronan> <20220223022504.3ghth7eckjnnubxa@alap3.anarazel.de> From: Tomas Vondra In-Reply-To: <20220223022504.3ghth7eckjnnubxa@alap3.anarazel.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2/23/22 03:25, Andres Freund wrote: > Hi, > > On 2022-02-18 12:10:51 +1300, David Rowley wrote: >> The other way I thought to fix it was by changing the logic for when >> generation blocks are freed. In the problem case mentioned above, the >> block being freed is the current block (which was just allocated). I >> made some changes to adjust this behaviour so that we no longer free >> the block when the final chunk is pfree()'d. Instead, that now lingers >> and can be reused by future allocations, providing they fit inside it. > > That makes sense to me, as long as we keep just one such block. > > >> The problem I see with this method is that there still could be some >> pathological case that causes us to end up storing just a single tuple per >> generation block. > > Crazy idea: Detect the situation, and recompact. Create a new context, copy > all the tuples over, delete the old context. That could be a win even in less > adversarial situations than "a single tuple per generation block". > What about pointers to the chunks in the old memory context? regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company