Re: We find few queries running three times simultaneously with same parameters on postgres db

From: Edson Carlos Ericksson Richter <richter(at)simkorp(dot)com(dot)br>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: We find few queries running three times simultaneously with same parameters on postgres db
Date: 2018-06-27 14:02:19
Message-ID: bb8d3da7-7544-e298-0701-46bb7e7aeb66@simkorp.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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<Person> qry = em.createQuery("select P from Person P where
P.city.name = :cityname");
qry.setParameter("cityname", "Porto Alegre");
qry.setMaxResults(3);
List<Person> 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2018-06-27 14:25:38 Re: Database name with semicolon
Previous Message Joby John 2018-06-27 13:22:33 Database name with semicolon