Profiler shows UniqueResult takes a lot of time

When running a program that converts data from an old, obscure database to PostgreSQL using Aurelius, I noticed the conversion took more time then I expected.
After ruling out the obvious reasons (indexes etc.) I used a profiler that showed me that the program did a lot of lookups on a particular table like this:


var
  nBedrijfImportID: Int64;
  bedrijven: Tbedrijven;
  OM: TObjectManager;

  bedrijven:=OM.Find<TBedrijven>.Add(TExpression.Eq('importid',nBedrijfImportID)).UniqueResult;


The field importid is indexed, so in my opinion this lookup should be very quick, but it took more than 10 ms on a local database.
Is this the best way to get fast results (with UniqueResult) or is it better to use conventional queries?

There isn't anything wrong with the above query. It doesn't make a difference if you use UniqueResult or List, the SQL executed is the same, the only difference is the way Aurelius interprets the result data.


One thing that might slow down is if TBedrijven class is too big, and maybe has many associations without the lazy-loading mechanism. If that's the case the SQL can be big and complex to retrieve all data, you could try to review your mapping, or use projections to retrieve just some properties in case you don't need to get the whole object and its associations.