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 1rnTbf-00DU5A-MG for pgsql-bugs@arkaria.postgresql.org; Fri, 22 Mar 2024 01:22:04 +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 1rnTbd-0000kA-GU for pgsql-bugs@arkaria.postgresql.org; Fri, 22 Mar 2024 01:22:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rnTbd-0000k1-7L for pgsql-bugs@lists.postgresql.org; Fri, 22 Mar 2024 01:22:01 +0000 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rnTbV-005p4r-PR for pgsql-bugs@lists.postgresql.org; Fri, 22 Mar 2024 01:22:00 +0000 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-3416a975840so979149f8f.0 for ; Thu, 21 Mar 2024 18:21:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1711070510; x=1711675310; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=dxpq0ZmBIL4+ZyG6pc35vK4TFuzDjDEsRJ1kLEBxXCg=; b=iKvPfRLQ+GCMsRkTTEbqKYNAHuAkJ2ZEZ+FzDzePIANewo1rhUkqbl1lmqXgSHMYkM t8WuVB60cl/PHqUS/Uon8xLwXExLXGpkuy6gBhDpbbYARsESWffmhvuTjqxxMv2D3QZK MiHwtSU+RtsB5Z2XUrtTO2rQ9u1krE5//Wf6e8/2dtMbVchykAkt61aonZUwYWIrIAbl haV5i0HFGqX6zjM4Xgqj5I+LGNA/THBINp4m3YHe6LYwuR9gR21U1fYCyWrGA5D8mvR+ +5mpZVvmevU6JRpZwoMDPDJ6EYKuPy6Rb773ceyUiR/WpCIPHgPfT4gEDX1VVeVr3jCZ fCig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711070510; x=1711675310; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dxpq0ZmBIL4+ZyG6pc35vK4TFuzDjDEsRJ1kLEBxXCg=; b=E4oQA7pAiNMI9RcLh5E0aXrkbwD+46lCdwtRBOLkhCtnfxe77Qll1mWXcig5pt3Y7z FxZpWuS5kqHM5BF5/gOUZy0Nfh7nYPGh4zHeJhgy7wsJy7ZPkby39HZGt/2XZEPMLeYu fO5m7etjqAb42BCjii01Vmnqngex1ckk2OxpzkWv7q3mVOXEvYEegrnmargvNw/GNs/k mxOx1n6n+5r+NFSQkUd8lIBhBvjt3ctKhgvTxdooP8xyzIHOi01VVmbtsgRj0dniWTxP Q6gp9IWoqxxHq9UczlpS9d7eeIIlmVkdVSnYEhPGAqJh7su90n0hOWGjEfskzjBkN9lu iXYA== X-Gm-Message-State: AOJu0YyJR15RSupuqE93RHrNKl2LbCIErP+2d7xLGCSUoLUNeeCow69T fCoT7qANPvqugV5LfqQlD9525VhqUysn66YLTflwaHDWUOe/LgMs8ltyn37Xpw== X-Google-Smtp-Source: AGHT+IH0R03G48hFN/Xgou3AHWWoeWl2mxMJD04LHXOjM/160DxXD4n5yt4nWRs4HVSjhbbtUUb0PQ== X-Received: by 2002:adf:ee4c:0:b0:33e:741b:4977 with SMTP id w12-20020adfee4c000000b0033e741b4977mr421432wro.60.1711070510642; Thu, 21 Mar 2024 18:21:50 -0700 (PDT) Received: from [10.137.0.18] (ip-86-49-229-30.bb.vodafone.cz. [86.49.229.30]) by smtp.gmail.com with ESMTPSA id dl17-20020a0560000b9100b0033d6bc17d0esm844912wrb.74.2024.03.21.18.21.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Mar 2024 18:21:50 -0700 (PDT) Message-ID: Date: Fri, 22 Mar 2024 02:21:49 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Index plan returns different results to sequential scan From: Tomas Vondra To: John Burns Cc: pgsql-bugs@lists.postgresql.org References: <3B86F188-F4BF-4331-AD79-E5FF2D0711A3@impactdatametrics.com> <72600f8a-4231-45b7-a116-8ceec5ccf66e@enterprisedb.com> <881DF028-5222-486C-A13B-451239C1316F@impactdatametrics.com> <27496161-e7ec-47bd-b559-3571fde4dcb4@enterprisedb.com> Content-Language: en-US In-Reply-To: <27496161-e7ec-47bd-b559-3571fde4dcb4@enterprisedb.com> 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 3/22/24 00:58, Tomas Vondra wrote: > > > On 3/21/24 21:08, John Burns wrote: >> >> >>> On 21 Mar 2024, at 20:27, Tomas Vondra wrote: >>> >>> >>> Sorry about that … the patched version of the package, plus a sample data set is in the attached zip file, >>> >>> -John >>> > > Thanks, I can reproduce the issue. I don't know why is it happening, but > the behavior I see is that the (postcode % 'NW10') query somehow misses > rows with postcodes 'NW10 0AA' - 'NW10 3NL' when executed using index. > > I don't see anything obviously wrong in the extension / index pages. > > You suggested it used to work OK and then broke. Do you perhaps know at > which version it broke? Or did you use 9.x until now, upgrades to 16 and > realized it's broken? > After some bisecting, this seems to be broken since this PG12 commit: https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=dd299df8189bd00fbe54b72c64f43b6af2ffeccd ========================================================================== commit dd299df8189bd00fbe54b72c64f43b6af2ffeccd tree 931ef720687d61cf5e75464fa0b1c1d75fb3f9d3 tree parent e5adcb789d80ba565ccacb1ed4341a7c29085238 commit | diff Make heap TID a tiebreaker nbtree index column. Make nbtree treat all index tuples as having a heap TID attribute. Index searches can distinguish duplicates by heap TID, since heap TID is always guaranteed to be unique. This general approach has numerous benefits for performance, and is prerequisite to teaching VACUUM to perform "retail index tuple deletion". ... ========================================================================== I don't know what the problem is, or whether it's a big in PG or in the postcode extension (I agree the extension is fairly straightforward). regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company