01: /*
02: * $Id: IndexNestedLoopJoinedRowIterator.java,v 1.3 2005/04/02 18:23:30 ahimanikya Exp $
03: * =======================================================================
04: * Copyright (c) 2005 Axion Development Team. All rights reserved.
05: *
06: * Redistribution and use in source and binary forms, with or without
07: * modification, are permitted provided that the following conditions
08: * are met:
09: *
10: * 1. Redistributions of source code must retain the above
11: * copyright notice, this list of conditions and the following
12: * disclaimer.
13: *
14: * 2. Redistributions in binary form must reproduce the above copyright
15: * notice, this list of conditions and the following disclaimer in
16: * the documentation and/or other materials provided with the
17: * distribution.
18: *
19: * 3. The names "Tigris", "Axion", nor the names of its contributors may
20: * not be used to endorse or promote products derived from this
21: * software without specific prior written permission.
22: *
23: * 4. Products derived from this software may not be called "Axion", nor
24: * may "Tigris" or "Axion" appear in their names without specific prior
25: * written permission.
26: *
27: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
30: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38: * =======================================================================
39: */
40:
41: package org.axiondb.engine.rowiterators;
42:
43: import org.axiondb.AxionException;
44: import org.axiondb.RowIterator;
45:
46: /**
47: * The Index Nested Loop Join or Augmented Nested Loop Join (ANL) is by far the most
48: * common join method and is the classic Axion join method. An augmented nested loop join
49: * is performed by doing a scan over the left subtree and for each row in it, performing
50: * an index bracket scan on a portion of the right subtree. The right subtree is read as
51: * many times as there are rows in the left subtree. To be a candidate for an ANL join,
52: * the subtree pair for a join node must meet the following criteria:
53: * <p>
54: * <li>There must be an index(es) defined on the join column(s) for the table in the
55: * right subtree.
56: * <li>No other scan on that index has already been set.
57: * <p>
58: * When there is an index defined on the left subtree’s table instead of on the right, the
59: * optimizer swaps the subtrees to make an ANL join possible. When neither subtree’s table
60: * has an index defined on the join column, the optimizer creats a dynamic index on one of
61: * the subtree.
62: *
63: * @version $Revision: 1.3 $ $Date: 2005/04/02 18:23:30 $
64: * @author Rodney Waldhoff
65: * @author Ahimanikya Satapathy
66: */
67: public class IndexNestedLoopJoinedRowIterator extends
68: AbstractJoinedRowIterator {
69: public IndexNestedLoopJoinedRowIterator(RowIterator left,
70: int leftJoinColumn, MutableIndexedRowIterator rightIndex,
71: int rightColumnCount, boolean rightOuter,
72: boolean swapLeftAndRight) throws AxionException {
73: setLeftRowIterator(left);
74: _joinColumnInLeft = leftJoinColumn;
75: _rightIndexRowIterator = rightIndex;
76: setRightSideColumnCount(rightColumnCount);
77: setRightOuter(rightOuter);
78: setSwapLeftAndRight(swapLeftAndRight);
79: }
80:
81: protected RowIterator generateRightRowIterator()
82: throws AxionException {
83: _rightIndexRowIterator.setIndexKey(getLeftRowIterator()
84: .current().get(_joinColumnInLeft));
85: return _rightIndexRowIterator;
86: }
87:
88: public String toString() {
89: return "IndexNestedLoop(" + super .toString() + ")";
90: }
91:
92: private MutableIndexedRowIterator _rightIndexRowIterator = null;
93: private int _joinColumnInLeft;
94: }
|