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 1rDpKz-003GAG-JJ for pgsql-bugs@arkaria.postgresql.org; Thu, 14 Dec 2023 17:17:29 +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 1rDpKx-00AQAT-E3 for pgsql-bugs@arkaria.postgresql.org; Thu, 14 Dec 2023 17:17:27 +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 1rDpKx-00AQAJ-5F for pgsql-bugs@lists.postgresql.org; Thu, 14 Dec 2023 17:17:27 +0000 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rDpKq-00BztJ-LS for pgsql-bugs@postgresql.org; Thu, 14 Dec 2023 17:17:26 +0000 Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-50bf69afa99so10801204e87.3 for ; Thu, 14 Dec 2023 09:17:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702574239; x=1703179039; darn=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=Ap+3OQkZ9RwltzhyF2Hcd1ARjL/yil4ZFOdlLmf0cHA=; b=adOsmRaLgTkZEF5rVGPZhMTqC0lI4TMDRxYr57lygzqhMqlRrcO8v5RPbifHyd6Q72 NLFt3CVvtPznZ/WVfM+5tKFQM73C0/JFXldgvSuegE3NhUS/TlLyvh6pCwNiDKXesUtP 1VuJrxWU7IVccQmFfOLqL7g95dfPbwCTzNVuS4EkEjsbKHvMWCMobhvQy1b8DDo7vOxH 16Ko4VVzFH3s5lNU6oqMa+yAUCFsCp/5/kp/JAEWr1Dppa5h9gtKV39bz1PJqi3ggXuK 4L09koP4NsnKNWUMbpmzTcgjIHtTybNKvFybeRJ8ozm7AwFu4kOVYwAhJXJllGOEAlpI zK3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702574239; x=1703179039; 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=Ap+3OQkZ9RwltzhyF2Hcd1ARjL/yil4ZFOdlLmf0cHA=; b=qwkILtlDuQR7UctMdYSOchZlDM9FMpH1xRMJ/NL7MY0IXA73P9yVnYvO0Fq5NNjYeB qafxDOu6Wj9mkyPDTTZxA6h0CrIcAFQEmlBwjVvqmVXh+4ZPX9UR3OrvnMuhWle0KukQ B6dD2F2BPGhrLnj9q2sxStXXHrarv4TpxGNeXAF13KOtWSf634UF2B9+zLyOc36eadKT k45AospF/9UWdgqY4ImoJmnzq79yfWx39vrg6lGIOUD1+LjGVqS5/cxxNnPah8kYrmlR kMZ2G7KpM3ndDA7sOpN/ZVOrhMJ/W5v3RpOYMi6fjZdnueOLI92wIVJCsvFs8LpLNWY1 kJLA== X-Gm-Message-State: AOJu0YymsInxCc8rVXp3t2geYfJYDg79n0YDXsWnlsOAiu1Nh0QWWdIQ Vp0uBHs58slmhDzCy59XKIk= X-Google-Smtp-Source: AGHT+IG5UIng+4r9RjutuD0IhTGsBNvujClRAWeKb90FwpfKnazSKTjlJmlkLvCydOYo5Ys2PXwQFQ== X-Received: by 2002:ac2:5e89:0:b0:50b:fb07:ccdd with SMTP id b9-20020ac25e89000000b0050bfb07ccddmr5068786lfq.13.1702574239271; Thu, 14 Dec 2023 09:17:19 -0800 (PST) Received: from [1.0.0.7] ([178.155.26.88]) by smtp.gmail.com with ESMTPSA id f19-20020a19ae13000000b0050e15b3a828sm258719lfc.227.2023.12.14.09.17.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Dec 2023 09:17:18 -0800 (PST) Message-ID: <59716bbe-fe82-92a9-1e35-171b2ed221be@gmail.com> Date: Thu, 14 Dec 2023 20:17:17 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [BUG] false positive in bt_index_check in case of short 4B varlena datum Content-Language: en-US To: Michael Zhilin , pgsql-bugs@postgresql.org Cc: y sokolov References: <7bdbe559-d61a-4ae4-a6e1-48abdf3024cc@postgrespro.ru> From: Alexander Lakhin In-Reply-To: <7bdbe559-d61a-4ae4-a6e1-48abdf3024cc@postgrespro.ru> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Michael, 14.12.2023 19:18, Michael Zhilin wrote: > Hi, > > Following example produces error raised from bt_index_check. > > drop table if exists t; > create table t (v text); > alter table t alter column v set storage plain; > insert into t values ('x'); > copy t to '/tmp/1.lst'; > copy t from '/tmp/1.lst'; > create index t_idx on t(v); > create extension if not exists amcheck; > select bt_index_check('t_idx', true); > > postgres=# select bt_index_check('t_idx', true); > ERROR:  heap tuple (0,2) from table "t" lacks matching index tuple within index "t_idx" > HINT:  Retrying verification using the function bt_index_parent_check() might provide a more specific error. > > As result table contains 2 logically identical tuples: >  - one contains varlena 'x' with 1B (1-byte) header (added by INSERT statement) >  - one contains varlena 'x' with 4B (4-bytes) header (added by COPY statement) > CREATE INDEX statement builds index with posting list referencing both heap tuples. > The function bt_index_check calculates fingerprints of 1B and 4B header datums, > they are different and function returns error. > > The attached patch allows to avoid such kind of false positives by converting short > 4B datums to 1B before fingerprinting. Also it contains test for provided case. By changing the storage mode for a column, you can also get another error: CREATE TABLE t(f1 text); CREATE INDEX t_idx ON t(f1); INSERT INTO t VALUES(repeat('1234567890', 1000)); ALTER TABLE t ALTER COLUMN f1 SET STORAGE plain; CREATE EXTENSION amcheck; SELECT bt_index_check('t_idx', true); ERROR:  index row requires 10016 bytes, maximum size is 8191 Best regards, Alexander