1 package com.daffodilwoods.daffodildb.server.sql99.dql.plan.table; 2 3 import com.daffodilwoods.daffodildb.server.sql99.common.*; 4 import com.daffodilwoods.daffodildb.server.sql99.dql.common.*; 5 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.*; 6 import com.daffodilwoods.database.resource.*; 7 import com.daffodilwoods.database.utility.P; 8 9 19 20 public abstract class JoinRelationAbstract implements TableExpressionConstants { 21 22 30 31 protected abstract void updateMapping(int[] mappingPositions, _TablePlan tablePlan) throws DException; 32 33 40 41 abstract protected void mergeJoinRelationInOrderSequencePlan(_TablePlan tablePlan1, _JoinRelation joinRelation) throws DException; 42 43 88 89 protected _TablePlan[] mergingOfJoinRelation(_TablePlan tablePlan1, _TablePlan tablePlan2, _JoinRelation joinRelation, TableDetails[] tableDetails, int[] mappingPositions, _TablePlan[] tablePlans) throws DException { 90 int type1 = tablePlan1.getType(); 91 int type2 = tablePlan2.getType(); 92 if (!tablePlan1.equals(tablePlan2)) { 93 switch (type1) { 94 case SINGLETABLEPLAN: 95 switch (type2) { 96 case SINGLETABLEPLAN: 97 TwoTableJoinPlan ttJp = new TwoTableJoinPlan(tablePlan1, tablePlan2, joinRelation.getCondition()); 98 updateMapping(mappingPositions, ttJp); 99 return updateTablePlans(ttJp, tablePlan1, tablePlan2, tablePlans); 100 case TWOTABLEJOINPLAN: 101 case TableExpressionConstants.NESTEDLOOPJOINPLAN: 102 ttJp = tablePlan2.containsOrderSequencePlan() ? 103 new TwoTableJoinPlan(tablePlan2, tablePlan1, joinRelation.getCondition()) : 104 new TwoTableJoinPlan(tablePlan1, tablePlan2, joinRelation.getCondition()); 105 updateMapping(mappingPositions, ttJp); 106 return updateTablePlans(ttJp, tablePlan1, tablePlan2, tablePlans); 107 108 case ORDERSEQUENCEPLAN: 109 TEMPORARARYMERGE: 110 ttJp = new TwoTableJoinPlan(tablePlan2, tablePlan1, joinRelation.getCondition()); 111 updateMapping(mappingPositions, ttJp); 112 return updateTablePlans(ttJp, tablePlan1, tablePlan2, tablePlans); 113 114 case QUALIFIEDLEFTPLAN: 115 case QUALIFIEDRIGHTPLAN: 116 case QUALIFIEDFULLPLAN: 117 case QUALIFIEDCROSSPLAN: 118 ( (_QualifiedPlan) tablePlan2).merge(tablePlan1, joinRelation, tableDetails[1]); 119 updateMapping(mappingPositions, tablePlan2); 120 return updateTablePlans(tablePlan2, tablePlan1, tablePlan2, tablePlans); 121 122 } 123 case TWOTABLEJOINPLAN: 124 switch (type2) { 125 case SINGLETABLEPLAN: 126 TwoTableJoinPlan ttJp = new TwoTableJoinPlan(tablePlan1, tablePlan2, joinRelation.getCondition()); 127 updateMapping(mappingPositions, ttJp); 128 return updateTablePlans(ttJp, tablePlan1, tablePlan2, tablePlans); 129 130 case ORDERSEQUENCEPLAN: 131 TEMPORARARYMERGE: 132 ttJp = new TwoTableJoinPlan(tablePlan2, tablePlan1, joinRelation.getCondition()); 133 updateMapping(mappingPositions, ttJp); 134 return updateTablePlans(ttJp, tablePlan2, tablePlan1, tablePlans); 135 136 case TWOTABLEJOINPLAN: 137 case TableExpressionConstants.NESTEDLOOPJOINPLAN: 138 ttJp = tablePlan2.containsOrderSequencePlan() ? 139 new TwoTableJoinPlan(tablePlan2, tablePlan1, joinRelation.getCondition()) : 140 new TwoTableJoinPlan(tablePlan1, tablePlan2, joinRelation.getCondition()); 141 updateMapping(mappingPositions, ttJp); 142 return updateTablePlans(ttJp, tablePlan1, tablePlan2, tablePlans); 143 144 case QUALIFIEDLEFTPLAN: 145 case QUALIFIEDRIGHTPLAN: 146 case QUALIFIEDFULLPLAN: 147 case QUALIFIEDCROSSPLAN: 148 ( (_QualifiedPlan) tablePlan2).merge(tablePlan1, joinRelation, tableDetails[1]); 149 updateMapping(mappingPositions, tablePlan2); 150 return updateTablePlans(tablePlan2, tablePlan2, tablePlan1, tablePlans); 151 152 } 153 break; 154 155 case QUALIFIEDLEFTPLAN: 156 case QUALIFIEDRIGHTPLAN: 157 case QUALIFIEDFULLPLAN: 158 case QUALIFIEDCROSSPLAN: 159 switch (type2) { 160 case SINGLETABLEPLAN: 161 case TWOTABLEJOINPLAN: 162 case TableExpressionConstants.NESTEDLOOPJOINPLAN: 163 ( (_QualifiedPlan) tablePlan1).merge(tablePlan2, joinRelation, tableDetails[0]); 164 updateMapping(mappingPositions, tablePlan1); 165 return updateTablePlans(tablePlan1, tablePlan1, tablePlan2, tablePlans); 166 167 case ORDERSEQUENCEPLAN: 168 case TEMPORARYMERGE: 169 TwoTableJoinPlan ttJp = new TwoTableJoinPlan(tablePlan2, tablePlan1, joinRelation.getCondition()); 170 updateMapping(mappingPositions, ttJp); 171 return updateTablePlans(ttJp, tablePlan1, tablePlan2, tablePlans); 172 173 case QUALIFIEDLEFTPLAN: 174 case QUALIFIEDRIGHTPLAN: 175 case QUALIFIEDFULLPLAN: 176 case QUALIFIEDCROSSPLAN: 177 ( (_QualifiedPlan) tablePlan2).merge(tablePlan1, joinRelation, tableDetails[1]); 178 updateMapping(mappingPositions, tablePlan2); 179 return updateTablePlans(tablePlan2, tablePlan1, tablePlan2, tablePlans); 180 181 } 182 break; 183 case ORDERSEQUENCEPLAN: 184 case TEMPORARYMERGE: 185 switch (type2) { 186 case QUALIFIEDLEFTPLAN: 187 case QUALIFIEDRIGHTPLAN: 188 case QUALIFIEDFULLPLAN: 189 case QUALIFIEDCROSSPLAN: 190 TwoTableJoinPlan ttJp = new TwoTableJoinPlan(tablePlan1, tablePlan2, joinRelation.getCondition()); 191 updateMapping(mappingPositions, ttJp); 192 return updateTablePlans(ttJp, tablePlan1, tablePlan2, tablePlans); 193 194 case SINGLETABLEPLAN: 195 case TWOTABLEJOINPLAN: 196 case TableExpressionConstants.NESTEDLOOPJOINPLAN: 197 ttJp = new TwoTableJoinPlan(tablePlan1, tablePlan2, joinRelation.getCondition()); 198 updateMapping(mappingPositions, ttJp); 199 return updateTablePlans(ttJp, tablePlan1, tablePlan2, tablePlans); 200 201 } 202 } 203 } else { 204 if (type1 == ORDERSEQUENCEPLAN || type1 == TEMPORARYMERGE) { 205 mergeJoinRelationInOrderSequencePlan(tablePlan1, joinRelation); 206 return tablePlans; 207 } else { 208 tablePlan1.merge(joinRelation); 209 return tablePlans; 210 } 211 } 212 throw new DException("DSE3537", new Object [] {joinRelation.toString()}); 213 } 214 215 223 protected _TablePlan[] updateTablePlans(_TablePlan tablePlan, _TablePlan tablePlan1, _TablePlan tablePlan2, _TablePlan[] tablePlans) throws DException { 224 int index1 = searchInTablePlans(tablePlan1, tablePlans); 225 int index2 = searchInTablePlans(tablePlan2, tablePlans); 226 if (index1 > index2) { 227 int temp = index1; 228 index1 = index2; 229 index2 = temp; 230 } 231 _TablePlan newTablePlans[] = new _TablePlan[tablePlans.length - 1]; 232 System.arraycopy(tablePlans, 0, newTablePlans, 0, index1); 233 newTablePlans[index1] = tablePlan; 234 System.arraycopy(tablePlans, index1 + 1, newTablePlans, index1 + 1, index2 - index1 - 1); 235 System.arraycopy(tablePlans, index2 + 1, newTablePlans, index2, tablePlans.length - index2 - 1); 236 return newTablePlans; 237 } 238 239 245 private int searchInTablePlans(_TablePlan tPlan, _TablePlan[] tablePlans) throws DException { 246 for (int i = 0; i < tablePlans.length; i++) { 247 if (tablePlans[i] == tPlan) { 248 return i; 249 } 250 } 251 return -1; 252 } 253 } 254 | Popular Tags |