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 1snmgq-0061OE-LW for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Sep 2024 22:16:57 +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 1snmgp-00222V-8p for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Sep 2024 22:16:55 +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 1snmgo-00222N-Uw for pgsql-hackers@lists.postgresql.org; Mon, 09 Sep 2024 22:16:54 +0000 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1snmgh-000NCx-Hc for pgsql-hackers@lists.postgresql.org; Mon, 09 Sep 2024 22:16:54 +0000 Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-5365392cfafso4605325e87.0 for ; Mon, 09 Sep 2024 15:16:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725920208; x=1726525008; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ZYcpcHYeeMzxvL2l09x5U+UB16ybcoEduGf2ainNZNY=; b=M9dbaZkLt76eZMrwdTeIPDHsVRzAQtxE0i4YLTmST97+45oUZWXG7rPlO1Piaa/l+Q lYK/0Zf+beXAYxoOaz/J7fzcIUYuVR+E2ksTJ7a+6oyEPBSRNNYICBUYQGvS7rze+Iet lJF6yyEPSozjgihpukqddawQ2XlFn8DLcNhy/0ZegJl56DaYS3TKu3EHqFWQ5cUxzXpJ sDrjUCMAfVgZ3sqVFSKtRnBIfe0+qxvw/Kl+OAoHgcSVlHq8FltcV5R2U+5tkGi0GNPS UFCC9TJEkXNDc7B5fGuYHRiU0/Pxe8n+xYuVYrHq7YBBwtp1DkrMtTQAZRiSic3S8D/X 4GFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725920208; x=1726525008; h=content-transfer-encoding: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=ZYcpcHYeeMzxvL2l09x5U+UB16ybcoEduGf2ainNZNY=; b=jGOwDY5MGUm/twlqS0vmSXLMTJ0KUbFNTiVRiI5fQigFqTKLG8R09R3xh0qHow6YCb 3wBlc8A8onR6u1EPe5j72rcAChQke73wz2/0vJxnAWdIgO64eG3idlJGw0x3PYo3Ve2N XntedS8K/zb0UXh83zG9zxfLdeEoCuJCY+8fRcPijjSH70v48mhQlmTHwIiJHiAaKjch 8WPF9ktmP/wYD7ywMcmJwRzpSRtc6uE/dZCml7hLYSPn8r+yAk2Xlv39lLCJZJvA7pHc pcPFqeobNt8FtUG0yturbTB22alKdO1GHqI8vp0mnbNYmntECkb2hC46qWG1k8wnMKLh gNgw== X-Gm-Message-State: AOJu0YyS2MGjE+FPb6FqVAGP6iFuuqPwx4P3qRrSPRlTNIOxI97L3e9/ 1uLOx/yyKbi3LttaXlRUULUPNUP4iLqmOKGHSbehAppeGT+EiZPqmcSpounqleO4c5sRJAK5WJM Y1wiNCB+H0TGu66wmtbl3vsSGo0U= X-Google-Smtp-Source: AGHT+IGZ4cV7ouSKfpk3j4cR7h3nhE09/rhZ5aPnVUcMs2a1rB9o6Mez8RO+fGlHbsbocknkBwroadPtaWUP04pp0HU= X-Received: by 2002:a05:6512:694:b0:52e:9b2f:c313 with SMTP id 2adb3069b0e04-536587ae740mr8908909e87.22.1725920206650; Mon, 09 Sep 2024 15:16:46 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: David Rowley Date: Tue, 10 Sep 2024 10:16:34 +1200 Message-ID: Subject: Re: Proposal to Enable/Disable Index using ALTER INDEX To: Shayon Mukherjee Cc: pgsql-hackers@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 10 Sept 2024 at 09:39, Shayon Mukherjee wrote: > Adding and removing indexes is a common operation in PostgreSQL. On large= r databases, however, these operations can be resource-intensive. When eval= uating the performance impact of one or more indexes, dropping them might n= ot be ideal since as a user you may want a quicker way to test their effect= s without fully committing to removing & adding them back again. Which can = be a time taking operation on larger tables. > > Proposal: > I propose adding an ALTER INDEX command that allows for enabling or disab= ling an index globally. This could look something like: > > ALTER INDEX index_name ENABLE; > ALTER INDEX index_name DISABLE; > > A disabled index would still receive updates and enforce constraints as u= sual but would not be used for queries. This allows users to assess whether= an index impacts query performance before deciding to drop it entirely. I personally think having some way to alter an index to stop it from being used in query plans would be very useful for the reasons you mentioned. I don't have any arguments against the syntax you've proposed. We'd certainly have to clearly document that constraints are still enforced. Perhaps there is some other syntax which would self-document slightly better. I just can't think of it right now. > Implementation: > To keep this simple, I suggest toggling the indisvalid flag in pg_index d= uring the enable/disable operation. That's not a good idea as it would allow ALTER INDEX ... ENABLE; to be used to make valid a failed concurrently created index. I think this would need a new flag and everywhere in the planner would need to be adjusted to ignore indexes when that flag is false. > Additional Considerations: > - Keeping the index up-to-date while it=E2=80=99s disabled seems preferab= le, as it avoids the need to rebuild the index if it=E2=80=99s re-enabled l= ater. The alternative would be dropping and rebuilding the index upon re-en= abling, which I believe would introduce additional overhead in terms of app= lication logic & complexity. I think the primary use case here is to assist in dropping useless indexes in a way that can very quickly be undone if the index is more useful than thought. If you didn't keep the index up-to-date then that would make the feature useless for that purpose. If we get the skip scan feature for PG18, then there's likely going to be lots of people with indexes that they might want to consider removing after upgrading. Maybe this is a good time to consider this feature as it possibly won't ever be more useful than it will be after we get skip scans. David