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 1sjWoV-001WRb-AV for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Aug 2024 04:31:15 +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 1sjWoS-00EV9F-Mk for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Aug 2024 04:31:13 +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 1sjWoR-00EV8V-PU for pgsql-hackers@lists.postgresql.org; Thu, 29 Aug 2024 04:31:12 +0000 Received: from m16.mail.163.com ([117.135.210.5]) by magus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sjWoJ-0021eB-K9 for pgsql-hackers@lists.postgresql.org; Thu, 29 Aug 2024 04:31:10 +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=gqxE8TWyA5mz9g3d5qg8cPSw0CGw7Kzkws+QjaMavzY=; b=WTiFhGSAzloUJunXSpgrAI4nDhLkx7nAR4/Vc1o/3w2YaAna8nKna1I0HQoh86 nRY6bMjYzxBj/Ru59Wo80eBdD1n1nrOroCRXfMoltaAT4yhBQEe8s+FbaTkVPxve uO8n1pQ2lsapKp+ajr1S5baIR7GkvV3RuIvFBCwowCUh0= Received: from lovely-coding (unknown [101.227.46.166]) by gzga-smtp-mta-g2-2 (Coremail) with SMTP id _____wD3_kp0+c9myVy0EQ--.36531S3; Thu, 29 Aug 2024 12:30:45 +0800 (CST) From: Andy Fan To: Tomas Vondra Cc: Tomas Vondra , Matthias van de Meent , PostgreSQL Hackers Subject: Re: Parallel CREATE INDEX for GIN indexes In-Reply-To: (Tomas Vondra's message of "Tue, 27 Aug 2024 13:16:25 +0200") References: <6ab4003f-a8b8-4d75-a67f-f25ad98582dc@enterprisedb.com> <87pltvmgdm.fsf@163.com> <3b721981-6fa3-4698-a9b6-70b2d8e8fa3b@enterprisedb.com> <87y18ektdn.fsf@163.com> <87jzjes2ia.fsf@163.com> <03abcca0-47b2-4bc1-be05-6c1a3f1c5511@enterprisedb.com> <74ef5493-c837-4861-afb0-7d07e3a35407@enterprisedb.com> <6db057fa-3990-4778-9578-aabc20f05db3@enterprisedb.com> <531c2afd-6118-4582-8d0a-7bd2ddbde6c5@enterprisedb.com> <3b011125-7489-4ecb-8973-bbe6f00cbf1b@enterprisedb.com> <148f0f59-55bf-40a9-ab28-51904aa8c325@enterprisedb.com> <87a5gyqnl5.fsf@163.com> Date: Thu, 29 Aug 2024 12:30:44 +0800 Message-ID: <87ikvkgdcb.fsf@163.com> MIME-Version: 1.0 Content-Type: text/plain X-CM-TRANSID: _____wD3_kp0+c9myVy0EQ--.36531S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7AFWUZw1DZF1UuryrKw43GFg_yoW8KFy7pF W3Kr4xXws7JrWUXrnrZw4FqF15JFs5Z3WUKF18WryDAFW7AFyjqrWrtrW3Z34I9w1xG34j 9F4jkw1kua93XaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziMqcUUUUUU= X-Originating-IP: [101.227.46.166] X-CM-SenderInfo: x2klx3xlid0iqsrtqiywtou0bp/xtbBZxlKU2V4I5W0ogAAsa List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tomas Vondra writes: Hi Tomas, > Yeah. I think we have agreement on 0001-0007. Yes, the design of 0001-0007 looks good to me and because of the existing compexitity, I want to foucs on this part for now. I am doing code review from yesterday, and now my work is done. Just some small questions: 1. In GinBufferStoreTuple, /* * Check if the last TID in the current list is frozen. This is the case * when merging non-overlapping lists, e.g. in each parallel worker. */ if ((buffer->nitems > 0) && (ItemPointerCompare(&buffer->items[buffer->nitems - 1], &tup->first) == 0)) buffer->nfrozen = buffer->nitems; should we do (ItemPointerCompare(&buffer->items[buffer->nitems - 1], &tup->first) "<=" 0), rather than "=="? 2. Given the "non-overlap" case should be the major case GinBufferStoreTuple , does it deserve a fastpath for it before calling ginMergeItemPointers since ginMergeItemPointers have a unconditionally memory allocation directly, and later we pfree it? new = ginMergeItemPointers(&buffer->items[buffer->nfrozen], /* first unfronzen */ (buffer->nitems - buffer->nfrozen), /* num of unfrozen */ items, tup->nitems, &nnew); 3. The following comment in index_build is out-of-date now :) /* * Determine worker process details for parallel CREATE INDEX. Currently, * only btree has support for parallel builds. * 4. Comments - Buffer is not empty and it's storing "a different key" looks wrong to me. the key may be same and we just need to flush them because of memory usage. There is the same issue in both _gin_process_worker_data and _gin_parallel_merge. if (GinBufferShouldTrim(buffer, tup)) { Assert(buffer->nfrozen > 0); state->buildStats.nTrims++; /* * Buffer is not empty and it's storing a different key - flush * the data into the insert, and start a new entry for current * GinTuple. */ AssertCheckItemPointers(buffer, true); I also run valgrind testing with some testcase, no memory issue is found. > I'm a bit torn about 0008, I have not expected changing tuplesort like > this when I started working > on the patch, but I can't deny it's a massive speedup for some cases > (where the patch doesn't help otherwise). But then in other cases it > doesn't help at all, and 0010 helps. Yes, I'd like to see these improvements both 0008 and 0010 as a dedicated improvement. -- Best Regards Andy Fan