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 1sUHuv-001tSB-0U for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Jul 2024 03:34:53 +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 1sUHus-008rsv-0o for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Jul 2024 03:34:50 +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 1sUHur-008rmA-DT for pgsql-hackers@lists.postgresql.org; Thu, 18 Jul 2024 03:34:50 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sUHun-0007hD-7K for pgsql-hackers@lists.postgresql.org; Thu, 18 Jul 2024 03:34:48 +0000 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-70ce3d66a8bso229136b3a.0 for ; Wed, 17 Jul 2024 20:34:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=illuminatedcomputing-com.20230601.gappssmtp.com; s=20230601; t=1721273684; x=1721878484; 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=5iCXUeiC/ihxiTF5c+NAHOLuaNkxKxWOjRwwcM2MNPw=; b=AOR+SnfC64DxEJ6lwEm3fFdJfLowvsGANOLWuwNRSir1JtLC//XyxSW47tXVFQYQV+ isXMj4I+Pz/+aos2EpZbNDR/uSIE/hPDts5TpxUZ489Cvg9ONVIVLeglGisKoU371Dzz lxSifiYKsLvZw/URVda/1m9+COY0BnCMYuhKVi5n+n+BTIeHArqxRahdZpZlvZ8o3LCo q7GhCXy5GYrfKHFY6f/RHerKMKqgp8/zFNQhMhj+6cr5S4hUzAnuf6pe3ZN6VWZOQaqa SmoKsw9wUp9hJmYoNMzvvOwMCIkbeAKnlI/XFYhmkz1jD5iUSZQz3O18Vjixx04QWNhK uaaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721273684; x=1721878484; 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=5iCXUeiC/ihxiTF5c+NAHOLuaNkxKxWOjRwwcM2MNPw=; b=UFEX/mQEBxjcJ9bGkfgoI3ehaUc8RCw3unmYnkWZnI9rVYuKPZAbc6ekixfTDd9wdS v6j+ZfVE/9ZNv4P4oAp4YAttApKxbRwcsm0t5QNHfNX92QkNp/48I1+dqG5mA7EzUUfu Ilw9hsvAIeBrkTWkV7z4adZuqdX5hZOIGC7VdYmA/+G3G7AlHci2ILGAbTLQD9TiTV+0 01h6a5QMjmA5uj7bjDetbdAAe9x1p6WRQ6Rpr2s33ajyo4iHBWzTZYqdP845ysEUPXnG JKwftqzNtG5g3wDeRcki95L4gXm0fZoi7LceUUcK8TyhbH9pvjwHOrBItcDv93M3wWl/ cLyA== X-Forwarded-Encrypted: i=1; AJvYcCUMGBx2ppGstZRxNSofLqcDrXP6PQ+P/CIEYsYVH9MbCRIsijkCtpA31nBT12kPkp+Ykx7VXyTrqPog98K7d9PCG5yief/AbNjPPjuOnmNCeY9Q X-Gm-Message-State: AOJu0YyevPL6mqyjU3EmZy1i/aKfq+AxXLGCGRQzC2s9y2l8hxLIfO1w 22Wys21lPOXHGE5jwB578yrhgAcM/Mac388eW1vQiZqIQAFgU76ozxdperAw65M= X-Google-Smtp-Source: AGHT+IEh148raDmvALmZtdOVmabTcWI3HzoQAWPVhp/mnFf8k5tC402Y27GeVCKjmN6FHEDk+EWgtQ== X-Received: by 2002:a05:6a00:2404:b0:70a:f22d:caeb with SMTP id d2e1a72fcca58-70ce4e8d2f1mr4693663b3a.4.1721273683956; Wed, 17 Jul 2024 20:34:43 -0700 (PDT) Received: from [192.168.2.139] ([50.39.255.79]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70b7ebb66b8sm8946335b3a.52.2024.07.17.20.34.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 17 Jul 2024 20:34:43 -0700 (PDT) Message-ID: Date: Wed, 17 Jul 2024 20:34:42 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: SQL:2011 application time To: jian he Cc: Isaac Morland , Robert Haas , Jeff Davis , 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> <64c2b2ab-7ce9-475e-ac59-3bfec528bada@eisentraut.org> <58b6687fe9de002e4c862a412719e4f918bad987.camel@j-davis.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 7/9/24 00:15, jian he wrote: >> **Option 2**: Add a new operator, called &&&, that works like && except an empty range *does* >> overlap another empty range. Empty ranges should still not overlap anything else. This would fix the >> exclusion constraint. You could add `(5, 'empty')` once but not twice. This would allow empties to >> people who want to use them. (We would still forbid them if you define a PERIOD, because those come >> with the CHECK constraint mentioned above.) >> And there is almost nothing to code. But it is mathematically suspect to say an empty range overlaps >> something small (something with zero width) but not something big. Surely if a && b and b <@ c, then >> a && c? So this feels like the kind of elegant hack that you eventually regret. > I think we can Forbid empties,not not mess with pg_class. > > to make the communication smooth, i've set the base commit to > 46a0cd4cefb4d9b462d8cc4df5e7ecdd190bea92 > {Add temporal PRIMARY KEY and UNIQUE constraints} > https://git.postgresql.org/cgit/postgresql.git/commit/?id=46a0cd4cefb4d9b462d8cc4df5e7ecdd190bea92 > you can git reset --hard 46a0cd4cefb4d9b462d8cc4df5e7ecdd190bea92 > then apply the attached patch. > > I hope I understand it correctly. > previously revert is only because the special value: empty. > i tried to use the operator &&&, new gist strategy number, pg_amop > entry to solve the problem. > Now with the applied patch, if the range column is specified WITHOUT OVERLAPS, > then this column is not allowed to have any empty range value. > > logic work through: > * duplicate logic of range_overlaps but disallow empty value. also > have the operator &&&, (almost equivalent to &&) > * add new gist strategy number > * thanks to add stratnum GiST support function > (https://git.postgresql.org/cgit/postgresql.git/commit/?id=6db4598fcb82a87a683c4572707e522504830a2b) > now we can set the strategy number to the mapped new function > (equivalent to range_overlaps, but error out empty value) > * in ComputeIndexAttrs, set the strategy number to the newly created > StrategyNumber in "else if (iswithoutoverlaps)" block. > * Similarly refactor src/backend/utils/adt/rangetypes_gist.c make the > index value validation using newly created function. I like this approach a lot, but I'd like to hear what some other people think? Jian he's &&& operator is similar to what I proposed upthread, but when either operand is an empty value it simply raises an error. (It should be an ereport, not an elog, and I think multirange_overlaps_multirange_internal is missing the empty check, but I can clean things up when I integrate it into the patch series.) This is much simpler than everything I'm doing: checking for empties in the executor phase, adding a field to pg_class, setting things in the relcache, and checking for empties in existing rows when you add an index. This patch uses existing infrastructure to do all the work. It seems like a much cleaner solution. Unlike my proposed &&& operator, it doesn't have weird mathematical consequences. At first I thought raising an error was not great, but it's the same thing you get when you divide by zero. It's fine for an operator to have a restricted domain of inputs. And we would only use this internally for primary keys and unique constraints, where indeed raising an error is just what we want. If I don't hear objections (or think of something myself :-), I'm inclined to use this approach. But what do people think? Yours, -- Paul ~{:-) pj@illuminatedcomputing.com