[teiid-commits] teiid SVN: r3355 - in branches/7.4.x/engine/src: main/java/org/teiid/query/metadata and 6 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Mon Aug 1 12:08:42 EDT 2011


Author: shawkins
Date: 2011-08-01 12:08:41 -0400 (Mon, 01 Aug 2011)
New Revision: 3355

Added:
   branches/7.4.x/engine/src/main/java/org/teiid/query/tempdata/AlterTempTable.java
Modified:
   branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/ResultSetInfo.java
   branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java
   branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeCriteria.java
   branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanToProcessVisitor.java
   branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanner.java
   branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlannerEnvironment.java
   branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java
   branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQueryPlanner.java
   branches/7.4.x/engine/src/main/java/org/teiid/query/processor/xml/ExecSqlInstruction.java
   branches/7.4.x/engine/src/main/java/org/teiid/query/processor/xml/ExecStagingTableInstruction.java
   branches/7.4.x/engine/src/main/java/org/teiid/query/processor/xml/RelationalPlanExecutor.java
   branches/7.4.x/engine/src/main/java/org/teiid/query/processor/xml/XMLProcessorEnvironment.java
   branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/InsertResolver.java
   branches/7.4.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
   branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLPlanningEnhancements.java
   branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java
Log:
TEIID-1691 using dependent join planning to improve xml document model staging

Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/ResultSetInfo.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/ResultSetInfo.java	2011-07-30 18:54:08 UTC (rev 3354)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/mapping/xml/ResultSetInfo.java	2011-08-01 16:08:41 UTC (rev 3355)
@@ -23,11 +23,13 @@
 package org.teiid.query.mapping.xml;
 
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import org.teiid.query.processor.ProcessorPlan;
 import org.teiid.query.sql.lang.Command;
 import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.sql.lang.Insert;
 import org.teiid.query.sql.lang.OrderBy;
 import org.teiid.query.sql.symbol.ElementSymbol;
 
@@ -61,21 +63,21 @@
     
     private boolean criteriaRaised = false;
     
-    private boolean stagedResult = false;
-    
-    //joined source node state
-    private int mappingClassNumber = 0;
     private ElementSymbol mappingClassSymbol;
 	private boolean inputSet;
 	private boolean isCritNullDependent;
+
+	//auto-staging related info
+	private String stagingRoot;
+	private String tempTable;
+	private Command tempSelect;
+	private Insert tempInsert;
+	private Command tempDrop;
+	private boolean isAutoStaged;
+	private List<ElementSymbol> fkColumns;
     
     public ResultSetInfo(String resultName) {
-        this(resultName, false);
-    }
-    
-    public ResultSetInfo(String resultName, boolean staged) {
         this.resultSetName = resultName;
-        this.stagedResult = staged;
     }    
     
     public String getResultSetName() {
@@ -144,14 +146,19 @@
     }    
     
     public Object clone() {
-        ResultSetInfo clone = new ResultSetInfo(this.resultSetName, this.stagedResult);
+        ResultSetInfo clone = new ResultSetInfo(this.resultSetName);
         clone.rsPlan = this.rsPlan;
         clone.userRowLimit = this.userRowLimit;
         clone.exceptionOnRowLimit = this.exceptionOnRowLimit;
         clone.rsCommand = (Command)this.rsCommand.clone();
         clone.criteriaRaised = this.criteriaRaised;
-        clone.mappingClassNumber = this.mappingClassNumber;
         clone.mappingClassSymbol = this.mappingClassSymbol;
+        clone.tempInsert = this.tempInsert;
+        clone.tempSelect = this.tempSelect;
+        clone.tempTable = this.tempTable;
+        clone.tempDrop = this.tempDrop;
+        clone.isAutoStaged = this.isAutoStaged;
+        clone.fkColumns = this.fkColumns;
         return clone;
     }
     
@@ -159,14 +166,6 @@
         return resultSetName + ", resultSetObject " + rsCommand; //$NON-NLS-1$
     }
 
-    public int getMappingClassNumber() {
-        return this.mappingClassNumber;
-    }
-
-    public void setMappingClassNumber(int mappingClassNumber) {
-        this.mappingClassNumber = mappingClassNumber;
-    }
-
     public ElementSymbol getMappingClassSymbol() {
         return this.mappingClassSymbol;
     }
@@ -175,10 +174,6 @@
         this.mappingClassSymbol = mappingClassSymbol;
     }
 
-    public boolean isStagedResult() {
-        return this.stagedResult;
-    }
-    
 	public boolean hasInputSet() {
 		return inputSet;
 	}
@@ -194,4 +189,60 @@
 	public boolean isCritNullDependent(){
 		return this.isCritNullDependent;
 	}
+	
+	public String getStagingRoot() {
+		return stagingRoot;
+	}
+	
+	public void setStagingRoot(String stagingRoot) {
+		this.stagingRoot = stagingRoot;
+	}
+
+	public void setTempSelect(Command tempSelect) {
+		this.tempSelect = tempSelect;
+	}
+	
+	public Command getTempSelect() {
+		return tempSelect;
+	}
+	
+	public void setTempInsert(Insert tempInsert) {
+		this.tempInsert = tempInsert;
+	}
+	
+	public Insert getTempInsert() {
+		return tempInsert;
+	}
+	
+	public Command getTempDrop() {
+		return tempDrop;
+	}
+	
+	public void setTempDrop(Command tempDrop) {
+		this.tempDrop = tempDrop;
+	}
+
+	public String getTempTable() {
+		return tempTable;
+	}
+	
+	public void setTempTable(String rsTempTable) {
+		this.tempTable = rsTempTable;
+	}
+	
+	public boolean isAutoStaged() {
+		return isAutoStaged;
+	}
+	
+	public void setAutoStaged(boolean isAutoStaged) {
+		this.isAutoStaged = isAutoStaged;
+	}
+
+	public void setFkColumns(List<ElementSymbol> fkColumns) {
+		this.fkColumns = fkColumns;
+	}
+
+	public List<ElementSymbol> getFkColumns() {
+		return this.fkColumns;
+	}
 }

Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java	2011-07-30 18:54:08 UTC (rev 3354)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java	2011-08-01 16:08:41 UTC (rev 3355)
@@ -325,7 +325,7 @@
             return true;
         }
         
-        if(groupID instanceof TempMetadataID) {                         
+        if(groupID instanceof TempMetadataID && !(actualMetadata instanceof TempMetadataAdapter)) {                         
             return false;
         }   
                 
@@ -347,7 +347,7 @@
             }
         }
         
-        if(groupID instanceof TempMetadataID) {                         
+        if(groupID instanceof TempMetadataID && !(actualMetadata instanceof TempMetadataAdapter)) {                         
             return null;
         }   
 

Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeCriteria.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeCriteria.java	2011-07-30 18:54:08 UTC (rev 3354)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleMergeCriteria.java	2011-08-01 16:08:41 UTC (rev 3355)
@@ -420,6 +420,7 @@
 			result.not = exists.isNegated();
 			//the correlations can only be in where (if no group by or aggregates) or having
 			result.mergeJoin = exists.getSubqueryHint().isMergeJoin();
+			result.makeInd = exists.getSubqueryHint().isDepJoin();
 			if (!UNNEST && !result.mergeJoin) {
 				return result;
 			}

Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanToProcessVisitor.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanToProcessVisitor.java	2011-07-30 18:54:08 UTC (rev 3354)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanToProcessVisitor.java	2011-08-01 16:08:41 UTC (rev 3355)
@@ -22,6 +22,8 @@
 
 package org.teiid.query.optimizer.xml;
 
+import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Stack;
@@ -70,7 +72,7 @@
     Stack<Program> programStack = new Stack<Program>(); 
     XMLPlannerEnvironment planEnv;
     Program originalProgram ;
-    Program cleanupProgram  = new Program();
+    Map<String, List<String>> unloadInstructions = new HashMap<String, List<String>>();
 
     public XMLPlanToProcessVisitor(XMLPlannerEnvironment env) {
         this.planEnv = env;
@@ -85,8 +87,7 @@
         // remove the current program from the stack; we no longer need this
         originalProgram=this.programStack.pop();
         
-        // cleanup program will have instructions to unload the staging table.
-        originalProgram.addInstructions(cleanupProgram);
+        addUnloads(originalProgram, null);
     }
         
     public void start(MappingAttribute attribute, Map context){
@@ -289,7 +290,6 @@
         Program currentProgram = programStack.peek();        
         
         String source = node.getActualResultSetName();  
-        ResultSetInfo info= node.getResultSetInfo();
         
         // move to next row.
         currentProgram.addInstruction(new MoveCursorInstruction(source));
@@ -327,15 +327,22 @@
         }
         
         List<String> stagingTables = node.getStagingTables();
+        Program currentProgram = programStack.peek();
+
         for (String table : stagingTables) {
-            Program currentProgram = programStack.peek();
-
             // load staging
-            currentProgram.addInstruction(new ExecStagingTableInstruction(table, planEnv.getStagingTableResultsInfo(table)));
+            ResultSetInfo stagingTableResultsInfo = planEnv.getStagingTableResultsInfo(table);
+			currentProgram.addInstruction(new ExecStagingTableInstruction(table, stagingTableResultsInfo));
             
             // unload staging
             String unloadName = planEnv.unLoadResultName(table);
-            cleanupProgram.addInstruction(new ExecStagingTableInstruction(unloadName, planEnv.getStagingTableResultsInfo(unloadName)));
+            String parent = stagingTableResultsInfo.getStagingRoot();
+            List<String> instructions = this.unloadInstructions.get(parent);
+            if (instructions == null) {
+            	instructions = new LinkedList<String>();
+            	this.unloadInstructions.put(parent, instructions);
+            }
+            instructions.add(unloadName);
         } // for
     }
     
@@ -344,7 +351,22 @@
             // stop recording and update the program
             endRootRecursive(node, context);            
         }
+
+        Program currentProgram = programStack.peek();
+        if (node instanceof MappingSourceNode) {
+	        String name = node.getSource();
+	        addUnloads(currentProgram, name);
+        }
     }
+
+	private void addUnloads(Program currentProgram, String name) {
+		List<String> unloads = this.unloadInstructions.get(name);
+        if (unloads != null) {
+        	for (String string : unloads) {
+            	currentProgram.addInstruction(new ExecStagingTableInstruction(string, planEnv.getStagingTableResultsInfo(string)));
+			}
+        }
+	}
     
     public void start(final MappingRecursiveElement element, Map context){
         Program currentProgram = programStack.peek();

Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanner.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanner.java	2011-07-30 18:54:08 UTC (rev 3354)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlanner.java	2011-08-01 16:08:41 UTC (rev 3355)
@@ -226,8 +226,8 @@
 	}
     
     static void removeExcluded(MappingNode node) {
-        for (Iterator i = node.getChildren().iterator(); i.hasNext();) {
-            MappingNode child = (MappingNode)i.next();
+        for (Iterator<MappingNode> i = node.getChildren().iterator(); i.hasNext();) {
+            MappingNode child = i.next();
             if (!(node instanceof MappingRecursiveElement) && child.isExcluded()) {
                 i.remove();
             } else {
@@ -305,7 +305,7 @@
                 by = new OrderBy();
             }
             ElementSymbol mappedSymbol = (ElementSymbol)sourceNode.getSymbolMap().get(new ElementSymbol(elementNode.getNameInSource()));
-            by.addVariable(mappedSymbol.clone(), ((Boolean)types.get(i)).booleanValue());
+            by.addVariable(mappedSymbol.clone(), types.get(i));
             rs.setOrderBy(by);
 		}
 	}

Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlannerEnvironment.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlannerEnvironment.java	2011-07-30 18:54:08 UTC (rev 3354)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLPlannerEnvironment.java	2011-08-01 16:08:41 UTC (rev 3355)
@@ -124,7 +124,7 @@
     public ResultSetInfo getStagingTableResultsInfo(String groupName) {
         ResultSetInfo info = (ResultSetInfo)this.stagingResultsInfo.get(groupName.toUpperCase());
         if (info == null) {
-            info = new ResultSetInfo(groupName, true);            
+            info = new ResultSetInfo(groupName);            
             this.stagingResultsInfo.put(info.getResultSetName().toUpperCase(), info);
         }
         return info;

Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java	2011-07-30 18:54:08 UTC (rev 3354)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLQueryPlanner.java	2011-08-01 16:08:41 UTC (rev 3355)
@@ -55,7 +55,6 @@
 import org.teiid.query.processor.relational.RelationalPlan;
 import org.teiid.query.resolver.QueryResolver;
 import org.teiid.query.resolver.util.ResolverUtil;
-import org.teiid.query.rewriter.QueryRewriter;
 import org.teiid.query.sql.lang.Command;
 import org.teiid.query.sql.lang.Criteria;
 import org.teiid.query.sql.lang.Drop;
@@ -140,10 +139,10 @@
                     
                     prepareQuery(sourceNode, planEnv, command);
                     
-                    QueryUtil.rewriteQuery(command, planEnv.getGlobalMetadata(), planEnv.context);
+                    Command cmd = QueryUtil.rewriteQuery(command, planEnv.getGlobalMetadata(), planEnv.context);
                     
                     // Plan the result set.
-                    ProcessorPlan queryPlan = optimizePlan(command, planEnv);
+                    ProcessorPlan queryPlan = optimizePlan(cmd, planEnv);
                     rsInfo.setPlan(queryPlan);                    
                 } catch (Exception e) {
                     throw new TeiidRuntimeException(e);
@@ -441,7 +440,7 @@
 		return finder.msn;
 	}
 
-    private static void updateSymbolMap(Map symbolMap, String oldGroup, final String newGroup, QueryMetadataInterface metadata) 
+    static void updateSymbolMap(Map symbolMap, String oldGroup, final String newGroup, QueryMetadataInterface metadata) 
         throws QueryResolverException,QueryMetadataException,TeiidComponentException {
         
         GroupSymbol oldGroupSymbol = new GroupSymbol(oldGroup);
@@ -485,7 +484,7 @@
 
         GroupSymbol srcGroup = QueryUtil.createResolvedGroup(srcGroupName, planEnv.getGlobalMetadata());
         
-        String intoGroupName =  "#"+stageGroupName.replace('.', '_'); //$NON-NLS-1$
+        String intoGroupName = getTempTableName(stageGroupName);
         GroupSymbol intoGroupSymbol = new GroupSymbol(intoGroupName); 
                 
         query.setInto(new Into(intoGroupSymbol));
@@ -571,6 +570,11 @@
         
         return true;
     }
+
+	static String getTempTableName(String stageGroupName) {
+		String intoGroupName =  "#"+stageGroupName.replace('.', '_'); //$NON-NLS-1$
+		return intoGroupName;
+	}
         
     /**
      * This builds a command in the following form; If staging table name is "FOO"

Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQueryPlanner.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQueryPlanner.java	2011-07-30 18:54:08 UTC (rev 3354)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/xml/XMLStagaingQueryPlanner.java	2011-08-01 16:08:41 UTC (rev 3355)
@@ -22,23 +22,54 @@
 
 package org.teiid.query.optimizer.xml;
 
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
 
 import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.api.exception.query.QueryParserException;
 import org.teiid.api.exception.query.QueryPlannerException;
 import org.teiid.api.exception.query.QueryResolverException;
 import org.teiid.core.TeiidComponentException;
 import org.teiid.core.TeiidRuntimeException;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
 import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.mapping.xml.MappingBaseNode;
 import org.teiid.query.mapping.xml.MappingDocument;
+import org.teiid.query.mapping.xml.MappingNode;
 import org.teiid.query.mapping.xml.MappingSourceNode;
 import org.teiid.query.mapping.xml.MappingVisitor;
 import org.teiid.query.mapping.xml.Navigator;
 import org.teiid.query.mapping.xml.ResultSetInfo;
+import org.teiid.query.metadata.TempMetadataStore;
 import org.teiid.query.optimizer.relational.RelationalPlanner;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.resolver.util.ResolverUtil;
+import org.teiid.query.resolver.util.ResolverVisitor;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.sql.lang.ExistsCriteria;
+import org.teiid.query.sql.lang.From;
+import org.teiid.query.sql.lang.GroupBy;
+import org.teiid.query.sql.lang.Insert;
 import org.teiid.query.sql.lang.Option;
 import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.Select;
+import org.teiid.query.sql.lang.UnaryFromClause;
+import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.ExpressionSymbol;
 import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.Reference;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
+import org.teiid.query.sql.visitor.ExpressionMappingVisitor;
 import org.teiid.query.sql.visitor.GroupCollectorVisitor;
 
 
@@ -47,7 +78,6 @@
  */
 public class XMLStagaingQueryPlanner {
     
-    
     static void stageQueries(MappingDocument doc, final XMLPlannerEnvironment planEnv) 
         throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
 
@@ -86,7 +116,7 @@
     }    
     
     static boolean stagePlannedQuery(MappingSourceNode sourceNode, XMLPlannerEnvironment planEnv) 
-        throws QueryPlannerException, QueryMetadataException, TeiidComponentException, QueryResolverException {
+        throws QueryPlannerException, QueryMetadataException, TeiidComponentException, QueryResolverException, QueryParserException {
     
         Option option = planEnv.xmlCommand.getOption();
         
@@ -114,18 +144,6 @@
             return false;
         }
         
-        //id as mapping class
-        Object metadataID = planEnv.getGlobalMetadata().getGroupID(sourceNode.getResultName());
-        if (RelationalPlanner.isNoCacheGroup(planEnv.getGlobalMetadata(), metadataID, option)) {
-            return false;
-        }
-
-        //id as generated mapping class name
-        metadataID = planEnv.getGlobalMetadata().getGroupID(sourceNode.getActualResultSetName());
-        if (RelationalPlanner.isNoCacheGroup(planEnv.getGlobalMetadata(), metadataID, option)) {
-            return false;
-        }
-        
         // get the original transformation of the mapping class before planning. 
         Query stagableQuery = (Query)QueryUtil.getQueryFromQueryNode(groupName, planEnv);
         
@@ -140,17 +158,192 @@
             }
         }
         
+        Criteria crit = ((Query)rsInfo.getCommand()).getCriteria();
+
+        GroupSymbol parent = null;
+        LinkedHashSet<ElementSymbol> outerReferences = new LinkedHashSet<ElementSymbol>();
+        LinkedHashSet<ElementSymbol> fkColumns = new LinkedHashSet<ElementSymbol>();
+        //see if we can perform a dependent join
+        for (Criteria conjunct : Criteria.separateCriteriaByAnd(crit)) {
+        	if (!(conjunct instanceof CompareCriteria)) {
+        		continue;
+        	}
+        	CompareCriteria cc = (CompareCriteria)conjunct;
+        	if (cc.getOperator() != CompareCriteria.EQ) {
+        		continue;
+        	}
+        	if (!(cc.getLeftExpression() instanceof ElementSymbol) 
+        			|| !(cc.getRightExpression() instanceof ElementSymbol)) {
+        		continue;
+        	}
+    		ElementSymbol les = (ElementSymbol)cc.getLeftExpression();
+    		ElementSymbol res = (ElementSymbol)cc.getRightExpression();
+    		if (les.getGroupSymbol().getNonCorrelationName().equalsIgnoreCase(groupName)) {
+				parent = res.getGroupSymbol();
+				outerReferences.add(res.clone());
+				fkColumns.add(les.clone());
+    		} else if (res.getGroupSymbol().getNonCorrelationName().equalsIgnoreCase(groupName)) {
+				parent = les.getGroupSymbol();
+				outerReferences.add(les.clone());
+				fkColumns.add(res.clone());
+    		}
+        }
+        String stagingGroupName = planEnv.getStagedResultName(groupName);  
+
+        boolean recursive = false;
+        MappingSourceNode msn = sourceNode;
+        while (!recursive && msn != null) {
+        	MappingNode mappingNode = msn.getChildren().get(0);
+			if (mappingNode instanceof MappingBaseNode) {
+            	recursive = ((MappingBaseNode)mappingNode).isRootRecursiveNode();
+        	}
+        	msn = msn.getParentSourceNode();
+        }
+        
+        if (parent != null && !recursive) {
+            stagableQuery = (Query)stagableQuery.clone();
+            String parentName = parent.getNonCorrelationName();
+            
+            String parentStagingName = planEnv.getStagedResultName(parentName);
+            GroupSymbol parentTempTable = new GroupSymbol(XMLQueryPlanner.getTempTableName(parentStagingName));
+        	ResultSetInfo parentRsInfo = planEnv.getStagingTableResultsInfo(parentStagingName);
+        	String stagingRoot = sourceNode.getParentSourceNode().getSource();
+        	
+        	boolean parentStaged = parentRsInfo.getPlan() != null;
+        	//TODO: check to see if the parent was manually staged
+        	
+        	if (!parentStaged) {
+                //TODO: if not a level 1 child we could use the old auto staging logic instead
+        		
+        		//switch the parent over to the source
+        		parentRsInfo = sourceNode.getParentSourceNode().getResultSetInfo();
+        		
+        		if (parentRsInfo.getTempTable() == null) {
+	        		//create a temp table to represent the resultset
+	                List<SingleElementSymbol> projectedSymbols = parentRsInfo.getCommand().getProjectedSymbols();
+	                ArrayList<SingleElementSymbol> elements = new ArrayList<SingleElementSymbol>(projectedSymbols.size());
+	        		for (SingleElementSymbol singleElementSymbol : projectedSymbols) {
+	        			singleElementSymbol = (SingleElementSymbol) singleElementSymbol.clone();
+						ResolverVisitor.resolveLanguageObject(singleElementSymbol, planEnv.getGlobalMetadata());
+						elements.add(singleElementSymbol);
+					}
+	                TempMetadataStore store = planEnv.getGlobalMetadata().getMetadataStore();
+	                // create a new group name and to the temp store
+	                GroupSymbol newGroup = new GroupSymbol(SourceNodePlannerVisitor.getNewName("#" + planEnv.getAliasName(parentName) + "_RS", store)); //$NON-NLS-1$ //$NON-NLS-2$
+	                newGroup.setMetadataID(store.addTempGroup(newGroup.getName(), elements, false, true));
+	
+	                parentStagingName = newGroup.getName();
+	                parentTempTable = newGroup;
+        		} else {
+        			parentStagingName = parentRsInfo.getTempTable();
+        			parentTempTable = new GroupSymbol(parentRsInfo.getTempTable());
+	                parentStaged = true;
+        		}
+        	} else {
+        		stagingRoot = parentRsInfo.getStagingRoot();
+        	}
+
+            Query query = new Query();
+            query.setSelect(new Select(Arrays.asList(new ExpressionSymbol("expr", new Constant(1))))); //$NON-NLS-1$
+
+            query.setFrom(new From(Arrays.asList(new UnaryFromClause(parentTempTable))));
+            
+            Map symbolMap = new HashMap();
+            String inlineViewName = planEnv.getAliasName(rsInfo.getResultSetName());
+            XMLQueryPlanner.updateSymbolMap(symbolMap, rsInfo.getResultSetName(), inlineViewName, planEnv.getGlobalMetadata());
+            XMLQueryPlanner.updateSymbolMap(symbolMap, parentName, parentTempTable.getName(), planEnv.getGlobalMetadata());
+            
+            crit = (Criteria) crit.clone();
+            ExpressionMappingVisitor.mapExpressions(crit, symbolMap);
+            
+            if (!stagableQuery.getSelect().isDistinct()) {
+            	query.setHaving(crit);
+                //group by is added so that subquery planning sees that we are distinct
+                query.setGroupBy(new GroupBy(new ArrayList<ElementSymbol>(outerReferences)));
+                ExpressionMappingVisitor.mapExpressions(query.getGroupBy(), symbolMap);
+            } else {
+            	query.setCriteria(crit);
+            }
+            ExistsCriteria ec = new ExistsCriteria();
+            ec.setSubqueryHint(new ExistsCriteria.SubqueryHint());
+            ec.getSubqueryHint().setDepJoin(true);
+            ec.setCommand(query);
+            Criteria existing = stagableQuery.getCriteria();
+            stagableQuery.setCriteria(Criteria.combineCriteria(existing, ec));
+            if (!XMLQueryPlanner.planStagaingQuery(false, groupName, stagingGroupName, stagableQuery, planEnv)) {
+            	return false;
+            }
+            if (!parentStaged) {
+            	//need to associate temp load/get/drop with the rsinfo for use by the execsqlinstruction
+            	Insert insert = new Insert();
+            	insert.setGroup(parentTempTable);
+            	int valCount = parentRsInfo.getCommand().getProjectedSymbols().size();
+            	ArrayList<Reference> vals = new ArrayList<Reference>(valCount);
+            	for (int i = 0; i < valCount; i++) {
+            		vals.add(new Reference(i+1));
+            	}
+            	insert.setValues(vals);
+	        	QueryResolver.resolveCommand(insert, planEnv.getGlobalMetadata());
+	        	
+	        	Command tempCommand = QueryParser.getQueryParser().parseCommand("select * from " + parentStagingName); //$NON-NLS-1$
+	        	QueryResolver.resolveCommand(tempCommand, planEnv.getGlobalMetadata());
+	        	
+            	Command dropCommand = QueryParser.getQueryParser().parseCommand("drop table " + parentStagingName); //$NON-NLS-1$
+	        	QueryResolver.resolveCommand(dropCommand, planEnv.getGlobalMetadata());
+
+	            parentRsInfo.setTempTable(parentStagingName);
+	            parentRsInfo.setTempSelect(tempCommand);
+	            parentRsInfo.setTempInsert(insert);
+	            parentRsInfo.setTempDrop(dropCommand);
+            }
+            LogManager.logDetail(LogConstants.CTX_XML_PLANNER, "Using a dependent join to load the mapping class", groupName); //$NON-NLS-1$
+            // add to the document that a staging table has been added
+            sourceNode.addStagingTable(stagingGroupName);
+            GroupSymbol tempGroup = new GroupSymbol(XMLQueryPlanner.getTempTableName(stagingGroupName));
+        	ResolverUtil.resolveGroup(tempGroup, planEnv.getGlobalMetadata());
+        	Collection<GroupSymbol> temp = Arrays.asList(tempGroup);
+        	List<ElementSymbol> fk = new ArrayList<ElementSymbol>(fkColumns.size());
+        	for (ElementSymbol elementSymbol : fkColumns) {
+        		ElementSymbol es = new ElementSymbol(elementSymbol.getShortName());
+        		ResolverVisitor.resolveLanguageObject(es, temp, planEnv.getGlobalMetadata());
+        		fk.add(es);
+			}
+            ResultSetInfo stagedInfo = planEnv.getStagingTableResultsInfo(stagingGroupName);
+        	stagedInfo.setStagingRoot(stagingRoot);
+        	stagedInfo.setAutoStaged(true);
+        	stagedInfo.setFkColumns(fk);
+        	stagedInfo.setTempTable(tempGroup.getName());
+        	
+        	rsInfo.setAutoStaged(true);
+            return true;
+        }
+
+        //id as mapping class
+        Object metadataID = planEnv.getGlobalMetadata().getGroupID(sourceNode.getResultName());
+        if (RelationalPlanner.isNoCacheGroup(planEnv.getGlobalMetadata(), metadataID, option)) {
+            return false;
+        }
+
+        //id as generated mapping class name
+        metadataID = planEnv.getGlobalMetadata().getGroupID(sourceNode.getActualResultSetName());
+        if (RelationalPlanner.isNoCacheGroup(planEnv.getGlobalMetadata(), metadataID, option)) {
+            return false;
+        }
+
         stagableQuery = (Query)stagableQuery.clone();
-                
+
         // stage the transformation query and it is successful
-        String stagingGroupName = planEnv.getStagedResultName(groupName);         
         if (!XMLQueryPlanner.planStagaingQuery(true, groupName, stagingGroupName, stagableQuery, planEnv)) {
             return false;
         }
         
         // add to the document that a staging table has been added
         sourceNode.addStagingTable(stagingGroupName);
-        
+        ResultSetInfo stagedInfo = planEnv.getStagingTableResultsInfo(stagingGroupName);
+    	stagedInfo.setAutoStaged(true);
+    	stagedInfo.setTempTable(XMLQueryPlanner.getTempTableName(stagingGroupName));
+    	
+    	rsInfo.setAutoStaged(true);
         return true;
     }
 

Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/processor/xml/ExecSqlInstruction.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/processor/xml/ExecSqlInstruction.java	2011-07-30 18:54:08 UTC (rev 3354)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/processor/xml/ExecSqlInstruction.java	2011-08-01 16:08:41 UTC (rev 3355)
@@ -36,7 +36,7 @@
  * Executes a SQL statement, defines a result set.
  */
 public class ExecSqlInstruction extends ProcessorInstruction {
-    private String resultSetName;
+    String resultSetName;
     ResultSetInfo info;
     
     public ExecSqlInstruction(String resultSetName, ResultSetInfo info) {
@@ -48,7 +48,16 @@
     public XMLContext process(XMLProcessorEnvironment env, XMLContext context)
         throws BlockedException, TeiidComponentException, TeiidProcessingException{
 
-        LogManager.logTrace(org.teiid.logging.LogConstants.CTX_XML_PLAN, new Object[]{"SQL: Result set DOESN'T exist:",resultSetName}); //$NON-NLS-1$
+        execute(env, context);
+        
+        env.incrementCurrentProgramCounter();
+        return context;
+    }
+
+	protected void execute(XMLProcessorEnvironment env, XMLContext context)
+			throws TeiidComponentException, BlockedException,
+			TeiidProcessingException {
+		LogManager.logTrace(org.teiid.logging.LogConstants.CTX_XML_PLAN, new Object[]{"SQL: Result set DOESN'T exist:",resultSetName}); //$NON-NLS-1$
         PlanExecutor executor = getPlanExecutor(env, context);
         
         // this execute can throw the blocked exception
@@ -60,10 +69,7 @@
         // save this executioner in the context, so that all the nodes
         // below can access the data.
         context.setResultSet(this.resultSetName, executor);
-        
-        env.incrementCurrentProgramCounter();
-        return context;
-    }
+	}
 
 	public PlanExecutor getPlanExecutor(XMLProcessorEnvironment env,
 			XMLContext context) throws TeiidComponentException {

Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/processor/xml/ExecStagingTableInstruction.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/processor/xml/ExecStagingTableInstruction.java	2011-07-30 18:54:08 UTC (rev 3354)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/processor/xml/ExecStagingTableInstruction.java	2011-08-01 16:08:41 UTC (rev 3355)
@@ -24,13 +24,10 @@
 
 import static org.teiid.query.analysis.AnalysisRecord.*;
 
-import java.util.Map;
-
 import org.teiid.client.plan.PlanNode;
 import org.teiid.common.buffer.BlockedException;
 import org.teiid.core.TeiidComponentException;
 import org.teiid.core.TeiidProcessingException;
-import org.teiid.logging.LogManager;
 import org.teiid.query.mapping.xml.ResultSetInfo;
 
 
@@ -38,20 +35,14 @@
 /** 
  * This instruction is to start loading a staging table. The difference between the loading the 
  * staging table and execute sql node is that sql node will capture the results and save them in
- * the context object, where as staging does not care about the results, beacuse they are actully
+ * the context object, where as staging does not care about the results, because they are actually
  * stored in the temp table store, will be accessed by required query directly from there, as these
  * results are nothing do with producing the document directly.
- * 
- * NOTE: In future we can improve this to load parallelly, if there are more than single 
- * staging table defined on the mapping document
  */
-public class ExecStagingTableInstruction extends ProcessorInstruction {
-    String resultSetName;
-    ResultSetInfo info;
+public class ExecStagingTableInstruction extends ExecSqlInstruction {
     
     public ExecStagingTableInstruction(String resultName, ResultSetInfo info) {
-        this.resultSetName = resultName;
-        this.info = info;
+    	super(resultName, info);
     }
     
     /** 
@@ -61,19 +52,8 @@
         throws BlockedException, TeiidComponentException, TeiidProcessingException {
         
         if (!env.isStagingTableLoaded(this.resultSetName)) {
-            LogManager.logTrace(org.teiid.logging.LogConstants.CTX_XML_PLAN, new Object[]{"SQL: Result set DOESN'T exist:",resultSetName}); //$NON-NLS-1$
+        	super.execute(env, context);
             
-            PlanExecutor executor = context.getResultExecutor(resultSetName);
-            if (executor == null) {
-                executor = env.createResultExecutor(resultSetName, info);
-                context.setResultExecutor(resultSetName, executor);
-            }
-            
-            // this execute can throw the blocked exception; note that staging tables will not have any
-            // bound references; they are not part of the document; so they do not know about document
-            // details.
-            Map referenceValues = null;
-            executor.execute(referenceValues, false);
             env.markStagingTableAsLoaded(this.resultSetName);
             
             // now that we done executing the plan; remove the plan from context

Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/processor/xml/RelationalPlanExecutor.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/processor/xml/RelationalPlanExecutor.java	2011-07-30 18:54:08 UTC (rev 3354)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/processor/xml/RelationalPlanExecutor.java	2011-08-01 16:08:41 UTC (rev 3355)
@@ -27,32 +27,53 @@
 
 import org.teiid.common.buffer.BlockedException;
 import org.teiid.common.buffer.BufferManager;
-import org.teiid.common.buffer.IndexedTupleSource;
+import org.teiid.common.buffer.TupleSource;
 import org.teiid.core.TeiidComponentException;
 import org.teiid.core.TeiidProcessingException;
+import org.teiid.logging.LogConstants;
 import org.teiid.logging.LogManager;
 import org.teiid.query.QueryPlugin;
 import org.teiid.query.mapping.xml.ResultSetInfo;
+import org.teiid.query.metadata.TempMetadataAdapter;
 import org.teiid.query.processor.BatchIterator;
 import org.teiid.query.processor.ProcessorDataManager;
 import org.teiid.query.processor.ProcessorPlan;
 import org.teiid.query.processor.QueryProcessor;
+import org.teiid.query.sql.lang.Insert;
 import org.teiid.query.sql.symbol.ElementSymbol;
 import org.teiid.query.sql.util.VariableContext;
+import org.teiid.query.tempdata.AlterTempTable;
 import org.teiid.query.util.CommandContext;
 
-
-
 /** 
  * This is a helper class which can execute a supplied relational plan and supply
  * resulting query results to the caller.
- * Note: in future we would want to replace this class with submitting the requests directly to
- * process worker queue.
  */
 class RelationalPlanExecutor implements PlanExecutor {
     
-    QueryProcessor internalProcessor;
+    private final class TempLoadTupleSource implements TupleSource {
+		@Override
+		public List<?> nextTuple() throws TeiidComponentException,
+				TeiidProcessingException {
+			try {
+				List<?> tuple = tupleSource.nextTuple();
+				if (tuple == null) {
+					doneLoading = true;
+				}
+				return tuple;
+			} catch (BlockedException e) {
+				return null;
+			}
+		}
 
+		@Override
+		public void closeSource() {
+			tupleSource.closeSource();
+		}
+	}
+
+	QueryProcessor internalProcessor;
+
     // information about the result set.
     ResultSetInfo resultInfo;
     // buffer store
@@ -60,16 +81,20 @@
     // flag to denote the end of rows
     boolean endOfRows = false;
     // results after the execution bucket.
-    IndexedTupleSource tupleSource;
+    TupleSource tupleSource;
     // cached current row of results.
-    List currentRow;
+    List<?> currentRow;
     int currentRowNumber = 0;
+    private ProcessorDataManager dataManager;
+    private boolean executed;
+    private boolean doneLoading;
     
     public RelationalPlanExecutor (ResultSetInfo resultInfo, CommandContext context, ProcessorDataManager dataMgr, BufferManager bufferMgr) 
         throws TeiidComponentException{
         
         this.resultInfo = resultInfo;
         this.bufferMgr = bufferMgr;
+        this.dataManager = dataMgr;
         
         ProcessorPlan plan = resultInfo.getPlan();
         CommandContext subContext = context.clone();
@@ -97,9 +122,38 @@
             	internalProcessor.init();
             }
         }
-        if (!openOnly) {
-	        //force execution
-	        this.tupleSource.hasNext();
+        if (!openOnly && !executed) {
+	        String tempTable = this.resultInfo.getTempTable();
+			if (tempTable != null && !doneLoading && !this.resultInfo.isAutoStaged()) {
+	        	LogManager.logDetail(LogConstants.CTX_XML_PLAN, "Loading result set temp table", tempTable); //$NON-NLS-1$
+
+	        	Insert insert = this.resultInfo.getTempInsert();
+	        	insert.setTupleSource(new TempLoadTupleSource());
+	        	this.dataManager.registerRequest(this.internalProcessor.getContext(), insert, TempMetadataAdapter.TEMP_MODEL.getName(), null, 0, -1);
+	        	if (!doneLoading) {
+	        		throw BlockedException.block("Blocking on result set load"); //$NON-NLS-1$
+	        	}
+        		internalProcessor.closeProcessing();
+				AlterTempTable att = new AlterTempTable(tempTable);
+				//mark the temp table as non-updatable
+				this.dataManager.registerRequest(this.internalProcessor.getContext(), att, TempMetadataAdapter.TEMP_MODEL.getName(), null, 0, -1);
+        		this.tupleSource = this.dataManager.registerRequest(this.internalProcessor.getContext(), this.resultInfo.getTempSelect(), TempMetadataAdapter.TEMP_MODEL.getName(), null, 0, -1);
+	        }
+			//force execution
+        	currentRow();
+        	
+			if (this.resultInfo.isAutoStaged() && tempTable != null) {
+				AlterTempTable att = new AlterTempTable(tempTable);
+				int size = (Integer)this.currentRow.get(0);
+				if (size > this.bufferMgr.getProcessorBatchSize() * 2) {
+					//TODO: if the parent is small, then this is not necessary
+					att.setIndexColumns(this.resultInfo.getFkColumns());
+				}
+				this.dataManager.registerRequest(this.internalProcessor.getContext(), att, TempMetadataAdapter.TEMP_MODEL.getName(), null, 0, -1);
+			}
+
+			this.currentRowNumber = 0;
+			this.executed = true;
         }
     }    
     
@@ -122,7 +176,9 @@
         if (!endOfRows) {
 
             // get the next row
-            this.currentRow = this.tupleSource.nextTuple();     
+        	if (this.currentRow == null || this.currentRowNumber > 0) {
+        		this.currentRow = this.tupleSource.nextTuple();     
+        	}
             this.currentRowNumber++;
 
             // check if we walked over the row limit
@@ -159,6 +215,19 @@
      */
     public void close() throws TeiidComponentException {
 		this.internalProcessor.closeProcessing();
+		if (this.tupleSource != null) {
+			this.tupleSource.closeSource();
+		}
+		String rsTempTable = this.resultInfo.getTempTable();
+		if (rsTempTable != null) {
+        	LogManager.logDetail(LogConstants.CTX_XML_PLAN, "Unloading result set temp table", rsTempTable); //$NON-NLS-1$
+        	internalProcessor.closeProcessing();
+        	try {
+				this.tupleSource = this.dataManager.registerRequest(this.internalProcessor.getContext(), this.resultInfo.getTempDrop(), TempMetadataAdapter.TEMP_MODEL.getName(), null, 0, -1);
+			} catch (TeiidProcessingException e) {
+		        LogManager.logDetail(org.teiid.logging.LogConstants.CTX_XML_PLAN, e, "Error dropping result set temp table", rsTempTable); //$NON-NLS-1$
+			}
+        }
         LogManager.logTrace(org.teiid.logging.LogConstants.CTX_XML_PLAN, new Object[]{"closed executor", resultInfo.getResultSetName()}); //$NON-NLS-1$
     }
   

Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/processor/xml/XMLProcessorEnvironment.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/processor/xml/XMLProcessorEnvironment.java	2011-07-30 18:54:08 UTC (rev 3354)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/processor/xml/XMLProcessorEnvironment.java	2011-08-01 16:08:41 UTC (rev 3355)
@@ -179,18 +179,25 @@
         if (programState.programCounter >= programState.lookaheadCounter && instrs.size() > programState.programCounter + 1) {
         	for (programState.lookaheadCounter = programState.programCounter; programState.lookaheadCounter < instrs.size(); programState.lookaheadCounter++) {
         		ProcessorInstruction pi = instrs.get(programState.lookaheadCounter);
+        		boolean staging = false;
         		if (pi instanceof ExecStagingTableInstruction) {
-        			//need to load staging tables prior to source queries
-        			break;
+        			staging = true;
+        			ExecStagingTableInstruction esti = (ExecStagingTableInstruction)pi;
+        			if (!esti.info.isAutoStaged()) {
+        				//need to load staging tables prior to source queries
+        				break;
+        			}
         		}
         		if (pi instanceof ExecSqlInstruction) {
         			ExecSqlInstruction esi = (ExecSqlInstruction)pi;
+        			if (!staging && esi.info.isAutoStaged() && esi.info.getTempTable() == null) {
+        				continue; //derived load
+        			}
         			PlanExecutor pe = esi.getPlanExecutor(this, context);
         			pe.execute(context.getReferenceValues(), true);
         		}
         	}
         }
-        
         return programState.program.getInstructionAt(programState.programCounter);
     }
     

Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/InsertResolver.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/InsertResolver.java	2011-07-30 18:54:08 UTC (rev 3354)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/resolver/command/InsertResolver.java	2011-08-01 16:08:41 UTC (rev 3355)
@@ -97,9 +97,9 @@
         
         if (insert.getVariables().isEmpty()) {
             if (insert.getGroup().isResolved()) {
-                List variables = ResolverUtil.resolveElementsInGroup(insert.getGroup(), metadata);
-                for (Iterator i = variables.iterator(); i.hasNext();) {
-                    insert.addVariable((ElementSymbol)((ElementSymbol)i.next()).clone());
+                List<ElementSymbol> variables = ResolverUtil.resolveElementsInGroup(insert.getGroup(), metadata);
+                for (Iterator<ElementSymbol> i = variables.iterator(); i.hasNext();) {
+                    insert.addVariable(i.next().clone());
                 }
             } else {
                 for (int i = 0; i < values.size(); i++) {
@@ -178,11 +178,11 @@
         }
         
         Iterator valueIter = values.iterator();
-        Iterator varIter = insert.getVariables().iterator();
+        Iterator<ElementSymbol> varIter = insert.getVariables().iterator();
         while(valueIter.hasNext()) {
             // Walk through both elements and expressions, which should match up
 			Expression expression = (Expression) valueIter.next();
-			ElementSymbol element = (ElementSymbol) varIter.next();
+			ElementSymbol element = varIter.next();
 			
 			if (!usingQuery) {
 				ResolverUtil.setDesiredType(expression, element.getType(), insert);

Added: branches/7.4.x/engine/src/main/java/org/teiid/query/tempdata/AlterTempTable.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/tempdata/AlterTempTable.java	                        (rev 0)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/tempdata/AlterTempTable.java	2011-08-01 16:08:41 UTC (rev 3355)
@@ -0,0 +1,78 @@
+package org.teiid.query.tempdata;
+
+import java.util.List;
+
+import org.teiid.query.sql.LanguageVisitor;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.SingleElementSymbol;
+
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+public class AlterTempTable extends Command {
+	
+	private String tempTable;
+	private List<ElementSymbol> indexColumns;
+	
+	public AlterTempTable(String tempTable) {
+		this.tempTable = tempTable;
+	}
+	
+	public String getTempTable() {
+		return tempTable;
+	}
+	
+	public List<ElementSymbol> getIndexColumns() {
+		return indexColumns;
+	}
+	
+	public void setIndexColumns(List<ElementSymbol> indexColumns) {
+		this.indexColumns = indexColumns;
+	}
+	
+	@Override
+	public boolean areResultsCachable() {
+		return false;
+	}
+
+	@Override
+	public Object clone() {
+		return this;
+	}
+
+	@Override
+	public List<SingleElementSymbol> getProjectedSymbols() {
+		return Command.getUpdateCommandSymbol();
+	}
+
+	@Override
+	public int getType() {
+		return Command.TYPE_UNKNOWN;
+	}
+
+	@Override
+	public void acceptVisitor(LanguageVisitor visitor) {
+		
+	}
+
+}


Property changes on: branches/7.4.x/engine/src/main/java/org/teiid/query/tempdata/AlterTempTable.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java	2011-07-30 18:54:08 UTC (rev 3354)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java	2011-08-01 16:08:41 UTC (rev 3355)
@@ -249,6 +249,15 @@
     		contextStore.removeTempTableByName(tempTableName);
             return CollectionTupleSource.createUpdateCountTupleSource(0);
     	}
+    	if (command instanceof AlterTempTable) {
+    		AlterTempTable att = (AlterTempTable)command;
+    		TempTable tt = contextStore.getOrCreateTempTable(att.getTempTable().toUpperCase(), command, bufferManager, true);
+    		tt.setUpdatable(false);
+    		if (att.getIndexColumns() != null) {
+    			tt.addIndex(att.getIndexColumns(), false);
+    		}
+    		return CollectionTupleSource.createUpdateCountTupleSource(0);
+    	}
         return null;
     }
 

Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLPlanningEnhancements.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLPlanningEnhancements.java	2011-07-30 18:54:08 UTC (rev 3354)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLPlanningEnhancements.java	2011-08-01 16:08:41 UTC (rev 3355)
@@ -28,6 +28,7 @@
 import java.util.List;
 import java.util.Map;
 
+import org.junit.Ignore;
 import org.junit.Test;
 import org.teiid.client.metadata.ParameterInfo;
 import org.teiid.common.buffer.BufferManager;
@@ -309,6 +310,7 @@
         TestXMLProcessor.helpTestProcess("SELECT * FROM xmltest.doc18a where supplierID<56", expectedDoc, metadata, dataMgr);         //$NON-NLS-1$
     }
     
+    @Ignore("Will plan with a dependent join")
     @Test public void testAutoStagingFailsForMappingClassWithProcRelational() throws Exception {
         TransformationMetadata metadata = getMetadata("SELECT supplierNum, supplierName, supplierZipCode FROM v1.supplierProc where itemnum = ?"); //$NON-NLS-1$
 
@@ -386,6 +388,7 @@
     /**
      * @see #testNested2WithCriteria2
      */
+    @Ignore("Will use a dependent join instead")
     @Test public void testAutoStagingFailsByCosting() throws Exception {
         TransformationMetadata metadata = TestXMLProcessor.exampleMetadata();
         FakeDataManager dataMgr = TestXMLProcessor.exampleDataManagerNested(metadata);
@@ -404,6 +407,7 @@
         assertNull(stats.get(ExecStagingTableInstruction.class));
     }
 
+    @Ignore("Will use dependent join instead")
     @Test public void testAutoStagingFailsByNoCache() throws Exception {
         QueryMetadataInterface metadata = TestXMLProcessor.exampleMetadataCached();
         FakeDataManager dataMgr = TestXMLProcessor.exampleDataManagerNested(metadata);
@@ -417,6 +421,7 @@
         assertNull(stats.get(ExecStagingTableInstruction.class));
     }    
     
+    @Ignore("Will use dependent join")
     @Test public void testAutoStagingFailsByNoCacheByGroup() throws Exception {
         QueryMetadataInterface metadata = TestXMLProcessor.exampleMetadataCached();
         FakeDataManager dataMgr = TestXMLProcessor.exampleDataManagerNested(metadata);

Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java	2011-07-30 18:54:08 UTC (rev 3354)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLProcessor.java	2011-08-01 16:08:41 UTC (rev 3355)
@@ -8866,33 +8866,6 @@
         helpTestProcess("SELECT * FROM xmltest.doc1 WHERE NOT (ItemID IN (SELECT itemNum FROM stock.items WHERE itemNum = '001') )", expectedDoc, metadata, dataMgr);         //$NON-NLS-1$
     }
 
-    public void XXXtestSubqueryInXMLQueryCriteria4() throws Exception {
-        QueryMetadataInterface metadata = exampleMetadataCached();
-        FakeDataManager dataMgr = exampleDataManager(metadata);
-        String expectedDoc = 
-            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" +  //$NON-NLS-1$
-            "<Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n" + //$NON-NLS-1$
-            "    <Catalog>\r\n" +  //$NON-NLS-1$
-            "        <Items>\r\n" +  //$NON-NLS-1$
-            "            <Item ItemID=\"001\">\r\n" +  //$NON-NLS-1$
-            "                <Name>Lamp</Name>\r\n" +  //$NON-NLS-1$
-            "                <Quantity>5</Quantity>\r\n" +  //$NON-NLS-1$
-            "            </Item>\r\n" +  //$NON-NLS-1$
-            "            <Item ItemID=\"002\">\r\n" +  //$NON-NLS-1$
-            "                <Name>Screwdriver</Name>\r\n" +  //$NON-NLS-1$
-            "                <Quantity>100</Quantity>\r\n" +  //$NON-NLS-1$
-            "            </Item>\r\n" +  //$NON-NLS-1$
-            "            <Item ItemID=\"003\">\r\n" +  //$NON-NLS-1$
-            "                <Name>Goat</Name>\r\n" +  //$NON-NLS-1$
-            "                <Quantity>4</Quantity>\r\n" +  //$NON-NLS-1$
-            "            </Item>\r\n" +  //$NON-NLS-1$
-            "        </Items>\r\n" +  //$NON-NLS-1$
-            "    </Catalog>\r\n" +  //$NON-NLS-1$
-            "</Catalogs>\r\n\r\n"; //$NON-NLS-1$
-        
-        helpTestProcess("SELECT * FROM xmltest.doc1 WHERE EXISTS (SELECT itemNum FROM stock.items WHERE itemNum = '001')", expectedDoc, metadata, dataMgr);         //$NON-NLS-1$
-    }
-
     @Test public void testSubqueryInXMLQueryCriteriaNestedSubquery() throws Exception {
         QueryMetadataInterface metadata = exampleMetadataCached();
         FakeDataManager dataMgr = exampleDataManager(metadata);



More information about the teiid-commits mailing list