Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mNpvH-00089m-Kr for pgsql-general@arkaria.postgresql.org; Wed, 08 Sep 2021 05:14:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mNpvG-0001wo-B1 for pgsql-general@arkaria.postgresql.org; Wed, 08 Sep 2021 05:14:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mNpvG-0001wg-1u for pgsql-general@lists.postgresql.org; Wed, 08 Sep 2021 05:14:58 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mNpvD-0001v8-L0 for pgsql-general@postgresql.org; Wed, 08 Sep 2021 05:14:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=In-Reply-To:Content-Type:MIME-Version:References:Reply-To: Message-ID:Subject:Cc:To:Sender:From:Date:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=x0nVxWKIyesiL+i66Qti3wI0+uyk7Oju+v83ac8jaC4=; b=O5A1T0UrXnJS1SkxwPVIA8dHrp SkGWtdYPtKD6kfk0sVtVan7M2X2WL8X84SqiCMJY60jPx8jI4Ug3wUJQMOSwHstlcC3vBHDceMBPn T6drvG+Z893rUPSI7p6in6nVXoQBvrJCL9C7tUGPlXHGvSShYR+VtAYS8DbYTfSTVxME=; Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by depesz.com with esmtpa (Exim 4.92) (envelope-from ) id 1mNpvB-0006HB-P3; Wed, 08 Sep 2021 07:14:53 +0200 Date: Wed, 8 Sep 2021 07:14:53 +0200 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: Alexander Kukushkin Cc: pgsql-general mailing list Subject: Re: Is there any technical reason why "alter table .. set not null" can't use index? Message-ID: <20210908051453.GB20274@depesz.com> Reply-To: depesz@depesz.com References: <20210908045919.GA29476@depesz.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Sep 08, 2021 at 07:09:31AM +0200, Alexander Kukushkin wrote: > Hi, > > On Wed, 8 Sep 2021, 06:59 hubert depesz lubaczewski, > wrote: > > > Hi, > > we needed recently to add not null constraint on some fields, and it > > struck me that it took long. > > Obviously - pg has to check the data. But it seems that it can't use > > index. > > > > It can't use the index, but can use an already existing CHECK CONSTRAINT, > that could be created as NOT VALID and validated without holding heavy > locks. After adding not null you can drop the constraint. Thanks. Forgot about these. Best regards, depesz