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 1vdvuL-006puP-14 for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Jan 2026 19:42:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vdvuK-0045ZY-0s for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Jan 2026 19:42:57 +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 1vdvuJ-0045ZQ-36 for pgsql-hackers@lists.postgresql.org; Thu, 08 Jan 2026 19:42:56 +0000 Received: from mail-vk1-xa32.google.com ([2607:f8b0:4864:20::a32]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vdvuH-005L1e-2P for pgsql-hackers@postgresql.org; Thu, 08 Jan 2026 19:42:56 +0000 Received: by mail-vk1-xa32.google.com with SMTP id 71dfb90a1353d-5634feea416so1359540e0c.2 for ; Thu, 08 Jan 2026 11:42:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767901372; x=1768506172; darn=postgresql.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=vdSEsfCGga8eZ47q91l0CCxBw4360+9iXnVyl1PA7nk=; b=Eu39O+Xhj7Nh7wONTvcgERUB89Ba2zCQc/hz47ap3tfjEEcTSaI+c+4joU0BHGclyZ vplGNOYGeMh+O1kOIgmOtnoCSDUjfXOxIJ3zToG7P66QyS9LkEaH6Q8AL3n1QALxylEY r9YPIG1vC1hZimeK9dBWqPsZPvn7s3TxrsHQGJhEUGG9Jmm8aNIuE98DhRM8NKGZFdVr qvKguk3729jO6mqxCbxcDUGg79GrM/u/SFsoWj4EppclBmsk/VK0L5+3EEdrR1FP2znJ +h/tEIfCEgw60jRnas9LRpIcU475VJjjrlNBELFKfnDYJF8SK9v+cO1jqvZaHkyjzyep XTHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767901372; x=1768506172; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=vdSEsfCGga8eZ47q91l0CCxBw4360+9iXnVyl1PA7nk=; b=O/Ig3P4R2oE9U9vPn5k9cE8b3lBSC7yaX9JOucJghCFg/J+OoYtVOJdtOtcPv4oyjk DJebOcTyavMgw19Yw5MkmyV/xU6GnuSCwz2u0YLJzLmPKHc/ztZiZ7GS6APbVHWws1NO K5FTTHL1a+RWyR/GO7zsw6/pTBq6AR/6VHv7ZRBcXEIEIzMKxiWndlPvbZYMVN5BO6MK PF9tvgeHHejtzG2HY4VIiKnLcTp9bGhYcxhbPub3B8KpZLG4fASLQwuFSNScBREUDA79 gsJ1ZYM+rpOyyl1eJmrzc6O2CkzPOf579dK7mWplZk08jkQdFxfeCR8RS+wf3Eudup4k bQYQ== X-Forwarded-Encrypted: i=1; AJvYcCWEijQIVzE0F9mVMGCvlMoSiP7ZCXiFk6O6hk6Z/Dea9UdsVEISK/6sn8bF3fkYvnin1zHIfd/VNReMEZAn@postgresql.org X-Gm-Message-State: AOJu0YzQIcTh8i5F2Tl5YiYKrt5PZmgxivFkOs7R0HE+tRxVX6izHVYX tzQQknIhHch+Rw11EOgIRWY+TEViy+svt830CyQb0vfkiOzv2PNlh3rV X-Gm-Gg: AY/fxX5SAN03cFIeia6Lc03/i+2EGSdxIFMOZL8k2Yt0SHRVngglThVEi9CrLdjnysh 3A5lOsTyWSAxcswFz9eelXXGLuDN+PPT8FjBDFU/COkqJBRqdnvXU66wilW6shjyKcp6P6+jrUa ZRQ178daLUsK27RUhIKsqwNP0nTkuwhumnw/DQqOs8jQPN/inaKdwDZhDJ0s5RK0ZjnNHd6Xfso nqIazjOSV2PmXOmcJ3hqDteBSEXsUcmwfA79lh518VgvB3kNTBghxtu5hulAKl6msTNZj2GYjed T9tQqKH+6cfqSZjon3GyYPBmPduPjQOJxqIQaxo5r6hTYCc9Z6nLqa6fCnBHVmcNsCHtWsKABYi H2WyewWT0MSuVXQ2OZxGPz2cWFEJoNDLRSVrhkpQelKBvwPI2CylRryU9FXNTSvGiBs6VLX0Ibo LxEUpHOPCE7ZtmQZw4g6LEa6g1ULa/XhUeYQ== X-Google-Smtp-Source: AGHT+IH59re58HpA5+95syxLQmH8rO32iF8Nf9w38Tr3nlT3+X0rHjtveiBp6U7RwodfbXp9+wcLSA== X-Received: by 2002:a05:6102:548b:b0:5db:cec7:810b with SMTP id ada2fe7eead31-5ecb6904d1cmr3162054137.29.1767901371660; Thu, 08 Jan 2026 11:42:51 -0800 (PST) Received: from localhost ([2804:14d:328a:a59c:4934:3e02:ac25:9aec]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-944124e97b1sm6871700241.15.2026.01.08.11.42.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 08 Jan 2026 11:42:51 -0800 (PST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 08 Jan 2026 16:42:47 -0300 Message-Id: Cc: "Michael Paquier" , "Ashutosh Bapat" , , , Subject: Re: Import Statistics in postgres_fdw before resorting to sampling. From: "Matheus Alcantara" To: "Corey Huinker" , "Etsuro Fujita" X-Mailer: aerc 0.21.0 References: In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed Jan 7, 2026 at 3:04 AM -03, Corey Huinker wrote: > Anyway, here's v8, incorporating the documentation feedback and Matheus's > notes. > +CREATE FOREIGN TABLE remote_analyze_ftable (id int, a text, b bigint) + SERVER loopback + OPTIONS (table_name 'remote_analyze_table', + fetch_stats 'true', + remote_analyze 'true'); I think that it would be good also to have a test case where remote_analyze is false. The test could manually execute an ANALYZE on the target table and ensure that an ANALYZE on the foreign table fetch the statistics correctly. --- If the table don't have columns it fails to fetch the statistics with remote_analyze=3Dfalse even if the target table has statistics: ERROR: P0002: Failed to import statistics from remote table public.t2, no = statistics found. And if I set remote_analyze=3Dtrue it fails with the following error: postgres=3D# analyze t2_fdw; ERROR: 08006: could not obtain message string for remote error CONTEXT: remote SQL command: SELECT DISTINCT ON (s.attname) attname, s.null_frac, s.avg_width, s.n_distinct, s.most_common_vals, s.most_common_freqs, s.histogram_bounds, s.correlation, s.most_common_elems, s.most_common_elem_freqs, s.elem_count_histogram, s.range_length_histogram, s.range_empty_frac, s.range_bounds_histogram FROM pg_catalog.pg_stats AS s WHERE s.schemaname =3D $1 AND s.tablename =3D $2 AND s.attname =3D ANY($3::text[]) ORDER BY s.attname, s.inherited DESC LOCATION: pgfdw_report_internal, connection.c:1037 --- If we try to run ANALYZE on a specific table column that don't exists we get: postgres=3D# analyze t(c); ERROR: 42703: column "c" of relation "t" does not exist LOCATION: do_analyze_rel, analyze.c:412 With fetch_stats=3Dfalse we get the same error: postgres=3D# ALTER FOREIGN TABLE t_fdw OPTIONS (add fetch_stats 'false'); ALTER FOREIGN TABLE postgres=3D# ANALYZE t_fdw(c); ERROR: 42703: column "c" of relation "t_fdw" does not exist But with fetch_stats=3Dtrue we get a different error: postgres=3D# ALTER FOREIGN TABLE t_fdw OPTIONS (drop fetch_stats); ALTER FOREIGN TABLE postgres=3D# ANALYZE t_fdw(c); ERROR: P0002: Failed to import statistics from remote table public.t, no s= tatistics found. Should all these errors be consistency? --- I hope that these comments are more useful now. Thanks. -- Matheus Alcantara EDB: https://www.enterprisedb.com