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 1qqQkA-00A6Nt-SN for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Oct 2023 04:22: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 1qqQk8-00CgnG-OA for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Oct 2023 04:22:45 +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 1qqQk8-00Cgn1-AP for pgsql-hackers@lists.postgresql.org; Wed, 11 Oct 2023 04:22:45 +0000 Received: from mail-oi1-x232.google.com ([2607:f8b0:4864:20::232]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qqQk2-0013tx-9Y for pgsql-hackers@lists.postgresql.org; Wed, 11 Oct 2023 04:22:43 +0000 Received: by mail-oi1-x232.google.com with SMTP id 5614622812f47-3af8b498d30so3766252b6e.0 for ; Tue, 10 Oct 2023 21:22:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=illuminatedcomputing-com.20230601.gappssmtp.com; s=20230601; t=1696998157; x=1697602957; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=3WwS4I59B1MdN5FBTIsscv18WaLiSvlLDemR3F4GB4w=; b=uVCyJm6CLb6XYqn5YMpL4oM0xllB3SZeGOvM0eAcWOTcKnvPkwfXWdGBufh21lHT99 m5AfJ8sTWEwhAwkos8mJK9/FUAm6CbQGAQ8fC+0VAudm3QTB0lnQjFt/ORtU1iImsUsD Ay1suxKSBJBdyu34PW/mNL0kgGZBM0tUHMMAe5BOTUaByNxzW2QmsZaZzY770ZKnghCm 6lDJ9Zu3ODAcWDOqnr2NkaL85I2s4/akGgdEw4xY9o8qV0dchDzhhtuaEOXPPpKbCdzA XO3sDvnsKD1ugUVY6BxqDm3U9/VcfCrlXLxpDYr95DSNGBReynpeMTMNXRvFgDEYC1fX mNaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696998157; x=1697602957; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3WwS4I59B1MdN5FBTIsscv18WaLiSvlLDemR3F4GB4w=; b=j2Uky3EpPX0+z9cN7zdEEClolQvrSgzn3eOKKyjUP6Vs1V7BiEA1l/SYk50WhcgLBV x7KrqDqFsNXkVeqmQpqmyGik5ptLO25D61ar19iX7Aoe+w2Bd8lIBefD1EQCUdKXylrw 00UIC//wVG+jlKd7AHhKWwp0YCxP5tPbCRIl/4lzKZpZjFgNIOyB9Dk5X5hkJE6YdeK5 T6FmiDSLVscV5z8WAKL8Xa+NKltAl3HXlRkOfuSygsdXggf5ad+F1JZEqdpAB8O8L2M+ jyvTHMTPdc4Ciu/qj78qHPX3g1HPQGB+mTqvgIzQ44OZAwWegVwS6PGRvVuXBTXJh0bC FNrQ== X-Gm-Message-State: AOJu0Yzws/0+qhsjGKVCPNAdQrkdcZlaHU+3F13mwL+z7Myx2n8P19qt oSTP0cxgTX8hWyBPBkJZuuT4OQ== X-Google-Smtp-Source: AGHT+IGHS87QXI21YL0n84C0hbglt7E7bGys3i2BFwOQnd7GK9QNiA/8gp5p7awhz4513rXVZ+sMhw== X-Received: by 2002:a05:6808:2225:b0:3ae:5372:3790 with SMTP id bd37-20020a056808222500b003ae53723790mr22833807oib.48.1696998157379; Tue, 10 Oct 2023 21:22:37 -0700 (PDT) Received: from [192.168.2.139] ([50.53.98.191]) by smtp.googlemail.com with ESMTPSA id m28-20020a638c1c000000b0059c8fa8f917sm1842364pgd.12.2023.10.10.21.22.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 10 Oct 2023 21:22:36 -0700 (PDT) Message-ID: Date: Tue, 10 Oct 2023 21:22:35 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: SQL:2011 application time Content-Language: en-US From: Paul Jungwirth To: Vik Fearing , Peter Eisentraut Cc: Corey Huinker , PostgreSQL Hackers References: <5650d77a-1d73-fd8d-4410-8e97dbeff572@illuminatedcomputing.com> <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> In-Reply-To: <88dadcc1-6652-ff7d-264d-73906a53dee9@illuminatedcomputing.com> 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 Hi Peter et al, On 9/1/23 12:56, Paul Jungwirth wrote: >> On 9/1/23 11:30, Peter Eisentraut wrote: >>> I think the WITHOUT OVERLAPS clause should be per-column, so that >>> something like UNIQUE (a WITHOUT OVERLAPS, b, c WITHOUT OVERLAPS) >>> would be possible.  Then the WITHOUT OVERLAPS clause would directly >>> correspond to the choice between equality or overlaps operator per >>> column. > I think allowing multiple uses of `WITHOUT OVERLAPS` (and in any > position) is a great recommendation that enables a lot of new > functionality. I've been working on implementing this, but I've come to think it is the wrong way to go. If we support this in primary key and unique constraints, then we must also support it for foreign keys and UPDATE/DELETE FOR PORTION OF. But implementing that logic is pretty tricky. For example take a foreign key on (id, PERIOD valid_at, PERIOD asserted_at). We need to ensure the referenced two-dimensional time space `contains` the referencing two-dimensional space. You can visualize a rectangle in two-dimensional space for each referencing record (which we validate one at a time). The referenced records must be aggregated and so form a polygon (of all right angles). For example the referencing record may be (1, [0,2), [0,2)) with referenced records of (1, [0,2), [0,1)) and (1, [0,1), [1,2)). (I'm using intranges since they're easier to read, but you could imagine these as dateranges like [2000-01-01,2002-01-01).) Now the range_agg of their valid_ats is [0,2) and of their asserted_ats is [0,2). But the referenced 2d space still doesn't contain the referencing space. It's got one corner missing. This is a well-known problem among game developers. We're lucky not to have arbitrary polygons, but it's still a tough issue. Besides `contains` we also need to compute `overlaps` and `intersects` to support these temporal features. Implementing that for 2d, 3d, etc looks very complicated, for something that is far outside the normal use case and also not part of the standard. It will cost a little performance for the normal 1d use case too. I think a better approach (which I want to attempt as an add-on patch, not in this main series) is to support not just range types, but any type with the necessary operators. Then you could have an mdrange (multi-dimensional range) or potentially even an arbitrary n-dimensional polygon. (PostGIS has something like this, but its `contains` operator compares (non-concave) *bounding boxes*, so it would not work for the example above. Still the similarity between temporal and spatial data is striking. I'm going to see if I can get some input from PostGIS folks about how useful any of this is to them.) This approach would also let us use multiranges: not for multiple dimensions, but for non-contiguous time spans stored in a single row. This puts the complexity in the types themselves (which seems more appropriate) and is ultimately more flexible (supporting not just mdrange but also multirange, and other things too). This approach also means that instead of storing a mask/list of which columns use WITHOUT OVERLAPS, I can just store one attnum. Again, this saves the common use-case from paying a performance penalty to support a much rarer one. I've still got my multi-WITHOUT OVERLAPS work, but I'm going to switch gears to what I've described here. Please let me know if you disagree! Yours, -- Paul ~{:-) pj@illuminatedcomputing.com