Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fYB1o-0007yo-BK for pgsql-general@arkaria.postgresql.org; Wed, 27 Jun 2018 14:02:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fYB1m-0005wO-PP for pgsql-general@arkaria.postgresql.org; Wed, 27 Jun 2018 14:02:34 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fYB1m-0005ve-Ex for pgsql-general@lists.postgresql.org; Wed, 27 Jun 2018 14:02:34 +0000 Received: from server5.simfrete.com ([177.52.183.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fYB1d-0006ld-0d for pgsql-general@lists.postgresql.org; Wed, 27 Jun 2018 14:02:32 +0000 Received: from [192.168.10.30] (unknown [177.52.183.17]) by server5.simfrete.com (Postfix) with ESMTPSA id 7796E473BF for ; Wed, 27 Jun 2018 11:06:27 -0300 (-03) Subject: Re: We find few queries running three times simultaneously with same parameters on postgres db To: pgsql-general@lists.postgresql.org References: From: Edson Carlos Ericksson Richter Message-ID: Date: Wed, 27 Jun 2018 11:02:19 -0300 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Em 26/06/2018 14:26, amandeep singh escreveu: > Hi Andreas > > The value for $1 is same in all queries. > > @Edson: number of such running queries are always  3. I see. It seems a programming logic error to me. I also use JPA (Hibernate and/or EclipseLink) and I don't have such problem. But I could replicate your scenario doing the following (with EclipseLink, didn't test with Hibernate): 1) In persistence.xml, disable all caches (this is very important for make reproducible) 2) Load three Person records that live on same city (objects Person and City mapped to tables Person and City, being city an attribute of Person object): TypedQuery qry = em.createQuery("select P from Person P where P.city.name = :cityname"); qry.setParameter("cityname", "Porto Alegre"); qry.setMaxResults(3); List rs = qry.getResultList(); 3) This will cause one query against Person table, and exactly 3 queries issued with same parameters to City table. I really don't know how your code works, and is quite hard to guess, but as you can see, it is easy to reproduce similar behavior. Now, if I enable EclipseLink caches, only one query is issued for each City key - so, I'll have one query for Person and one query for  only. Hope this helps to enlighten your problem. :-) Regards, Edson