maf123sp wrote:
Thanks for your answer.
- but I completely disagree.
(I'm using ORACLE)
In my case the DB optimizer is using a FULL TABLE scan in case without DISTINCT: As soon I have the DISTINCT clause the optimizer changes to use the existing index on PARAMREF and can switch to a FULL INDEX SCAN. Depending on the number of distinct entries this can be an extrem difference - in my case a diferent of costs 800/1 and in memory 5000:1.
hmmm... so without the distinct it doesn't use the index? that's pretty silly, but not something you can change, I guess.
This distinct clause is a very important tool for query optimization.
... for when the 'optimizer' is away on vacation, you mean?
But Ok, in situations like this, you probably have to.
The particular method you're using uses an optimization here where it finds the query doesn't need wrapping and simply passes on the individual fragments. This skips the Distinct.
What you can do is the following (this is allowed btw, so no licensing issues here):
copy the FieldCompareSetPredicate.cs class to your own project. Rename it to a different name, e.g. FieldCompareSetWithDistinctPredicte.cs.
Add a boolean property: UseDistinct.
In the ToQueryText method of the class, you'll see:
IRetrievalQuery subQuery = this.DatabaseSpecificCreator.CreateSubQuery(setFieldList, setFieldPersistenceInfo, _setFilter, _maxNumberOfItemsToReturn, _setSorter, _setRelations, _groupByClause);
Change it to:
IRetrievalQuery subQuery = this.DatabaseSpecificCreator.CreateSubQuery(setFieldList, setFieldPersistenceInfo, _setFilter, _maxNumberOfItemsToReturn, _setSorter, _setRelations, _groupByClause, this.UseDistinct);
In your query, use it like:
Factory.DataAccessAdapter.DeleteEntitiesDirectly(typeof (TabBEntity), new RelationPredicateBucket(
new FieldCompareSetWithDistinctPredicate(TabBFields.Ak, null, TabAFields.ParamRef, null, SetOperator.In, null) { UseDistinct = true, Negate=true}));
It's a little lowlevel, but it gets the job done. I'll add a workitem to v5.2 to honor Distinct in this situation, as it's currently a problem on Oracle.