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 1r8Omm-009ftS-SV for pgsql-hackers@arkaria.postgresql.org; Wed, 29 Nov 2023 17:55:44 +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 1r8Oml-00CIEQ-Ba for pgsql-hackers@arkaria.postgresql.org; Wed, 29 Nov 2023 17:55:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r8Oml-00CIEG-1q for pgsql-hackers@lists.postgresql.org; Wed, 29 Nov 2023 17:55:43 +0000 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r8Omd-007yYR-Bg for pgsql-hackers@lists.postgresql.org; Wed, 29 Nov 2023 17:55:41 +0000 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a04196fc957so4131466b.2 for ; Wed, 29 Nov 2023 09:55:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1701280533; x=1701885333; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=onK3JeUOkAIYbf4qY0HrEvm8hTHJWBbMFCUMj0TMHMs=; b=BpKGD3Y8u5yauIA9Ww+YVZrnr+ESWZDgEuyaS4IVLXWQIMT3Iift4ngbYSFqBeg9HX 7n9jHQU1II6wllt/MTc4Ldc+qeReNTmmJqtIo5tANAsAy8mOb27ADNDX4bDuJTMq0Hw1 CjjPLymaqwvRxwjXwySaAOd5ksPdhP0WQ4ZaQ/YL6UhrU12NV8XlTYRz7lnSiV+58sMw kdsFl05QgcyPKdn/HCym808k7HL/DXhW8kEtDhYdCMuLTXW/zd23Lal3JoCXCHegxD0v muZGIuaKCGcb9gL6Soev9KC/L4vj2Mjvs+Gjr9CIgpbhKR4L9VWfAurptQDSWXj3bbjk nG/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701280533; x=1701885333; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=onK3JeUOkAIYbf4qY0HrEvm8hTHJWBbMFCUMj0TMHMs=; b=F7FvtMWjYK1pXiVe6gPObVP+jkR+UYAUhiMQ7Hsq1xZEBShkKfdfe7kOwA2ChTMj5J iehqGIAM3c6L9qJNiDoW0EpR8Bo8w0lUnRLPcS2gHNLLVv0Lr8mK9hGBUwGRr8btti4M umn9LrhHK7BDANO7zzuNLFqdKGLp/SqN64M5xYs6eH9rV+oQCmYomAjlyGwWhcKstnV9 dQBKAHU76NSamUmE/Hbiujlgv2Fmph890zbIE/NNDb1UiSyIVy37Qkdt8Yo3jTpjAGbC CkmbJNKLmAsFwXJC8TKxjcMQgOpWGq5U2ByJ0a+ABjonm4EBsJI972hu5t4wrxxN74tV 5rzQ== X-Gm-Message-State: AOJu0YzQlBVY7azbjQ8pVRFr3Kar1IgNKhR9nqLnCw4t70fNumaapCvI xJqKZLFV96MvoDnZzTPxxt2/bg== X-Google-Smtp-Source: AGHT+IEnENfspIlQD+4PyG/rynB4FDqgpXGOHD9ndpUBM6c9j5kfN74V20clPDcn1YT2bQXHQLfalg== X-Received: by 2002:a17:906:2ad7:b0:9b7:37de:601a with SMTP id m23-20020a1709062ad700b009b737de601amr13729921eje.49.1701280533396; Wed, 29 Nov 2023 09:55:33 -0800 (PST) Received: from [10.137.0.17] (srv1.mobissw.com. [89.235.0.226]) by smtp.gmail.com with ESMTPSA id s8-20020a170906354800b00a0ca5672f7bsm4979556eja.123.2023.11.29.09.55.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Nov 2023 09:55:33 -0800 (PST) Message-ID: <64adb9cb-3474-e0ff-7a38-9bed4f5170e6@enterprisedb.com> Date: Wed, 29 Nov 2023 18:55:31 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: Parallel CREATE INDEX for BRIN indexes Content-Language: en-US From: Tomas Vondra To: Matthias van de Meent Cc: PostgreSQL Hackers References: <2d7c64de-716e-346e-b01e-03db0c2bc5ac@enterprisedb.com> <2e86059f-4004-eec1-2bc1-9e7fd119c9e2@enterprisedb.com> <5384d42e-1961-c2fd-1955-1a5a99fa1234@enterprisedb.com> <9a646c51-a4c3-ce34-cccd-99d00fd1dc6a@enterprisedb.com> 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 11/29/23 15:52, Tomas Vondra wrote: >> ... >> >> This also made me think a bit more about how we're working with the >> tuples. With your latest patch, we always deserialize and re-serialize >> the sorted brin tuples, just in case the next tuple will also be a >> BRIN tuple of the same page range. Could we save some of that >> deserialization time by optimistically expecting that we're not going >> to need to merge the tuple and only store a local copy of it locally? >> See attached 0002; this saves some cycles in common cases. >> > > Good idea! > FWIW there's a bug, in this part of the optimization: ------------------ + if (memtuple == NULL) + memtuple = brin_deform_tuple(state->bs_bdesc, btup, + memtup_holder); + union_tuples(state->bs_bdesc, memtuple, btup); continue; ------------------ The deforming should use prevbtup, otherwise union_tuples() jut combines two copies of the same tuple. Which however brings me to the bigger issue with this - my stress test found this issue pretty quickly, but then I spent quite a bit of time trying to find what went wrong. I find this reworked code pretty hard to understand, and not necessarily because of how it's written. The problem is it the same loop tries to juggle multiple pieces of information with different lifespans, and so on. I find it really hard to reason about how it behaves ... I did try to measure how much it actually saves, but none of the tests I did actually found measurable improvement. So I'm tempted to just not include this part, and accept that we may deserialize some of the tuples unnecessarily. Did you actually observe measurable improvements in some cases? regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company