KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > compile > BaseJoinStrategy


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.BaseJoinStrategy
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.compile;
23
24 import org.apache.derby.iapi.services.loader.GeneratedMethod;
25
26 import org.apache.derby.iapi.services.compiler.MethodBuilder;
27
28 import org.apache.derby.iapi.sql.compile.ExpressionClassBuilderInterface;
29 import org.apache.derby.iapi.sql.compile.JoinStrategy;
30 import org.apache.derby.iapi.sql.compile.Optimizable;
31 import org.apache.derby.iapi.sql.compile.OptimizablePredicateList;
32
33 import org.apache.derby.iapi.sql.Activation;
34
35 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
36 import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor;
37 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
38 import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
39
40 import org.apache.derby.iapi.store.access.Qualifier;
41 import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo;
42 import org.apache.derby.iapi.store.access.TransactionController;
43
44 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;
45
46 import org.apache.derby.iapi.error.StandardException;
47
48 import org.apache.derby.iapi.services.sanity.SanityManager;
49 import org.apache.derby.iapi.reference.ClassName;
50
51 import org.apache.derby.iapi.util.PropertyUtil;
52
53 abstract class BaseJoinStrategy implements JoinStrategy {
54     BaseJoinStrategy() {
55     }
56
57     /** @see JoinStrategy#bulkFetchOK */
58     public boolean bulkFetchOK() {
59         return true;
60     }
61
62     /** @see JoinStrategy#ignoreBulkFetch */
63     public boolean ignoreBulkFetch() {
64         return false;
65     }
66
67     /**
68      * Push the first set of common arguments for obtaining a scan ResultSet from
69      * ResultSetFactory.
70      * The first 11 arguments are common for these ResultSet getters
71      * <UL>
72      * <LI> ResultSetFactory.getBulkTableScanResultSet
73      * <LI> ResultSetFactory.getHashScanResultSet
74      * <LI> ResultSetFactory.getTableScanResultSet
75      * <LI> ResultSetFactory.getRaDependentTableScanResultSet
76      * </UL>
77      * @param tc
78      * @param mb
79      * @param innerTable
80      * @param predList
81      * @param acbi
82      * @param resultRowAllocator
83      * @throws StandardException
84      */

85     void fillInScanArgs1(
86                                 TransactionController tc,
87                                 MethodBuilder mb,
88                                 Optimizable innerTable,
89                                 OptimizablePredicateList predList,
90                                 ExpressionClassBuilderInterface acbi,
91                                 MethodBuilder resultRowAllocator
92                                 )
93                     throws StandardException {
94         boolean sameStartStopPosition = predList.sameStartStopPosition();
95         ExpressionClassBuilder acb = (ExpressionClassBuilder) acbi;
96         long conglomNumber =
97                                 innerTable.getTrulyTheBestAccessPath().
98                                     getConglomerateDescriptor().
99                                         getConglomerateNumber();
100         StaticCompiledOpenConglomInfo scoci = tc.getStaticCompiledConglomInfo(conglomNumber);
101         
102         acb.pushThisAsActivation(mb);
103         mb.push(conglomNumber);
104         mb.push(acb.addItem(scoci));
105
106         acb.pushMethodReference(mb, resultRowAllocator);
107         mb.push(innerTable.getResultSetNumber());
108
109         predList.generateStartKey(acb, mb, innerTable);
110         mb.push(predList.startOperator(innerTable));
111
112         if (! sameStartStopPosition) {
113             predList.generateStopKey(acb, mb, innerTable);
114         } else {
115             mb.pushNull(ClassName.GeneratedMethod);
116         }
117
118         mb.push(predList.stopOperator(innerTable));
119         mb.push(sameStartStopPosition);
120
121         predList.generateQualifiers(acb, mb, innerTable, true);
122         mb.upCast(ClassName.Qualifier + "[][]");
123     }
124
125     final void fillInScanArgs2(MethodBuilder mb,
126                                 Optimizable innerTable,
127                                 int bulkFetch,
128                                 int colRefItem,
129                                 int indexColItem,
130                                 int lockMode,
131                                 boolean tableLocked,
132                                 int isolationLevel)
133         throws StandardException
134     {
135         mb.push(innerTable.getBaseTableName());
136         //User may have supplied optimizer overrides in the sql
137
//Pass them onto execute phase so it can be shown in
138
//run time statistics.
139
if (innerTable.getProperties() != null)
140             mb.push(PropertyUtil.sortProperties(innerTable.getProperties()));
141         else
142             mb.pushNull("java.lang.String");
143
144         ConglomerateDescriptor cd =
145             innerTable.getTrulyTheBestAccessPath().getConglomerateDescriptor();
146         if (cd.isConstraint())
147         {
148             DataDictionary dd = innerTable.getDataDictionary();
149             TableDescriptor td = innerTable.getTableDescriptor();
150             ConstraintDescriptor constraintDesc = dd.getConstraintDescriptor(
151                                                         td, cd.getUUID());
152             mb.push(constraintDesc.getConstraintName());
153         } else if (cd.isIndex()) {
154             mb.push(cd.getConglomerateName());
155         } else {
156             mb.pushNull("java.lang.String");
157         }
158
159         // Whether or not the conglomerate is the backing index for a constraint
160
mb.push(cd.isConstraint());
161
162         // tell it whether it's to open for update, which we should do if
163
// it's an update or delete statement, or if it's the target
164
// table of an updatable cursor.
165
mb.push(innerTable.forUpdate());
166
167         mb.push(colRefItem);
168
169         mb.push(indexColItem);
170
171         mb.push(lockMode);
172
173         mb.push(tableLocked);
174
175         mb.push(isolationLevel);
176
177         if (bulkFetch > 0) {
178             mb.push(bulkFetch);
179         }
180
181         /* 1 row scans (avoiding 2nd next()) are
182          * only meaningful for some join strategies.
183          * (Only an issue for outer table, which currently
184          * can only be nested loop, as avoidance of 2nd next
185          * on inner table already factored in to join node.)
186          */

187         if (validForOutermostTable())
188         {
189             mb.push(innerTable.isOneRowScan());
190         }
191
192         mb.push(
193                 innerTable.getTrulyTheBestAccessPath().
194                                                 getCostEstimate().rowCount());
195
196         mb.push(
197                         innerTable.getTrulyTheBestAccessPath().
198                                         getCostEstimate().getEstimatedCost());
199     }
200
201     /**
202      * @see JoinStrategy#isHashJoin
203      */

204     public boolean isHashJoin()
205     {
206         return false;
207     }
208
209     /**
210      * Can this join strategy be used on the
211      * outermost table of a join.
212      *
213      * @return Whether or not this join strategy
214      * can be used on the outermose table of a join.
215      */

216     protected boolean validForOutermostTable()
217     {
218         return false;
219     }
220 }
221
Popular Tags