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 1pQ4bf-0002o4-66 for pgsql-performance@arkaria.postgresql.org; Thu, 09 Feb 2023 10:56:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pQ4bd-0003io-Rz for pgsql-performance@arkaria.postgresql.org; Thu, 09 Feb 2023 10:56:45 +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 1pQ4bd-0003if-8b for pgsql-performance@lists.postgresql.org; Thu, 09 Feb 2023 10:56:45 +0000 Received: from disco.pogo.org.uk ([93.93.128.62]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pQ4bY-0002W7-Sc for pgsql-performance@lists.postgresql.org; Thu, 09 Feb 2023 10:56:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xwax.org; s=swing; h=Content-Type:MIME-Version:References:Message-ID:In-Reply-To: Subject:cc:To:From:Date:Sender:Reply-To: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=/aEzcnceCx4iG6ZDmb4b+v+WartK2SL42NixuNV6AJM=; b=fNP7Mzhf4BGn7DeNt0dqoKxuPP oOOQMx0KSvIIh6xGaCcNV2jOeKLWQx+6kpDnrBvIUcesV0cVNl1SxnDAQPYzrNQ8r97kvHtz0S7Tg nQv9zzzD9T/LkMXfI4YCHPFRah5/hAAq1ZggcbJX3krDNPYDu4sn6XYoZJunTBona8wE=; Received: from [2001:470:1d21:0:428d:5cff:fe1b:f3e5] (helo=stax) by disco.pogo.org.uk with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.95 (FreeBSD)) (envelope-from ) id 1pQ4bO-000Ako-GT; Thu, 09 Feb 2023 10:56:39 +0000 Received: from localhost (stax.localdomain [local]) by stax.localdomain (OpenSMTPD) with ESMTPA id 3f4820b2; Thu, 9 Feb 2023 10:56:36 +0000 (UTC) Date: Thu, 9 Feb 2023 10:56:35 +0000 (GMT) From: Mark Hills To: Laurenz Albe cc: pgsql-performance@lists.postgresql.org Subject: Re: Domain check taking place unnecessarily? In-Reply-To: <4b1a0c9e36280b1d4abeb4fb6336832409df6ae0.camel@cybertec.at> Message-ID: <2302091035450.14632@stax.localdomain> References: <2302081605290.5352@stax.localdomain> <4b1a0c9e36280b1d4abeb4fb6336832409df6ae0.camel@cybertec.at> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="-1463793916-464543087-1675940196=:14632" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---1463793916-464543087-1675940196=:14632 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE On Wed, 8 Feb 2023, Laurenz Albe wrote: > On Wed, 2023-02-08 at 18:01 +0000, Mark Hills wrote: > > I've ruled out waiting on a lock; nothing is reported with=20 > > log_lock_waits=3Don. This is a test database with exclusive access (2.5= =20 > > million rows): > >=20 > > This is PostgreSQL 14.5 on Alpine Linux. Thanks. > >=20 > > CREATE DOMAIN hash AS text > > =C2=A0=C2=A0=C2=A0 CHECK (VALUE ~ E'^[a-zA-Z0-9]{8,32}$'); > > =C2=A0 > > devstats=3D> ALTER TABLE invite ADD COLUMN test text; > > ALTER TABLE > > Time: 8.988 ms > > =C2=A0 > > devstats=3D> ALTER TABLE invite ADD COLUMN test hash; > > ALTER TABLE > > Time: 30923.380 ms (00:30.923) > > =C2=A0 > > devstats=3D> ALTER TABLE invite ADD COLUMN test hash DEFAULT NULL; > > ALTER TABLE > > Time: 30344.272 ms (00:30.344) > > =C2=A0 > > devstats=3D> ALTER TABLE invite ADD COLUMN test hash DEFAULT '123abc123= '::hash; > > ALTER TABLE > > Time: 67439.232 ms (01:07.439) >=20 > It takes 30 seconds to schan the table and determine that all existing=20 > rows satisky the constraint. But there's no existing data (note this is adding column, not constraint) Existing rows are guaranteed to satisfy the domain check, because the=20 domain check is guaranteed to be immutable (per [1] in my original mail) Of course, if it were a table constraint it may involve multiple columns,= =20 requiring it to be evaluated per-row. But the docs make it clear the domain check is expected to be evaluated on= =20 input, precisely for this purpose. So I wondered if this was a shortcoming or even a bug. It seems that adding a column of NULL (or even default) values for a=20 domain can (should?) be as quick as a basic data type like text or=20 integer...? --=20 Mark ---1463793916-464543087-1675940196=:14632--