1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.sql.compile.Optimizable; 25 26 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 27 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor; 28 29 import org.apache.derby.iapi.types.TypeId; 30 import org.apache.derby.iapi.types.DataTypeDescriptor; 31 32 import org.apache.derby.iapi.store.access.ScanController; 33 34 import org.apache.derby.iapi.error.StandardException; 35 36 import org.apache.derby.iapi.services.loader.GeneratedMethod; 37 38 import org.apache.derby.iapi.services.compiler.MethodBuilder; 39 40 import org.apache.derby.iapi.services.sanity.SanityManager; 41 42 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder; 43 44 import org.apache.derby.iapi.util.JBitSet; 45 46 import java.sql.Types ; 47 48 import java.util.Vector ; 49 50 56 57 public class UnaryComparisonOperatorNode extends UnaryOperatorNode 58 { 59 72 73 public ValueNode bindExpression( 74 FromList fromList, SubqueryList subqueryList, 75 Vector aggregateVector) 76 throws StandardException 77 { 78 super.bindExpression(fromList, subqueryList, 79 aggregateVector); 80 81 82 bindComparisonOperator(); 83 84 return this; 85 } 86 87 94 public void bindComparisonOperator() 95 throws StandardException 96 { 97 102 setType(new DataTypeDescriptor(TypeId.BOOLEAN_ID, false)); 103 } 104 105 121 ValueNode eliminateNots(boolean underNotNode) 122 throws StandardException 123 { 124 if (! underNotNode) 125 { 126 return this; 127 } 128 129 130 return getNegation(operand); 131 } 132 133 142 UnaryOperatorNode getNegation(ValueNode operand) 143 throws StandardException 144 { 145 148 if (SanityManager.DEBUG) 149 SanityManager.ASSERT(false, 150 "expected to call getNegation() for subclass " + 151 getClass().toString()); 152 return this; 153 } 154 155 156 157 158 public ColumnReference getColumnOperand( 159 Optimizable optTable, 160 int columnPosition) 161 { 162 FromBaseTable ft; 163 164 if (SanityManager.DEBUG) 165 { 166 SanityManager.ASSERT(optTable instanceof FromBaseTable); 167 } 168 169 ft = (FromBaseTable) optTable; 170 ColumnReference cr; 171 if (operand instanceof ColumnReference) 172 { 173 177 cr = (ColumnReference) operand; 178 if (cr.getTableNumber() == ft.getTableNumber()) 179 { 180 181 if (cr.getSource().getColumnPosition() == columnPosition) 182 { 183 184 return cr; 185 } 186 } 187 } 188 189 190 return null; 191 } 192 193 194 public ColumnReference getColumnOperand(Optimizable optTable) 195 { 196 ColumnReference cr; 197 198 if (operand instanceof ColumnReference) 199 { 200 204 cr = (ColumnReference) operand; 205 if (cr.getTableNumber() == optTable.getTableNumber()) 206 { 207 208 return cr; 209 } 210 } 211 212 213 return null; 214 } 215 216 217 public ValueNode getOperand(ColumnReference cRef, int refSetSize, 218 boolean otherSide) 219 { 220 if (otherSide) 221 return null; 223 224 ColumnReference cr; 225 if (operand instanceof ColumnReference) 226 { 227 231 JBitSet cRefTables = new JBitSet(refSetSize); 232 JBitSet crTables = new JBitSet(refSetSize); 233 BaseTableNumbersVisitor btnVis = 234 new BaseTableNumbersVisitor(crTables); 235 236 cr = (ColumnReference) operand; 237 try { 238 cr.accept(btnVis); 239 btnVis.setTableMap(cRefTables); 240 cRef.accept(btnVis); 241 } catch (StandardException se) { 242 if (SanityManager.DEBUG) 243 { 244 SanityManager.THROWASSERT("Failed when trying to " + 245 "find base table number for column reference check:\n" + 246 se.getMessage()); 247 } 248 } 249 crTables.and(cRefTables); 250 if (crTables.getFirstSetBit() != -1) 251 { 252 255 if (cr.getSource().getColumnPosition() == 256 cRef.getColumnNumber()) 257 { 258 259 return operand; 260 } 261 } 262 } 263 264 265 return null; 266 } 267 268 269 public boolean selfComparison(ColumnReference cr) 270 { 271 ValueNode otherSide; 272 JBitSet tablesReferenced; 273 274 if (SanityManager.DEBUG) 275 { 276 SanityManager.ASSERT(cr == operand, 277 "ColumnReference not found in IsNullNode."); 278 } 279 280 281 return false; 282 } 283 284 287 public ValueNode getExpressionOperand(int tableNumber, 288 int columnNumber, 289 FromTable ft) 290 { 291 return null; 292 } 293 294 299 public void generateExpressionOperand(Optimizable optTable, 300 int columnPosition, 301 ExpressionClassBuilder acb, 302 MethodBuilder mb) 303 throws StandardException 304 { 305 acb.generateNull(mb, operand.getTypeCompiler()); 306 } 307 308 309 public int getStartOperator(Optimizable optTable) 310 { 311 if (SanityManager.DEBUG) 312 { 313 SanityManager.THROWASSERT( 314 "getStartOperator not expected to be called for " + 315 this.getClass().getName()); 316 } 317 318 return ScanController.GE; 319 } 320 321 322 public int getStopOperator(Optimizable optTable) 323 { 324 if (SanityManager.DEBUG) 325 { 326 SanityManager.THROWASSERT( 327 "getStopOperator not expected to be called for " + 328 this.getClass().getName()); 329 } 330 331 return ScanController.GT; 332 } 333 334 335 public void generateOrderedNulls(MethodBuilder mb) 336 { 337 mb.push(true); 338 } 339 340 345 public void generateQualMethod(ExpressionClassBuilder acb, 346 MethodBuilder mb, 347 Optimizable optTable) 348 throws StandardException 349 { 350 MethodBuilder qualMethod = acb.newUserExprFun(); 351 352 353 acb.generateNull(qualMethod, operand.getTypeCompiler()); 354 qualMethod.methodReturn(); 355 qualMethod.complete(); 356 357 358 acb.pushMethodReference(mb, qualMethod); 359 } 360 361 362 public void generateAbsoluteColumnId(MethodBuilder mb, 363 Optimizable optTable) 364 { 365 int columnPosition = getAbsoluteColumnPosition(optTable); 367 368 mb.push(columnPosition); 369 } 370 371 372 public void generateRelativeColumnId(MethodBuilder mb, 373 Optimizable optTable) 374 { 375 int columnPosition = getAbsoluteColumnPosition(optTable); 377 columnPosition = optTable.convertAbsoluteToRelativeColumnPosition( 379 columnPosition); 380 381 mb.push(columnPosition); 382 } 383 384 392 private int getAbsoluteColumnPosition(Optimizable optTable) 393 { 394 ColumnReference cr = (ColumnReference) operand; 395 int columnPosition; 396 ConglomerateDescriptor bestCD; 397 398 399 columnPosition = cr.getSource().getColumnPosition(); 400 401 bestCD = 402 optTable.getTrulyTheBestAccessPath().getConglomerateDescriptor(); 403 404 408 if (bestCD.isIndex()) 409 { 410 columnPosition = bestCD.getIndexDescriptor(). 411 getKeyColumnPosition(new Integer (columnPosition)).intValue(); 412 413 if (SanityManager.DEBUG) 414 { 415 SanityManager.ASSERT(columnPosition > 0, 416 "Base column not found in index"); 417 } 418 } 419 420 return columnPosition - 1; 422 } 423 424 425 public boolean orderedNulls() 426 { 427 return true; 428 } 429 430 431 public boolean isQualifier(Optimizable optTable, boolean forPush) 432 { 433 437 if ( ! (operand instanceof ColumnReference)) 438 return false; 439 440 ColumnReference cr = (ColumnReference) operand; 441 FromTable ft = (FromTable) optTable; 442 443 if (cr.getTableNumber() != ft.getTableNumber()) 444 return false; 445 446 return true; 447 } 448 449 454 public int getOrderableVariantType(Optimizable optTable) 455 throws StandardException 456 { 457 return operand.getOrderableVariantType(); 458 } 459 } 460 | Popular Tags |