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 1rk0eY-009cHS-Lu for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Mar 2024 11:50:43 +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 1rk0eW-00BCX9-Lf for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Mar 2024 11:50:41 +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 1rk0eW-00BCUe-B3 for pgsql-hackers@lists.postgresql.org; Tue, 12 Mar 2024 11:50:40 +0000 Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rk0eS-0046el-Mx for pgsql-hackers@postgresql.org; Tue, 12 Mar 2024 11:50:40 +0000 Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2d4360ab3daso33680921fa.3 for ; Tue, 12 Mar 2024 04:50:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710244236; x=1710849036; 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=8o1Pp1dzwuZNGFIaAV496LwEFn/wgej4E5wFwYOlVXA=; b=cpr9/YcVWsirf8lcySGaFuup/ba4rLcH0diQCKMe4XNZO96qHUQAJKxi6RS5iW1Y+i KvfrGxvtGJLqmv1eU2OGowvHj/maQxOPJ/NtsVcG3GTD6XquUxY1aVGkw8AjJK9BDY+P wmaW2gruObQKMeAcYNiUuwN+ZaCacGS3BTH/5vMoy71eDFsJotUW9iwO/d+yZ5/tD0Aq DbCklZYWXskme6DXHxtDlyudtKwUZXtWfQWEs5Bx2AyYadITghxXk1PTZQPcli/19GiY lesTrUdFnGtLP5u6/sh3oVThsAgaShU5y5gD5q5khjUfpQGYw/iznRuehQ2R6ie+s7IO bLLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710244236; x=1710849036; 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=8o1Pp1dzwuZNGFIaAV496LwEFn/wgej4E5wFwYOlVXA=; b=LHpNjj3pIiaiftLNYqxPJp0dnBrm4O+jmff3/ciufuCfplSEQQKxzZz5/+USdF9H+P PAjUBju/fq8TnhRpIENEIQIY057zedKQ2jBjCCptBenA5s/fwL6igdIle7BRYLeFhb6w s3q6tK5jGQkBKXTaQ3bOReVXErbgIwpf/BCtSF8YfKpgrjPKekQ/sbl17XgmOpamimET k6QqcYDPpl+3dbbZMd4EPu8UHwuccCCgJT4Swrs5oB3fbe8Oey9QcMmJVnFzobjMFWvF Xr8wyn6pwXHi21BYKk+XPMtOZ/Q3OlWbbRlsUAeKpHMotSsyDpbcEqdnpRBIqJpuwTDK qHog== X-Forwarded-Encrypted: i=1; AJvYcCWmm9OBo2jZ5tjjfPybZaEvCYzFi9tpAf2jT8CCUXAYzhxXofBj3kfKxjyWC74hlZcHGtLh4rNGxIiBJHooBl2P8bLO/nh9uaDtIJG+ X-Gm-Message-State: AOJu0Yw1wbFCfRpU6z9q4JbQJujuAEwGkdDh7aMe6f43AoFSX6HI1OBZ wUH/sfycCUuJtVbL1VLEjNWtqlonE9uIu722ZoudLoCzrv6hRVhLXUwvpQoC9Hc6pdQGZRxbADR xcfI6MZMnXW2VeKSIX7rq/WmySdc= X-Google-Smtp-Source: AGHT+IH81yZa0aHbU0vx28FN3YOkAl5SZOLR5VGJuWpwkfEzq6THFFLHDmgGc7FLakvRD8qwXDLzu2f2z77HudW9eX4= X-Received: by 2002:a2e:be0b:0:b0:2d2:3810:552 with SMTP id z11-20020a2ebe0b000000b002d238100552mr1320860ljq.53.1710244235947; Tue, 12 Mar 2024 04:50:35 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Matthias van de Meent Date: Tue, 12 Mar 2024 12:50:24 +0100 Message-ID: Subject: Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements To: Michail Nikolaev Cc: Melanie Plageman , PostgreSQL Hackers , Alvaro Herrera Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 7 Mar 2024 at 19:37, Michail Nikolaev wrote: > > Hello! > > > I'm not a fan of this approach. Changing visibility and cleanup > > semantics to only benefit R/CIC sounds like a pain to work with in > > essentially all visibility-related code. I'd much rather have to deal > > with another index AM, even if it takes more time: the changes in > > semantics will be limited to a new plug in the index AM system and a > > behaviour change in R/CIC, rather than behaviour that changes in all > > visibility-checking code. > > Technically, this does not affect the visibility logic, only the > clearing semantics. > All visibility related code remains untouched. Yeah, correct. But it still needs to update the table relations' information after finishing creating the indexes, which I'd rather not have to do. > But yes, still an inelegant and a little strange-looking option. > > At the same time, perhaps it can be dressed in luxury > somehow - for example, add as a first class citizen in ComputeXidHorizonsResult > a list of blocks to clear some relations. Not sure what you mean here, but I don't think ComputeXidHorizonsResult should have anything to do with actual relations. > > But regardless of second scan snapshots, I think we can worry about > > that part at a later moment: The first scan phase is usually the most > > expensive and takes the most time of all phases that hold snapshots, > > and in the above discussion we agreed that we can already reduce the > > time that a snapshot is held during that phase significantly. Sure, it > > isn't great that we have to scan the table again with only a single > > snapshot, but generally phase 2 doesn't have that much to do (except > > when BRIN indexes are involved) so this is likely less of an issue. > > And even if it is, we would still have reduced the number of > > long-lived snapshots by half. > > Hmm, but it looks like we don't have the infrastructure to "update" xmin > propagating to the horizon after the first snapshot in a transaction is taken. We can just release the current snapshot, and get a new one, right? I mean, we don't actually use the transaction for much else than visibility during the first scan, and I don't think there is a need for an actual transaction ID until we're ready to mark the index entry with indisready. > One option I know of is to reuse the > d9d076222f5b94a85e0e318339cfc44b8f26022d (1) approach. > But if this is the case, then there is no point in re-taking the > snapshot again during the first > phase - just apply this "if" only for the first phase - and you're done. Not a fan of that, as it is too sensitive to abuse. Note that extensions will also have access to these tools, and I think we should build a system here that's not easy to break, rather than one that is. > Do you know any less-hacky way? Or is it a nice way to go? I suppose we could be resetting the snapshot every so often? Or use multiple successive TID range scans with a new snapshot each? Kind regards, Matthias van de Meent Neon (https://neon.tech)