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 1sHQDw-007GdY-00 for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Jun 2024 15:49:20 +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 1sHQDu-0025Y7-Fu for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Jun 2024 15:49:19 +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 1sHQDu-0025Xz-52 for pgsql-hackers@lists.postgresql.org; Wed, 12 Jun 2024 15:49:19 +0000 Received: from mail-lj1-x231.google.com ([2a00:1450:4864:20::231]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sHQDs-001Icp-3Z for pgsql-hackers@lists.postgresql.org; Wed, 12 Jun 2024 15:49:18 +0000 Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2ebe3bac675so10156231fa.1 for ; Wed, 12 Jun 2024 08:49:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718207354; x=1718812154; 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=TkRtt2P6RpNlchhW4sOkevnc+d6Knf1xgDI8xhwKEPU=; b=mRz9ak+0qlq6TL/oSC/+uPRq/AV7tT+gofA4dLQKfJbHlAVNMyEnKLIP5RplosPwa+ So/U8kbDz31duNpRFacjOLG13ngAzEQPo8KzasqXIcHLTBtd9vkIkLJkciQUXz4ryK/c htjZjX16Yip9TqGQaqvRcOxnwjK4rDmOvuc5ggXmEYr2qUIj+AwFpHNoXeqz65X+CZiw uhyL7TmG3VChjnOnW7CYFq/Grv21JNgO0VeiBbgeYm9DEz7lLgC+qU92D2dK97G4XZgW J4cZgfJyEAjUEPvt27sZrj7fUZZsIyv0wNkSc+tExcEu66xnn9E9su46pklJIP59VlCu LD2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718207354; x=1718812154; 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=TkRtt2P6RpNlchhW4sOkevnc+d6Knf1xgDI8xhwKEPU=; b=TlYElbiZVPPNaOWYxbpu6ivhlVjidZqH/KiAE850X4oZFCYGJcFg86lMJlgzkdNhHc 3CpoPlZbNP03JXV09va84pH4BAD5HVrIX48/c4PUCpT9AkZNMAomMQ3xuElWhepzv/dm g1TlvCoJlcY8NrRg5HQ9IF9VWb3pRN98Cfuh9gJ8ueE3NeKZIROYdS5xHSH47cQC779U VB8juN3w66MY7DE+B3EAMPYfUhCUUaM0A1ybavmLU8KL5YVunhYmpgU7V5qto0Jz5Smd MZ+nzfBBL0CJEYSS/fKV38Q7v+g7rBvjO26Tkf71Ro2BZQ7Cx/toihR78wwTSoRI75VL jugw== X-Forwarded-Encrypted: i=1; AJvYcCVshMKSOWSkfjbo3cne6g9NJKThLwQ0S6u/SKOwhrtrUNj7Zd5ruIYvtn4aJoy2W2uGH7flnFXNZdYqTA4pcNLFEHCmWRmXZpbwGi/Raylz/UA+ X-Gm-Message-State: AOJu0YzaB4txMKmIexct9++R0RS/4tWftjVLGvOk1S3Tq3XKhv2LUWR5 VAkusEptxORL9h9SyXyijSp6QjR7Gogicl+f6vEdPLWFts3qxG+wbiTB6yiNmLgmUFxNHJZmSJr lJwv0KwZBXMiQz3C0hW2rpiOHtLM= X-Google-Smtp-Source: AGHT+IEkZbBwxoX05RVlRJLiRceEzgD9Wejw1UhkknHOScaRoo6X/OmlPU9R0YsdlxKxQoHX87FSGM8ntfrEf8jPa1k= X-Received: by 2002:a2e:9b03:0:b0:2ea:abac:f97b with SMTP id 38308e7fff4ca-2ec02a6b194mr188021fa.4.1718207354215; Wed, 12 Jun 2024 08:49:14 -0700 (PDT) MIME-Version: 1.0 References: <49c07eac-18ec-4aff-929c-e81b87df1092@eisentraut.org> <1edb3b79-a4bc-43b1-80aa-2e090472fe32@eisentraut.org> <47550967-260b-4180-9791-b224859fe63e@illuminatedcomputing.com> <1b2ab118-82c1-4e79-a094-04dab382e2c4@illuminatedcomputing.com> <3775839b-3f0f-4c8a-ac03-a253222e6a4b@illuminatedcomputing.com> <731ef81e-d4c3-41c6-ba8f-f6131f4f6407@eisentraut.org> <1426589a-83cb-4a89-bf40-713970c07e63@illuminatedcomputing.com> <5aefa87e-ba20-4a34-88aa-233255643c1b@illuminatedcomputing.com> <3ad31f4c-8caf-4b9e-9f1f-b949c6330005@illuminatedcomputing.com> In-Reply-To: <3ad31f4c-8caf-4b9e-9f1f-b949c6330005@illuminatedcomputing.com> From: Matthias van de Meent Date: Wed, 12 Jun 2024 17:48:59 +0200 Message-ID: Subject: Re: SQL:2011 application time To: Paul Jungwirth Cc: Peter Eisentraut , Robert Haas , jian he , PostgreSQL Hackers 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 Wed, 5 Jun 2024 at 22:57, Paul Jungwirth w= rote: > > On Thu, May 9, 2024 at 5:44=E2=80=AFPM Matthias van de Meent wrote: > > Additionally, because I can't create my own non-constraint-backing > > unique GIST indexes, I can't pre-create my unique constraints > > CONCURRENTLY as one could do for the non-temporal case > > We talked about this a bit at pgconf.dev. I would like to implement it, s= ince I agree it is an > important workflow to support. Here are some thoughts about what would ne= ed to be done. > > First we could take a small step: allow non-temporal UNIQUE GiST indexes.= This is possible according > to [1], but in the past we had no way of knowing which strategy number an= opclass was using for > equality. With the stratnum support proc introduced by 6db4598fcb (revert= ed for v17), we could > change amcanunique to true for the GiST AM handler. If the index's opclas= ses had that sproc and it > gave non-zero for RTEqualStrategyNumber, we would have a reliable "defini= tion of uniqueness". UNIQUE > GiST indexes would raise an error if they detected a duplicate record. Cool. > But that is just regular non-temporal indexes. To avoid a long table lock= you'd need a way to build > the index that is not just unique, but also does exclusion based on &&. = We could borrow syntax from > SQL:2011 and allow `CREATE INDEX idx ON t (id, valid_at WITHOUT OVERLAPS)= `. But since CREATE INDEX > is a lower-level concept than a constraint, it'd be better to do somethin= g more general. You can > already give opclasses for each indexed column. How about allowing operat= ors as well? For instance > `CREATE UNIQUE INDEX idx ON t (id WITH =3D, valid_at WITH &&)`? Then the = index would know to enforce > those rules. I think this looks fine. I'd like it even better if we could default to the equality operator that's used by the type's default btree opclass in this syntax; that'd make CREATE UNIQUE INDEX much less awkward for e.g. hash indexes. > This is the same data we store today in pg_constraint.conexclops. So that= would get > moved/copied to pg_index (probably moved). I'd keep the pg_constraint.conexclops around: People are inevitably going to want to keep the current exclusion constraints' handling of duplicate empty ranges, which is different from expectations we see for UNIQUE INDEX's handling. > Then when you add the constraint, what is the syntax? Today when you say = PRIMARY KEY/UNIQUE USING > INDEX, you don't give the column names. So how do we know it's WITHOUT OV= ERLAPS? I guess if the > underlying index has (foo WITH =3D [, bar WITH =3D], baz WITH &&) we just= assume the user wants WITHOUT > OVERLAPS, and otherwise they want a regular PK/UQ constraint? Presumably you would know this based on the pg_index.indisunique flag? > In addition this workflow only works if you can CREATE INDEX CONCURRENTLY= . I'm not sure yet if we'll > have problems there. I noticed that for REINDEX at least, there were plan= s in 2012 to support > exclusion-constraint indexes,[2] but when the patch was committed in 2019= they had been dropped, > with plans to add support eventually.[3] Today they are still not support= ed. Maybe whatever caused > problems for REINDEX isn't an issue for just INDEX, but it would take mor= e research to find out. I don't quite see where exclusion constraints get into the picture? Isn't this about unique indexes, not exclusion constraints? I understand exclusion constraints are backed by indexes, but that doesn't have to make it a unique index, right? I mean, currently, you can write an exclusion constraint that makes sure that all rows with a certain prefix have the same suffix columns (given a btree-esque index type with <> -operator support), which seems exactly opposite of what unique indexes should do. Kind regards, Matthias van de Meent Neon (https://neon.tech)