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 1u521w-00B4tH-Er for pgsql-performance@arkaria.postgresql.org; Wed, 16 Apr 2025 12:38:16 +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 1u521t-00E32U-Dz for pgsql-performance@arkaria.postgresql.org; Wed, 16 Apr 2025 12:38:14 +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 1u521t-00E32M-33 for pgsql-performance@lists.postgresql.org; Wed, 16 Apr 2025 12:38:13 +0000 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u521r-000N2f-2r for pgsql-performance@lists.postgresql.org; Wed, 16 Apr 2025 12:38:13 +0000 Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-5f4c30f8570so702801a12.2 for ; Wed, 16 Apr 2025 05:38:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1744807091; x=1745411891; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=5CDkboAi2l+8DN0tMoyLqHLA0HPppxh4MVLw8AMxkSM=; b=pY/IMSiA3hUEFL+LnATyBSGyJtFvUvseBQ8eD1s+q4AnhDIySBbZN8tYM2ctO6o+Ol SIixtn2hX89Pq41Q59mPTedfDs8BmB9Skfo/28aEfzUvcbJzxA2ja3UkJPkp4rEfcIyv JcVjiLZ09eHgwmPwdhJBQXf57lHs1KIoV4Jk6x/6AqZJS87LtiwiuZzTONsH/7MND/Cf dFGpe/lj/THmt9qXdXjb9qNj1oIBN0BfnP6nuaGQsJwd1Q7PNPZ4xfoo6jGcUKBmEKwm okhpstdwKoAUZeExziGQl+aa/iaLv2YnM3HXa+R2AFSmS8V2guFGO/67jY/CK1nSTjlQ y1Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744807091; x=1745411891; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=5CDkboAi2l+8DN0tMoyLqHLA0HPppxh4MVLw8AMxkSM=; b=WKLE6i+brGRXrkBGY+OjrX1skp1wCgo7q2Cxg5BwUmySd/8MUPnsa9TRt4pAOsvj3H vzA4Rwabcze12wmGqjW1JKJmsDOyiJ4EsCYy14qaGXl4K8BiD8Qvg1qzHa+08zbg0GA4 kM7AOjq44l8F0swBZxeC5RSQO2mGr0CiW8PO6t2Q/BxOjQTrgYovnl9HDk4rzjYZOQ3v rNHwG5KVKdNI7JAmcA9E60mmpIXgdrvSgYPPIWzoBDmxfOCxnlI5Z/zi+Hz5cfw2QmhA xA5PiK5Q5ouoB3bpBtaZk6bsY/P7oXT5v8LV/bCXDC7eULs0bvWcbxXNUpuUBdciTpdA BoyA== X-Forwarded-Encrypted: i=1; AJvYcCXR/uSti19a9QwMj/bfjAiK/XrUkSXw4pSpFl/zWIxdUXU1JIP3yYx8hAGKsNamhHP2AiuNi58uGwm5gTcBrTQoVA==@lists.postgresql.org X-Gm-Message-State: AOJu0YxmJsJPwGDWAOg4YnkXhYuIUodPx9PyCFJiIYALXSY2YxV5xD2D 6etSzC0U46B0Iy0CTrZd6WUlrsGBpyFXR+Yz27lkViuYWYcoXIQlxr8rIkQ7BBGqmcKj/8iffmb c X-Gm-Gg: ASbGncvphNuGtVyUKDMHDslMTiF50kXieAID1ZzXq5tBVt2UISBWo+cLjMZRDEDAraM x9myCPEDPMDDd20xttQhRVBSuKRwchQIN9DgIyaO92x7QpuLSJhGJZFW77OUZpzchLZaIG+9Ats z8ExEJoLQ43j8smxT+cfT+b9bTyEEghlUuxDzH4bDDVtyyCeeQDDLB9V0yp2hcml4XiPE1gacFd 8I3DNXSVGJ3LprgQRaXA14ZU00QPtmmaPIv7imDGhvcYWUCw+K1IF60Dp3M4ZhZf/gAwtH6Yebk rhLdt3wxN/Qaj4VUZN8XsGEKdRz59OXcru85FH3ZwzQSXIEVi5TPyOBjajv3 X-Google-Smtp-Source: AGHT+IFJ/KCzZAsNAlU5Wq+EPYpE2E2Y6T7RGuTp/97qeICegdByJmBuNW2JulZ8u68ELi2lM61kEA== X-Received: by 2002:a17:907:7da3:b0:aca:c4a6:cd90 with SMTP id a640c23a62f3a-acb428827cbmr128115966b.5.1744807090849; Wed, 16 Apr 2025 05:38:10 -0700 (PDT) Received: from localhost.localdomain ([2001:871:5e:b709:9349:713f:cd9e:e764]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-acb3d1a948dsm116923966b.126.2025.04.16.05.38.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Apr 2025 05:38:10 -0700 (PDT) Message-ID: <3ee9caa4d50df99916922693b987df551a02d991.camel@cybertec.at> Subject: Re: Constraints elimination during runtime From: Laurenz Albe To: "Weck, Luis" , "pgsql-performance@lists.postgresql.org" Date: Wed, 16 Apr 2025 14:38:10 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.54.3 (3.54.3-1.fc41) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, 2025-04-16 at 11:16 +0000, Weck, Luis wrote: > I am not sure if this list is the most appropriate, but I figured I=E2=80= =99d share it here=E2=80=A6 >=20 > If a column has a check constraint, such as CHECK (length(value) < 10) or= even > something like a VARCHAR(10) shouldn=E2=80=99t a query like this become a= no-op/false instantly? >=20 > create table test_constraint ( > =C2=A0 =C2=A0 =C2=A0value varchar(10) // could be a CHECK constraint also > =C2=A0 ); >=20 > insert into=C2=A0test_constraint values (=E2=80=98small=E2=80=99); >=20 > -- shouldn=E2=80=99t this qual always evaluate to false?=C2=A0 > select * from test_constraint where value =3D =E2=80=98way too big to fit= anyway=E2=80=99; I am sure that it could be done, but I doubt it would be a good idea. These extra checks would slow down query planning for most queries a bit, and only very few queries would benefit from it. If you are writing a query that uses a user-defined constant, you could write the query as SELECT ... FROM test_constraint WHERE value =3D $1 AND length($1) <=3D 10; If the query planner knows the value of the constant, it will evaluate the second condition when it plans the query and replace it with a "One-Time Filter: false", which would do exactly what you want. Yours, Laurenz Albe