1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.services.context.ContextManager; 25 26 import org.apache.derby.iapi.error.StandardException; 27 import org.apache.derby.iapi.sql.compile.CompilerContext; 28 import org.apache.derby.iapi.sql.compile.CostEstimate; 29 import org.apache.derby.iapi.sql.compile.OptimizerFactory; 30 import org.apache.derby.iapi.sql.compile.Optimizer; 31 import org.apache.derby.iapi.sql.compile.OptimizableList; 32 import org.apache.derby.iapi.sql.compile.OptimizablePredicateList; 33 import org.apache.derby.iapi.sql.compile.Parser; 34 import org.apache.derby.iapi.sql.compile.Visitable; 35 import org.apache.derby.iapi.sql.compile.Visitor; 36 import org.apache.derby.iapi.sql.compile.RequiredRowOrdering; 37 import org.apache.derby.iapi.sql.compile.RowOrdering; 38 import org.apache.derby.iapi.sql.compile.C_NodeTypes; 39 40 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 41 42 import org.apache.derby.iapi.sql.dictionary.ColumnDescriptor; 43 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 44 import org.apache.derby.iapi.sql.dictionary.DefaultDescriptor; 45 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 46 47 import org.apache.derby.iapi.sql.execute.ExecutionContext; 48 49 import org.apache.derby.iapi.sql.Activation; 50 import org.apache.derby.iapi.types.DataTypeDescriptor; 51 import org.apache.derby.iapi.sql.ResultColumnDescriptor; 52 import org.apache.derby.iapi.sql.ResultDescription; 53 import org.apache.derby.iapi.sql.ResultSet; 54 55 import org.apache.derby.iapi.types.TypeId; 56 57 import org.apache.derby.iapi.store.access.TransactionController; 58 59 import org.apache.derby.iapi.services.loader.GeneratedMethod; 60 61 import org.apache.derby.iapi.services.sanity.SanityManager; 62 import org.apache.derby.iapi.reference.ClassName; 63 64 import org.apache.derby.iapi.services.compiler.MethodBuilder; 65 66 import org.apache.derby.impl.sql.compile.ActivationClassBuilder; 67 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder; 68 69 import org.apache.derby.iapi.util.JBitSet; 70 import org.apache.derby.iapi.services.classfile.VMOpcode; 71 72 import org.apache.derby.catalog.types.DefaultInfoImpl; 73 74 import java.util.Properties ; 75 import java.util.Vector ; 76 import java.util.Set ; 77 78 86 87 public abstract class ResultSetNode extends QueryTreeNode 88 { 89 int resultSetNumber; 90 91 JBitSet referencedTableMap; 92 ResultColumnList resultColumns; 93 boolean statementResultSet; 94 boolean cursorTargetTable; 95 boolean insertSource; 96 97 CostEstimate costEstimate; 98 CostEstimate scratchCostEstimate; 99 Optimizer optimizer; 100 101 CostEstimate finalCostEstimate; 105 106 112 113 public String toString() 114 { 115 if (SanityManager.DEBUG) 116 { 117 return "resultSetNumber: " + resultSetNumber + "\n" + 118 "referencedTableMap: " + 119 (referencedTableMap != null 120 ? referencedTableMap.toString() 121 : "null") + "\n" + 122 "statementResultSet: " + statementResultSet + "\n" + 123 super.toString(); 124 } 125 else 126 { 127 return ""; 128 } 129 } 130 131 137 138 public void printSubNodes(int depth) 139 { 140 if (SanityManager.DEBUG) 141 { 142 super.printSubNodes(depth); 143 144 if (resultColumns != null) 145 { 146 printLabel(depth, "resultColumns: "); 147 resultColumns.treePrint(depth); 148 } 149 } 150 } 151 152 158 159 public int getResultSetNumber() 160 { 161 return resultSetNumber; 162 } 163 164 169 public CostEstimate getCostEstimate() 170 { 171 if (SanityManager.DEBUG) 172 { 173 if (costEstimate == null) 174 { 175 SanityManager.THROWASSERT( 176 "costEstimate is not expected to be null for " + 177 getClass().getName()); 178 } 179 } 180 return costEstimate; 181 } 182 183 188 public CostEstimate getFinalCostEstimate() 189 throws StandardException 190 { 191 if (SanityManager.DEBUG) 192 { 193 if (finalCostEstimate == null) 194 { 195 SanityManager.THROWASSERT( 196 "finalCostEstimate is not expected to be null for " + 197 getClass().getName()); 198 } 199 } 200 return finalCostEstimate; 201 } 202 203 209 210 public void assignResultSetNumber() throws StandardException 211 { 212 resultSetNumber = getCompilerContext().getNextResultSetNumber(); 213 resultColumns.setResultSetNumber(resultSetNumber); 214 } 215 216 227 228 public ResultSetNode bindNonVTITables(DataDictionary dataDictionary, 229 FromList fromListParam) 230 throws StandardException { 231 return this; 232 } 233 234 235 245 246 public ResultSetNode bindVTITables(FromList fromListParam) 247 throws StandardException { 248 return this; 249 } 250 251 260 public void bindExpressions(FromList fromListParam) 261 throws StandardException 262 { 263 if (SanityManager.DEBUG) 264 SanityManager.ASSERT(false, 265 "bindExpressions() is not expected to be called for " + 266 this.getClass().toString()); 267 } 268 269 278 public void bindExpressionsWithTables(FromList fromListParam) 279 throws StandardException 280 { 281 if (SanityManager.DEBUG) 282 SanityManager.ASSERT(false, 283 "bindExpressionsWithTables() is not expected to be called for " + 284 this.getClass().toString()); 285 } 286 287 296 297 public void bindTargetExpressions(FromList fromListParam) 298 throws StandardException 299 { 300 if (SanityManager.DEBUG) 301 SanityManager.ASSERT(false, 302 "bindTargetExpressions() is not expected to be called for " + 303 this.getClass().toString()); 304 } 305 306 314 void setTableConstructorTypes(ResultColumnList typeColumns) 315 throws StandardException 316 { 317 if (SanityManager.DEBUG) 318 SanityManager.ASSERT(resultColumns.size() <= typeColumns.size(), 319 "More columns in ResultColumnList than in base table"); 320 321 322 int rclSize = resultColumns.size(); 323 for (int index = 0; index < rclSize; index++) 324 { 325 ResultColumn rc = (ResultColumn) resultColumns.elementAt(index); 326 327 ValueNode re = rc.getExpression(); 328 329 if (re.requiresTypeFromContext()) 330 { 331 ResultColumn typeCol = 332 (ResultColumn) typeColumns.elementAt(index); 333 334 338 re.setType(typeCol.getTypeServices()); 339 } 340 else if (re instanceof CharConstantNode) 341 { 342 378 ResultColumn typeCol = 379 (ResultColumn) typeColumns.elementAt(index); 380 381 TypeId colTypeId = typeCol.getTypeId(); 382 383 if (colTypeId.isStringTypeId()) { 384 385 if (colTypeId.getJDBCTypeId() != java.sql.Types.CHAR) { 386 387 int maxWidth = re.getTypeServices().getMaximumWidth(); 388 389 re.setType(new DataTypeDescriptor(colTypeId, true, maxWidth)); 390 } 391 } 392 else if (colTypeId.isBitTypeId()) { 393 if (colTypeId.getJDBCTypeId() == java.sql.Types.VARBINARY) { 394 TypeId tId = TypeId.getBuiltInTypeId(java.sql.Types.VARCHAR); 402 re.setType(new DataTypeDescriptor(tId, true)); 403 typeColumns.setElementAt(typeCol, index); 404 } 405 else if (colTypeId.getJDBCTypeId() == java.sql.Types.LONGVARBINARY) { 406 TypeId tId = TypeId.getBuiltInTypeId(java.sql.Types.LONGVARCHAR); 407 re.setType(new DataTypeDescriptor(tId, true)); 408 typeColumns.setElementAt(typeCol, index); 409 } 410 } 411 412 } 413 else if (re instanceof BitConstantNode) 414 { 415 ResultColumn typeCol = 416 (ResultColumn) typeColumns.elementAt(index); 417 418 TypeId colTypeId = typeCol.getTypeId(); 419 420 if (colTypeId.isBitTypeId()) { 421 422 if ((colTypeId.getJDBCTypeId() != java.sql.Types.BINARY) && 426 (colTypeId.getJDBCTypeId() != java.sql.Types.BLOB)) { 427 428 int maxWidth = re.getTypeServices().getMaximumWidth(); 429 430 re.setType(new DataTypeDescriptor(colTypeId, true, maxWidth)); 431 } 432 } 433 else if (colTypeId.isStringTypeId()) { 434 if (colTypeId.getJDBCTypeId() == java.sql.Types.VARCHAR) { 435 TypeId tId = TypeId.getBuiltInTypeId(java.sql.Types.VARBINARY); 443 re.setType(new DataTypeDescriptor(tId, true)); 444 typeColumns.setElementAt(typeCol, index); 445 } 446 else if (colTypeId.getJDBCTypeId() == java.sql.Types.LONGVARCHAR) { 447 TypeId tId = TypeId.getBuiltInTypeId(java.sql.Types.LONGVARBINARY); 448 re.setType(new DataTypeDescriptor(tId, true)); 449 typeColumns.setElementAt(typeCol, index); 450 } 451 } 452 } 453 } 454 } 455 456 459 public void setInsertSource() 460 { 461 insertSource = true; 462 } 463 464 472 public void verifySelectStarSubquery(FromList outerFromList, int subqueryType) 473 throws StandardException 474 { 475 if (SanityManager.DEBUG) 476 SanityManager.ASSERT(false, 477 "verifySelectStarSubquery() is not expected to be called for " + 478 this.getClass().toString()); 479 } 480 481 491 public ResultColumnList getAllResultColumns(TableName allTableName) 492 throws StandardException 493 { 494 if (SanityManager.DEBUG) 495 SanityManager.THROWASSERT( 496 "getAllResultColumns() not expected to be called for " + this.getClass().getName() + this); 497 return null; 498 } 499 500 513 514 public ResultColumn getMatchingColumn( 515 ColumnReference columnReference) 516 throws StandardException 517 { 518 if (SanityManager.DEBUG) 519 SanityManager.THROWASSERT( 520 "getMatchingColumn() not expected to be called for " + this); 521 return null; 522 } 523 524 539 public void setResultToBooleanTrueNode(boolean onlyConvertAlls) 540 throws StandardException 541 { 542 BooleanConstantNode booleanNode; 543 ResultColumn resultColumn; 544 545 548 if (resultColumns.elementAt(0) instanceof AllResultColumn) 549 { 550 resultColumn = (ResultColumn) getNodeFactory().getNode( 551 C_NodeTypes.RESULT_COLUMN, 552 "", 553 null, 554 getContextManager()); 555 } 556 else if (onlyConvertAlls) 557 { 558 return; 559 } 560 else 561 { 562 resultColumn = (ResultColumn) resultColumns.elementAt(0); 563 564 565 if (resultColumn.getExpression().isBooleanTrue()) 566 { 567 return; 568 } 569 } 570 571 booleanNode = (BooleanConstantNode) getNodeFactory().getNode( 572 C_NodeTypes.BOOLEAN_CONSTANT_NODE, 573 Boolean.TRUE, 574 getContextManager()); 575 576 resultColumn.setExpression(booleanNode); 577 resultColumn.setType(booleanNode.getTypeServices()); 578 579 resultColumn.setVirtualColumnId(1); 580 resultColumns.setElementAt(resultColumn, 0); 581 } 582 583 593 public FromList getFromList() 594 throws StandardException 595 { 596 return (FromList) getNodeFactory().getNode( 597 C_NodeTypes.FROM_LIST, 598 getNodeFactory().doJoinOrderOptimization(), 599 getContextManager()); 600 } 601 602 605 public void disablePrivilegeCollection() 606 { 607 super.disablePrivilegeCollection(); 608 if (resultColumns != null) 609 resultColumns.disablePrivilegeCollection(); 610 } 611 612 622 623 public void bindResultColumns(FromList fromListParam) 624 throws StandardException 625 { 626 resultColumns.bindResultColumnsToExpressions(); 627 } 628 629 655 656 public void bindResultColumns(TableDescriptor targetTableDescriptor, 657 FromVTI targetVTI, 658 ResultColumnList targetColumnList, 659 DMLStatementNode statement, 660 FromList fromListParam) 661 throws StandardException 662 { 663 666 if (this instanceof SelectNode) 667 { 668 resultColumns.expandAllsAndNameColumns(((SelectNode)this).fromList); 669 } 670 671 674 if (targetColumnList != null) 675 { 676 resultColumns.copyResultColumnNames(targetColumnList); 677 } 678 679 if (targetColumnList != null) 680 { 681 if (targetTableDescriptor != null) 682 { 683 resultColumns.bindResultColumnsByName( 684 targetTableDescriptor, (DMLStatementNode)statement); 685 } 686 else 687 { 688 resultColumns.bindResultColumnsByName( 689 targetVTI.getResultColumns(), targetVTI, statement); 690 } 691 } 692 else 693 resultColumns.bindResultColumnsByPosition(targetTableDescriptor); 694 } 695 696 706 public void bindUntypedNullsToResultColumns(ResultColumnList rcl) 707 throws StandardException 708 { 709 return; 710 } 711 712 730 731 public ResultSetNode preprocess(int numTables, 732 GroupByList gbl, 733 FromList fromList) 734 throws StandardException 735 { 736 if (SanityManager.DEBUG) 737 SanityManager.THROWASSERT( 738 "preprocess() not expected to be called for " + getClass().toString()); 739 return null; 740 } 741 742 745 void projectResultColumns() throws StandardException 746 { 747 } 749 750 758 public ResultSetNode ensurePredicateList(int numTables) 759 throws StandardException 760 { 761 if (SanityManager.DEBUG) 762 SanityManager.THROWASSERT( 763 "ensurePredicateList() not expected to be called for " + getClass().toString()); 764 return null; 765 } 766 767 778 public ResultSetNode addNewPredicate(Predicate predicate) 779 throws StandardException 780 { 781 if (SanityManager.DEBUG) 782 SanityManager.THROWASSERT( 783 "addNewPredicate() not expected to be called for " + getClass().toString()); 784 return null; 785 } 786 787 799 public boolean flattenableInFromSubquery(FromList fromList) 800 { 801 if (SanityManager.DEBUG) 802 SanityManager.THROWASSERT( 803 "flattenableInFromSubquery() not expected to be called for " + getClass().toString()); 804 return false; 805 } 806 807 818 ResultSetNode genProjectRestrictForReordering() 819 throws StandardException 820 { 821 ResultColumnList prRCList; 822 823 826 prRCList = resultColumns; 827 resultColumns = resultColumns.copyListAndObjects(); 828 829 835 prRCList.genVirtualColumnNodes(this, resultColumns, false); 836 837 838 return (ResultSetNode) getNodeFactory().getNode( 839 C_NodeTypes.PROJECT_RESTRICT_NODE, 840 this, 841 prRCList, 842 null, 843 null, 844 null, 845 null, 846 null, 847 getContextManager() ); 848 } 849 850 867 868 public ResultSetNode optimize(DataDictionary dataDictionary, 869 PredicateList predicates, 870 double outerRows) 871 throws StandardException 872 { 873 if (SanityManager.DEBUG) 874 SanityManager.ASSERT(false, 875 "optimize() is not expected to be called for " + 876 this.getClass().toString()); 877 return null; 878 } 879 880 889 public ResultSetNode modifyAccessPaths() throws StandardException 890 { 891 892 return this; 893 } 894 895 905 public ResultSetNode modifyAccessPaths(PredicateList predList) 906 throws StandardException 907 { 908 return modifyAccessPaths(); 910 } 911 912 ResultColumnDescriptor[] makeResultDescriptors(ExecutionContext ec) 913 { 914 return resultColumns.makeResultDescriptors(ec); 915 } 916 917 928 929 boolean columnTypesAndLengthsMatch() 930 throws StandardException 931 { 932 return resultColumns.columnTypesAndLengthsMatch(); 933 } 934 935 940 public void setResultColumns(ResultColumnList newRCL) 941 { 942 resultColumns = newRCL; 943 } 944 945 950 public ResultColumnList getResultColumns() 951 { 952 return resultColumns; 953 } 954 955 960 public void setReferencedTableMap(JBitSet newRTM) 961 { 962 referencedTableMap = newRTM; 963 } 964 965 970 public JBitSet getReferencedTableMap() 971 { 972 return referencedTableMap; 973 } 974 975 980 public void fillInReferencedTableMap(JBitSet passedMap) 981 { 982 } 983 984 991 992 public void rejectParameters() throws StandardException 993 { 994 995 if (resultColumns != null) 996 { 997 resultColumns.rejectParameters(); 998 } 999 } 1000 1001 1011 public void rejectXMLValues() throws StandardException 1012 { 1013 if (resultColumns != null) 1014 { 1015 resultColumns.rejectXMLValues(); 1016 } 1017 } 1018 1019 1023 public void renameGeneratedResultNames() throws StandardException 1024 { 1025 for (int i=0; i<resultColumns.size(); i++) 1026 { 1027 ResultColumn rc = (ResultColumn) resultColumns.elementAt(i); 1028 if (rc.isNameGenerated()) 1029 rc.setName(Integer.toString(i+1)); 1030 } 1031 } 1032 1033 1038 public void markStatementResultSet() 1039 { 1040 statementResultSet = true; 1041 } 1042 1043 1064 public ResultSetNode enhanceRCLForInsert(int numTargetColumns, int[] colMap, 1065 DataDictionary dataDictionary, 1066 TableDescriptor targetTD, 1067 FromVTI targetVTI) 1068 throws StandardException 1069 { 1070 ResultColumnList newResultCols = 1072 (ResultColumnList) getNodeFactory().getNode( 1073 C_NodeTypes.RESULT_COLUMN_LIST, 1074 getContextManager()); 1075 int numResultSetColumns = resultColumns.size(); 1076 1077 1081 for (int index = 0; index < numTargetColumns; index++) 1082 { 1083 ResultColumn newResultColumn = null; 1084 ColumnReference newColumnReference; 1085 1086 if (colMap[index] != -1) 1087 { 1088 newResultColumn = resultColumns.getResultColumn(colMap[index]+1); 1090 } 1091 else 1092 { 1093 newResultColumn = genNewRCForInsert(targetTD, targetVTI, index + 1, dataDictionary); 1094 } 1095 1096 newResultCols.addResultColumn(newResultColumn); 1097 } 1098 1099 1100 resultColumns = newResultCols; 1101 1102 return this; 1103 } 1104 1105 1117 ResultColumn genNewRCForInsert(TableDescriptor targetTD, 1118 FromVTI targetVTI, 1119 int columnNumber, 1120 DataDictionary dataDictionary) 1121 throws StandardException 1122 { 1123 ResultColumn newResultColumn = null; 1124 1125 1129 if( targetVTI != null) 1130 { 1131 newResultColumn = targetVTI.getResultColumns().getResultColumn( columnNumber); 1132 newResultColumn = newResultColumn.cloneMe(); 1133 newResultColumn.setExpressionToNullNode(); 1134 } 1135 else 1136 { 1137 ColumnDescriptor colDesc = targetTD.getColumnDescriptor(columnNumber); 1139 DataTypeDescriptor colType = colDesc.getType(); 1140 1141 DefaultInfoImpl defaultInfo = (DefaultInfoImpl) colDesc.getDefaultInfo(); 1143 1144 if (defaultInfo != null && ! colDesc.isAutoincrement()) 1147 { 1148 1155 { 1156 String defaultText = defaultInfo.getDefaultText(); 1158 ValueNode defaultTree = parseDefault(defaultText); 1159 defaultTree = defaultTree.bindExpression( 1160 getFromList(), 1161 (SubqueryList) null, 1162 (Vector ) null); 1163 newResultColumn = (ResultColumn) getNodeFactory().getNode( 1164 C_NodeTypes.RESULT_COLUMN, 1165 defaultTree.getTypeServices(), 1166 defaultTree, 1167 getContextManager()); 1168 1169 DefaultDescriptor defaultDescriptor = colDesc.getDefaultDescriptor(dataDictionary); 1170 if (SanityManager.DEBUG) 1171 { 1172 SanityManager.ASSERT(defaultDescriptor != null, 1173 "defaultDescriptor expected to be non-null"); 1174 } 1175 getCompilerContext().createDependency(defaultDescriptor); 1176 } 1177 } 1178 else if (colDesc.isAutoincrement()) 1179 { 1180 newResultColumn = 1181 (ResultColumn)getNodeFactory().getNode( 1182 C_NodeTypes.RESULT_COLUMN, 1183 colDesc, null, 1184 getContextManager()); 1185 newResultColumn.setAutoincrementGenerated(); 1186 } 1187 else 1188 { 1189 newResultColumn = (ResultColumn) getNodeFactory().getNode( 1190 C_NodeTypes.RESULT_COLUMN, 1191 colType, 1192 getNullNode( 1193 colType.getTypeId(), 1194 getContextManager() 1195 ), 1196 getContextManager() 1197 ); 1198 } 1199 } 1200 1201 newResultColumn.markGeneratedForUnmatchedColumnInInsert(); 1203 1204 return newResultColumn; 1205 } 1206 1207 1216 public ValueNode parseDefault 1217 ( 1218 String defaultText 1219 ) 1220 throws StandardException 1221 { 1222 Parser p; 1223 ValueNode defaultTree; 1224 LanguageConnectionContext lcc = getLanguageConnectionContext(); 1225 CompilerContext compilerContext = getCompilerContext(); 1226 1227 1228 1229 1232 String values = "VALUES " + defaultText; 1233 1234 1239 CompilerContext newCC = lcc.pushCompilerContext(); 1240 1241 p = newCC.getParser(); 1242 1243 1244 QueryTreeNode qt = p.parseStatement(values); 1247 if (SanityManager.DEBUG) 1248 { 1249 if (! (qt instanceof CursorNode)) 1250 { 1251 SanityManager.THROWASSERT( 1252 "qt expected to be instanceof CursorNode, not " + 1253 qt.getClass().getName()); 1254 } 1255 CursorNode cn = (CursorNode) qt; 1256 if (! (cn.getResultSetNode() instanceof RowResultSetNode)) 1257 { 1258 SanityManager.THROWASSERT( 1259 "cn.getResultSetNode() expected to be instanceof RowResultSetNode, not " + 1260 cn.getResultSetNode().getClass().getName()); 1261 } 1262 } 1263 1264 defaultTree = ((ResultColumn) 1265 ((CursorNode) qt).getResultSetNode().getResultColumns().elementAt(0)). 1266 getExpression(); 1267 1268 lcc.popCompilerContext(newCC); 1269 1270 return defaultTree; 1271 } 1272 1273 1280 1281 public ResultDescription makeResultDescription() 1282 { 1283 ExecutionContext ec = (ExecutionContext) getContextManager().getContext( 1284 ExecutionContext.CONTEXT_ID); 1285 ResultColumnDescriptor[] colDescs = makeResultDescriptors(ec); 1286 1287 return ec.getExecutionFactory().getResultDescription(colDescs, null ); 1288 } 1289 1290 1297 boolean isUpdatableCursor(DataDictionary dd) throws StandardException 1298 { 1299 if (SanityManager.DEBUG) 1300 SanityManager.DEBUG("DumpUpdateCheck","cursor is not a select result set"); 1301 return false; 1302 } 1303 1304 1308 FromTable getCursorTargetTable() 1309 { 1310 return null; 1311 } 1312 1313 1318 public boolean markAsCursorTargetTable() 1319 { 1320 return false; 1321 } 1322 1323 1327 void notCursorTargetTable() 1328 { 1329 cursorTargetTable = false; 1330 } 1331 1332 1353 1354 public ResultSetNode genProjectRestrict() 1355 throws StandardException 1356 { 1357 ResultColumnList prRCList; 1358 1359 1362 prRCList = resultColumns; 1363 resultColumns = resultColumns.copyListAndObjects(); 1364 1365 1369 prRCList.genVirtualColumnNodes(this, resultColumns); 1370 1371 1372 return (ResultSetNode) getNodeFactory().getNode( 1373 C_NodeTypes.PROJECT_RESTRICT_NODE, 1374 this, 1375 prRCList, 1376 null, 1377 null, 1378 null, 1379 null, 1380 null, 1381 getContextManager() ); 1382 } 1383 1384 1406 1407 protected ResultSetNode genProjectRestrict(int numTables) 1408 throws StandardException 1409 { 1410 return genProjectRestrict(); 1411 } 1412 1413 1440 1441 public NormalizeResultSetNode 1442 genNormalizeResultSetNode(ResultSetNode normalizeChild, 1443 boolean forUpdate) 1444 throws StandardException 1445 { 1446 NormalizeResultSetNode nrsn; 1447 ResultColumnList prRCList; 1448 1449 1452 prRCList = resultColumns; 1453 resultColumns = resultColumns.copyListAndObjects(); 1454 1455 1459 prRCList.genVirtualColumnNodes(this, resultColumns); 1460 1461 1462 nrsn = (NormalizeResultSetNode) getNodeFactory().getNode( 1463 C_NodeTypes.NORMALIZE_RESULT_SET_NODE, 1464 normalizeChild, 1465 prRCList, 1466 null, new Boolean (forUpdate), 1467 getContextManager()); 1468 if (normalizeChild.getReferencedTableMap() != null) 1470 { 1471 nrsn.setReferencedTableMap((JBitSet) normalizeChild.getReferencedTableMap().clone()); 1472 } 1473 return nrsn; 1474 } 1475 1476 1492 public void generateNormalizationResultSet( 1493 ActivationClassBuilder acb, 1494 MethodBuilder mb, 1495 int resultSetNumber, 1496 ResultDescription resultDescription) 1497 throws StandardException 1498 { 1499 int erdNumber = acb.addItem(resultDescription); 1500 1501 1503 mb.push(resultSetNumber); 1504 mb.push(erdNumber); 1505 mb.push(getCostEstimate().rowCount()); 1506 mb.push(getCostEstimate().getEstimatedCost()); 1507 mb.push(false); 1508 1509 mb.callMethod(VMOpcode.INVOKEINTERFACE, (String ) null, "getNormalizeResultSet", 1510 ClassName.NoPutResultSet, 6); 1511 } 1512 1513 1528 public ResultSetNode changeAccessPath() throws StandardException 1529 { 1530 return this; 1531 } 1532 1533 1543 public boolean referencesTarget(String name, boolean baseTable) 1544 throws StandardException 1545 { 1546 return false; 1547 } 1548 1549 1559 boolean subqueryReferencesTarget(String name, boolean baseTable) 1560 throws StandardException 1561 { 1562 return false; 1563 } 1564 1565 1574 public boolean isOneRowResultSet() throws StandardException 1575 { 1576 return false; 1578 } 1579 1580 1586 public boolean isNotExists() 1587 { 1588 return false; 1590 } 1591 1592 1598 protected Optimizer getOptimizer( 1599 OptimizableList optList, 1600 OptimizablePredicateList predList, 1601 DataDictionary dataDictionary, 1602 RequiredRowOrdering requiredRowOrdering) 1603 throws StandardException 1604 { 1605 if (optimizer == null) 1606 { 1607 1608 OptimizerFactory optimizerFactory = getLanguageConnectionContext().getOptimizerFactory(); 1609 1610 optimizer = optimizerFactory.getOptimizer( 1611 optList, 1612 predList, 1613 dataDictionary, 1614 requiredRowOrdering, 1615 getCompilerContext().getNumTables(), 1616 getLanguageConnectionContext()); 1617 } 1618 1619 optimizer.prepForNextRound(); 1620 return optimizer; 1621 } 1622 1623 1630 protected OptimizerImpl getOptimizerImpl() 1631 { 1632 return (OptimizerImpl)optimizer; 1639 } 1640 1641 1646 protected CostEstimate getNewCostEstimate() 1647 throws StandardException 1648 { 1649 OptimizerFactory optimizerFactory = getLanguageConnectionContext().getOptimizerFactory(); 1650 return optimizerFactory.getCostEstimate(); 1651 } 1652 1653 1661 public Visitable accept(Visitor v) 1662 throws StandardException 1663 { 1664 Visitable returnNode = v.visit(this); 1665 1666 if (v.skipChildren(this)) 1667 { 1668 return returnNode; 1669 } 1670 1671 if (resultColumns != null && !v.stopTraversal()) 1672 { 1673 resultColumns = (ResultColumnList)resultColumns.accept(v); 1674 } 1675 return returnNode; 1676 } 1677 1678 1686 public ResultSetNode considerMaterialization(JBitSet outerTables) 1687 throws StandardException 1688 { 1689 return this; 1690 } 1691 1692 1700 public boolean performMaterialization(JBitSet outerTables) 1701 throws StandardException 1702 { 1703 return false; 1704 } 1705 1706 1719 protected FromTable getFromTableByName(String name, String schemaName, boolean exactMatch) 1720 throws StandardException 1721 { 1722 if (SanityManager.DEBUG) 1723 { 1724 SanityManager.THROWASSERT("getFromTableByName() not expected to be called for " + 1725 getClass().getName()); 1726 } 1727 return null; 1728 } 1729 1730 1737 abstract void decrementLevel(int decrement); 1738 1739 1747 void pushOrderByList(OrderByList orderByList) 1748 { 1749 if (SanityManager.DEBUG) 1750 { 1751 SanityManager.THROWASSERT("pushOrderByList() not expected to be called for " + 1752 getClass().getName()); 1753 } 1754 } 1755 1756 1767 1768 public void generateResultSet(ExpressionClassBuilder acb, 1769 MethodBuilder mb) 1770 throws StandardException 1771 { 1772 System.out.println("I am a " + getClass()); 1773 if (SanityManager.DEBUG) 1774 SanityManager.NOTREACHED(); 1775 return; 1776 } 1777 1778 1779 1788 public int updateTargetLockMode() 1789 { 1790 return TransactionController.MODE_TABLE; 1791 } 1792 1793 1796 void notFlattenableJoin() 1797 { 1798 } 1799 1800 1815 boolean isOrderedOn(ColumnReference[] crs, boolean permuteOrdering, Vector fbtVector) 1816 throws StandardException 1817 { 1818 return false; 1819 } 1820 1821 1829 boolean returnsAtMostOneRow() 1830 { 1831 return false; 1832 } 1833 1834 1842 void replaceDefaults(TableDescriptor ttd, ResultColumnList tcl) 1843 throws StandardException 1844 { 1845 } 1847 1848 1855 boolean isPossibleDistinctScan(Set distinctColumns) 1856 { 1857 return false; 1858 } 1859 1860 1863 void markForDistinctScan() 1864 { 1865 if (SanityManager.DEBUG) 1866 { 1867 SanityManager.THROWASSERT( 1868 "markForDistinctScan() not expected to be called for " + 1869 getClass().getName()); 1870 } 1871 } 1872 1873 1878 void markOrderingDependent() 1879 { 1880 if (SanityManager.DEBUG) 1881 { 1882 SanityManager.THROWASSERT( 1883 "markOrderingDependent() not expected to be called for " + 1884 getClass().getName()); 1885 } 1886 } 1887 1888 1889 1896 protected static final int numDistinctAggregates(Vector aggregateVector) 1897 { 1898 int count = 0; 1899 int size = aggregateVector.size(); 1900 1901 for (int index = 0; index < size; index++) 1902 { 1903 count += (((AggregateNode) aggregateVector.elementAt(index)).isDistinct() == true) ? 1904 1 : 0; 1905 } 1906 1907 return count; 1908 } 1909 1910 public JBitSet LOJgetReferencedTables(int numTables) 1913 throws StandardException 1914 { 1915 if (this instanceof FromTable) 1916 { 1917 if (((FromTable)this).tableNumber != -1) 1918 { 1919 JBitSet map = new JBitSet(numTables); 1920 map.set(((FromTable)this).tableNumber); 1921 return map; 1922 } 1923 } 1924 1925 return null; 1926 } 1927 1928} 1929 | Popular Tags |