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 1vcvS0-00CCVq-08 for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Jan 2026 01:01:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vcvRy-005MZm-1m for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Jan 2026 01:01:31 +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 1vcvRy-005MZe-0e for pgsql-hackers@lists.postgresql.org; Tue, 06 Jan 2026 01:01:30 +0000 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vcvRx-004Q4N-1U for pgsql-hackers@postgresql.org; Tue, 06 Jan 2026 01:01:30 +0000 Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-64b921d9e67so746069a12.3 for ; Mon, 05 Jan 2026 17:01:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767661286; x=1768266086; darn=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=eQ0xoNr4OxRb3GeHAC5oSqA8VMVZ/zcDydiyCcpuPbg=; b=H+AAtktnG4zT8fLh8dGtm1Lh4/P3l++EFLIresiFB5i14CAwUC6xaFh5z3TsqkbcjE 3GHBkdqlYG3n69pq4B4lZ8kQcSn12CBC8EzXe0LEkWUSQHwBuaviUrxrf4npDzshAc69 ztrk/OCzbzxmqSVmO+0U2gb5cYYbJLm1loPre87vv+o7S0Mm9ublinR+fkLkXO0oAEaK 7pLINkfP5dLXD7ZYhKFZyJVQj0pLYJx/ATI4nllWKQVQW2TCIZZar9UAivy0PdsSElYm 516cUB3Vw26B2gTJD4ztLrBg4swnctdF0LlDvQBw+JrCo+zo3925i6pO++o4HYFkCx/w f99Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767661286; x=1768266086; 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=eQ0xoNr4OxRb3GeHAC5oSqA8VMVZ/zcDydiyCcpuPbg=; b=TK0VIIWPFXj6g3a6rphLFXX8YJ8yEtj8EVNPcjSW/GUsYOi0joCWZT3WBRZqwx9tt2 1Efv4N5ZIoPaSHF0L2Q2dObVWZzVoTToircrW6853I40Dz1nC7Rb5E1R/Ub5NMsaQ3rY Ws+ZmZbx3Jhaj6RugWAqn9CZmVvmAXmYvR+Hq2D8LtbePBGp69ks2TrOXuvzdX6hY+Zy Z3XSN+y1mJBH46QC1OGcVL7VxaDm/E3qBp3XhbtvKWb8Cojg62BewSmbIUKtBQ6dP0L5 hhWNGgsPxkBzu99U38U0dqNw3F04scUyhNpPszgOaiwbOFYcwH82gOXv+5HySyezVw8J Uj/Q== X-Forwarded-Encrypted: i=1; AJvYcCVMM7lGfGC0bBr6E06dSl0AyZp0OrlCxnqa+ENo1aZJ3Hw3OMF52eapzVxd+lDE1QmaLkz9+N6KJ1mZM1ds@postgresql.org X-Gm-Message-State: AOJu0YzYoWjsPXFcpZxzrke7qublscQncD7JItWASr5daZ62fCDcDuzW 7rlJcQRHRsDN1H2oyL9TbhJnTHnB4KeqJHybqBSOEnwInQcIBfdSe0ERjjdYrc4/oOIvjY8H8La I79nedsYhJqPA7mayGSDUlBempPFnaxo= X-Gm-Gg: AY/fxX7lq6hs9xzRqz+azzQDTlb7A2MlRfNo6fxugdReMsO4DHSk/f8PsbRxzXlygdX GwbDmIdodz9MXllgdlHbgi+jhOIgfw520u2EQTBXyVWzv2kr+WNX7RYfmf6Ds7COvEmfdkkQwLy UQuiMtPxNUTBy/BSm6GHqhQWSOvTEWERhZ7WuXwT2B4acZV0RLaWcVpJfMNgxclZIIYWpYsw4ah 1NQGgKnuXGmPjaKzUhgw3xoi/0sq/RgMPRt5BSO3xPkfeB9PaEcQWKYCviNaeb//OVQHQ== X-Google-Smtp-Source: AGHT+IFhBD3Uvw6mQSl35hjQlKPFSMx0yefngeygXetFylj/JBcOp8GBURnWn6E1r7B7VQKINtALIfxBE79/k25Ex8s= X-Received: by 2002:a17:907:d1d:b0:b80:3fb3:bdf6 with SMTP id a640c23a62f3a-b8426be68ddmr173284866b.40.1767661285670; Mon, 05 Jan 2026 17:01:25 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Sami Imseih Date: Mon, 5 Jan 2026 19:01:12 -0600 X-Gm-Features: AQt7F2qTT74sh_pJbHFLQqg5jdcjovbn4bpKtzYcpfALUcvx_--VF2s_IaKHr54 Message-ID: Subject: Re: Refactor query normalization into core query jumbling To: Lukas Fittl Cc: Michael Paquier , zengman , pgsql-hackers , Julien Rouhaud Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk >> backwards compatible. Basically, we keep JumbleState a non-constant, >> but provide core APIs for any operation, such as >> generate_normalized_query, >> that needs to modify the state. So, my approach was not about enforcing a >> read-only JumbleState, but about providing the API to dissuade an author >> from modifying a JumbleState. > Given the lack of public APIs to modify JumbleState today, I don't see how > an extension would do > modifications in a meaningful way, short of copying the code. I think we > should be a bit bolder here in > enforcing a convention, either clearly making it read-only or dropping the > argument again. Based on the discussion so far I am leaning towards making JumbleState read-only as described here [0]. I don't see how we can drop JumbleState completely from hooks, since normalization needs to occur on-demand by the extension. > 1) An extension that wants to display normalized query strings > > This seems to be the biggest kind of what I can find with code search. > Extensions like pg_stat_monitor [1], that > want to do something like pg_stat_statements, and have to copy a bunch of > normalization code today that is 1:1 what > Postgres does. Such extensions don't need the JumbleState argument if they > can get the normalized text directly. Yes, I don't know how that's possible; besides generating the normalized string during JumbleQuery and making it available to post_parse_analyze hook ( and other executor hooks ). But this also means we are incurring the normalization overhead for every execution. > 2) An extension that wants to capture parameter values > > Some extensions may want to remember additional context for normalized > queries, like pg_tracing's logic for > optionally passing parameter values (post normalization) in the trace > context [2]. If we kept passing a read-only > JumbleState then such extensions could presumably still get this, but I > wonder if it wouldn't be better for core to > have a helper for this? This could be like a core GenerateNormalizedQuery which can optionally track the constant values. That will be an enhancement to normalization and a new requirement. [0] https://www.postgresql.org/message-id/CAA5RZ0sbWmqdUBFo8JXMJe72pnwjxVY58htJ6pKbwnyQuRctQw%40mail.gmail.com -- Sami Imseih Amazon Web Services (AWS)