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 1wTPUR-000Vel-2z for pgsql-hackers@arkaria.postgresql.org; Sat, 30 May 2026 19:37:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wTPUO-006NaJ-1w for pgsql-hackers@arkaria.postgresql.org; Sat, 30 May 2026 19:36:56 +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.96) (envelope-from ) id 1wTPUO-006Na9-06 for pgsql-hackers@lists.postgresql.org; Sat, 30 May 2026 19:36:56 +0000 Received: from mail-oa1-x2e.google.com ([2001:4860:4864:20::2e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wTPUL-00000000JZB-3Jay for pgsql-hackers@lists.postgresql.org; Sat, 30 May 2026 19:36:55 +0000 Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-43c2fbe2117so2795241fac.0 for ; Sat, 30 May 2026 12:36:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1780169813; cv=none; d=google.com; s=arc-20240605; b=LkUuwVZqCtbA3d48RWyvsVmW8ydVnvbQox2d5XsheLaqKWlcFY0x1JSFc7dlmX88k7 53KZSlbvrGtS8th+b8OLxgh70lbKWLomQBGUbAw5pW0WZ29CXqBD6fI4uFRRX9Rg5UKN 5tqfE/lXDGUxFng3BokUXcIgYfxb0MkYNEl5xbaiyojM+Ph6eErehZ6vIe/vL5VedJZn 2SoeLu8K8pfv8zZXEEUB8Kata4l2MvrSeys/IbdeuryMW0mgwY4QJxplonO00o51wvIw TXFbirbTWpykKMIxobf9gCs1YRJLaFfOb5ibcCOXYN4Q2XWeqMdtp3XabRHFZc7k6B75 nGlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=TzDG+sHfLeNfJQkJWuacQm0662EhhLHy+uyZD0Q7JN8=; fh=XN7XC/Sui4CIE6OCP3yoesr9pGHMvvFkYv2JY8kZEYk=; b=XtKjhjB4NQzH4/RWbN9nPfgW7081RS83beuP+8Q/EFmRz/VEWfliLESRKWpKr90V// +DtpkeLO9H2FXQ3qsnyH4l0e6mf2qVBJCdOfNbmeDhw9Zrd6ozY1VIanEWtdKeDIWAg0 y+BXZRpkjTBtfK+y+Y4E7ATLhqrqFfMuT9l3/qStr4QDLETbXAYSoNC7cbze2K97GdxZ scXTnqao4qx8W0TR4HMHg56jHNOud6+BPlh4Cf+EL49PoE2XVANFQPgaRVQKSd9bjP9X MJ/lc+XuD+lBBmBJcNl2iaXGrmK29P9HK06Ece1A2nfzLX1B7uVfOuMAuAMAtU47p6gZ comw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780169813; x=1780774613; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=TzDG+sHfLeNfJQkJWuacQm0662EhhLHy+uyZD0Q7JN8=; b=GWAMjevzKhLZU7TAy3B62FIjFPj74geJWxZrzNK0Pu06QLQ3YFEEvA7YEuf/lLDKe8 LXS154wVJ0HgWQ70DD9GVGVnGf5swc0y/jgAVGzkB/tngHzmX2of05NHmt5zfHY6lwbh ycfrB240Yr2iqFe7kn7eGnfKm4Qv51xxkB3RvpjfBZuXmh2x+CVhmRdk8+WqXn6BCs4V bFYJnHq+PYGgVQceZPJyoFwU4tA0iXkcmhkpdi7Ss2y4fcMey4dgLLEicc/YGcyFwDnu LooMYmDgqM03LBh9I4f0gVRI30PkA4FLqoY+W1mxMRvmlYjNsOAy9NWfTChcLuUVKQvT jr4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780169813; x=1780774613; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=TzDG+sHfLeNfJQkJWuacQm0662EhhLHy+uyZD0Q7JN8=; b=Gh6Fl6/yjZbDFMbhTQFDAfCk/cJtFgzV9To60hbRuv8QaYNf7aeP1NdZlLoDOLp698 ylkCzle5aFRAVyeQd5O4qr32zP5RvFblh74ZK94qwfmrMn56WamUJzoB+a6FlPMhMdBw +RHTf6kHPjjI+BQ30b3fbJvtg3JN7vxMtaTnnlySqp37frxEnAbscvHxN7SJd4EIxtoO QYtwGSxaTBz7Hd8y2CSaAp+vaQTyY+3ysIfv17dYO61K4h63eGqFDLClT9+hfmXdxWfz hpk10YX4V/82EfIgwQAx0+TzosTvgLiP4EJG9HnZP+bRtYrUm+vboIK29tot2aySBScD cvOg== X-Gm-Message-State: AOJu0Yw2f23zIaMvOKVzTtPOZfDntiVBFvwdwRTDiWKkM4dA0WEgdDwe yCpGl1ysBWua7fLKUNxGzCT6SUq8ZZ0ozB0K3veHTNxrGphwnPZg9r95Wh692mwdmnU3AKhJ2oz IdKsAMSerT+yz/f6bVy3jK29Z0JAvIB6mMIuMdTEKhQ== X-Gm-Gg: Acq92OEnbH+zSxYnY+u6+9HVtkrbhDoiuQbyJ1Q3v8D+uja4uIgNLkHF8iNi7k2TAD8 h1O5BgH+ZS0cC4RYmxBMy51BFMXhMCE9eFLGXF6OnDzmW+hmgThNsqgAf41ikcAxJh6jsHNKsQ+ Xa2Ik8bh1lkHf8/iX4+BDVIW9dC1HVJ8Ef4vxRzJcWRpGBg7NwPwcZj275Ieq68/80GQed13wZa fPewjdMtGKGa/6Fq0KB94mh7TmlkQMrDJVEYH1pvt63iSuWfSJghvOZEUsRDKaQYDzZBxuaWx+7 XGFteqofckmPwH8qK2c+Ld36gUlU5tvW/FgLIFgTmQAJOrVuvq1Uepr8y4hNhx2oUjvbnVp1eVV BPTB2p//yZlYYJUO7 X-Received: by 2002:a05:6820:2018:b0:694:9252:1992 with SMTP id 006d021491bc7-69e102af1c9mr2206502eaf.0.1780169813214; Sat, 30 May 2026 12:36:53 -0700 (PDT) MIME-Version: 1.0 References: <987e51f7-e266-4377-8f44-5a1653c161bc@postgrespro.ru> In-Reply-To: <987e51f7-e266-4377-8f44-5a1653c161bc@postgrespro.ru> From: Alexander Korotkov Date: Sat, 30 May 2026 22:36:39 +0300 X-Gm-Features: AVHnY4KjmUlRubeonerL6GXd_FWi3xQdUGeUJf0vJgSqWhTWoEy6KW0ofA-Xka0 Message-ID: Subject: Re: Dump statistic issue with index on expressions To: "Maksim.Melnikov" Cc: pgsql-hackers@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, Maksim! On Wed, May 20, 2026 at 12:52=E2=80=AFPM Maksim.Melnikov wrote: > On 5/11/26 02:42, Alexander Korotkov wrote: > > On Wed, Feb 25, 2026 at 6:37=E2=80=AFPM 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 =3D UTF8 > >> pg_dump: saving "standard_conforming_strings =3D on" > >> pg_dump: saving "search_path =3D " > >> 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_stat= s > >> 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 =3D 1.0; /* fix later if partial */ > if (indexInfo->ii_Expressions !=3D NIL && va_cols =3D=3D NIL= ) > { > ListCell *indexpr_item =3D > list_head(indexInfo->ii_Expressions); > > thisdata->vacattrstats =3D (VacAttrStats **) > palloc(indexInfo->ii_NumIndexAttrs * > sizeof(VacAttrStats *)); > ..... > thisdata->attr_cnt =3D 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. Thank you. Now this is clear. No user-facing error, but an internal inconsistency. I'm going to push (and backpatch) this after release freeze is lifted. ------ Regards, Alexander Korotkov Supabase