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 1rJi2M-00F6uU-Lz for pgsql-hackers@arkaria.postgresql.org; Sat, 30 Dec 2023 22:42:34 +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 1rJi2K-003C1q-C8 for pgsql-hackers@arkaria.postgresql.org; Sat, 30 Dec 2023 22:42:32 +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 1rJi2K-003C1i-1x for pgsql-hackers@lists.postgresql.org; Sat, 30 Dec 2023 22:42:32 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rJi2G-00EiW9-KS for pgsql-hackers@lists.postgresql.org; Sat, 30 Dec 2023 22:42:30 +0000 Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-555bd21f9fdso1664002a12.0 for ; Sat, 30 Dec 2023 14:42:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1703976147; x=1704580947; 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=FVFYhS6Gm01CixkNPPJl0HRVG0SaxIldrwxvwAu4gdY=; b=gruz2S7vG8e+zDpyZj/KuQPR5gK0AtNdbRJ1LQcNdUcDO4BBIvmXC2izLFbHa2GmQI TKF2HXUaguO3R1ehF2Qdf5vlAC6EiUtgVpQXfXnTev8uhDphfeAkkyU1sTAWvjs94m87 gjzmiIjEdZNB8jg9fPHTlWuuJWwQnJc8jCFaZuyII6fJracUoEsBF6r+jisELt2e/Yl3 ysJScXtEItNYESyevanoJxBEacTWpwZJzQc0jk5MHzryLPt5Q2bEItxdmy/Ghx5P1nBe C3QXVYcj7ZYuhlETUSjjOatF6mxA448jk+hFRrZfP3JjzlfeWKJ2JxJl0pW8zXpNlX2L tsKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703976147; x=1704580947; 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=FVFYhS6Gm01CixkNPPJl0HRVG0SaxIldrwxvwAu4gdY=; b=V+p7rh19ETcSLAGFRMQLcZKxeyXaAe79EslapaslCvMXekDQJEc0uXjhTCEZzuJIQd VYZEHZIFTLyiISqcFLn5kLkhReOSXwJwpnn6UjjmKx3Gp95RZD4gPOWW9YcuB1om4glR 2OPa9PwyIA8WexttCgJD+CWdplVHSnoTL7vUi58B4GQzOPNn2X8qGSxzbVPhLsi0m4p1 bNumfsAJ3C+t/WPxCVuiuF2IPgqhXYqVCdura/Ox0WgdZqrDbPQgecqzIaU8gucpfpfJ 1TrM1vI3E1+XokgBm5pVeXDTuzsvjAxLnbBkmIdVYuogX14VeGBXOAXF9Kg1dnTM39g6 aYzw== X-Gm-Message-State: AOJu0YzZFkXuSCyXbs0d613oYQ1tAZIm9bkKIYrL/pMhCzY6qlvzOTKE 8zsSCy3eb1R75RrMLQS286abGLzdZITB X-Google-Smtp-Source: AGHT+IGEtxZfypCM9nikIVyIMPx3ZMP87Q5UdhJdlApRg0jBPR9w4KnXBP3Gf+jKknsvYnhkWVp5rA== X-Received: by 2002:a50:d69d:0:b0:553:dcb7:c1cc with SMTP id r29-20020a50d69d000000b00553dcb7c1ccmr7427507edi.50.1703976146934; Sat, 30 Dec 2023 14:42:26 -0800 (PST) Received: from [10.137.0.17] (ip-86-49-229-30.bb.vodafone.cz. [86.49.229.30]) by smtp.gmail.com with ESMTPSA id b10-20020a0564021f0a00b00552d45bd8e7sm12761928edb.77.2023.12.30.14.42.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 30 Dec 2023 14:42:26 -0800 (PST) Message-ID: <3733d042-71e1-6ae6-5fac-00c12db62db6@enterprisedb.com> Date: Sat, 30 Dec 2023 23:42:24 +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: <5384d42e-1961-c2fd-1955-1a5a99fa1234@enterprisedb.com> <9a646c51-a4c3-ce34-cccd-99d00fd1dc6a@enterprisedb.com> <64adb9cb-3474-e0ff-7a38-9bed4f5170e6@enterprisedb.com> <99f9ecbe-0976-8012-67b5-dbff58c7dbec@enterprisedb.com> <32e3f645-389d-87f9-2ce7-33d0087f47d4@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 Hi, While cleaning up some unnecessary bits of the code and slightly inaccurate comments, I ran into a failure when the parallel scan (used by the parallel build) happened to be a synchronized scan. When the scan did not start on page 0, the parallel callback failed to correctly handle tuples after wrapping around to the start of the table. AFAICS the extensive testing I did during development did not detect this because strictly speaking the index was "correct" (as in not returning incorrect results in queries), just less efficient (missing some ranges, and some ranges being "wider" than necessary). Or perhaps the tests happened to not trigger synchronized scans. Should be fixed by 1ccab5038eaf261f. It took me ages to realize what the problem is, and I initially suspected there's some missing coordination between the workers/leader, or something. So I started comparing the code to btree, which is where it originated, and I realized there's indeed one difference - the BRIN code only does half the work with the workersdonecv variable. The workers do correctly update the count and notify the leader, but the leader never waits for the count to be 0. That is, there's nothing like _bt_parallel_heapscan. I wonder whether this actually is a problem, considering the differences between the flow in BRIN and BTREE. In particular, the "leader" does the work in _brin_end_parallel() after WaitForParallelWorkersToFinish(). So it's not like there might be a worker still processing data, I think. But now that I think about it, maybe it's not such a great idea to do this kind of work in _brin_end_parallel(). Maybe it should do just stuff related to termination of workers etc. and the merging of results should happen elsewhere - earlier in brinbuild()? Then it'd make sense to have something like _bt_parallel_heapscan ... regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company