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 1sExha-005LWg-BC for pgsql-hackers@arkaria.postgresql.org; Wed, 05 Jun 2024 20:57:47 +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 1sExha-00BsfJ-Dl for pgsql-hackers@arkaria.postgresql.org; Wed, 05 Jun 2024 20:57:46 +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 1sExha-00BsfA-08 for pgsql-hackers@lists.postgresql.org; Wed, 05 Jun 2024 20:57:46 +0000 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sExhX-003dPW-6Z for pgsql-hackers@lists.postgresql.org; Wed, 05 Jun 2024 20:57:44 +0000 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-2c29c487a94so4127a91.1 for ; Wed, 05 Jun 2024 13:57:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=illuminatedcomputing-com.20230601.gappssmtp.com; s=20230601; t=1717621062; x=1718225862; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=UOWFw//gF0s4ey2u0SajKirJ91uSaFI4LcyFjJCljaI=; b=X0a0Ak8HuevNyUy5NpqgB6/8s91UI5VR6gbK78R1IZ5waIILHVafl5Af6GVlz0fhsQ IB44Tp2SMFy8bldA1R5rP86pzW7grPv3pV9yDyfF4MPk5qgRu3yiAySOUUaspp7hVmdd T8VGSEB5Mq65++PAygeVCLu5fIsniYgp2VuwKUy3j5sCkA9M4u/OK07x9N3wwlv28R/o TEvJakp4PJfxi6qSCpwVNfxJSCePCIZTLRMi4FRRtRHhHnIpYh0fEeqnRJxz6XqDsrXW SO4WXsR5ntz1ncLu1cWu+SCq0fvSDIdLRgJzqq6QJml9C8luhDgLP96CUzaAQzjYmQ6B Wwxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717621062; x=1718225862; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UOWFw//gF0s4ey2u0SajKirJ91uSaFI4LcyFjJCljaI=; b=Sp4C2GRXfGI7Vxe0ZXV2rID+v8Af+6Vzs3DoO5irUwVskaDfCjsRFrdtTh2LT2bX78 OT2amLoscfOyqEroN7U/WiXViwl3ogQtyI+pIKXgZ0lFdmkCsZq3OOeyDtKRkRIAuKSP cRQNveWIPNi2wytw+Z/0Bk/SJ3d7ddTAcUXlpaqJh90sgnKC7SFki4lRDGgyeybL0iNi Cm6c17E6mXDTQUMM0i4LMmHjzBKOM56co3H/wtNyywy2AidAICqaaN+ojS+zfF+ykvXK wGBu0Gr16+u6K1B8oUH/ShQNlX/fJ0Kg2T2kzdY9ICVLTymLtOZsaxWmQm5Li28cvoaO A0rg== X-Forwarded-Encrypted: i=1; AJvYcCWJSHGaY68nMJS3JbR3ayaco4zpcp2EinAyetTWqjchbvTl7zXrYFPvQl7GAMOpaXr4Apo3keW5+PJrSERfB0Ik8jQEZYGIakYer61B+QPp6mNm X-Gm-Message-State: AOJu0Yzl6mRo8M04Vbo5XInac82ZfR/LTOidkTq/DEMxOiuiXdjMh4kC bvanl50bVb/i9Xu9V/YZL/jlDW0EK9gFMHF/bK5rNN8zOg/+GfCY6LSw+DaJbZc= X-Google-Smtp-Source: AGHT+IF9zQz8N3ybZf8dLxNl/ukAtS4IeOCSyxhIl/W8aeGNmGZM8KVuMHdFLBA9NeBEs3hTfEXwLA== X-Received: by 2002:a17:90b:3810:b0:2c2:4129:9069 with SMTP id 98e67ed59e1d1-2c27db68442mr3544445a91.44.1717621062044; Wed, 05 Jun 2024 13:57:42 -0700 (PDT) Received: from [192.168.2.139] ([50.39.255.79]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2c28066cfe2sm1923600a91.14.2024.06.05.13.57.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 05 Jun 2024 13:57:41 -0700 (PDT) Message-ID: <3ad31f4c-8caf-4b9e-9f1f-b949c6330005@illuminatedcomputing.com> Date: Wed, 5 Jun 2024 13:57:40 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: SQL:2011 application time To: Matthias van de Meent Cc: Peter Eisentraut , Robert Haas , jian he , PostgreSQL Hackers 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> Content-Language: en-US From: Paul Jungwirth In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, May 9, 2024 at 5:44 PM 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, since I agree it is an important workflow to support. Here are some thoughts about what would need 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 (reverted for v17), we could change amcanunique to true for the GiST AM handler. If the index's opclasses had that sproc and it gave non-zero for RTEqualStrategyNumber, we would have a reliable "definition of uniqueness". UNIQUE GiST indexes would raise an error if they detected a duplicate record. Incidentally, this would also let us correct the error message about GiST not supporting unique, fixing the problem you raised here: On Sun, May 12, 2024 at 8:51 AM Paul Jungwirth wrote: > > On 5/12/24 05:55, Matthias van de Meent wrote: > >> > pg=# CREATE UNIQUE INDEX ON temporal_testing USING gist (id, valid_during); > >> > ERROR: access method "gist" does not support unique indexes > >> > >> To me that error message seems correct. The programmer hasn't said anything about the special > >> temporal behavior they are looking for. > > > > But I showed that I had a GIST index that does have the indisunique > > flag set, which shows that GIST does support indexes with unique > > semantics. > > > > That I can't use CREATE UNIQUE INDEX to create such an index doesn't > > mean the feature doesn't exist, which is what the error message > > implies. > > True, the error message is not really telling the truth anymore. 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 something more general. You can already give opclasses for each indexed column. How about allowing operators as well? For instance `CREATE UNIQUE INDEX idx ON t (id WITH =, valid_at WITH &&)`? Then the index would know to enforce those rules. This is the same data we store today in pg_constraint.conexclops. So that would get moved/copied to pg_index (probably moved). 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 OVERLAPS? I guess if the underlying index has (foo WITH = [, bar WITH =], baz WITH &&) we just assume the user wants WITHOUT OVERLAPS, and otherwise they want a regular PK/UQ constraint? 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 plans 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 supported. Maybe whatever caused problems for REINDEX isn't an issue for just INDEX, but it would take more research to find out. [1] https://dsf.berkeley.edu/papers/sigmod97-gist.pdf [2] Original patch thread from 2012: https://www.postgresql.org/message-id/flat/CAB7nPqS%2BWYN021oQHd9GPe_5dSVcVXMvEBW_E2AV9OOEwggMHw%40mail.gmail.com#e1a372074cfdf37bf9e5b4e29ddf7b2d [3] Revised patch thread, committed in 2019: https://www.postgresql.org/message-id/flat/60052986-956b-4478-45ed-8bd119e9b9cf%402ndquadrant.com#74948a1044c56c5e817a5050f554ddee Yours, -- Paul ~{:-) pj@illuminatedcomputing.com