Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pTTSX-0004Aa-Cd for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Feb 2023 20:05:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pTTSW-0000T0-5Z for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Feb 2023 20:05:24 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pTTSV-0000S4-NW for pgsql-hackers@lists.postgresql.org; Sat, 18 Feb 2023 20:05:23 +0000 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pTTSN-0001lj-W9 for pgsql-hackers@lists.postgresql.org; Sat, 18 Feb 2023 20:05:22 +0000 Received: by mail-ed1-x52c.google.com with SMTP id i28so4509183eda.8 for ; Sat, 18 Feb 2023 12:05:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; 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=OhjfXi1LeAz0GGqcISq1XLYL6qJHGMG2kGNa82D1Vqc=; b=mR+xKhvZBCG0KO1bMeVqgBzIUNseWff6Eif5RNlvXex/Fhy+xtZDOHkblxdstdcAPL AqoPI0S2DaBY+ucXEm4RFxeJcTzIGHP73DtW4jn7I5JRuI/FUaWe65+tZRjXPpB6lvVx 1mSD0UAg8qizh149oB6lbY2ulwcnE/U7kDwW5oihPqDo393GWiQJ/Al4uZGJNfVN4Vgm ylrgZyzZxTqBmkCzAf5ggxFzKZA20TSbqoROKQjBiVo6auW8n5J5O883l8d2kbwD662t bxm9F+CHzPszecXGYCM5EOgFOS/5Av34D8Tnph1Rizq65QLWsFvnGt3WCrcQWJKvWLBM z5fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=OhjfXi1LeAz0GGqcISq1XLYL6qJHGMG2kGNa82D1Vqc=; b=ambVBixPevcJoFbsUX2hvJY5zzlioCEzzs9kZpPR9RlGHQrJIGK69aHZNTgJZU02x7 KfpAxrIpJ1k4w3eLoMxedY5ENKWqlXXe/sqmK20rsFhjYjrkrLrCylhdSEO6oAAcKwGw ZO0fymsYQTNJZWoH9Uqx/EXz/l0RZpA55pHpWOl3gPmAhcmjr9Nyr34w+yLfD84QqH04 x8PCQYsjKU6/3MgKJPIxUMgqwh1E+Ptg76giKrALwHXDqw4t5mZGoIZFrHeRdjQOML3n orwZZt3p5Fh/vy+oFqhgFK6R69Eo64U70v3VKyGrNSUVEPjrQHqrpIZNr9dsnlCW2cOt 59Cg== X-Gm-Message-State: AO0yUKVq37adwEhgi8mXcgeUlPc12A+iKfgVNnpV8AskACOFZIh0jOyh czV3q4HW932SWYwqiTtnCMczE4GDM1jxV3pyvD5UzTreG23w5EMXT/Sd/Eekj9aZvtltuytnpko 2a8FlNM4f7QlmKtTiul9zJ7+glI/Si3PYgDyTl1tMDKHW4BFE+FnL/z/llknLM836M3VyA5xS/Y 3/PADzGszcI7/0gZ9dWHcEH+/yZU16KI3mQngRu+/wPLyJ6aeulOv2 X-Google-Smtp-Source: AK7set+41WWv2Dj4G7EvsnwJ5TqpuMsC+oXjoqxYsacPuzsRgpke5p0insYMTy8uW8VHk3Xb+HFNEw== X-Received: by 2002:a17:906:6d84:b0:87f:2d81:1d2a with SMTP id h4-20020a1709066d8400b0087f2d811d2amr4518696ejt.35.1676750713039; Sat, 18 Feb 2023 12:05:13 -0800 (PST) Received: from [10.137.0.17] (ip-86-49-228-162.bb.vodafone.cz. [86.49.228.162]) by smtp.gmail.com with ESMTPSA id s21-20020a1709060c1500b00887f6c39ac0sm3717762ejf.98.2023.02.18.12.05.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 18 Feb 2023 12:05:12 -0800 (PST) Message-ID: <23a61b2e-e6cb-0c07-0316-447487fc313e@enterprisedb.com> Date: Sat, 18 Feb 2023 21:05:10 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: PATCH: Using BRIN indexes for sorted output Content-Language: en-US To: Justin Pryzby Cc: Andres Freund , Greg Stark , Matthias van de Meent , Zhihong Yu , pgsql-hackers@lists.postgresql.org References: <87964cda-e440-8759-2838-bc4628072a18@enterprisedb.com> <14568731-ac91-ce2d-1477-0e2504c72775@enterprisedb.com> <20221206185143.ivy3afwmkhloksgv@awork3.anarazel.de> <4e679562-fd9a-33a3-ce71-cd7a27525f8e@enterprisedb.com> <20230216161016.GV1653@telsasoft.com> <9f73f798-1dac-c75d-d834-aa012ba13b65@enterprisedb.com> <8f1374d1-6f4b-ce99-84eb-ffa852c0dadb@enterprisedb.com> <20230218185109.GH1653@telsasoft.com> From: Tomas Vondra In-Reply-To: <20230218185109.GH1653@telsasoft.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2/18/23 19:51, Justin Pryzby wrote: > Are (any of) these patches targetting v16 ? > Probably not. Maybe if there's more feedback / scrutiny, but I'm not sure one commitfest is enough to polish the patch (especially considering I haven't done much on the costing yet). > typos: > ar we - we are? > morestly - mostly > interstect - intersect > >> + * XXX We don't sort the bins, so just do binary sort. For large number of values >> + * this might be an issue, for small number of values a linear search is fine. > > "binary sort" is wrong? > >> + * only half of there ranges, thus 1/2. This can be extended to randomly > > half of *these* ranges ? > Thanks, I'll fix those. >> From 7b3307c27b35ece119feab4891f03749250e454b Mon Sep 17 00:00:00 2001 >> From: Tomas Vondra >> Date: Mon, 17 Oct 2022 18:39:28 +0200 >> Subject: [PATCH 01/11] Allow index AMs to build and use custom statistics > > I think the idea can also apply to btree - currently, correlation is > considered to be a property of a column, but not an index. But that > fails to distinguish between a freshly built index, and an index with > out of order heap references, which can cause an index scan to be a lot > more expensive. > > I implemented per-index correlation stats way back when: > https://www.postgresql.org/message-id/flat/20160524173914.GA11880%40telsasoft.com > > See also: > https://www.postgresql.org/message-id/14438.1512499811@sss.pgh.pa.us > > With my old test case: > > Index scan is 3x slower than bitmap scan, but index scan is costed as > being cheaper: > > postgres=# explain analyze SELECT * FROM t WHERE i>11 AND i<55; > Index Scan using t_i_idx on t (cost=0.43..21153.74 rows=130912 width=8) (actual time=0.107..222.737 rows=128914 loops=1) > > postgres=# SET enable_indexscan =no; > postgres=# explain analyze SELECT * FROM t WHERE i>11 AND i<55; > Bitmap Heap Scan on t (cost=2834.28..26895.96 rows=130912 width=8) (actual time=16.830..69.860 rows=128914 loops=1) > > If it's clustered, then the index scan is almost twice as fast, and the > costs are more consistent with the associated time. The planner assumes > that the indexes are freshly built... > > postgres=# CLUSTER t USING t_i_idx ; > postgres=# explain analyze SELECT * FROM t WHERE i>11 AND i<55; > Index Scan using t_i_idx on t (cost=0.43..20121.74 rows=130912 width=8) (actual time=0.084..117.549 rows=128914 loops=1) > Yeah, the concept of indexam statistics certainly applies to other index types, and for btree we might collect information about correlation etc. I haven't looked at the 2017 patch, but it seems reasonable. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company