Hi Marcel,
Unfortunately, the way you want it is not an option in Mendix 😥
I did do a reconstruction in Mx 7, 8 and 9 and this is indeed behavior you cannot control in any way.
So, as far as I can see, you have a few options left:
Good luck!
Johan
I think there is a access rule for the user active on the entity you tried to retrieve.
the in statement is more/less the restriction which is applied to the productlist (you are only allowed to see the products which are associated with this company)
and because this company might have many products, a lot of id's will be applied to IN part of the main query.
I don't see your historic xpath part within the sql statement.
Try to copy/paste the sql into pgadmin sql tab and click the explain button. there you can see which part of the query is the heaviest (highest cost).
The result shown on screen might also be validated with the access rules. this also might be a bottleneck.
Maybe you can make use of OQL, which bypasses security, and put the result into a helper entity on which you can apply sorting etc.
be sure that you add the company constraint within the OQL.
to get the actual product by ID, you can make use of RetrieveById from the saferOQL module.
Another approach would be to have a helper object on the page as a context object. Then manually create your search fields as input / dropdowns. Then on change you can trigger a microflow that retrieves that correct records and applies the correct sorting etc. Then you can associate the resulting list to you helper object and show only the associated objects in the list. A bit of a workaround tho, but if Mendix doesnt work out of the box you have to get creative.
Maybe it's also a good idea to share your example with the Mendix devs via a support ticket. Maybe they can suggest other solutions, or take this example to improve the platform.
Hi Marcel,
What are the settings you use for the datagrid? Retrieve by association or XPath?
Does Mendix generate the same SQL when you do a similar retrieve but in a retrieve action in a microflow, or is that performance perhaps better?
Hi Marcel,
Could you share your XPath? Did you already try changing the order of the XPath, with the most restrictive line on top?
Hi Marcel,
I haven't setup a test project (yet), but this seems quite the challenge!
You mention that the IN operator originates via the security, but I see a company id in the query. Is that because a UserAccount is associated to a single company?
In that case, you could try an enveloping Company dataview (loaded by MF/NF via your UserAccount) and retrieve using Database or XPath the associated Products? Maybe then the IN is replaced.