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 1vT3ev-00Bzlk-1l for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Dec 2025 19:46: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 1vT3eu-006X6V-0T for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Dec 2025 19:46: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 1vT3et-006X6K-2l for pgsql-hackers@lists.postgresql.org; Tue, 09 Dec 2025 19:46:04 +0000 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vT3er-0046Ow-3A for pgsql-hackers@lists.postgresql.org; Tue, 09 Dec 2025 19:46:03 +0000 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-b735e278fa1so1059240066b.0 for ; Tue, 09 Dec 2025 11:46:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765309561; x=1765914361; 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=vvWXq/1aYl4uLlJVvtgp4N2NEIc3mHnFe87g/KTTRvY=; b=S3lGGeWYvw4tWWG0v/l7TKlB0xjVKx5AHn8++8CwVng/2daoli840Pu4RLT67xv3AC 1t9v/SgnTit6/pb4Ad21/nlUr4xRaVTOd5QnFc5D0e9BT8T5jMWZ+2efYS45ZVaeqKVJ OyLOO8T5dQPw1LS5GORtclQS6oAWpBlUS7+7hQeVL/rr69yJLJlYCIrtNa8Nrvr/5ezt SMGxlszkIViGzEjwgpvtU1i/D3u1Niybq9Vfeu8deLB8q2TckBHUOidrIHPY8j7fLeep QBCIGuKDeRM+4SNFGm5T1xnbcBhgTsKKD8fP0tz83lZnVooW9KnuOHBRezHqzRZsy4+z S2Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765309561; x=1765914361; 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=vvWXq/1aYl4uLlJVvtgp4N2NEIc3mHnFe87g/KTTRvY=; b=n5MHCg4u24Wx7Fgbe4eMX5oYOhE5Yj+X1zXlnoVgWKwSFs2IDPq2aM32HE6sduZjgt i/OLzxYPWUP+RaROIcoe3DPn4Ob041q8cRzcg+LRW6oiwoRA1M2vaYyojZiFyY1eQigX iYgwug9tyDJXcBD0Bf7od3XwijWluQsRPlQkgKRinYtk5x1hXQhxC0OkcF20psiQKx3t 6uIUhU+gj3iYf8/r1UD1tX1JW6itKNdfUm6P3+gX+OuBBwfyQIdI882ATJU4B0XvcntU RSOI52171XoULYi3MxAfmDMG6IRL1cNXmvJtMyj29rZOdN1SqBCSMzjPrM7M8egE/Ftq uEWQ== X-Forwarded-Encrypted: i=1; AJvYcCXwnFFRfdHK2swh0QHrRYp0S7mu9OQUEPO+LtJ2mVTxvu845/OInm3M6+fg2TDMOKrL9uvt1ZQTqerLHAL2@lists.postgresql.org X-Gm-Message-State: AOJu0Yyh8r8N5H0ybrEZSoX0zaVYLMKlLk3XivL2CTJr2vlMaUsyXNo3 zbA+JseM25Nto9dGsSUJy7KDNBWXFtqsfkZul0DY04ajDevrkbfQnFTEp70k5Rfj6nXrBilIRDT Hmss03nOusm9ezyyytW2asXZATrAYtOA= X-Gm-Gg: ASbGncv2odQHD5CYNE6weUS7lT1eSl13lCei+zokl01/y38JQyBu7z/s7FY2XHrbCO8 CEeQ1l5kFdiV0USyM219dUBtQRZFeFf8cfI0VvPogLCDmbuNotEs3WVSiqlu3xBaYBLsnjXzH5K 77sgWpYBa+R5NK4YdPNGNHLR/yk+i+nabpfyg2cVd6pLMTwCgC91rYp7Or8zeAbCeKh7aLB+8xA ttEGx9fbSQ5uDUm+I9Y9bZIbM9dT+Z3X0ly1G08Nhc+UTLvf1zYmFtodOaPezOd/uuLlyi1u0BH mfTPnlkCeN30rdA0I3SNAITpblA= X-Google-Smtp-Source: AGHT+IFTNivDuoP5wJtVl+fhZDi61F9ce5SGToICXerJqgvDmZlvCTr9dyaSTaEtmOhXwp/GXPFg0VREaXCdsqxku0g= X-Received: by 2002:a17:907:9403:b0:b79:b317:16b3 with SMTP id a640c23a62f3a-b7a24818491mr1426083866b.53.1765309560560; Tue, 09 Dec 2025 11:46:00 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Robert Haas Date: Tue, 9 Dec 2025 14:45:47 -0500 X-Gm-Features: AQt7F2pCVNOYI091lOzxOmg9zWelbSQqgKnkrJXubA9e8Tzfj1Xo3lpGscoUDG8 Message-ID: Subject: Re: pg_plan_advice To: Jacob Champion Cc: Dian Fay , Matheus Alcantara , Jakub Wartak , PostgreSQL Hackers 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 On Mon, Dec 8, 2025 at 8:19=E2=80=AFPM Jacob Champion wrote: > I really like this idea! Telling the planner, "if you need to make a > decision for [this thing], choose [this way]," seems to be a really > nice way of sidestepping many of the concerns with "user control". > > I've started an attempt to throw a fuzzer at this, because I'm pretty > useless when it comes to planner/optimizer review. I don't really know > what the overall fuzzing strategy is going to be, given the multiple > complicated inputs that have to be constructed and somehow correlated > with each other, but I'll try to start small and expand: > > a) fuzz the parser first, because it's easy and we can get interesting in= puts > b) fuzz the AST utilities, seeded with "successful" corpus members from a= ) > c) stare really hard at the corpus of b) and figure out how to > usefully mutate a PlannedStmt with it > d) use c) to fuzz pgpa_plan_walker, then pgpa_output_advice, then...? Cool. I'm bad at fuzzing, but I think fuzzing by someone who is good at it is very promising for this kind of patch. > I'm in the middle of an implementation of b) now, and it noticed the > following code (which probably bodes well for the fuzzer itself!): > > > if (rid->partnsp =3D=3D NULL) > > result =3D psprintf("%s/%s", result, > > quote_identifier(rid->partnsp)); > > I assume that should be quote_identifier(rid->partrel)? Yes, thanks. Fixed locally. By the way, if your fuzzer can also produces some things to add contrib/pg_plan_advice/sql for cases like this, that would be quite helpful. Ideally I would have caught this with a manually-written test case, but obviously that didn't happen. > =3D Other Notes =3D > > GCC 11 complains about the following code in pgpa_collect_advice(): > > > dsa_area *area =3D pg_plan_advice_dsa_area(); > > dsa_pointer ca_pointer; > > > > pgpa_make_collected_advice(userid, dbid, queryId, now, > > query_string, advice_string, area, > > &ca_pointer); > > pgpa_store_shared_advice(ca_pointer); > > It doesn't know that area is guaranteed to be non-NULL, so it can't > prove that ca_pointer is initialized. I don't know what to do about that. I can understand why it might be unable to prove that, but I don't see an obvious way to change the code that would make life easier. I could add Assert(area !=3D NULL) before the call to pgpa_make_collected_advice() if that helps. > (GCC also complains about unique_nonjoin_rtekind() not initializing > the rtekind, but I think that's because of a bug [1].) This one could be fixed with a dummy initialization, if needed. -- Robert Haas EDB: http://www.enterprisedb.com