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 1tViIc-00AnVe-AF for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Jan 2025 02:29:30 +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 1tViIa-00AGDK-BG for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Jan 2025 02:29:28 +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.94.2) (envelope-from ) id 1tViIa-00AGBZ-1K for pgsql-hackers@lists.postgresql.org; Thu, 09 Jan 2025 02:29:27 +0000 Received: from mail-lj1-x236.google.com ([2a00:1450:4864:20::236]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tViIX-000csL-1j for pgsql-hackers@postgresql.org; Thu, 09 Jan 2025 02:29:26 +0000 Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-303489e8775so3418101fa.3 for ; Wed, 08 Jan 2025 18:29:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736389763; x=1736994563; 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=ZQZF7NOgNeMruj4Oz9xicXWnfGtB6l00qV+00urZVt4=; b=RuJJUGl7zR1eKYjM0p2GaR8UnrC1VSesrLxhpJuhddvKFZEegHQzGnQ6nFMmIuzjre L9WAgxnbX+PtQ1XOeBpgg7WVfrs+z8aW1jYKmzhzyYP36qeN6AmQrPzX9NATdNG/X2Cg IRgolMDAytq0HwhPsLytZrAirP015HX+4cYt+X0AkAlfTpVGhMvwXJxfOwOZc7HNPUdf hEkUF/us/dKIgvoRjdf6Q5KvyhDMnyduIiLZ6Wg9Y/keMRE+8zrNkhQ8YjFcnS02RSQq B2xMZmRCs2EyQxSV/L0KLijMNT3kAzvkDZ1FynkJWyT8D7bBDcR9QsI6MUQCeZVU3d1d vmWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736389763; x=1736994563; 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=ZQZF7NOgNeMruj4Oz9xicXWnfGtB6l00qV+00urZVt4=; b=lx2pNQVhYEkxBI7HVBccvFqV17861jEN64LNwBFl0S8ci5LtkIlzk9vdRqNAj/Gnnw 1Nk9uHesaUWofWOdsgIwD0Evkn/rpc+BftOM2dw5K0bCmPTIi/ooseK++vgws73JcuO2 GXtQJuRiA6b5oWjqQr9XSR/1FB7ZIzMAj3Ic/DPBwCZB9qtQksQPvGOOwRmI00dKos++ FvT6nngRZNctpJzWlIpQxaQPg7f9YO/rv3a24IQ5udaEvQgFxNmq84eW3GzMSeR5byVH cPItGc915GoR7P7h4yxI32c0kOXjRfJqjczY2m56bS5r30gxIz9bH7TKuArlpLpOmnHD vkZg== X-Forwarded-Encrypted: i=1; AJvYcCWmxxKE2QqKm18fkSRZCpN834gUMOyKFwnGXLsyx6Ywz1NqlAeNuToWsqCu0b59CfXPpkfgR6lRVQnaqmNm@postgresql.org X-Gm-Message-State: AOJu0YzH54C9RTlincljyqMh6ISXRFDMmhfy+MmHD4x60ysQ72w1WQwX 4PuwcJg45jSwl9TJ+quUDal2mS1Al9flEKDX9CzRR8MqSqmGKAAgcRDMsaKIogIe5+FpybCtK7A lTytiZQZsIet4AWTYQkiiqAzLiCk= X-Gm-Gg: ASbGncsENR414qxjwVKVvBv8ox9nYi69TpQ3i1TzcYWs/UcKYvJLql0cpl4rHCcz3ip 8/imXAXXrYW9rnia0JgLnZc08M1WEg9q1Eg== X-Google-Smtp-Source: AGHT+IGvX4wRGisgGOIas8TELvha4HWz8OAn0grQ6XOffL1+LLjbyDC45NMS9N7DryCAxVOlE/bhOIjwNZoM7RvyvCs= X-Received: by 2002:a05:651c:401a:b0:302:4115:191 with SMTP id 38308e7fff4ca-305f459b5f9mr9606611fa.20.1736389763007; Wed, 08 Jan 2025 18:29:23 -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> <20994d10-ab44-4c6b-91bc-c4675cd2e58e@tantorlabs.com> <9D8A5BC8-A3A5-4DA9-9382-F30D343247D1@yandex-team.ru> <6cf6270b-e8fa-4d99-b74a-17e781cdf309@tantorlabs.com> <9af7cb4e-d191-421f-85a2-22d8c406b47a@tantorlabs.com> In-Reply-To: <9af7cb4e-d191-421f-85a2-22d8c406b47a@tantorlabs.com> From: Sami Imseih Date: Wed, 8 Jan 2025 20:29:11 -0600 X-Gm-Features: AbW1kvb419iq8q6WyOlSzjWLnI5h1KiGMUWyPO47XuDk3duYk2ZblMMTF2HmNTE Message-ID: Subject: Re: Sample rate added to pg_stat_statements To: Ilia Evdokimov Cc: "Andrey M. Borodin" , 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 > Unfortunately, these changes do not achieve the intended sampling goal. > I looked into this more deeply: while the sampled-out queries do not > appear in pg_stat_statements, an entry is still allocated in the hash > table after normalization, which, in my view, should not happen when > sampling is in effect. Therefore, patch v9 is unlikely to meet our needs. pg_stat_statements creates entries as "sticky" initially to give them more time to stay in the hash before the first execution completes. It's not perfect, but it works for the majority of cases. So, what you are observing is how pg_stat_statements currently works. If an entry is popular enough, we will need it anyways ( even with the proposed sampling ). An entry that's not popular will eventually be aged out. From my understanding, what the proposed sampling will do is to reduce the overhead of incrementing counters of popular entries, because of the spinlock to update the counters. This is particularly the case with high concurrency on large machines ( high cpu count ), and especially when there is a small set of popular entries. IMO, This patch should also have a benchmark that proves that a user can benefit with sampling in those types of workloads. Regards, Sami Sami Regards, Sami