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.94.2) (envelope-from ) id 1tUrGU-003LA3-Tu for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jan 2025 17:51:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tUrGU-00AuEK-0r for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jan 2025 17:51:45 +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.94.2) (envelope-from ) id 1tUrGT-00AuEC-No for pgsql-hackers@lists.postgresql.org; Mon, 06 Jan 2025 17:51:45 +0000 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tUrGQ-000CZ4-26 for pgsql-hackers@postgresql.org; Mon, 06 Jan 2025 17:51:45 +0000 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-54020b0dcd2so16795853e87.1 for ; Mon, 06 Jan 2025 09:51:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736185902; x=1736790702; 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=ROiCunmKHR3yZEd2NYhJNas4kbxA8Cqu1VpTuywxMvA=; b=kNWE7Nt9O4v3iFP44EZybpJGCv3lxQQBoupnI8JBcH2MGLCDyfi8u6kHDAWKCnPe4J x7v5xdJAYyKpeJSO3a3JbExpiV/mGe6rV9+1/TQi7S2Js9H8layiB8v4uQ5ViFQCx0y1 kuW9fYvkz9D+Cpy3OFWURWLJiAH5i6knsslEMHHnG2jEkAVPVBc9z/Doyw8nI4DxauwC GGwtNBLgXys7CNT+eBdaVY0uVyF0tZz9Blorto+jzDTKS5thfn5Uv/NgHz19WtCeUDr1 DOvCP5LSul/c+rgK3YvToY1TsZyu8b4UqJiyYcavbY+jQCIvZmzq//B+pwnB5vBUiUZl siqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736185902; x=1736790702; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ROiCunmKHR3yZEd2NYhJNas4kbxA8Cqu1VpTuywxMvA=; b=Z+W8J5r2XS2uhyybzhBOiPILIrQIAu6Ym7lL4LxSYC/pj6+IINR+C+CjYWYYJfXWyL 5gt2BXuwhnv5Jy38SwhD8TfnGE0ePvpG5X/iCRJco7Z7DGqnTjSduubVUwUVNuhPtb8E aXPQ5ZBAogcFfMpm3dY+uPqU8oOqvWOu+sAMPbgvWxQ1BHs4GcM3BjOx5gi3TUWaFDLT /hLSdFrZoXMK4pN/medCjnIUZQLFxm6reJAVcxB2PNpwY3D+FLQAii+MjmwJSuQK/9Mo YhAHiLTOph3AhjMe93JpmEf5Oq4jSDIR3dMcQInM/FnUO6D1P3qwBHo/QMAQt41cdWSc hljA== X-Forwarded-Encrypted: i=1; AJvYcCVmHq/H+wpzRrjYb5xPfbtbS22/pl92RZn9lFibgLnmTow1e5cx8pzIOkyQcnOwi3zdnfRKUDI4DjA4hYNb@postgresql.org X-Gm-Message-State: AOJu0Yzi8iPNWOge6knO9MbKnnJJdc4GON6RRizfHcLCk5/yKAWK3atg YaoyOHS/gRuh5l1nSA2OTxxiotVVrst0x9Y+09v84SsXwF6xq4lcFTyllJceOuU8AmlOl2hGerD cI9VfKBF6qfbBVIEWJkETKzC1TiU= X-Gm-Gg: ASbGncuJSOPMT+MVtqJ8igdlCIpeeQloi2oDVtAJgCUoxL5VsrNCw/3VjnAQqVEhR5A V7I4cKodXQavNrKQq7J1A78IR1YR8PE7gNg== X-Google-Smtp-Source: AGHT+IFt2FJIWZ9xyeXmKfNkFVGDzEia3/dLK3XIAzSiGtE5TFeDZp7Ni15USnNCiVGE3wTD807CvS1bN4hPAqOHt3U= X-Received: by 2002:a05:6512:220f:b0:540:16b3:3699 with SMTP id 2adb3069b0e04-5427e970564mr46491e87.9.1736185901614; Mon, 06 Jan 2025 09:51:41 -0800 (PST) MIME-Version: 1.0 References: <6707FCA9-FD1A-4609-A1A6-142456C14E0C@yandex-team.ru> <320a31e6-4c91-438b-ab17-8a1d72384727@tantorlabs.com> <52e5e3aa-066a-4daf-8d65-77c34a2f0d98@tantorlabs.com> <6482A576-4465-4E46-A42C-F1767E8DDE30@yandex-team.ru> In-Reply-To: <6482A576-4465-4E46-A42C-F1767E8DDE30@yandex-team.ru> From: Sami Imseih Date: Mon, 6 Jan 2025 11:51:30 -0600 Message-ID: Subject: Re: Sample rate added to pg_stat_statements To: "Andrey M. Borodin" Cc: Ilia Evdokimov , Alexander Korotkov , Michael Paquier , Greg Sabino Mullane , pgsql-hackers 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 was looking at this patch, and I was specifically curious about how this works with prepared statements. The way the patch works now is that it determines if the statement is to be sampled at post_parse_analyze time which could lead to unexpected behavior. Let's take an example below in which the pg_stat_statements.sample_rate is set to 0 ( to mimic some sampling rate < 1 in which this query does not get sampled ). At that point, all subsequent executions of the statement will not get tracked at all. Is this what is expected for prepared statements? My concern is we will even lose more stats than what a user may expect. This of course will not be an issue for simple query. postgres=# set pg_stat_statements.sample_rate = 0; SET postgres=# select pg_stat_statements_reset(); pg_stat_statements_reset ------------------------------- 2025-01-06 11:45:23.484793-06 (1 row) postgres=# SELECT $1 \parse stmt postgres=# postgres=# \bind_named stmt 1 \g ?column? ---------- 1 (1 row) postgres=# \bind_named stmt 1 \g ?column? ---------- 1 (1 row) postgres=# set pg_stat_statements.sample_rate = 1; SET postgres=# \bind_named stmt 1 \g ?column? ---------- 1 (1 row) postgres=# \bind_named stmt 1 \g ?column? ---------- 1 (1 row) postgres=# SELECT query, calls FROM pg_stat_statements; query | calls -------+------- (0 rows) Regards, Sami Imseih Amazon Web Services (AWS)