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 1s50yA-002bkz-Jw for pgsql-hackers@arkaria.postgresql.org; Thu, 09 May 2024 10:25:46 +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 1s50y8-0069PP-R3 for pgsql-hackers@arkaria.postgresql.org; Thu, 09 May 2024 10:25:45 +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 1s50y8-0069Ow-HH for pgsql-hackers@lists.postgresql.org; Thu, 09 May 2024 10:25:44 +0000 Received: from m16.mail.163.com ([220.197.31.3]) by magus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1s50y3-000AVm-8V for pgsql-hackers@lists.postgresql.org; Thu, 09 May 2024 10:25:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version: Content-Type; bh=Tz+njzWoz6yRUAw4PJZp8W59ErlD5QsiTe8KB4EkWt0=; b=mz3jqxAkv4WuTUDAlj6Yr8m2xi27b3gKijtEoOubk2+zn7yO3ooyszfEppdMGY FQ39BloE2nHgwevO952++XsqkW4WFvL4RBysNBW3P9NHlD4HICoqr2OuslbPJ+0e xWe8nYSqyMWFsvCmFLC1cSEGpl4S48aCrzm54vTBC+feI= Received: from 8235eee8a2a0 (unknown [140.205.118.149]) by gzga-smtp-mta-g3-1 (Coremail) with SMTP id _____wDHD5yVpDxmqlFMDQ--.27975S3; Thu, 09 May 2024 18:25:26 +0800 (CST) References: <6ab4003f-a8b8-4d75-a67f-f25ad98582dc@enterprisedb.com> User-agent: mu4e 1.10.7; emacs 29.1 From: Andy Fan To: Tomas Vondra Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Parallel CREATE INDEX for GIN indexes Date: Thu, 09 May 2024 18:14:40 +0800 In-reply-to: <6ab4003f-a8b8-4d75-a67f-f25ad98582dc@enterprisedb.com> Message-ID: <87pltvmgdm.fsf@163.com> MIME-Version: 1.0 Content-Type: text/plain X-CM-TRANSID:_____wDHD5yVpDxmqlFMDQ--.27975S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7WF48JrWkGrWrZF17AFykuFg_yoW8uw4DpF 9xtasIkFsrGrW8Ary7ZF4xKFy0yw1fXF13Arn5ur1jy3y5uFsF9r9IkFs7uFykWrs3CFyj vrZ0gw1kGan8ZaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ztg4kNUUUUU= X-Originating-IP: [140.205.118.149] X-CM-SenderInfo: x2klx3xlid0iqsrtqiywtou0bp/1tbiNhnZU2XAlXLERAAAsn List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tomas Vondra writes: > 3) v20240502-0003-Remove-the-explicit-pg_qsort-in-workers.patch > > In 0002 the workers still do an explicit qsort() on the TID list before > writing the data into the shared tuplesort. But we can do better - the > workers can do a merge sort too. To help with this, we add the first TID > to the tuplesort tuple, and sort by that too - it helps the workers to > process the data in an order that allows simple concatenation instead of > the full mergesort. > > Note: There's a non-obvious issue due to parallel scans always being > "sync scans", which may lead to very "wide" TID ranges when the scan > wraps around. More about that later. This is really amazing. > 7) v20240502-0007-Detect-wrap-around-in-parallel-callback.patch > > There's one more efficiency problem - the parallel scans are required to > be synchronized, i.e. the scan may start half-way through the table, and > then wrap around. Which however means the TID list will have a very wide > range of TID values, essentially the min and max of for the key. > > Without 0006 this would cause frequent failures of the index build, with > the error I already mentioned: > > ERROR: could not split GIN page; all old items didn't fit I have two questions here and both of them are generall gin index questions rather than the patch here. 1. What does the "wrap around" mean in the "the scan may start half-way through the table, and then wrap around". Searching "wrap" in gin/README gets nothing. 2. I can't understand the below error. > ERROR: could not split GIN page; all old items didn't fit When the posting list is too long, we have posting tree strategy. so in which sistuation we could get this ERROR. > issue with efficiency - having such a wide TID list forces the mergesort > to actually walk the lists, because this wide list overlaps with every > other list produced by the worker. If we split the blocks among worker 1-block by 1-block, we will have a serious issue like here. If we can have N-block by N-block, and N-block is somehow fill the work_mem which makes the dedicated temp file, we can make things much better, can we? -- Best Regards Andy Fan