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 1tL6oV-00CloB-Fx for pgsql-performance@arkaria.postgresql.org; Tue, 10 Dec 2024 20:26:35 +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 1tL6oR-008itp-VB for pgsql-performance@arkaria.postgresql.org; Tue, 10 Dec 2024 20:26:33 +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 1tL6oR-008ith-9a for pgsql-performance@lists.postgresql.org; Tue, 10 Dec 2024 20:26:32 +0000 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tL6oL-0028bk-PV for pgsql-performance@lists.postgresql.org; Tue, 10 Dec 2024 20:26:31 +0000 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-434f150e9b5so8195e9.0 for ; Tue, 10 Dec 2024 12:26:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733862383; x=1734467183; darn=lists.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=1hpki+NOVOgjPIS3VHru9ogW4kL0gtzTrk5RhcF4fBk=; b=m5dXC5o96FqUAVoBoLPZJzbnHwJmYAU+0OxRdfcP/EaOIZuUk+jTvIOuWHouo1zoIH lqdxGqQmBAKYzdf9i++BFLT9zYCxLo0meMuIgWDoz/PTSXMn+9AKXsTVTECjRJNXAyrz PQS5pFfjW4eZhKy0MzHsv6SofqO17F23ThJMBvxgK4IorbW2ARnqgvkLJNT6KUsxuyt5 fkvY/lBCnat+xhRABOFcFtpMCK8s4c/Z27WROrGyOOzfCAW97t7QA3l34k8RAqo5zkLv O7+u2YFDIkl5tECZ0UFL8atI9xLB4rHt5tPyrABzLCyEYH/UXiTwp6LPd+S6eM/K0cfJ bVYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733862383; x=1734467183; 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=1hpki+NOVOgjPIS3VHru9ogW4kL0gtzTrk5RhcF4fBk=; b=QVqiQcYQBYNAvZrB7k1TSYKrmn8F4J1IOsDcv3clxSXmj50Drx3jkzrLPYxsc/kfSJ PzS0YDdpZZCp80DpJmnhBQpWHHBnTes5evxe9TioVPEAVdWbHmx9b3puPlmZtOGnd++p 6RkGKBU58euZclJD9EymRHtUy63uyB4OpPFbl4aoGuQ5v3JxkqL0UVbPLSSroz4RkUg1 cRJ9poAo6O4bvvSBtZBYKEuylc6Ojc6i89ZErZzqaEgiH08jQ6mq/n+aUOsUCTDvNMQ2 GsN3OIs1MBFoezPGoOHthDxz5/fs4FuqGhN1t5QcH/3Wy1ikTncfLktKy8T2ARHUUP3I Maug== X-Forwarded-Encrypted: i=1; AJvYcCUEcJXdr3HIkPZ65zRcAtXoNll5S+2M057QGrEi3GoZApHtKKG5JfdRCaDjSLEvocqVXkfzqUVfjFBEB2xsJV5Jxg==@lists.postgresql.org X-Gm-Message-State: AOJu0YwpNqpJe4IvUpKbqmR6ioDF6hjA+VF1IpI2Pj/+ql8yh5ZSAF1O 9a184N55PngKShdhm/pDKIxZiuy6+euGJleriE2AeMhrPC9Q/K2pCCWQ39qJDlACcKGgDWT9JR3 waZlbCNiJNyP3uEauNq38+FK/Rk+N7xpUiKZE X-Gm-Gg: ASbGncush6lEWx4i/OinXDdlvfSB0Nk6cgIcUhdPpFcWjrdfRNihfU3n6bLoKwAbPbv VcuyazhCIjnXc49DtuAaj9NeFdxLmUna72sk= X-Google-Smtp-Source: AGHT+IFnDXE9nEJN1FlxC8d6tqDymTTRVRj7+wkATO4qXCkKoDJvx9P47hcNd9ts68u8LY1F9kOYKx3MArGkPomV2uA= X-Received: by 2002:a05:600c:3403:b0:434:9e1d:44ef with SMTP id 5b1f17b1804b1-4361c217ba4mr150425e9.7.1733862382567; Tue, 10 Dec 2024 12:26:22 -0800 (PST) MIME-Version: 1.0 References: <5EE4CC0C-E624-4E82-A2E8-B2EBA44D3521@thebuild.com> <3908773.1733760455@sss.pgh.pa.us> In-Reply-To: From: Hannu Krosing Date: Tue, 10 Dec 2024 21:26:11 +0100 Message-ID: Subject: Re: PostgreSQL and a Catch-22 Issue related to dead rows To: Greg Sabino Mullane Cc: Lars Aksel Opsahl , Tom Lane , Christophe Pettus , "pgsql-performance@lists.postgresql.org" Content-Type: multipart/alternative; boundary="000000000000675c810628f04b22" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000675c810628f04b22 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable If there are unremovable rows it usually also means that index-only scan degrades to index-scan-with-visibility-checks-in-tables. I think the ask is to be able to remove the recently dead rows that are not visible in any current snapshot and can never become visible to any future snapshot, Something that Tom described as currently not easily doable above. Maybe we could figure out a way for long-running transactions to upload their snapshot set to some meta-vacuum process which can use it to determine which rows fall into that category. In this way the change would affect only the long-running transactions and if we do it onl maybe once a minute it should not be too heavy overhead even for these transactions. On Tue, Dec 10, 2024 at 4:32=E2=80=AFPM Greg Sabino Mullane wrote: > Thanks for that link; seeing actual queries is a big help. One thing to > try is to get some index-only scans to run. Regular indexes need to consu= lt > the heap (main table) for visibility information, and a bloated table can > make that consultation expensive. > > For example, an index like this should work to trigger an index-only scan= : > > create index gregtest on node(geom) include(node_id) where > containing_face=3D0; > > For those not following that link, the query is: > > SELECT node_id, geom FROM node WHERE containing_face IN (0) > AND geom && > '0102000020A21000000200000025DDA6B95DC62540F4E713991CE84D4017EE7636A3C625= 404E468D0D23E84D40'::geometry > > Or if containing_face is not always 0, a more generic variant: > > create index gregtest on node(geom, containing_face) include (node_id); > > What is the nature of the updates that are causing that many dead rows in > the first place? > > Cheers, > Greg > > --000000000000675c810628f04b22 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
If there are unremovable rows it usually also means that i= ndex-only scan degrades to index-scan-with-visibility-checks-in-tables.
=
I think the ask is to be able to remove the recently dead rows that are= not visible in any current snapshot and can never become visible to any fu= ture snapshot,=C2=A0
Something that Tom described as currently not easi= ly doable above.

Maybe we could figure out a way for long-running tr= ansactions to upload their snapshot set to some meta-vacuum process which c= an use it to determine which rows fall into that category. In this way the = change would affect only the long-running transactions and if we do it onl = maybe once a minute it should not be too heavy overhead even for these tran= sactions.

<= div dir=3D"ltr" class=3D"gmail_attr">On Tue, Dec 10, 2024 at 4:32=E2=80=AFP= M Greg Sabino Mullane <htamfids@gm= ail.com> wrote:
Thanks for that link; seeing actual queries is a bi= g help. One thing to try is to get some index-only scans to run. Regular in= dexes need to consult the heap (main table) for visibility=C2=A0information= , and a bloated table can make that consultation expensive.

<= div>For example, an index like this should work to trigger an index-only sc= an:

create index gregtest on node(geom) include(nod= e_id) where containing_face=3D0;

For those not followin= g that link, the query is:

SELECT node_id, geom FROM node WHERE cont= aining_face IN (0)
AND geom && '0102000020A21000000200000025= DDA6B95DC62540F4E713991CE84D4017EE7636A3C625404E468D0D23E84D40'::geomet= ry

Or if containing_face is not always 0, a = more generic variant:

create index gregtest on nod= e(geom, containing_face) include (node_id);

What i= s the nature of the updates that are causing that many dead rows in the fir= st place?

Cheers,
Greg

--000000000000675c810628f04b22--