Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kt74a-0006fi-1C for pgsql-hackers@arkaria.postgresql.org; Sat, 26 Dec 2020 10:45:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kt74W-0008J4-LP for pgsql-hackers@arkaria.postgresql.org; Sat, 26 Dec 2020 10:45:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1kt74W-0008Iw-9l for pgsql-hackers@lists.postgresql.org; Sat, 26 Dec 2020 10:45:16 +0000 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1kt74T-0001Tg-4o for pgsql-hackers@postgresql.org; Sat, 26 Dec 2020 10:45:15 +0000 Received: by mail-ed1-x52d.google.com with SMTP id r5so5632646eda.12 for ; Sat, 26 Dec 2020 02:45:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=CYFj5oxC0+0YCbbpeRcmeg6sjh1PpfBBNTo46zX8Udo=; b=fDzk9sJF5l+AiJA/wREJIDfEzoFGfwcaw6ASW4RQ2pDJRZGZKj2YTaoPjGlUz7slwx yutp02cbcoYiaz/i6+d01NrXT5LKlq+oJAwSjtXLv/TXZXNNsXwWdHGow/fEfLu84Nnu kqGAeEyPwqkcLfeUI1lcH/iDSas2bP8h0RSVofBvmQLa2VjpaX4faNIC+fL2oewFyLXk WpbsoVqpQWB7YUuXLI2PldXEQpXZqE3vbwAJMMon/ucIWgTP9t4WOamvDe3RqdOOuEXD 4v4gqfZ+Mke1Z2ycKY5akECwtdkvtjzD+Se24tWGQy/f48VtfCHhoRRJBzw8IFnYDEVf OARQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=CYFj5oxC0+0YCbbpeRcmeg6sjh1PpfBBNTo46zX8Udo=; b=b7mqp9imXn3rGQ1hUwRxZ6ekT5gYTTJhPCNZ6bfUDTiEn41HwUCX5vh5l/AIv/wWRE pDsA0ZIE8ITWjmH8IuVANLGgS6YP/jJpg/zwO2M5b3CFbWlLIA0SzLQGlhpe9h1KuSGe rripIOuG2HewZb+C9m0f/R7DW+EFJMJ0SXGujgVfO7a8HaLB7rgjEzrI7pBl81e9MpOc xks3Gy9c1FR3tgpcyl9K0ssPqbraF/A8ExjwVsTyGqZ8w0Ib/hI9HRXvIHc1xX+5f1/y QZpD2gqDxGZnMW8rsnxZ2ngNRzeTZVPeDwXUDRi5arsGeAuEwbHZUSQRIK65qylWK2LW 6LSw== X-Gm-Message-State: AOAM533nXOD+LWZMLgyeIpMorryAZbIsKAuD3Kh7fB4sCei9JLdw7Q8+ KVyVidDgKsSOAi2B472JUeHvjlnnDhjvug== X-Google-Smtp-Source: ABdhPJyM3IC0C+ehCPo44Wkws0QkrXpR1I1CJPknuBj/sYAJUYmTnteuJNGJp3sftNbQtS6+fQFCWA== X-Received: by 2002:a05:6402:1684:: with SMTP id a4mr34895964edv.348.1608979509772; Sat, 26 Dec 2020 02:45:09 -0800 (PST) Received: from localhost (dslb-094-222-016-204.094.222.pools.vodafone-ip.de. [94.222.16.204]) by smtp.gmail.com with ESMTPSA id ng1sm14703062ejb.112.2020.12.26.02.45.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Dec 2020 02:45:08 -0800 (PST) Date: Sat, 26 Dec 2020 11:46:35 +0100 From: Dmitry Dolgov <9erthalion6@gmail.com> To: PostgreSQL-development , Tom Lane , Greg Stark , Pavel Trukhanov Subject: Re: pg_stat_statements and "IN" conditions Message-ID: <20201226104635.uvzkftzu72zg5qux@localhost> References: <20201118160432.hyko73sqc2bf7nkj@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="2rxgos7csfshja6i" Content-Disposition: inline In-Reply-To: <20201118160432.hyko73sqc2bf7nkj@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --2rxgos7csfshja6i Content-Type: text/plain; charset=us-ascii Content-Disposition: inline > On Wed, Nov 18, 2020 at 05:04:32PM +0100, Dmitry Dolgov wrote: > > On Wed, Aug 12, 2020 at 06:19:02PM +0200, Dmitry Dolgov wrote: > > > > I would like to start another thread to follow up on [1], mostly to bump up the > > topic. Just to remind, it's about how pg_stat_statements jumbling ArrayExpr in > > queries like: > > > > SELECT something FROM table WHERE col IN (1, 2, 3, ...) > > > > The current implementation produces different jumble hash for every different > > number of arguments for essentially the same query. Unfortunately a lot of ORMs > > like to generate these types of queries, which in turn leads to > > pg_stat_statements pollution. Ideally we want to prevent this and have only one > > record for such a query. > > > > As the result of [1] I've identified two highlighted approaches to improve this > > situation: > > > > * Reduce the generated ArrayExpr to an array Const immediately, in cases where > > all the inputs are Consts. > > > > * Make repeating Const to contribute nothing to the resulting hash. > > > > I've tried to prototype both approaches to find out pros/cons and be more > > specific. Attached patches could not be considered a completed piece of work, > > but they seem to work, mostly pass the tests and demonstrate the point. I would > > like to get some high level input about them and ideally make it clear what is > > the preferred solution to continue with. > > I've implemented the second approach mentioned above, this version was > tested on our test clusters for some time without visible issues. Will > create a CF item and would appreciate any feedback. After more testing I found couple of things that could be improved, namely in the presence of non-reducible constants one part of the query was not copied into the normalized version, and this approach also could be extended for Params. These are incorporated in the attached patch. --2rxgos7csfshja6i Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-Prevent-jumbling-of-every-element-in-ArrayExpr.patch"