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 1qKJgb-000H8o-Q5 for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Jul 2023 14:22:22 +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 1qKJfa-002vvm-U9 for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Jul 2023 14:21:18 +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 1qKJfa-002vve-JA for pgsql-hackers@lists.postgresql.org; Fri, 14 Jul 2023 14:21:18 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qKJfX-000O3k-7M for pgsql-hackers@lists.postgresql.org; Fri, 14 Jul 2023 14:21:16 +0000 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-3142ee41fd2so2012530f8f.3 for ; Fri, 14 Jul 2023 07:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1689344473; x=1691936473; 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=HLDonVGIeXC60gBfbCD6NPyE/v7LMs4Xbm6BFebp3qk=; b=Iv/f3wfe2NPmtPCtjvrB6r+7jBowW6S5mTO4Y9m1eRpop9MFdZ+XjhRjhT6CGRAE6/ 1WCD7ILWAQa90a2mzAex4UamXWhBSQ4axlXgM5ExTz+UHrcF9lf/VFJzCDPJk/ZvV8a4 at10bwDi6PYZh7fOXkIcO8Z4hoMbJ75R0DhAoqf0w4bfEL72PpCafacGGyGLXBIgk2jN ZGS1ttH4pZpJCAVlgSAekAs9xHyTIu87KZRFWOW0lLahsaaTY6tGYsl4NcmGF+twGQ3g p8x2lSziGP+88b59zuQi/textjXl+RC9g+rDmNV9aRBkscHIG1CE6Awye33pG+9ve/XW CTgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689344473; x=1691936473; 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=HLDonVGIeXC60gBfbCD6NPyE/v7LMs4Xbm6BFebp3qk=; b=OQedhI8NKiHpXO4YHfrP/EEgVw+3m+KnRgK3HM8RgGPTAepG7Gefc5jFW7QTchwZzw pmAJ6oyKGWPrvpQRzzf1+XAyc/vi3eMk3KB4ce5i3Cb1COdYzZMJpeQ1uZOsIh2BPLad BhB2UaZNrZzCNLT9Wa76NiFnNxvQoJuCfJBoHJVZrdj6jSTuHLa6xgRRxDCeIVxuXMZK 1qyavEf8uBUYrtstoy3J/HWzsik/cVLdlOOvlH7xzDfeMv4jeNxy86Z920zDxgftpi8d g2dAieX+pQn3vFkOeOy/a2XU1ED4IjpIaLpICDK8tPTFZaEO/RV6F/y5c8y2WqxzW6SI itBQ== X-Gm-Message-State: ABy/qLZjKzgRLCNa2WMzIvkDyZISYoPtco6Z406fIjGjQgRdgcMPUscF OnQHO00p82dlARIIaUceIU1sBCiRopfVeN5QAUA= X-Google-Smtp-Source: APBJJlHDVZdddyrOjRg9QRXmepRR3EC76JJNy5HFzrYiYsc2RGL29NqNV7ZLdYuD35ryeqevkQVxTA== X-Received: by 2002:a05:6000:1081:b0:30f:c5b1:23ef with SMTP id y1-20020a056000108100b0030fc5b123efmr4010586wrw.41.1689344473251; Fri, 14 Jul 2023 07:21:13 -0700 (PDT) Received: from [10.137.0.17] (static-84-42-175-93.bb.vodafone.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id q4-20020adfcd84000000b0031134bcdacdsm11064508wrj.42.2023.07.14.07.21.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 14 Jul 2023 07:21:12 -0700 (PDT) Message-ID: <065bb749-71ee-6bd2-7a4b-1088cb26a31a@enterprisedb.com> Date: Fri, 14 Jul 2023 16:21:11 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: PATCH: Using BRIN indexes for sorted output Content-Language: en-US To: Matthias van de Meent Cc: Justin Pryzby , Andres Freund , Greg Stark , PostgreSQL Hackers References: <1607e037-8c5b-1626-9f98-496f067b9eb5@enterprisedb.com> <20230216161016.GV1653@telsasoft.com> <9f73f798-1dac-c75d-d834-aa012ba13b65@enterprisedb.com> <8f1374d1-6f4b-ce99-84eb-ffa852c0dadb@enterprisedb.com> <30f37aae-57fa-e7ab-9444-7b82969ed68f@enterprisedb.com> <825f648f-2a31-1870-942f-03fba2b6b3cf@enterprisedb.com> <0c331bf8-0cd3-e9fe-ae81-9e3d68f1f95c@enterprisedb.com> <1992ff4f-bf0e-3ad0-a859-cf054f6abc74@enterprisedb.com> <5c92f99a-e83e-c1b3-2c47-d75857a70b73@enterprisedb.com> From: Tomas Vondra In-Reply-To: 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 7/11/23 13:20, Matthias van de Meent wrote: > On Mon, 10 Jul 2023 at 22:04, Tomas Vondra > wrote: >> On 7/10/23 18:18, Matthias van de Meent wrote: >>> On Mon, 10 Jul 2023 at 17:09, Tomas Vondra >>> wrote: >>>> On 7/10/23 14:38, Matthias van de Meent wrote: >>>>>> I haven't really thought about geometric types, just about minmax and >>>>>> minmax-multi. It's not clear to me what the benefit for these types be. >>>>>> I mean, we can probably sort points lexicographically, but is anyone >>>>>> doing that in queries? It seems useless for order by distance. >>>>> >>>>> Yes, that's why you would sort them by distance, where the distance is >>>>> generated by the opclass as min/max distance between the summary and >>>>> the distance's origin, and then inserted into the tuplesort. >>>>> >>>> >>>> OK, so the query says "order by distance from point X" and we calculate >>>> the min/max distance of values in a given page range. >>> >>> Yes, and because it's BRIN that's an approximation, which should >>> generally be fine. >>> >> >> Approximation in what sense? My understanding was we'd get a range of >> distances that we know covers all rows in that range. So the results >> should be accurate, no? > > The distance is going to be accurate only to the degree that the > summary can produce accurate distances for the datapoints it > represents. That can be quite imprecise due to the nature of the > contained datapoints: a summary of the points (-1, -1) and (1, 1) will > have a minimum distance of 0 to the origin, where the summary (-1, 0) > and (-1, 0.5) would have a much more accurate distance of 1. Ummm, I'm probably missing something, or maybe my mental model of this is just wrong, but why would the distance for the second summary be more accurate? Or what does "more accurate" mean? Is that about the range of distances for the summary? For the first range the summary is a bounding box [(-1,1), (1,1)] so all we know the points may have distance in range [0, sqrt(2)]. While for the second summary it's [1, sqrt(1.25)]. > The point I was making is that the summary can only approximate the > distance, and that approximation is fine w.r.t. the BRIN sort > algoritm. > I think as long as the approximation (whatever it means) does not cause differences in results (compared to not using an index), it's OK. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company