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 1s5zrX-009RdI-TS for pgsql-hackers@arkaria.postgresql.org; Sun, 12 May 2024 03:27:00 +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 1s5zqW-008V7Z-77 for pgsql-hackers@arkaria.postgresql.org; Sun, 12 May 2024 03:25:56 +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 1s5zqV-008V7R-PH for pgsql-hackers@lists.postgresql.org; Sun, 12 May 2024 03:25:56 +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 1s5zqO-000Zj8-Ol for pgsql-hackers@lists.postgresql.org; Sun, 12 May 2024 03:25:54 +0000 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-2b5f3e20615so2963633a91.1 for ; Sat, 11 May 2024 20:25:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=illuminatedcomputing-com.20230601.gappssmtp.com; s=20230601; t=1715484347; x=1716089147; 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=VKaCOsQH734BvQS7AjEecyOQcyR9k4iuh3rl5xhR6os=; b=xdMoJ5stcjCorQQgqBX5ZOcJOdUMU3JP7BXhE1y6Nblx1XaZWLyveL6cV9dF7bHw1x 4dsW5HRD23ztmKsmS1j+skf8JV4czQlgxX8Ubpvks1F2H0e9pMIK93WOnpmVRj4OprIV X+S6V+38LrZdDFyu9pqNDOvan6zAYCWCymvJZCvyBRixdCatohP1c87fgT1vf9J0nfZH rxjYupBY6p/R8QBzRl5N6kJ/5745lP9Bf0fRgwRrQYnxedapY6+uiOZ5kfHqLEG6em20 RuofLmbhkMCpYfGOQHpt0zDGK5vmnoQh6XXsp/0jxAWSqyFCdnege75NtNPX1MvFjX9w 0Vww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715484347; x=1716089147; 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=VKaCOsQH734BvQS7AjEecyOQcyR9k4iuh3rl5xhR6os=; b=KhXow59aipuTpxhZxC0TyukYi5nbEbFVtPJ2KN5ILnQ9YqgdtUSmj+sC6pPiEFfBn0 3c8eiiT1i7WInyyCvyt3UvGsGDy12j0rCDjkWqWXGG0im1p79G6KSityX47caMingz2R wmzDxslsf1AFXjfXADOlWUS0qWa9m4NGuLfkHeg3OLBqMD22PDdbG98wtttMtkP4ldmU 6jneSbwguTfea+yfABwytiQ1kY1k4knuETuTX1CddypqVaVZW4c+188SUJdLWHDL9Esq sFcX/X9Kx7Q1UiW8vtntuVJxxqjmCx3PB9z8FmX4xrE974yE+k3HCjLZ4sfkdiGY2kk3 JdcQ== X-Forwarded-Encrypted: i=1; AJvYcCU6HyNHlyEZ1yIWiamjN0RSL+NHqiUc0eLQlfdCbEpkktoUPqfvVdI+rl2olYGZXVEnZmzDBro+b9vbfWrk3IJtrxFFF0eIw2u3zSq5N4JiPQPP X-Gm-Message-State: AOJu0YxdrB9FTOPoQMiTCFeMdvw+hmPYOhpO5C0f3eoCGnwhQmQAvbF9 63HYliggSBmbcY1Sf04yD8FaltPfBfCeTeozUxHJEf9cJnDgUAsOYdf4/3cTjbk= X-Google-Smtp-Source: AGHT+IHk30qJLDA08jcv88jd50bR7q8MkQTrgipo++DvxmxJxi/UyzJIqjJXi/+C4pjnVS0Xs3Ttqw== X-Received: by 2002:a17:902:b905:b0:1e8:26e4:d084 with SMTP id d9443c01a7336-1ef44059acemr73580305ad.60.1715484346990; Sat, 11 May 2024 20:25:46 -0700 (PDT) Received: from [192.168.2.139] ([50.39.255.79]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1ef0c13823asm55625045ad.263.2024.05.11.20.25.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 11 May 2024 20:25:46 -0700 (PDT) Message-ID: <1f22c9c2-3879-4ece-8a4e-f69ba6df9df7@illuminatedcomputing.com> Date: Sat, 11 May 2024 20:25:45 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: SQL:2011 application time To: jian he Cc: Robert Haas , Peter Eisentraut , PostgreSQL Hackers References: <85dd3ad0-fa79-46e8-a08b-c426c76825f3@eisentraut.org> <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> Content-Language: en-US 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 5/11/24 17:00, jian he wrote: >> I hope I understand the problem correctly. >> my understanding is that we are trying to solve a corner case: >> create table t(a int4range, b int4range, primary key(a, b WITHOUT OVERLAPS)); >> insert into t values ('[1,2]','empty'), ('[1,2]','empty'); >> > > > but we still not yet address for cases like: > create table t10(a int4range, b int4range, unique (a, b WITHOUT OVERLAPS)); > insert into t10 values ('[1,2]','empty'), ('[1,2]','empty'); > > one table can have more than one temporal unique constraint, > for each temporal unique constraint adding a check isempty constraint > seems not easy. I think we should add the not-empty constraint only for PRIMARY KEYs, not all UNIQUE constraints. The empty edge case is very similar to the NULL edge case, and while every PK column must be non-null, we do allow nulls in ordinary UNIQUE constraints. If users want to have 'empty' in those constraints, I think we should let them. And then the problems you give don't arise. > Maybe we can just mention that the special 'empty' range value makes > temporal unique constraints not "unique". Just documenting the behavior is also an okay solution here I think. I see two downsides though: (1) it makes rangetype temporal keys differ from PERIOD temporal keys (2) it could allow more planner/etc bugs than we have thought of. So I think it's worth adding the constraint instead. > also we can make sure that > FOREIGN KEY can only reference primary keys, not unique temporal constraints. > so the unique temporal constraints not "unique" implication is limited. > I played around with it, we can error out these cases in the function > transformFkeyCheckAttrs. I don't think it is a problem to reference a temporal UNIQUE constraint, even if it contains empty values. An empty value means you're not asserting that row at any time (though another row might assert the same thing for some time), so it could never contribute toward fulfilling a reference anyway. I do think it would be nice if the *reference* could contain empty values. Right now the FK SQL will cause that to never match, because we use `&&` as an optimization, but we could tweak the SQL (maybe for v18 instead) so that users could get away with that kind of thing. As I said in an earlier email, this would be you an escape hatch to reference a temporal table from a non-temporal table. Otherwise temporal tables are "contagious," which is a bit of a drawback. Yours, -- Paul ~{:-) pj@illuminatedcomputing.com