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 1tcY6T-000tCP-CK for pgsql-hackers@arkaria.postgresql.org; Mon, 27 Jan 2025 23:01:13 +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 1tcY6R-00FP3r-BC for pgsql-hackers@arkaria.postgresql.org; Mon, 27 Jan 2025 23:01:11 +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 1tcY6R-00FP3U-1E for pgsql-hackers@lists.postgresql.org; Mon, 27 Jan 2025 23:01:11 +0000 Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tcY6L-001rQA-21 for pgsql-hackers@postgresql.org; Mon, 27 Jan 2025 23:01:10 +0000 Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-30613802a59so54577901fa.0 for ; Mon, 27 Jan 2025 15:01:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738018864; x=1738623664; 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=+FsJs9L3uKwwP2h49g0p37DfqBVQDb4UWUW4MdC1vyQ=; b=I5dPX1f82IRfcE5MZ53gieSMYl0o2qfi+5gsaY0LqtPkb1hrMZhjSg6MSiOC9QLxtp /4M5XNGYoLtmgs2UcxM7FOPMx+qPe/FaL9vdA52xEFhqtENpmSjLoqvTGwifuZ6KGxB0 wYN6btM6b2V+hu39XNyPL2Wer3vYIHj5hHJ6WA7zbuxPygIZF1kES/puUw3mw0AqfJBd SGvig1mpur+8n5whR3IjWccoeHcenMou+QxgDZmqcqwOi7+EIHcvHxhOO2iZfSZ+sV4v K4kjcQ3fG3VWW95paqTV0R9BwcFniz5UhN52ePl+YA8N08iuUh1qbA5pPCuk5WbYwIp5 AEUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738018864; x=1738623664; 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=+FsJs9L3uKwwP2h49g0p37DfqBVQDb4UWUW4MdC1vyQ=; b=DKPj857RIcTaczWtWm6n1P3kTWdmoVJcvexuhapkMWVfmvEhOvWyDODJrr41Wozy5e fKOfac887udWjTRo8Cdz16bNV2KR5gXBplXvIFuJbe/MVZcxVvHSfW8p7oVMY/vD9MLB Rgvz8h+6TedOgxVzGSzzoxT26NrcBG42myC0FM7SHZuQM9ptnEI5M4ummPPitI0SCsiD wEZKBdR/ItXxC0PNeDWFzZjY6XoI8CT8MzwIw64tBDsrXSYKo+FMlFvi2/EtWnBaViF6 wut/8utrNJOneGjMkt+qcJ4cy453UGG0KoASrhh8hiP1ZrzFl4wNUY2ZRdQWp8OWW/SJ aADQ== X-Forwarded-Encrypted: i=1; AJvYcCV7Qh2K5ksouRpwpYYuG/C9tfDohq9vTRpbuVlt6zs8/MQTykMS4IaQNKuvQN0G0MIMOVXKPOPzuPbynVpZ@postgresql.org X-Gm-Message-State: AOJu0YxFkgUjf+9uWG59dR7dV1Wl+OeRA0xvxq5RZSII2WpKXkDIDFeA TbEfHm0QT3If5ditpNdAdnQ9r1+Al1uD4uppnwgjNKdZeCwKIfyrLYne5H8fvdyByf5ilvloteP PYSCG9oLdyy4eVzatsJhL+cWjR68= X-Gm-Gg: ASbGncvAulYX0jg1dVcgSS6ak1oUjAOOh/UwnHFvxqSRqCkWhe7+gywvRnpL0anfV6U vUyXJ2YD+FX9SZAMXiEtwI7VGJFuVCIyCqHh7JTaiXOzjndKPjI8gnG6EaQ== X-Google-Smtp-Source: AGHT+IGaxKrjcAMjCcPOu/NlctPSF37uW0EIMibLJvjyft0wB7NPEGNOSeMG/WeAHV4hfHoGuMru2uZ/XHw7MW278qU= X-Received: by 2002:a2e:a487:0:b0:2ff:d81f:7bbe with SMTP id 38308e7fff4ca-3072ca698cbmr103252351fa.15.1738018864119; Mon, 27 Jan 2025 15:01:04 -0800 (PST) MIME-Version: 1.0 References: <320a31e6-4c91-438b-ab17-8a1d72384727@tantorlabs.com> <52e5e3aa-066a-4daf-8d65-77c34a2f0d98@tantorlabs.com> <6482A576-4465-4E46-A42C-F1767E8DDE30@yandex-team.ru> <20994d10-ab44-4c6b-91bc-c4675cd2e58e@tantorlabs.com> <9D8A5BC8-A3A5-4DA9-9382-F30D343247D1@yandex-team.ru> <6cf6270b-e8fa-4d99-b74a-17e781cdf309@tantorlabs.com> <3a27c830-b81f-4560-9774-a87d9b922fbd@tantorlabs.com> <7AD765EF-14DE-4B3E-8282-E82A9B44DBAA@yandex-team.ru> In-Reply-To: From: Sami Imseih Date: Mon, 27 Jan 2025 17:00:53 -0600 X-Gm-Features: AWEUYZkfBNW5xaftrqk6eoojMa7lYv9bDmD1CdgJiVmXxTahNdG4TeOP0XyvC64 Message-ID: Subject: Re: Sample rate added to pg_stat_statements To: Ilia Evdokimov Cc: Andrey Borodin , Alena Rybakina , 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 have a few comments about the patch. 1/ tests are missing for pg_stat_statements.track=all and with a sample rate < 1 applied. Can we add tests for this case? 2/ This declaration: +static bool current_query_sampled = false; should be moved near the declaration of nesting_level, the other local variable. 3/ I do not really like the calls to update_current_query_sampled() the way there are, and I think the pgss_enabled should encapsulate the new sample rate check as well. My thoughts are: 1/ change the name of the function from update_current_query_sampled to current_query_sampled Also, the static bool should be called is_query_sampled or something like that. The function should also allow you to skip the sample rate check, such as if called from pgss_post_parse_analyze. We can also remove the IsParallelWorker() check in this case, since that is done in pgss_enabled. something like this is what I am thinking: static bool current_query_sampled(bool skip) { if (skip) return true; if (nesting_level == 0) { is_query_sampled = pgss_sample_rate != 0.0 && (pgss_sample_rate == 1.0 || pg_prng_double(&pg_global_prng_state) <= pgss_sample_rate); } return is_query_sampled; } #define pgss_enabled(level, skip_sampling_check) \ (!IsParallelWorker() && \ (pgss_track == PGSS_TRACK_ALL || \ (pgss_track == PGSS_TRACK_TOP && (level) == 0)) && \ current_query_sampled(skip_sampling_check)) What do you think? 4/ Now we have pg_stat_statements.track = "off" which is effectively the same thing as pg_stat_statements.sample_rate = "0". Does this need to be called out in docs? Regards, Sami