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 1qgouG-00HW0h-0W for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Sep 2023 16:09:28 +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 1qgouE-009QTX-OZ for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Sep 2023 16:09:26 +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 1qgouE-009QTG-7K for pgsql-hackers@lists.postgresql.org; Thu, 14 Sep 2023 16:09:26 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qgouA-0054IP-Te for pgsql-hackers@lists.postgresql.org; Thu, 14 Sep 2023 16:09:25 +0000 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-68fb79ef55eso1027413b3a.0 for ; Thu, 14 Sep 2023 09:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=illuminatedcomputing-com.20230601.gappssmtp.com; s=20230601; t=1694707760; x=1695312560; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=s05VthJe9VFoNBFbf3kc8qxvxQoH7HPiZoEKzpvTiTY=; b=k3pjxX9C/+FTdWW6p6fk3kbD5iHzZlGBf6Etv2VZJbv03nuImePkHq4cp26fxX7JXy DmE353FcFlVXGRdUMwNjLasNfDdn6DhbVMVagpzc83OM4kyjUGTtocFWUjdp6B5EOaw+ 3tBRghdSDryTMJt4dwpje9mp6ijfC/1FDhmxGrZp9/OkbOHNZf+EMu/feodDghT1neB9 krlkSe2sdnku/kXJ0ysvNyjm3FG2QuQVWXTBkfmehmUvo/Y2ajgf8gz+Iz/XS3WYveUw k1qEAGMrP+/qh1YBp4hCm0w6WEK/mAhcYaiP1uxUVq9WLAdxLveoYfp1gN3W19ILw450 ltEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694707760; x=1695312560; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=s05VthJe9VFoNBFbf3kc8qxvxQoH7HPiZoEKzpvTiTY=; b=TDcJzG9z5qolcGL8Fztcpr/n3+TKRrsxIbbg+beSHcNgXdCfqxXGYauA/yeTwnaAv+ OIoIyvKYoQoM3+kyG2B6zcFIERM2fFs++gbHfAhNNFS6ayZR4L3W2m9bPEAwpLeiWsfF rPsALvs0YJ/z9+/Cm+4qhUi5QQfBu7VMM2gkKuQv8DR9ZXdx5EctW/0HVf4UTfaaUzgQ JyQ6GYM7LSwxO1cPwNtzc8zd/CZf4sgnYUDWEgmbwitpAINtQDE2wntLdLlU8JbH4QkT Y1v7X06OU7vAf9AgIRYDIw5IJcTIgcwAemPTW16YqF0iGzZraUPIC39Q3F7nC2rOTdkh fotA== X-Gm-Message-State: AOJu0YyctY6aZR0AkDqdtMzPMaLc9TLsgPE3iF8PjTxhgjc1zY1CQ3ez ew2NJawWouEoaxycmFYZOUoCfQ== X-Google-Smtp-Source: AGHT+IEWo1Efahx4wwu6LdLjoY3a6RsUYOTTCpWg37hWeVbqePM7WvWxdIrIi6fClCPegPohFA5ICg== X-Received: by 2002:a05:6a00:440b:b0:690:33d6:11e7 with SMTP id br11-20020a056a00440b00b0069033d611e7mr1680420pfb.12.1694707760672; Thu, 14 Sep 2023 09:09:20 -0700 (PDT) Received: from [192.168.2.139] ([50.53.98.191]) by smtp.googlemail.com with ESMTPSA id ey20-20020a056a0038d400b0063f00898245sm1564956pfb.146.2023.09.14.09.09.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Sep 2023 09:09:19 -0700 (PDT) Message-ID: Date: Thu, 14 Sep 2023 09:09:19 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: SQL:2011 application time Content-Language: en-US To: jian he Cc: Vik Fearing , Peter Eisentraut , Corey Huinker , PostgreSQL Hackers References: <21964319-46e5-3e47-217b-6ac4169bdf13@enterprisedb.com> <27361388-f5ab-ea36-ea35-41d68a90e60d@illuminatedcomputing.com> <152e4c2c-36b4-bdc0-1b62-e9f9e8b68adc@enterprisedb.com> <251B44D1-D3E0-47E4-AB9D-4A848EDB495E@yesql.se> <1c674adf-4114-e8d8-cec7-ac10e2f424c7@enterprisedb.com> <831f17ba-ff36-1380-a475-a7cd2c65a89c@enterprisedb.com> <6f010a6e-8e20-658b-dc05-dc9033a694da@eisentraut.org> <7d44dade-ff31-5eef-80ac-78ed838066f6@postgresfriends.org> <88dadcc1-6652-ff7d-264d-73906a53dee9@illuminatedcomputing.com> From: Paul Jungwirth In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 9/7/23 18:24, jian he wrote: > for a range primary key, is it fine to expect it to be unique, not > null and also not overlap? (i am not sure how hard to implement it). > > ----------------------------------------------------------------- > quote from 7IWD2-02-Foundation-2011-12.pdf. 4.18.3.2 Unique > constraints, page 97 of 1483. > > ... > ----------------------------------------------------------------- > based on the above, the unique constraint does not specify that the > column list must be range type. UNIQUE (a, c WITHOUT OVERLAPS). > Here column "a" can be a range type (that have overlap property) and > can be not. > In fact, many of your primary key, foreign key regess test using > something like '[11,11]' (which make it more easy to understand), > which in logic is a non-range usage. > So UNIQUE (a, c WITHOUT OVERLAPS), column "a" be a non-range data type > does make sense? I'm not sure I understand this question, but here are a few things that might help clarify things: In SQL:2011, a temporal primary key, unique constraint, or foreign key may have one or more "scalar" parts (just like a regular key) followed by one "PERIOD" part, which is denoted with "WITHOUT OVERLAPS" (in PKs/UNIQUEs) or "PERIOD" (in FKs). Except for this last key part, everything is still compared for equality, just as in a traditional key. But this last part is compared for overlaps. It's exactly the same as `EXCLUDE (id WITH =, valid_at WITH &&)`. The overlap part must come last and you can have only one (but you may have more than one scalar part if you like). In the patch, I have followed that pattern, except I also allow a regular range column anywhere I allow a PERIOD. In fact PERIODs are mostly implemented on top of range types. (Until recently PERIOD support was in the first patch, not the last, and there was code all throughout for handling both, e.g. within indexes, etc. But at pgcon Peter suggested building everything on just range columns, and then having PERIODs create an "internal" GENERATED column, and that cleaned up the code considerably.) One possible source of confusion is that in the tests I'm using range columns *also* for the scalar key part. So valid_at is a tsrange, and int is an int4range. This is not normally how you'd use the feature, but you need the btree_gist extension to mix int & tsrange (e.g.), and that's not available in the regress tests. We are still comparing the int4range for regular equality and the tsrange for overlaps. If you search this thread there was some discussion about bringing btree_gist into core, but it sounds like it doesn't need to happen. (It might be still desirable independently. EXCLUDE constraints are also not really something you can use practically without it, and their tests use the same trick of comparing ranges for plain equality.) The piece of discussion you're replying to is about allowing *multiple* WITHOUT OVERLAPS modifiers on a PK/UNIQUE constraint, and in any position. I think that's a good idea, so I've started adapting the code to support it. (In fact there is a lot of code that assumes the overlaps key part will be in the last position, and I've never really been happy with that, so it's an excuse to make that more robust.) Here I'm saying (1) you will still need at least one scalar key part, (2) if there are no WITHOUT OVERLAPS parts then you just have a regular key, not a temporal one, (3) changing this obliges us to do the same for foreign keys and FOR PORTION OF. I hope that helps! I apologize if I've completely missed the point. If so please try again. :-) Yours, -- Paul ~{:-) pj@illuminatedcomputing.com