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.96) (envelope-from ) id 1wPdav-000ur3-0u for pgsql-hackers@arkaria.postgresql.org; Wed, 20 May 2026 09:52:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wPdat-006zbl-0y for pgsql-hackers@arkaria.postgresql.org; Wed, 20 May 2026 09:52:04 +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.96) (envelope-from ) id 1wPdas-006zbd-2l for pgsql-hackers@lists.postgresql.org; Wed, 20 May 2026 09:52:03 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wPdar-00000000Wqp-3Qjr for pgsql-hackers@lists.postgresql.org; Wed, 20 May 2026 09:52:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1779270720; bh=Vrrj4amwl7z1ZhkNd1aaZW3VD2S1bi5csr8KvjFoEwk=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=BZGkjPoS6uoGfF3lZyt9UTcYDOQm2WG0RerzPSevzMTzoFoO/d0Y4b+WYIRW683zi mp/87vlfo16SjxsZK0U1s2wN0fCk5pLqjLty4tvasidHVnO8Sz0p4DCYgQaKIL/yQw ENBDtcbgRhwI4VU+w13vLqfTJYiRoRKWCCLhQ75iyt9srMhJkk6zAzOxAEpj82337y S1JPxXjdCjqas1AqEkQtQoobvCnwlaqOUuj9DzkChDzpXMVPKQTPu+KHO4BBPB5tF/ rZ4crT4DzubXD+RNVzqdmzr6y2NeVK7Wjir9JnumoSH3n7cjoYO1I/Diw5RTOR9miu ZmV53KIxGqz5Q== Received: from [172.30.48.98] (debian11-template.l.postgrespro.ru [192.168.2.254]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: m.melnikov@postgrespro.ru) by mail.postgrespro.ru (Postfix/465) with ESMTPSA id 4EDB760C71; Wed, 20 May 2026 12:52:00 +0300 (MSK) Message-ID: <987e51f7-e266-4377-8f44-5a1653c161bc@postgrespro.ru> Date: Wed, 20 May 2026 12:51:59 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Dump statistic issue with index on expressions To: Alexander Korotkov Cc: pgsql-hackers@lists.postgresql.org References: Content-Language: en-US From: "Maksim.Melnikov" In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-KSMG-AntiPhishing: NotDetected X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 3.0.0.9059, bases: 2026/05/20 05:56:00 #28197168 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Alexander, hello! On 5/11/26 02:42, Alexander Korotkov wrote: > Hi, Maksim! > > On Wed, Feb 25, 2026 at 6:37 PM Maksim.Melnikov > wrote: >> There is an issue on new feature dump statistics related to index >> processing. >> In case when table has more then one index and if one of them is index >> on expressions >> we can get error like this: >> >> pg_dump --verbose --statistics-only > /dev/null >> ... >> pg_dump: reading subscriptions >> pg_dump: reading subscription membership of tables >> pg_dump: reading dependency data >> pg_dump: saving encoding = UTF8 >> pg_dump: saving "standard_conforming_strings = on" >> pg_dump: saving "search_path = " >> pg_dump: error: could not find index attname "source_system" >> >> For clarity, schema ddl attached >> >> CREATE TABLE test_table_stats ( >> id uuid NOT NULL, >> body jsonb, >> source_system character varying, >> source_id character varying, >> model_name character varying NOT NULL >> ); >> >> CREATE INDEX test_table_stats_source_system_text ON test_table_stats >> USING btree (upper((source_system)::text)); >> CREATE UNIQUE INDEX test_table_stats_json_system_un ON test_table_stats >> USING btree (source_system, source_id, model_name); >> >> When pg_dump sequentially process indexes in case when index is >> processed after index on expression, >> it can use index attrs names of previously processed index. I've >> attached simple patch to fix it. > I see this is a bug indeed: an index with no expression can get its > indAttNames and nindAttNames from the previous index. But I didn't > manage to reproduce your case. dumpRelationStats_dumper() only > iterates indexes with pg_stats entry, and those are indexes with > expressions. Could you give more details on how did you reproduce > user-facing error? Which particular git commit did you use? How did > you fill the database step by step? > > ------ > Regards, > Alexander Korotkov > Supabase > > Sorry for delay, I've tried to reproduce this issue for some time and detect that it isn't reproducable on vanilla postgresql. It seems, that our fork generate more records for pg_statistics unlike vanilla, that generate records only for indexes with expressions, more details can be found here in src/backend/commands/analyze.c static void do_analyze_rel(Relation onerel, VacuumParams *params,                List *va_cols, AcquireSampleRowsFunc acquirefunc,                BlockNumber relpages, bool inh, bool in_outer_xact,                int elevel) { ......             thisdata->tupleFract = 1.0; /* fix later if partial */             if (indexInfo->ii_Expressions != NIL && va_cols == NIL)             {                 ListCell   *indexpr_item = list_head(indexInfo->ii_Expressions);                 thisdata->vacattrstats = (VacAttrStats **)                     palloc(indexInfo->ii_NumIndexAttrs * sizeof(VacAttrStats *)); .....                 thisdata->attr_cnt = tcnt; Anyway, it seems code, reported before, isn't ideal and prone to bugs. In my opinion better fix it. Hope it will be helpful. Best regards, Maksim Melnikov