db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Manish Khettry" <manish.khet...@gmail.com>
Subject Re: [jira] Commented: (DERBY-47) Some possible improvements to IN optimization
Date Mon, 12 Mar 2007 17:49:37 GMT
>
> > 4) The code which traverses predicate lists seems to always traverse
> them
> >    in backwards order, e.g. this code from HashJoinStrategy.java:
> >
> >             for (int i = storeRestrictionList.size() - 1; i >= 0; i--)
> >
> >    Why do we always traverse these backwards? Is this just an
> optimization
> >    in order to call the size() method only once? Or is there something
> >    deeper going on?
>
> This is just habit more than anything.  A lot of the optimizer-related
> work that I've been doing requires the removal of certain predicates from
> predicate lists at various points in the code, and in that case reverse
> traversal is better (because removal of elements from the rear does not
> require adjustments to the loop index).  So I often write loop iteration
> with backwards traversal out of sheer habit, even when removal of predicates
> is not happening.  If you think this makes the code more confusing or less
> intuitive I have no problems with switching to forward traversal.


A small suggestion on this backwards traversal-- if you use the Iterator
class, you can achieve the same thing in a much more readable way. The
change can be as simple as making the Vector in QueryTreeNodeVector a List
and adding an iterator method in QTNV class.

Mime
View raw message