orenpeled wrote:
In my database I have thousands of records, and according to your dialog I shouldn't consider using relation-using fetch....or am I wrong....
Is there any case in which I should prefer relation-using-fetch over FieldCompareSetPredicate/PrefetchPath?
Most databases use the same execution plans for subqueries as for joins, though in some situations it might be different. The thing with joins is that it can result in duplicate rows. For example, if you want to fetch all customers with orders lasts year, with a join it would result in something like this:
select customer.* from customer inner join orders .... where...
this leads to duplicate customer rows if a customer had more than 1 order last year.
This can be prevented by 'DISTINCT', but if the entity has a blob in the select list, DISTINCT can't be used. In that case, the code has to filter out duplicates on the client, i.e. outside the database. It then filters out duplicate rows in the fetch logic. With a lot of duplicates this is significant slower than when you would have used a subquery which doesn't produce duplicates.
When 1:n relations are used in a join, it can lead to a lot of duplicate rows, which in turn can lead to a lot of data being transported to the client (== llblgen pro runtime) unnecessarily. It therefore depends on the # of rows in the db what to do: use a subquery or a join. the subquery can be slower as well, as joins are easier to optimize and for example a subquery with a compound FK is slow, as you have to specify the subquery multiple times (once for each field in the FK)