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 1qtOug-00CGye-24 for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Oct 2023 09:01:54 +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 1qtOud-00G9FG-HR for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Oct 2023 09:01:52 +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 1qtOud-00G9F8-7D for pgsql-hackers@lists.postgresql.org; Thu, 19 Oct 2023 09:01:51 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qtOua-001Ebb-G1 for pgsql-hackers@lists.postgresql.org; Thu, 19 Oct 2023 09:01:50 +0000 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4064876e8b8so77294105e9.0 for ; Thu, 19 Oct 2023 02:01:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1697706106; x=1698310906; 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=UZudPn/0CmIvpVpSKCLFfpXPjsg7aPbeZBaRhFbZ8hQ=; b=WQRYLaZbzJqk8z8Hf+dTYYAWG5m1G3DLTHzHvD1sjhd2ru3ssP89IBKokBnQvMgzlX IKRDW2kFkS7Nzm6CYeRmVVmogkvLyg9inQTkaa35O352nzmfsFQsR5HIqRat23HA+e9g U0MJoPIV/iQgbSKe8TqKl8aS9pzobSHeC+2zAGZ04p1w1KYjEnhKTrF7d3dhQRTNnvWS +AlBLr4uCuwxkFT1fQPjZ5PpQe9SYgIGZKbKvq0IAk+FrIMDiJjUHtiaboVTYANOk/8P d30QVLFuDXw/iSySXe379jHBTfGj1Ug3FSeIP2Bot0nzVNxvN1W1r6Oqq3Ay8ngxuuxt +wfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697706106; x=1698310906; 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=UZudPn/0CmIvpVpSKCLFfpXPjsg7aPbeZBaRhFbZ8hQ=; b=m3vXTrWfxZTzlcSdFH/ngO+4iUyx9k2oW690M4b/xUtQbypIATH+UCxijJ1xA15Pq0 9spMDW3efEMgfhgLoNADqCKclcNVBMJ+RlRUUpZA5BphbVwFm7YeX3STzrJCfp3RkG6k IX2NUXzIwK61EpWDicp8NSsoXr0TIo1wsQieN+VSFW3DWWLGT7FAlz8m0T7Hup38V2vy PRFqj8yaH/ahIX6Gk6ja0UNbXvdYk7hx1zIJior8iuiosipw9Om5mdNgecp5FWqCXMEv j7pIxdZm+Ry/miU7eeaBTQgwdq99XlNX6VgNOyIuqOg17NXDmXyLOgMpy10I677gKL5g 2vow== X-Gm-Message-State: AOJu0YxMwLRSj2Veo3itG5tv3EnCIQKUZ6uX4SJ3sVJeZjzR0aqa94aL CIDubYjYowV+wNkYl4tkQBWKsA== X-Google-Smtp-Source: AGHT+IFOJe+dqufUUu1mzFP4uOGRtUwvd0HO5z7Ffu6bsd1Wt5BhgSPX5H02hDNL9Vv3E0MaiaSSqQ== X-Received: by 2002:a05:600c:19c9:b0:401:b2c7:34a4 with SMTP id u9-20020a05600c19c900b00401b2c734a4mr1338504wmq.11.1697706105386; Thu, 19 Oct 2023 02:01:45 -0700 (PDT) Received: from [10.137.0.17] (srv1.mobissw.com. [89.235.0.226]) by smtp.gmail.com with ESMTPSA id f13-20020a1c6a0d000000b004064ac107cfsm3826478wmc.39.2023.10.19.02.01.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Oct 2023 02:01:45 -0700 (PDT) Message-ID: Date: Thu, 19 Oct 2023 11:01:44 +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 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> <575aa0fe-311d-d3d0-1f1a-abb1b9665a63@enterprisedb.com> From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10/19/23 06:32, Ashutosh Bapat wrote: > On Wed, Oct 18, 2023 at 8:23 PM Tomas Vondra > wrote: > >> >> I did use that many values to actually force "compaction" and merging of >> points into ranges. We only keep 32 values per page range, so with 2 >> values we'll not build a range. You're right it may still trigger the >> overflow (we probably still calculate distances, I didn't realize that), >> but without the compaction we can't check the query plans. >> >> However, I agree 60 values may be a bit too much. And I realized we can >> reduce the count quite a bit by using the values_per_range option. We >> could set it to 8 (which is the minimum). >> > > I haven't read BRIN code, except the comments in the beginning of the > file. From what you describe it seems we will store first 32 values as > is, but later as the number of values grow create ranges from those? > Please point me to the relevant source code/documentation. Anyway, if > we can reduce the number of rows we insert, that will be good. > I don't think we have documentation other than what's at the beginning of the file. What the comment tries to explain is that the summary has a maximum size (32 values by default), and each value can be either a point or a range. A point requires one value, range requires two. So we accumulate values one by one - until 32 values that's fine. Once we get 33, we have to merge some of the points into ranges, and we do that in a greedy way by distance. For example, this may happen: 33 values -> 31 values + 1 range [requires 33] -> 30 values + 1 range [requires 32] ... The exact steps depend on which values/ranges are picked for the merge, of course. In any case, there's no difference between the initial 32 values and the values added later. Does that explain the algorithm? I'm not against clarifying the comment, of course. >>> >> >> Not sure what you mean by "crash". Yes, it doesn't hit an assert, >> because there's none when calculating distance for date. It however >> should fail in the query plan check due to the incorrect order of >> subtractions. >> >> Also, the commit message does not claim to fix overflow. In fact, it >> says it can't overflow ... >> > > > Reading the commit message > "Tests for overflows with dates and timestamps in BRIN ... > > ... > > The new regression tests check this for date and timestamp data types. > It adds tables with data close to the allowed min/max values, and builds > a minmax-multi index on it." > > I expected the CREATE INDEX statement to throw an error or fail the > "Assert(delta >= 0);" in brin_minmax_multi_distance_date(). But a > later commit mentions that the overflow is not possible. > Hmmm, yeah. The comment should mention the date doesn't have issue with overflows, but other bugs. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company