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 1qt1jC-00AWxw-AM for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Oct 2023 08:16:30 +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 1qt1jA-001GFI-31 for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Oct 2023 08:16:28 +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 1qt1j9-001GF9-GJ for pgsql-hackers@lists.postgresql.org; Wed, 18 Oct 2023 08:16:28 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qt1j6-0013XO-HY for pgsql-hackers@lists.postgresql.org; Wed, 18 Oct 2023 08:16:26 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4083740f92dso8607385e9.3 for ; Wed, 18 Oct 2023 01:16:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1697616983; x=1698221783; 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=wCGmjEceIfvkbTB41vod8N6cizg0LAVreazM2bbijcM=; b=ZauQvS6L5oQUcXDu9eQhFw81aQjy5Ix0A04PwAmir9C8fH1NQUjgaGoCRM9Rr2fnI+ LNkI1Z2tv+8cQ/eS70to/3faTJ6gH8icoaXyOlYqinbkkL4224yDu/rjy34+dh8qz8+1 V/PPmYJMxibVoPYRB3ScUtKl7VJmLcPFVLaRQnFkeBpzQ2XCQIQGHal3PHJn+SKTqU22 V/bYQsU1ZMhargWzU+8ztRO4gcPZ9BBVrT2S+E9tqTJCdk479uf2SsEkspmXuqNMfVOq 0Ynx7Tqp4ModR3wge0HCK4BD8qbaMp91NXk0IVmHIzDZmFRvCKp5WjACpVGNdbjqoaFT 2B9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697616983; x=1698221783; 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=wCGmjEceIfvkbTB41vod8N6cizg0LAVreazM2bbijcM=; b=WfrCkojZnFfG3nw1XMsoxvjXPcXwNpb3XDsg8/09e6gjPUP51OYLrM4T3SOoQcF2d1 E3sOELqmNQGOx2Fw9BLjvle33+sul4ncbkDdSunqn4fblYUv6NeTUOoXReiFeu1sfsTJ IGUPAifIK0k4PzQ2JeoqmOUIilEDiTQF/uz2BQ/AvXSAchoiz8+5+krFPxLhYtQAEo8J R+N5lhNxKwov+urJAMzv5vhuipUZx9ZMods90wAekFrL1+Vueo7s2jenXfckATOVWTJM DgNoxeXL0SSWyaNd8Ye6eCn7X1PQ8AWvqlvI3zdD+OhMtUnWUxsytj5mIRB2wBjlrZat VmJQ== X-Gm-Message-State: AOJu0Yyib0kPrWeU8dIECeu4GAnqY1a+UVwfCGp2gNL2+9dU3t3Rbaxx +CQ8qQ10ps8ZRmnaepSbeyBczA== X-Google-Smtp-Source: AGHT+IFBKBDXwCN2u/Ouzk5vzQJso3LvTE/G9yRKkE/5+B2Afq/CTHqwRjO7xKRbF1AWAp23YzoJyg== X-Received: by 2002:a1c:4b18:0:b0:405:49aa:d578 with SMTP id y24-20020a1c4b18000000b0040549aad578mr3734004wma.37.1697616982663; Wed, 18 Oct 2023 01:16:22 -0700 (PDT) Received: from [10.137.0.17] (srv1.mobissw.com. [89.235.0.226]) by smtp.gmail.com with ESMTPSA id x12-20020a5d444c000000b0032da022855fsm1513996wrr.111.2023.10.18.01.16.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Oct 2023 01:16:22 -0700 (PDT) Message-ID: <968df036-44a5-a71b-5d9e-136701fcb2ba@enterprisedb.com> Date: Wed, 18 Oct 2023 10:16:21 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: BRIN minmax multi - incorrect distance for infinite timestamp/date Content-Language: en-US From: Tomas Vondra To: Ashutosh Bapat Cc: Dean Rasheed , PostgreSQL Hackers References: <14c205c6-fbf4-d2f2-3ea8-a7d5c5d63180@enterprisedb.com> <75de1895-3bd9-242e-cf13-3f5b0281e676@enterprisedb.com> <31400145-6f71-a6b2-e371-048a8e1584ef@enterprisedb.com> In-Reply-To: <31400145-6f71-a6b2-e371-048a8e1584ef@enterprisedb.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10/17/23 22:25, Tomas Vondra wrote: > Hi, > > Here's a couple cleaned-up patches fixing the various discussed here. > I've tried to always add a regression test demonstrating the issue > first, and then fix it in the next patch. > > In particular, this deals with these issues: > > 1) overflows in distance calculation for large timestamp values (0002) > > 2) incorrect subtraction in distance for date values (0003) > > 3) incorrect distance for infinite date/timestamp values (0005) > > 4) failing distance for extreme interval values (0007) > > All the problems except "2" have been discussed earlier, but this seems > a bit more serious than the other issues, as it's easier to hit. It > subtracts the values in the opposite order (smaller - larger), so the > distances are negated. Which means we actually merge the values from the > most distant ones, and thus are "guaranteed" to build very a very > inefficient summary. People with multi-minmax indexes on "date" columns > probably will need to reindex. > BTW when adding the tests with extreme values, I noticed this: test=# select '5874897-01-01'::date; date --------------- 5874897-01-01 (1 row) test=# select '5874897-01-01'::date + '1 second'::interval; ERROR: date out of range for timestamp IIUC this happens because the first thing date_pl_interval does is date2timestamp, ignoring the fact that the ranges of those data types are different - dates allow values up to '5874897 AD' while timestamps only allows values up to '294276 AD'. This seems to be a long-standing behavior, added by a9e08392dd6f in 2004. Not sure how serious it is, I just noticed when I tried to do arithmetics on the extreme values in tests. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company