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 1tQT5d-002n8A-IV for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Dec 2024 15:14:26 +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 1tQT5a-00E4Vq-Gv for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Dec 2024 15:14:22 +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 1tQT5a-00E4Vh-0U for pgsql-hackers@lists.postgresql.org; Wed, 25 Dec 2024 15:14:21 +0000 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tQT5Y-000W6w-0z for pgsql-hackers@postgresql.org; Wed, 25 Dec 2024 15:14:20 +0000 Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-5d41848901bso11117171a12.0 for ; Wed, 25 Dec 2024 07:14:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735139658; x=1735744458; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=TVkbNztc6T1HKT4clwQJmfSVFFCu2tELJrE3z2LzZ9Q=; b=mTSDDSMf9HUgL7LkQKKHyQrS6TiRyO2ryEwf1fRYv4IxVtw8uPm4octwvXYYFzRhrz 5RmS/X2HAVp5bMq20DsLJ1XxvgKLQRwwYwDGPO55foaLdDrmmpVtsFv5L8Sn3dMuq222 D7A7Fexn6yS5KiA3wpLiCSfHJTaHbIj+oKKEzYqCgi8r7SE6Pn0rFGl1hHdxkAzPFcBm 3sYtHiaY3Ri0oI+ycpp1ZZNpiTRa8FckJf1rQOHBISvH7j3Iw5mSvOaMs2i/iC6AOym3 dpl5k4yJiYmMpCSlnbY0QaPVm0W3eAsZ8LruIIqKy43tuSa6jBqbj3kQWboLnhfjUEcB hZ8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735139658; x=1735744458; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TVkbNztc6T1HKT4clwQJmfSVFFCu2tELJrE3z2LzZ9Q=; b=vZ0UgZY8PIQmlJfdgnl6nHH+Ze2VhDxep2slxXwb3s/3qK6Z7b5ccrPunmv+RdHWAb PIiI1fY8JcUSVKEUAmTxBa6qpWWEPIsw4gafpSsCA/YbI4m5GZtyNWhzcg3eOVKdWtgV 9HMjhDXc3iW5eZXqy236kAavFSs/ot3UyHAv7YKnE7tCNYcztgWVsZoBqJvUUHT3/RL/ 0Fg376FMzXtq4hVoVqN9dLOvGfddNILTt6N8125HjwAppgebuK5hMbefe1XiouITSzUv pvXNFRexLDZpIt1CxRfZs4qX6n19xlGuAgxyHQe3y8ya5REFAbm4YEbGVIZpY4DGS4lz 6zHA== X-Forwarded-Encrypted: i=1; AJvYcCU3jS2OIwO7PrkULD3rSUxZ4/EMmy/TuW4iQQnZIayJ2BJPBy+K5HVYKKcgPF4QWhYyNMnfQIghzsqWPq6p@postgresql.org X-Gm-Message-State: AOJu0YzBlfmPwtWx4le+SfQV8FCE1J/1xUgDyjWxEqOPoC7HbWs5XBYj SrPwR7qVicfry1KRIw7PPm4Zb28WKGfaBIZBm38Nix7EfY4cjaEf3QqqGia+ter0/b9pH9ufo2/ U4GaJBX0zrPd73XqgtvEL5CMw4qw= X-Gm-Gg: ASbGncsDKGCUmHMv6cXKY7W3Hsb67il/W+j93em7N9S3ChxjSUGH3y7vSEF2VCz/Du+ jrdf9x6aCJ2hwuJo1PzldxeObT1KAqfXXqJjFJy8BbEYqtPSbI3Xqb/OmMaUerVOKt8Er2Vqb X-Google-Smtp-Source: AGHT+IHxlKWpKv43c9KAImwXe0QlgG0yvT+LGTK6fUZOiwhrb3zPZkSN5tt28gGcWic3nhN8B/VYQ1UGvDVLV9Vj+HI= X-Received: by 2002:a05:6402:520c:b0:5d0:d328:3a43 with SMTP id 4fb4d7f45d1cf-5d81e71a038mr18869031a12.6.1735139657406; Wed, 25 Dec 2024 07:14:17 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Michail Nikolaev Date: Wed, 25 Dec 2024 16:14:00 +0100 Message-ID: Subject: Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements To: Michael Paquier Cc: Matthias van de Meent , PostgreSQL Hackers , Andrey Borodin , Melanie Plageman Content-Type: multipart/alternative; boundary="000000000000ea615b062a19ae8e" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000ea615b062a19ae8e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello, Michael! Thank you for your comments and feedback! Yes, this patch set contains a significant amount of code, which makes it challenging to review. Some details are explained in the commit messages, but I=E2=80=99m doing my best to structure the patch set in a way that is a= s committable as possible. Once all the parts are ready, I plan to write a detailed letter explaining everything, including benchmark results and other relevant information. Meanwhile, here=E2=80=99s a quick overview of the patch structure. If you h= ave suggestions for an alternative decomposition approach, I=E2=80=99d be happy= to hear. The primary goals of the patch set are to: * Enable the xmin horizon to propagate freely during concurrent index builds * Build concurrent indexes with a single heap scan The patch set is split into the following parts. Technically, each part could be committed separately, but all of them are required to achieve the goals. Part 1: Stress tests - 0001: Yes, this patch is from another thread and not directly required, it=E2=80=99s included here as a single commit because it=E2=80=99s necessar= y for stress testing this patch set. Without it, issues with concurrent reindexing and upserts cause failures. - 0002: Yes, I agree these tests need to be refactored or moved into a separate task. I=E2=80=99ll address this later. Part 2: During the first phase of concurrently building a index, reset the snapshot used for heap scans between pages, allowing xmin to go forward. - 0003: Implement such snapshot resetting for non-parallel and non-unique cases - 0004: Extends snapshot resetting to parallel builds - 0005: Extends snapshot resetting to unique indexes Part 3: Build concurrent indexes in a single heap scan - 0006: Introduces the STIR (Short-Term Index Replacement) access method, a specialized method for auxiliary indexes during concurrent builds - 0007: Implements the auxiliary index approach, enabling concurrent index builds to use a single heap scan. In a few words, it works like this: create an empty auxiliary STIR index to track new tuples, scan heap and build new index, merge STIR tuples into new index, drop auxiliary index. - 0008: Enhances the auxiliary index approach by resetting snapshots during the merge phase, allowing xmin to propagate Part 4: This part depends on all three previous parts being committed to make sense (other parts are possible to apply separately). - 0009: Remove PROC_IN_SAFE_IC logic, as it is no more required I have a plan to add a few additional small things (optimizations) and then do some scaled stress-testing and benchmarking. I think that without it, no one is going to spend his time for such an amount of code :) Merry Christmas, Mikhail. --000000000000ea615b062a19ae8e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello, Michael!

Th= ank you for your comments and feedback!

Yes, this patch set contains = a significant amount of code, which makes it challenging to review. Some de= tails are explained in the commit messages, but I=E2=80=99m doing my best t= o structure the patch set in a way that is as committable as possible. Once= all the parts are ready, I plan to write a detailed letter explaining ever= ything, including benchmark results and other relevant information.

M= eanwhile, here=E2=80=99s a quick overview of the patch structure. If you ha= ve suggestions for an alternative decomposition approach, I=E2=80=99d be ha= ppy to hear.

The primary goals of the patch set are to:
= =C2=A0 =C2=A0 * Enable the xmin horizon to propagate freely during concurre= nt index builds
=C2=A0 =C2=A0 * Build concurrent indexes with a single h= eap scan

The patch set is split into the following parts. Technically, each part cou= ld be committed separately, but all of them are required to achieve the goa= ls.

Part 1: Stress tests
- 0001: Yes,=20 this patch is from another thread and not directly required, it=E2=80=99s i= ncluded here as a single commit because it=E2=80=99s necessary for stress t= esting this patch set. Without it, issues with concurrent reindexing and up= serts cause failures.
- 0002: Yes, I agree these tests need to be= refactored or moved into a separate task. I=E2=80=99ll address this later.=

Part 2: During the first phase of concurrently building a=C2= =A0 index, reset the snapshot used for heap scans between pages, allowing x= min to go forward.
- 0003: Implement such snapshot resetting for = non-parallel and non-unique cases
- 0004:=20 Extends snapshot resetting to parallel builds
- 0005:=20 Extends snapshot resetting to unique indexes

Part = 3: Build concurrent indexes in a single heap scan
- 0006: Introdu= ces the STIR (Short-Term Index Replacement) access method, a specialized me= thod for auxiliary indexes during concurrent builds
- 0007:=20 Implements the auxiliary index approach, enabling concurrent index builds t= o use a single heap scan.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 In a few=C2=A0words, it works like this: create an empty auxiliary STIR= index to track new tuples, scan heap and build new index, merge STIR tuple= s into new index, drop auxiliary index.
- 0008: Enhances the auxi= liary index approach by resetting snapshots during the merge phase, allowin= g xmin to propagate

Part 4:=20 This part depends on all three previous parts being committed to make sense (other parts are possible to apply separately).
- 0009:=C2=A0 Re= move PROC_IN_SAFE_IC logic, as it is no more required

<= div>I have a plan to add a few additional small things (optimizations) and = then do some scaled stress-testing and benchmarking. I think that without i= t, no one is going to spend his time for such an amount=C2=A0of code :)=C2= =A0

Merry Christmas,
Mikhail.
--000000000000ea615b062a19ae8e--