Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f4BmI-00031e-SR for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Apr 2018 20:46:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f4BmH-00010I-BB for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Apr 2018 20:46:37 +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 1f4BmG-000108-S8 for pgsql-hackers@lists.postgresql.org; Thu, 05 Apr 2018 20:46:37 +0000 Received: from mail-wr0-x229.google.com ([2a00:1450:400c:c0c::229]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1f4BmC-0007lm-Rb for pgsql-hackers@postgresql.org; Thu, 05 Apr 2018 20:46:35 +0000 Received: by mail-wr0-x229.google.com with SMTP id l49so30543585wrl.4 for ; Thu, 05 Apr 2018 13:46:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=M/MYU8vD4dsbTzWaI/z4crKDmbypT305L3oKcXlMI44=; b=rdXn6n4bIG8+/BgmX0xHZ3ab/bvvuNBOtTZzDle+fawv+GYYZcazyIxvkZ3bJBR0s9 OBRf9x5lPH2o/le9cNKlfZzZgOHnXSq5IbSwnnIG/pmFY47okKQsWoiZNNr/lQbKOpv9 j1uIaHlJdywsHg7Zh/PmCw8SEtbfmk9PNg9eqcZUsKN27LqLPS8mUVLH4ni7P3K36E0f nGP9H/Rt5qUQgDctb3Iid9qisa7m1WHzDBKW2NtVTXxBMPiXYUxGMECeIGsNPINlu8d8 BNRkHqSnQ26kcBOT+KqUDjVxnul5l3W31vB+nFrXj60HhjoAMGXCBuiLwVIBfzhfp38I yCpQ== 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=M/MYU8vD4dsbTzWaI/z4crKDmbypT305L3oKcXlMI44=; b=M0II0hbkPpPrlgBMrWgAw/O3ZvfUHkAowxrpy8y50g6zNHpW0opg2ileqo3GMIgmil ZaKol2gd4WzzBEDosI1A55bBOeLTrDdB7dTm5IIF5vv9Tut6jTzI7e23XWWMX3DD6SAK TVLinCOkjGPDpv1RiEAESyg5WlWiicZEMLiWSEhIDZ4utPYHZuYM80R2eavdCz71eHAu 12Ck93hyKg/I0mXF2tlTWF7LaaTs1LxNiDs71TpqK4RM5ZsvZb71STzzx+gspQd0Ekjv 6JSyswW8hcop4Q3q3dv2MZFhs9+WBwe0wyHFyoqv7iwBCj2tE892Mfv4Cpoyij3J8D6W /SBA== X-Gm-Message-State: AElRT7EToS/e6Ks14IPEMTcA+VaP6uQp8UMYNGAviuTeK+HNH6njgihM Q2bT81c/4fnDQJ+MzhhMTDqeGFBUSsju4VZeCDK2AxxUuhPAU0eXSW6Ta2Rvna8Osod9yi+cHLK QpPPgYYlfinh2dL28ILf/lhIoyxlJXw6PSXm7Q8tKxH61Mg7i4XB37TXlrsA4O7GPjP4N9WLc2i sqK6DInoeAiSA= X-Google-Smtp-Source: AIpwx481i8fXCVDAgMwVMfPZwjoEfacY84+Q82TQNRAowM41r1VouIKrRfN/o1mwaFXADrZzuI69fw== X-Received: by 10.223.136.183 with SMTP id f52mr15891623wrf.74.1522961190453; Thu, 05 Apr 2018 13:46:30 -0700 (PDT) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id k11sm9978017wmi.35.2018.04.05.13.46.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Apr 2018 13:46:29 -0700 (PDT) Subject: Re: Parallel Aggregates for string_agg and array_agg To: Tels , David Rowley Cc: Tom Lane , Stephen Frost , Andres Freund , PostgreSQL-development References: <6538.1522096067@sss.pgh.pa.us> <25812.1522108164@sss.pgh.pa.us> <19216.1522207699@sss.pgh.pa.us> <18741.1522245278@sss.pgh.pa.us> <1ffa699d-ff84-4c21-10cb-4d8b36017bab@2ndquadrant.com> <13e3fd13-8152-72be-4e3c-8095e6ec0995@2ndquadrant.com> <73ea70fa-9ada-deb5-549e-02fa2f0969c6@2ndquadrant.com> From: Tomas Vondra Message-ID: Date: Thu, 5 Apr 2018 22:46:26 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 04/05/2018 09:10 PM, Tels wrote: > Moin, > > On Wed, April 4, 2018 11:41 pm, David Rowley wrote: >> Hi Tomas, >> >> Thanks for taking another look. >> >> On 5 April 2018 at 07:12, Tomas Vondra >> wrote: >>> Other than that, the patch seems fine to me, and it's already marked as >>> RFC so I'll leave it at that. >> >> Thanks. > > I have one more comment - sorry for not writing sooner, the flu got to me ... > > Somewhere in the code there is a new allocation of memory when the string > grows beyond the current size - and that doubles the size. This can lead > to a lot of wasted space (think: constructing a string that is a bit over > 1 Gbyte, which would presumable allocate 2 GByte). > I don't think we support memory chunks above 1GB, so that's likely going to fail anyway. See #define MaxAllocSize ((Size) 0x3fffffff) /* 1 gigabyte - 1 */ #define AllocSizeIsValid(size) ((Size) (size) <= MaxAllocSize) But I get your point - we may be wasting space here. But that's hardly something this patch should mess with - that's a more generic allocation question. > The same issue happens when each worker allocated 512 MByte for a 256 > Mbyte + 1 result. > > IMHO a factor of like 1.4 or 1.2 would work better here - not sure what > the current standard in situations like this in PG is. > With a 2x scale factor, we only waste 25% of the space on average. Consider that you're growing because you've reached the current size, and you double the size - say, from 1MB to 2MB. But the 1MB wasted space is the worst case - in reality we'll use something between 1MB and 2MB, so 1.5MB on average. At which point we've wasted just 0.5MB, i.e. 25%. That sounds perfectly reasonable to me. Lower factor would be more expensive in terms of repalloc, for example. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services