Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r80Cl-007mKi-TW for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Nov 2023 15:40:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r80Bl-005som-W5 for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Nov 2023 15:39:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r80Bl-005sod-Lu for pgsql-hackers@lists.postgresql.org; Tue, 28 Nov 2023 15:39:53 +0000 Received: from mail-lj1-x229.google.com ([2a00:1450:4864:20::229]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r80Bh-0090HS-23 for pgsql-hackers@lists.postgresql.org; Tue, 28 Nov 2023 15:39:53 +0000 Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2c87adce180so69023561fa.0 for ; Tue, 28 Nov 2023 07:39:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701185987; x=1701790787; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ASsvcv7roa7hIpfxHAu9t9Mzwae7nZpIn0tKBJ/o3J8=; b=idJQmr9q2QYNbDhzlAFtndLybFjTw5VVs9HmbtDJgxdBcuku5MPeEJ3QWLWrCBBCl/ ExPlwFEg3cNqPAUUObqX+TUKuwH6lonP0w4QW0/0Ge7Hlohp+WXd4oZHVznd67CbBDMG /UnZaBoW0wOkfIR0nhWI3oUQA6qq+grtqg7wPEBovuMnBV0xiogb0dYqaUD2WexUFGMb 8kMqv3YwpajCfMQnuPsMgu+itkZmJmox1a9DMm839YFLNcw4Jm/+eoBV7opcUGIb5ure gefM9FGXPsSswmPkY/86GLBWjInTxSP8WG11zW1SBF/2bb8Ct0JRhRTQgNOId+l+l709 WIsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701185987; x=1701790787; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ASsvcv7roa7hIpfxHAu9t9Mzwae7nZpIn0tKBJ/o3J8=; b=wm83lPvz5QO787jkpPiEe4XVLu/f9tFJGkc7WTlkVEOIp6oleH6Zugy3GxnxtfYIql rJ5t4t8ylJp9Pdzzu8H5FpJoLYXWbanx7eCaXao1K3W+l0K4RPa6AUnIySykbs6yEfhI qtngXqtDSqflLECbHZRPgQDDf8KNtwP9KEnE2ljDeJitD3qg1vwdXCY30imQEaCfJ4O/ quqrjXM9ikc8MVjFltRGUd75L6jMAx//8BgN/iozh87y/iXJTScB3IYF8JXFp9eYIZpq SN5TVjJx47K7ZnKwhsvkr1FitFSkDbMnlak/mEJ8DQERDRERv5DGJzt0MnoOebyB/GBd HHwQ== X-Gm-Message-State: AOJu0YzAPXwF7OoPfxEGdND5szPo2AM85Q+7d8HJwyUSZd5j3u4meANH RCxgOEQ8Mx7jgskS163cL+4EVWxjSrzRr4K2zAA13LYA9M8= X-Google-Smtp-Source: AGHT+IF+GMUTdguB7+rQGolMNMo6pP+OYYGOqmUZdIM6xaWnvNKH48vb5XxpS/HJOGXq1ZoDSQ8K8wwsGQFSpF98EtE= X-Received: by 2002:a2e:87c8:0:b0:2c9:b8b4:8499 with SMTP id v8-20020a2e87c8000000b002c9b8b48499mr994358ljj.29.1701185986729; Tue, 28 Nov 2023 07:39:46 -0800 (PST) MIME-Version: 1.0 References: <2d7c64de-716e-346e-b01e-03db0c2bc5ac@enterprisedb.com> <2e86059f-4004-eec1-2bc1-9e7fd119c9e2@enterprisedb.com> <5384d42e-1961-c2fd-1955-1a5a99fa1234@enterprisedb.com> In-Reply-To: <5384d42e-1961-c2fd-1955-1a5a99fa1234@enterprisedb.com> From: Matthias van de Meent Date: Tue, 28 Nov 2023 16:39:33 +0100 Message-ID: Subject: Re: Parallel CREATE INDEX for BRIN indexes To: Tomas Vondra Cc: PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 23 Nov 2023 at 14:35, Tomas Vondra wrote: > On 11/23/23 13:33, Matthias van de Meent wrote: >> The union operator may leak (lots of) memory, so I think it makes >> sense to keep a context around that can be reset after we've extracted >> the merge result. >> > > But does the current code actually achieve that? It does create a "brin > union" context, but then it only does this: > > /* Use our own memory context to avoid retail pfree */ > cxt = AllocSetContextCreate(CurrentMemoryContext, > "brin union", > ALLOCSET_DEFAULT_SIZES); > oldcxt = MemoryContextSwitchTo(cxt); > db = brin_deform_tuple(bdesc, b, NULL); > MemoryContextSwitchTo(oldcxt); > > Surely that does not limit the amount of memory used by the actual union > functions in any way? Oh, yes, of course. For some reason I thought that covered the calls to the union operator function too, but it indeed only covers deserialization. I do think it is still worthwhile to not do the create/delete cycle, but won't hold the patch back for that. >>> However, I don't think the number of union_tuples calls is likely to be >>> very high, especially for large tables. Because we split the table into >>> 2048 chunks, and then cap the chunk size by 8192. For large tables >>> (where this matters) we're likely close to 8192. >> >> I agree that the merging part of the index creation is the last part, >> and usually has no high impact on the total performance of the reindex >> operation, but in memory-constrained environments releasing and then >> requesting the same chunk of memory over and over again just isn't >> great. > > OK, I'll take a look at the scratch context you suggested. > > My point however was we won't actually do that very often, because on > large tables the BRIN ranges are likely smaller than the parallel scan > chunk size, so few overlaps. OTOH if the table is small, or if the BRIN > ranges are large, there'll be few of them. That's true, so maybe I'm concerned about something that amounts to only marginal gains. I noticed that the v4 patch doesn't yet update the documentation in indexam.sgml with am->amcanbuildparallel. Once that is included and reviewed I think this will be ready, unless you want to address any of my comments upthread (that I marked with 'not in this patch') in this patch. Kind regards, Matthias van de Meent Neon (https://neon.tech)