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 1pYQQm-0005Lo-Bs for pgsql-general@arkaria.postgresql.org; Sat, 04 Mar 2023 11:52:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pYQQj-0008PL-2k for pgsql-general@arkaria.postgresql.org; Sat, 04 Mar 2023 11:52:01 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pYQQi-0008PA-G0 for pgsql-general@lists.postgresql.org; Sat, 04 Mar 2023 11:52:00 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pYQQd-0008TY-Cs for pgsql-general@lists.postgresql.org; Sat, 04 Mar 2023 11:51:59 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id E55291A30F; Sat, 4 Mar 2023 12:51:52 +0100 (CET) Date: Sat, 4 Mar 2023 12:51:52 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Dropping behavior for unique CONSTRAINTs Message-ID: <20230304115152.df5pmrgny7z5ogkm@hjp.at> Mail-Followup-To: pgsql-general@lists.postgresql.org References: <3d7d49f0-7eef-4d6d-8dc3-1993ba2fc2cb@me.com> <20230304080303.a3oimbvcoo5lo3d5@hjp.at> <0d0e4771-a1f2-f883-a983-4a4aee1bce9b@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="poi3zkbvrqbwoq4n" Content-Disposition: inline In-Reply-To: <0d0e4771-a1f2-f883-a983-4a4aee1bce9b@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --poi3zkbvrqbwoq4n Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2023-03-04 02:34:02 -0600, Ron wrote: > On 3/4/23 02:03, Peter J. Holzer wrote: > [snip] > > So your plan is to create a unique constraint (backed by a unique > > index) and then to drop the index and keep the constraint? > >=20 > > That doesn't work. A unique constraint can't exist without a (unique) > > index. Think about it: With a unique constraint PostgreSQL needs to > > check for every insert whether the value already exists in the table. > > Without an index this would mean a full table scan. >=20 > I cut my teeth on an RDBMS which didn't automagically create a backing > index.=A0 You had to do it yourself... Just curious: Which RDBMS was that? I'm pretty sure Oracle did that automatically when I first used it (version 8.0.5). Not sure about MySQL, but if it didn't have an index it probably didn't enfocre the constraint either (it definitely didn't enforce foreign key constraints). Speaking of foreign key constraints: Neither Oracle nor PostgreSQL automatically add an index on a foreign key. That bit me hard back in the day ... hp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --poi3zkbvrqbwoq4n Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmQDMNQACgkQ8g5IURL+ KF1Cmw/+IDblh9S7eGhZ/jpE6LY01Y8WrzbRdG9VXFBb28opHJnR+UFGX+J8PoJx iqy/ZlTmcfGPcHbw2MWtLa455MCsbhZdybublkP/9AV3X8BE+jWZq1iRaGQHPHGK y9Kyuh0sgJhI+SQ+BntjSyLJxO8N1fuTw+CIoJ0DtqNmnxJaRXZmXuexXjUFnA23 rim1ZyA3Qj+FyxOYDbJ7MsqM8eGz0Rr2DyHDiOTrgjxUXCDJbK/9yC+ebyc0ZjrW fEw5WcoF0RKfjP7zGHxz92TU3vf5m4xX2wkccreclSiyPUBdGOaclwTdNaFDvjlZ EexMRbMRPvMeeMnbe3aDOc/OPaAnkgC4nRt2Uo59NdETbnIPK3khSKXLAaKfvuDq x5rjsuKNLmN7UG+27ZVzoJu2Uv2Ac7s7wJ11jVvy663A4whO0xPYKJvauo+1ZaRu 4tKUMT/P5P2kk0W8PEyZmXZgcXHDZU478qcCPjkmUhKMBjaUFUbNjo5PDtBJJjsm WjJJlKIeEhiKcU0OVUr+mf0oBq2O0Mq2lJ7Z95uZfeq5RkLwI4kSvjSCvFLfNBXB gmSTA49iLtgNZxV5iXqgUSU+ZkBwpqt2pSQJENvXAhM9ptdls9VSKEqXGUpEjrAW TQ4bRsFimV5oAxDhgVgn2E0h04OmM6dRft6UBrTZ+1CkJWoDoMg= =sYP5 -----END PGP SIGNATURE----- --poi3zkbvrqbwoq4n--