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 1wZBSi-000q4E-0U for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Jun 2026 17:51:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wZBSg-00Cy2L-2g for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Jun 2026 17:51:02 +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 1wZBSg-00Cy2C-1k for pgsql-hackers@lists.postgresql.org; Mon, 15 Jun 2026 17:51:02 +0000 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wZBSf-00000000W6V-06CK for pgsql-hackers@postgresql.org; Mon, 15 Jun 2026 17:51:01 +0000 Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-bf0170c80f7so621457166b.3 for ; Mon, 15 Jun 2026 10:51:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1781545859; cv=none; d=google.com; s=arc-20240605; b=hSjpt7UNkoJWrGGO17jg6JBA4QcsTXqSW6ghVqO81ZrYQ8AXGnZmQE+Zm9U6VfI8BW J7iTG5yb+pieh56rNZP0mMKvRS8rQZdMrwuT26XboNugQloHUshGL7fZ9FLGcLCNef4Z IM3uX28ZQmHPrz9Kk9QvLFBeV58JGmNDFAsAoyguzKnOpSgAeunQgJo0wQ9fCtM/I6aR IRwXiSjfKABH0EpMTI7QxAkI9fWz8gWNLcGigwHgOIKBvob2ml2dvOqQNXpVL9WfuGYL Sc5VyZKkKxavOEQjwZcj1qBCWA2pj9Hjaz6udqnAl0HAgQPh2Efx38C6Y9pz6PgrtP6T D5cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=to:subject:message-id:date:from:mime-version:dkim-signature; bh=9+Y0F0JrunjiyTnU6ic5uld50AWQ3ekp8g962jmskus=; fh=P2KqPuSxsMYvGotaH8BN+uO3qerQSb36Hkx3QHdoIKo=; b=Gr5aHQNKPv+T0l1giehqPMrUQ+4uW0j+vOPy8lzS0nPdiDoK8856cF/3Yj86RwR2Qv s3uUWKztLpOEwdY/DkkdhFN4T6RdeWZ5RVr8KZ4buccawy59XTAhdnigN0wLmkl4aVB2 tK9Dz5a8eZeu0wzA4CDgYwiV4c9v/B1n0GXyuUQ61IuwHRJLFykHCbOxRQHy1hX2BUhh UO+kCGBt0zXoc1r+/eBtSUJVtmDaBQYnC8esJMtwxqccIDLHVLmJNQglyOIpvypiVPWE 5oHE7XXzSR/qSdXHIBkrMn02l26XJhYg57DKULlWr4lLKan0qVH4KkjWPmmoZiFNc7X7 2UyA==; darn=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=1781545859; x=1782150659; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=9+Y0F0JrunjiyTnU6ic5uld50AWQ3ekp8g962jmskus=; b=ZBIzli12htTcyMGn4UkXo15aXoBt9/sEE5Dg2bJUlhGyngjoZX9YIcRJ2izegwHvJX Ob1aKGgh4L4W+kIVUwjwY2tRJ9Z3lH5tgf2bDR+bnG6gvT0AEy7kbDL5s1bsYMjoG/JS YZjqVdtMALPJ7fGh78bzw2oDBti60RBzu097oUmh0X30DrlBL1scpzIcCw27OM5gSj/e QSxpL+lKTCGneu4qyzud1xHbTAMH5EFopvHYjwgwFfF/rDhZWTUy2MkfNg/gtAmTFvge /RE/FqnFHDfFqncn/xdwdpw9/F26pkxcCws98Mc/za2dQPdrP3RRGidTbfTGqOhJAtQ5 1tgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781545859; x=1782150659; h=to:subject:message-id:date:from:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9+Y0F0JrunjiyTnU6ic5uld50AWQ3ekp8g962jmskus=; b=E7JLBv/Wt0uDN49k1gCWamXAazrCGWLz8b1InzOLu++qCHxlSp8pm0x8ienjzGa5Oi XXB7cL+kKWy7utTTxp1byDFeCqw2uI7EeEw7+2VUrd3/QYeV/YlxyUussH9GiBujbNkO ULmnk/8tw5WXExC/VfMVl0oQ4wYnJ7HUqAV5OR2Hb26h44SubHtAvYFs7K47auiE7L46 5MHDARWgI8DV1WECBiO06L3JClzoUi0ppVDrM/WKuBGAKwZLk7+mH66lRH9EjCRvB6ZR 91j1NR6ETktZhTL9bp1PkogoauorV5zVoO/7vRN3iyrJTH0YKKUqsoUza4QgOUK2mMR3 fUOA== X-Forwarded-Encrypted: i=1; AFNElJ/1tOgkwRyXe8Iismp8/xNJFo7mMqmB3MFtJgwrSkremhkL0aZzDn1JIqRjlXKIdndXFJFr353vUq5pp8KW@postgresql.org X-Gm-Message-State: AOJu0YyNyg+SFIg+BDmJlBLeC8sEpxNU7v3mL3lUEhouz8BTuvtO8WNN hbtjAq00gWR+pIgTSNSCiHeudWAn0xBP6tBlvcZT7UG0qb8BBZ0LcDxopNDE/UUU8jurvlcrs+W zsVarN6A7s/1H39KFyRYMcGu92qWd/T0= X-Gm-Gg: Acq92OG+o0RzsxfTFJehju5N/d6eIkqU6kWoKGJ1sF1GIqxWK8X4OtRdpM5Ogb8Kic+ 8x1MjJVdj/P4rlLqmxRTUxc2osuHf46BXyLyzUln2cbSTgXwcJjFCdp+VQnySwfIfwqaALt32dx rrSt14Fo/xCPtJEEQQLOF3HJpDeRDdav2q4vhJs1pLh7W7S7PqviEl/+8BtYbL8EEmu0ZYqB4QD lzmLhKRAth89TQaV7/u+YK/eFhxIAeQxQS2clqmAP94hKqBZfYDAH13uug5lvD0slHQyMatCViJ yIGZ9oGudRhAtpSmMx0+jkkTl8RIH4+CEezQses= X-Received: by 2002:a17:907:1ca9:b0:bea:f5ec:e70d with SMTP id a640c23a62f3a-bff4a10c543mr643647566b.10.1781545858704; Mon, 15 Jun 2026 10:50:58 -0700 (PDT) MIME-Version: 1.0 From: Robert Haas Date: Mon, 15 Jun 2026 13:50:46 -0400 X-Gm-Features: AVVi8Cf_piiHZNr3vkTDkHW1uBDoP4r5xLylqqQrGF-p2U7M0oKLfPnJIRqal90 Message-ID: Subject: use of SPI by postgresImportForeignStatistics To: Etsuro Fujita , "pgsql-hackers@postgresql.org" , Corey Huinker Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, I'm concerned about the way that postgresImportForeignStatistics is doing what it does. First, it's using SPI to execute two constant SQL queries, attimport_sql and attclear_sql. However, it doesn't seem to set the search_path, and these queries aren't fully robust against a possibly-unsafe search_path (e.g. the call to pg_restore_attribute_stats is schema-qualified, but the type names are not!). Furthermore, the function we're calling takes a schema name and a relation name as two separate arguments, rather than a single OID argument. I'm not sure it's completely guaranteed that we'll end up affecting the same relation that we locked in postgresImportForeignStatistics, because e.g. what if the containing schema is being concurrently renamed? But even if it is absolutely guaranteed that we latch onto the correct relation, this seems like the fundamentally wrong way to do this kind of thing. It seems crazy to me that instead of exposing an interface that would be well-suited to direct use by an FDW, the statistics-import stuff exposes an interface that can only be reasonably called via the FunctionCallInfo interface, which then results in postgres_fdw needing to jump through hoops to construct and execute SQL statements. This doesn't look entirely easy to straighten out. A function like attribute_statistics_update() is just not a good idea -- it mixes together considerations that only exist when you want to call something from SQL with general validity checking that's needed regardless. But I don't think we should ship this like this. Best case scenario, it's overly complicated. Medium case scenario, it's also unreliable. Worst case scenario, there are security vulnerabilities in here. -- Robert Haas EDB: http://www.enterprisedb.com