When retrieving a entity from the database does Mendix retrieve all associated entities and put them into memory?

4
Hi All, I am curious. When retrieving a entity from the database does Mendix retrieve all associated entities and put them into memory? If i retrieve the first entity from the DB can i retrieve the associated entity “By association” and will mendix have it in memory or will it be retrieved from the DB. We are optimizing our system to be as fast as possible and to cut down Database calls. Regards, Patrick    
asked
2 answers
3

Retrieving an entity from the database will only retrieve that entity, no associated records.  You can imagine that a simple retrieve of Customer could end up retrieving a ton of data if it also automatically pulled order, the items on those orders, the details of payment, the related inventory records, etc, etc.

Yes, after pulling from db if you then pull by association it will go back to the db, assuming some other step had not causes it to be retrieved. 

answered
2

Hi Patrick, 

If it helps:

https://www.auraq.com/retrieving-data-in-mendix

https://docs.mendix.com/refguide/retrieve

We must also remember, that there is a efficient caching layer developed in mendix to optmise the performance of application. 

I am also currently working with the same things for my product. 

Regards,

Nirmal

 

UPDATE: 24th June

Patrick, as said I am also currently working with some similar task. During this, I observed the following:

  1. I was looking at the database queries being executed when an object retrieval is made
  2. I saw queries executed for retrieving the association tables
  3. For example:
    • Entity A and Entity B is associated
    • We know there is an association (join) table A_B as well
    • When we retrieve Object A, then association table A_B is queried as well
    • You can also observe this behavior when debugging the microflows. It will show associations
  4. I think this is done for proxying the results mostly. So only id’s are loaded
  5. But objects from B is only retrieved with explicit retrieve

 

I was using the query to observe the queries: SELECT query FROM pg_stat_activity where datname = '<DB name>' and client_addr = '<host>';

I hope this helps further. Will keep you posted if I have additions to this.

answered