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 1qL3XT-002DHg-GX for pgsql-bugs@arkaria.postgresql.org; Sun, 16 Jul 2023 15:19:59 +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 1qL3XR-00Ffhj-Gg for pgsql-bugs@arkaria.postgresql.org; Sun, 16 Jul 2023 15:19:57 +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 1qL3XR-00Ffhb-87 for pgsql-bugs@lists.postgresql.org; Sun, 16 Jul 2023 15:19:57 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qL3XO-000k88-4E for pgsql-bugs@lists.postgresql.org; Sun, 16 Jul 2023 15:19:55 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3fbdfda88f4so32110455e9.1 for ; Sun, 16 Jul 2023 08:19:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1689520791; x=1692112791; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Bnoz9QaPPdx6/g3Amq9c9zo9sYwHtSnTijFjLm+SVm4=; b=KxXqdrPM4zsJzaz5ShSLomLEiJonVKl9g2fhb4UjD+ICjgr9Uc7iB/ZXFRjDV3GHHv 0vfEZyYqgzJ4gvXhqfV0nIOcGsXogDDF8NT74gNjWw9ObJynKBUVG0Uc6og7sFCXuxKb U71bhLVaCBdDdwAnJ6zxqa55O4hW5/4Z0MZjY/oaovfdh2SS7pIiaUF5WwKwgvQAQLHF k9ghe/NuE74eZkUf/F0NTiVLMYj3xqdS3YYyEF9zXhCKW2mgu2JxCBSdlI9EVSvSBpWp pO0O9lfS0qAFdR/rJYRETf0zCDjEskcb0o+ywCefU0KO7cFawXbEWESxQSuEgAj8tG/V Ln/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689520791; x=1692112791; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Bnoz9QaPPdx6/g3Amq9c9zo9sYwHtSnTijFjLm+SVm4=; b=HB6l0EGD2DcmtqlyMN+cfVFj6N81W8L3UwogTsThSBzZEJnDq0yIH70fKqltvJbd1s QMMjCiDg9vyONrCJjDvnAzs+HDBExF1MincuBhgj1QcBIJasNPB/JSf+yQa4osTOdKAz jOgwxPfM5sqI5yjp1LUlKcLzN5M/Y0vSaecz7qxh0TU+WFdoImGpTJO+5y+967y7PbMr 6PpshZoaJaLlzewFs8vjnvo/OstroRURmboUuboD6C1f+4wdJMLecvoiktt/ikWt0Nh3 tjuYPeRYZL7DnxtN0kJVRYIH4Dm9sdo9gHilbT9xtytI4LuJdLihA1JFvE7QkAQxvuCr QMBw== X-Gm-Message-State: ABy/qLY20G3Ls59as6QyveEtA2klg4efEONJsyYEv8FdSRXSuVQjc9Rt glj0nSjR8uHmBEXVKWt7AcpDIw== X-Google-Smtp-Source: APBJJlHB9TMMI0ffkVjMHyx9fIFntcS+REa3mgvdtGvgG9X8ZU+zKQJaGbndgB4XYftMxhQVp5ztIQ== X-Received: by 2002:a05:600c:3795:b0:3fa:93b0:a69c with SMTP id o21-20020a05600c379500b003fa93b0a69cmr7503585wmr.24.1689520791519; Sun, 16 Jul 2023 08:19:51 -0700 (PDT) Received: from [10.137.0.17] (ip-86-49-228-220.bb.vodafone.cz. [86.49.228.220]) by smtp.gmail.com with ESMTPSA id p26-20020a7bcc9a000000b003fbb5506e54sm5826429wma.29.2023.07.16.08.19.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 16 Jul 2023 08:19:50 -0700 (PDT) Message-ID: <8dd1ef3e-378c-83dc-229b-e3d3e251ac11@enterprisedb.com> Date: Sun, 16 Jul 2023 17:19:49 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: BUG #17552: pg_stat_statements tracks internal FK check queries when COPY used to load data Content-Language: en-US To: Sergei Kornilov , Julien Rouhaud Cc: maxim.boguk@gmail.com, pgsql-bugs@lists.postgresql.org References: <17552-213b534c56ab5d02@postgresql.org> <20220718101955.5erjttxbbjupm2xr@jrouhaud> <430591679487667@lma6oifqwmuo4pt7.myt.yp-c.yandex.net> From: Tomas Vondra In-Reply-To: <430591679487667@lma6oifqwmuo4pt7.myt.yp-c.yandex.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/22/23 13:21, Sergei Kornilov wrote: > Hello > > I have a similar problem with exactly the same reason. Queries are counted as top level, although they are not called at the top level. Another small example: > > set pg_stat_statements.track_utility to off; > set pg_stat_statements.track to 'top'; > do $$ declare i int; begin select 1 as n into i; end $$ language plpgsql; > select toplevel, query from pg_stat_statements order by query; > toplevel | query > ----------+----------------------------------- > t | select $1 as n > t | select pg_stat_statements_reset() > (2 rows) > > But "select $1 as n" was not a top-level query. > > In the first patch, a testcase showing the behavior now. The second patch adds a nesting level increment if track_utility is disabled. I need to duplicate the PGSS_HANDLED_UTILITY check here because it's documented above: > >> If it's an EXECUTE statement, we don't track it and don't increment the nesting level. > I took a look, and the patch seems correct to me. It'll need better comments explaining the change, but I'll take care of that. Barring objections, I'll get this committed and backpatched. FWIW it's probably a good idea to post patches on pgsql-hackers - not everyone watches pgsql-bugs and/or CF app. Furthermore, when a patch is switched to "RFC" it's customary to mention that in the thread, along with a review. Otherwise these silent changes are quite puzzling. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company