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 1vvhn4-00EzC7-1j for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Feb 2026 20:16:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vvhn2-00FD1S-1Z for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Feb 2026 20:16:52 +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 1vvhn2-00FD1D-0C for pgsql-hackers@lists.postgresql.org; Thu, 26 Feb 2026 20:16:52 +0000 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vvhmy-00000001Rvx-1Q5O for pgsql-hackers@lists.postgresql.org; Thu, 26 Feb 2026 20:16:51 +0000 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-b8f92f3db6fso209149066b.0 for ; Thu, 26 Feb 2026 12:16:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1772137008; cv=none; d=google.com; s=arc-20240605; b=bQGfrVq3yGnzzFXARnfRFCeeIA3ttHjktPALexRvB16F9o7v/dXZKT3rrkI7xY2CNy lV/hsw5KLZJEUyHKgm73KBafUMgNYHXNkL3pXyB1hClC+3wjvwz3zjiD6wFbLuqe0rBY Zbw5EoqZEF2+BbB48g0YQ40zrAjPfiV0QXvcZGPN2krQseOWmQrSQSNzqvNzkCdU40lJ dBtHW6XVwqqCbWnzbpslm4vxJnbVv3K1uVvWFGDcSX/cn8VeuYnBQwXNOD636MOF1+VB uldmrbmexGVS1qpH+FOKnAEP2sJvzaIqVGHHu8wL7ZyRNGu/PpjFouuyJ1ZN84w6MK3O 1eng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=MGLJSBMZ70JvrN2gjIPi7cAqw05+sHBOoOZ/qHmF+Sc=; fh=UO1PyQiK6qpg9qQaNVhREWYmg/VYiYERoS+uZ8BjxYM=; b=IX6P/tKo40Z7+N/T9Ol4I31uNk5ByoFaMAlIPHVZtF1HG7of/bGpc7wFiju5sHdDmL 92IAebLey4SbBb0IPWsl6JrxU6oPrtAAumzyVp+MCek2XwSAVJ3Lr43LUhTZnP6h43/Q 8X8095ir7dutPU4oxAdbv8fzcMLijCEyP+FUb6c63DniVVHbYsPRG6B8AIHsnsm/pQQZ /cS46eIh3RbTeZt21wujEyZZEsekoRpMVn3O5tgn5UmQtymnJw+3gQ2Qh/4oZ48eFaOR BsJksH+JxsUsxwQKLjRm4imcbXe+W+LZVazsFbQ64GQBPqStscEUTZh4Eq1STLDSdOl+ VqUg==; 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=20230601; t=1772137008; x=1772741808; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=MGLJSBMZ70JvrN2gjIPi7cAqw05+sHBOoOZ/qHmF+Sc=; b=hXPDWKxEfzTlPWKfvA3yEyl2xZzIv3iwyU8FAxgZwuqx445z0p3OTUpVCu/PFQuyxS jC6rF/6oxGPRZjpJ4KQyWsUBDXsHszqF2SZpeHn0cHA0t/I2AvPJpsjOo+dm+0HOvm1v 7Dl89UrhDSVgzwLywYulpJaDMRHLcZFbGluQIaZ3cZ74WohnCyN4NmJJsoIuW7KjhKEf qJ/2T1JmkHWuV17QKnHCj/Wy+qCexQ0ok1kfZmMt7khzwzuaEoEtoTnTCnpyg72OJTqv abUWLQtG9xOaoGYn9/pwBIU2duKZRKbdGuEO7KMV4OlZUhsO7cGjqGG7JIZKWn1dz4FZ hklw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772137008; x=1772741808; h=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=MGLJSBMZ70JvrN2gjIPi7cAqw05+sHBOoOZ/qHmF+Sc=; b=XsKLPjIpOFqf5hJo5XjGQ7Sb9riO73EI/6m43TPTUWo8G4nISrIXmQPhvRu0pQfnyT cRcYfmn/7kJpijruebGZWAEvKPelBka/MCaRvaACGTWus4roR8Olc72PvK8G0bpNLWm5 X63P0mwD3t1YoR1YzwzQPTfBESRA+qPV0+5UkxkujJ9U7f1igjw9UPbvrgtVYghkGufd x90QQVrKwKPanZaTxXuD/j5/aAz9ROT0qssxa3onK9/cIgGPwDlmmxi5TesyrTv1J5z2 6arDNX8yL3AFVLp6wYfk9vaAcczeaoJr23ptNC5kLohOqcLD1agyj6zxmepJdTs6jdki OsJA== X-Forwarded-Encrypted: i=1; AJvYcCWY0tMwViUo1nu0R265fBn0xandK3dIfeQ3DPiCZ5hOAODA2CUkQUv19feGy0R90MeBnNozP7Qtq9FQHRXb@lists.postgresql.org X-Gm-Message-State: AOJu0Yx63hXg3yI3Pp6b3+KSCDn47CM/UT7CUEtGoRFEsKcLdPC/51t5 LeA5G5xi/+KXBHyd2O8D25bhXYy3sKTCMOP0NFHFI8eHAmzcEGfc2mV7+/gdUY8jHi/Txa0ICuj f51efodXdYBIbDb8WH/4RsVrL3cLhObw= X-Gm-Gg: ATEYQzzr7fo10fwUEI43Oo9wGOkOtlOCHlyK6vgCk9ewN1yDAuB+XvxCsvZOJZ2QD6D 9o/EIwogWD8X5zJLg/g5rd+lqPugf3UDFlvzoCPdwVy32d8/GtAOFvKlOtWfAuhOX9yiQ8nl8SQ 71lhgxl+Ngnr1kOAcpIYa/8jI15hX50oGtWbm5am7olC8H2g4owNo8gY3+FEwdq/wCJxNfdj4u9 reYXrHNxMZzgqrmWRylNcmAeESzu0FrTPNcxfhthwb60Hc2oG4cpUK+YS4hL4Yaq6qah6bK3YPv z5zoMTjKKA6ZnVei X-Received: by 2002:a17:906:9fc8:b0:b87:efa:8786 with SMTP id a640c23a62f3a-b937657d99fmr10508866b.55.1772137007561; Thu, 26 Feb 2026 12:16:47 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Sami Imseih Date: Thu, 26 Feb 2026 14:16:36 -0600 X-Gm-Features: AaiRm51rDUdsJB8G4N6qnMe20bfIiOCgMImQQxlMaAy6-JrUZbqoNYZDAgiar0A Message-ID: Subject: Re: Add starelid, attnum to pg_stats and leverage this in pg_dump To: Corey Huinker Cc: nathandbossart@gmail.com, pgsql-hackers@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, > Per side conversation in [1], this patch exposes pg_statistic.starelid in the pg_stats view (0001) > and then changes pg_dump to use the starelid in the queries on pg_stats rather than the > combination of schemaname+relname, which gets a bit clumsy in bulk array fetching, and > also leads to bad query plans against pg_stats because the security barrier is also an > optimization barrier, which means that queries often try to hash join, which causes the > very large table pg_statistic to be sequentially scanned, and that's a bad time. Currently > we get around this by adding a redundant qual to the query which gooses the plan towards > an index, and that works fine for now, but there's no guarantee that it will continue to work > in the future, so this change brings some plan safety as well. This alone seems like a good enough reason to include startled in pg_stat, besides other future use-cases this will simplify as discussed in [1] > 0001 also exposes pg_statistic.attnum. This is no direct application of this in 0002, > but people have often expressed surprise that pg_dump orders the > pg_restore_attribute_stats() calls by attname rather than attnum, > and if we wanted to change that now we could (albeit only on new versions). This seems logical v1-0001 comments: 1/ - nspname AS schemaname, - relname AS tablename, - attname AS attname, + n.nspname AS schemaname, + c.relname AS tablename, + s.starelid AS starelid, + a.attnum AS attnum, + a.attname AS attname, Ideally, we would want the OID and attnum to be first columns to match the pg_stat_activity/pg_stat_progress style, but that will be too invasive. The new attname column should be moved after tablename, however. 2/ + + + attnum name + (references pg_attribute.attnum) + + + Position of column described by this row + + - This should be int2 - Maybe for the describtion, it should be something like: "The number of the column, as in pg_attribute.attnum" to be close to the description in pg_attribute 3/ + + + starelid oid + + + ID of the relation + + This should indicate it is a reference to pg_class.oid, like so: ``` (references pg_class.oid) ``` Maybe "ID of the table or index" is better, since this can only be a table or index for pg_stats. I dislike the existing "pg_stats.tablename", since this can also be an expression index. "pg_stats.relation" with a description of "Name of table or index" is more appropriate. It is a change that we can possibly make in a major version. Looked through the archives, and did not see this being reported/discussed. v1-0002: I examined the version variants of getAttributeStats and all looks good, and also ran a test on a 18 and 19 server version with the patched pg_dump client and all looks good. One minor comment is: + pg_fatal("statistics table oid information missing"); I noticed in other pg_fatal messages, we include OIDs pg_fatal("could not find function definition for function with OID %u", cast->castfunc); Should we do the same here? [1] https://www.postgresql.org/message-id/aZ3RbTE8Racscykc@nathan -- Sami Imseih Amazon Web Services (AWS)