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 1qGoCm-0001D3-6f for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Jul 2023 22:09:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qGoCj-0001Lk-3q for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Jul 2023 22:09:01 +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 1qGoCi-0001La-QW for pgsql-hackers@lists.postgresql.org; Tue, 04 Jul 2023 22:09:00 +0000 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qGoCe-002E2c-Vg for pgsql-hackers@lists.postgresql.org; Tue, 04 Jul 2023 22:08:59 +0000 Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-992f15c36fcso558318866b.3 for ; Tue, 04 Jul 2023 15:08:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1688508534; x=1691100534; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=n0WwWUUio+RyWZn6PLSN1fXK6wZ1KfdnDCh+bnPfzHQ=; b=bTFOhKcs0aoLAnemeUNNPubCD8Ae2xT4qG5fwku7Gimi+/qO4Jt5N8NIptGb7vizYO TPvTMZ3EpplwwGnOtDJSc8C9fK+Fvl7Gz6sHl9yzKcBMTRLhb2dlA0ePRNRTdLq5sGs1 bsilEkhpQkeepCfU93+JxSyk8oL0/oZ6TEw2DX64zxuXpTEDNt48MB9P61zwPehSuaiG vuXsmdiQLlk50uEfsKvbkomW9FPxiH9snKyBtniUm9aDkJjypUe6Krq3nBoa9id9lIYx VAmKXJDxrM+PPwEOrxgYDJWYlx4ouALZBHFDQiEDt/qIgbogCHeqNWMDzqea7Gkhe/dF /lSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688508534; x=1691100534; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=n0WwWUUio+RyWZn6PLSN1fXK6wZ1KfdnDCh+bnPfzHQ=; b=eaZJfqQKgqW7iE4T/XbnamgeRlkEhR48UB0F9SbB1xHqxRhohEa0VUnPU3kyJ/ZLx9 T6wBGMIXaSqMHuoOUQf5tEXchVxO07pT17o4ED2viY2W39UI+OElUvqurQmRE5Ysk4jJ AcdARR7VhReV4+8j3e/6uOavMS6U3hpdv+FLKWV4MCRT7p7o4L9mj/6mnhmNs/lIZMDy gWSBRdm8KoE4/nG4QW9LYyasHobYS9vJ9xU8nsA9TD3xJo6n4rtcvfKQAuNXDR5CAHN6 ieh0FiL/r0XmPx7IBnM9OxSugIrxKAyNYPmDD1B40l5mMRWpp4GimT0A0rcpDC9hfjmW xZ8w== X-Gm-Message-State: ABy/qLYmLIAY5jfDSW+AQ7QSV5DeGlZ58VCIydehe0vIwiGC/+wmRK0M HHYulS+cppeefVOglz514UAYjQ== X-Google-Smtp-Source: APBJJlGPwjo0cr7+vKalAPM5x9gv6GF7aq0E64aHjoittuQBN1+OXZzvj6fQCbQaPcBHAp+LzMF61Q== X-Received: by 2002:a17:906:e58:b0:992:b3a3:81f9 with SMTP id q24-20020a1709060e5800b00992b3a381f9mr8699537eji.71.1688508534316; Tue, 04 Jul 2023 15:08:54 -0700 (PDT) Received: from [10.137.0.17] (ip-86-49-228-220.bb.vodafone.cz. [86.49.228.220]) by smtp.gmail.com with ESMTPSA id kf24-20020a17090776d800b00977cad140a8sm13760905ejc.218.2023.07.04.15.08.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Jul 2023 15:08:53 -0700 (PDT) Message-ID: Date: Wed, 5 Jul 2023 00:08:52 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: Parallel CREATE INDEX for BRIN indexes Content-Language: en-US To: Matthias van de Meent Cc: PostgreSQL Hackers References: From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/4/23 23:53, Matthias van de Meent wrote: > On Thu, 8 Jun 2023 at 14:55, Tomas Vondra wrote: >> >> Hi, >> >> Here's a WIP patch allowing parallel CREATE INDEX for BRIN indexes. The >> infrastructure (starting workers etc.) is "inspired" by the BTREE code >> (i.e. copied from that and massaged a bit to call brin stuff). > > Nice work. > >> In both cases _brin_end_parallel then reads the summaries from worker >> files, and adds them into the index. In 0001 this is fairly simple, >> although we could do one more improvement and sort the ranges by range >> start to make the index nicer (and possibly a bit more efficient). This >> should be simple, because the per-worker results are already sorted like >> that (so a merge sort in _brin_end_parallel would be enough). > > I see that you manually built the passing and sorting of tuples > between workers, but can't we use the parallel tuplesort > infrastructure for that? It already has similar features in place and > improves code commonality. > Maybe. I wasn't that familiar with what parallel tuplesort can and can't do, and the little I knew I managed to forget since I wrote this patch. Which similar features do you have in mind? The workers are producing the results in "start_block" order, so if they pass that to the leader, it probably can do the usual merge sort. >> For 0002 it's a bit more complicated, because with a single parallel >> scan brinbuildCallbackParallel can't decide if a range is assigned to a >> different worker or empty. And we want to generate summaries for empty >> ranges in the index. We could either skip such range during index build, >> and then add empty summaries in _brin_end_parallel (if needed), or add >> them and then merge them using "union". >> >> >> I just realized there's a third option to do this - we could just do >> regular parallel scan (with no particular regard to pagesPerRange), and >> then do "union" when merging results from workers. It doesn't require >> the sequence of TID scans, and the union would also handle the empty >> ranges. The per-worker results might be much larger, though, because >> each worker might produce up to the "full" BRIN index. > > Would it be too much effort to add a 'min_chunk_size' argument to > table_beginscan_parallel (or ParallelTableScanDesc) that defines the > minimum granularity of block ranges to be assigned to each process? I > think that would be the most elegant solution that would require > relatively little effort: table_block_parallelscan_nextpage already > does parallel management of multiple chunk sizes, and I think this > modification would fit quite well in that code. > I'm confused. Isn't that pretty much exactly what 0002 does? I mean, that passes pagesPerRange to table_parallelscan_initialize(), so that each pagesPerRange is assigned to a single worker. The trouble I described above is that the scan returns tuples, and the consumer has no idea what was the chunk size or how many other workers are there. Imagine you get a tuple from block 1, and then a tuple from block 1000. Does that mean that the blocks in between are empty or that they were processed by some other worker? regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company