[teiid-commits] teiid SVN: r2759 - in trunk: documentation/caching-guide/src/main/docbook/en-US/content and 6 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Mon Dec 6 11:56:23 EST 2010


Author: rareddy
Date: 2010-12-06 11:56:22 -0500 (Mon, 06 Dec 2010)
New Revision: 2759

Modified:
   trunk/build/kits/jboss-container/teiid-releasenotes.html
   trunk/documentation/caching-guide/src/main/docbook/en-US/content/hint-option.xml
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
   trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
   trunk/engine/src/main/java/org/teiid/query/sql/lang/CacheHint.java
   trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
   trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
   trunk/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java
Log:
TEIID-1253: Adding cache scope to the Cache Hint. The added scopes are "session|user|vdb". If the scope hint is provided, it will override the computed scope from query.

Modified: trunk/build/kits/jboss-container/teiid-releasenotes.html
===================================================================
--- trunk/build/kits/jboss-container/teiid-releasenotes.html	2010-12-06 14:40:09 UTC (rev 2758)
+++ trunk/build/kits/jboss-container/teiid-releasenotes.html	2010-12-06 16:56:22 UTC (rev 2759)
@@ -28,7 +28,7 @@
 <UL>
 	<LI><B>Subquery Optimization</B> - added rewrite to INNER JOIN for applicable WHERE clause subqueries. Also added cost based SEMI and ANTI-SEMI join handling for applicable non-pushed WHERE and HAVING subqueries.
 	<LI><B>Updatable Views</B> - added support to perform simple pass-through and more complicated updates through views by default.
-	<LI><B>UDF</B> - new API objects added to teiid-api to support user defined functions that are capable of pushdown to source.
+	<LI><B>UDF</B> - new API objects added to teiid-api to support user defined functions that are capable of pushdown to source.	
 </UL>
 
 <h2><a name="Compatibility">Compatibility Issues</a></h2>
@@ -49,6 +49,7 @@
   <li>By default the "ENV" system function is now turned off. To enable it, edit the teiid-jboss-beans.xml configuration file.
   <li>The use of VARIABLES.ROWCOUNT is now reserved.
   <li>Exec statements of the form "var = EXEC foo()" are only valid if the procedure foo has a return parameter.
+  <li>Cache hint now supports "scope" definition. For ex: /* cache(scope:user) */ select * from T1; This hint will override the computed scope based on the query.  
 </ul>
 <h4>from 7.0</h4>
 <ul>

Modified: trunk/documentation/caching-guide/src/main/docbook/en-US/content/hint-option.xml
===================================================================
--- trunk/documentation/caching-guide/src/main/docbook/en-US/content/hint-option.xml	2010-12-06 14:40:09 UTC (rev 2758)
+++ trunk/documentation/caching-guide/src/main/docbook/en-US/content/hint-option.xml	2010-12-06 16:56:22 UTC (rev 2759)
@@ -15,7 +15,7 @@
 	   		<listitem><para>Indicate that a virtual procedure should be cachable and set the cache entry memory preference or time to live.
 	   		</para></listitem>
 	   	</itemizedlist>
-	   	<para><synopsis>/*+ cache[([pref_mem] [ttl:n] [updatable])] */ sql ...</synopsis>
+	   	<para><synopsis>/*+ cache[([pref_mem] [ttl:n] [updatable])] [scope:(session|user|vdb)] */ sql ...</synopsis>
 	   	<itemizedlist>
 	   		<listitem><para>The cache hint should appear at the beginning of the SQL.  It will not have any affect on INSERT/UPDATE/DELETE statements or virtual update procedure definitions.</para></listitem>
 	   		<listitem><para><emphasis>pref_mem</emphasis> - if present indicates that the cached results should prefer to remain in memory.  They are not however required to be memory only.
@@ -24,6 +24,10 @@
 	   		</para></listitem>
 	   		<listitem><para><emphasis>updatable</emphasis> - if present indicates that the cached results can be updated.  This is currently only applicable to materialized views.
 	   		</para></listitem>
+            <listitem><para><emphasis>scope</emphasis> - if present indicates the override scope of query results. Using this flag, user can override the computed scope, to improve or force the results to cache.
+            There are three different cache scopes, session - cached only for current session, user - cached for any session by the current user, vdb - cached for any user connected to the same vdb. 
+            </para></listitem>
+            
 	 	</itemizedlist>
 	   	</para>
 	   	   	<section>

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java	2010-12-06 14:40:09 UTC (rev 2758)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java	2010-12-06 16:56:22 UTC (rev 2759)
@@ -38,6 +38,7 @@
 import org.teiid.dqp.internal.process.SessionAwareCache.CacheID;
 import org.teiid.logging.LogConstants;
 import org.teiid.logging.LogManager;
+import org.teiid.metadata.FunctionMethod.Determinism;
 import org.teiid.query.QueryPlugin;
 import org.teiid.query.eval.Evaluator;
 import org.teiid.query.metadata.QueryMetadataInterface;
@@ -140,7 +141,14 @@
 		        // Defect 13751: Clone the plan in its current state (i.e. before processing) so that it can be used for later queries
 		        prepPlan.setPlan(processPlan.clone());
 		        prepPlan.setAnalysisRecord(analysisRecord);
-		        this.prepPlanCache.put(id, this.context.getDeterminismLevel(), prepPlan, userCommand.getCacheHint() != null?userCommand.getCacheHint().getTtl():null);
+				
+		        Determinism hintDeterminismLevel = null;
+				if (userCommand.getCacheHint() != null && userCommand.getCacheHint().getDeterminism() != null) {
+					hintDeterminismLevel = userCommand.getCacheHint().getDeterminism();
+					LogManager.logTrace(LogConstants.CTX_DQP, new Object[] { "Cache hint modified the query determinism from ",this.context.getDeterminismLevel(), " to ", hintDeterminismLevel }); //$NON-NLS-1$ //$NON-NLS-2$
+				}		        
+		        
+		        this.prepPlanCache.put(id, hintDeterminismLevel!= null?hintDeterminismLevel:this.context.getDeterminismLevel(), prepPlan, userCommand.getCacheHint() != null?userCommand.getCacheHint().getTtl():null);
         	}
         } else {
         	ProcessorPlan cachedPlan = prepPlan.getPlan();

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java	2010-12-06 14:40:09 UTC (rev 2758)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java	2010-12-06 16:56:22 UTC (rev 2759)
@@ -390,6 +390,12 @@
 	            	cr.setCommand(originalCommand);
 	                cr.setAnalysisRecord(analysisRecord);
 	                cr.setResults(resultsBuffer);
+	                
+					if (originalCommand.getCacheHint() != null && originalCommand.getCacheHint().getDeterminism() != null) {
+						determinismLevel = originalCommand.getCacheHint().getDeterminism();
+						LogManager.logTrace(LogConstants.CTX_DQP, new Object[] { "Cache hint modified the query determinism from ",processor.getContext().getDeterminismLevel(), " to ", determinismLevel }); //$NON-NLS-1$ //$NON-NLS-2$
+					}		                
+	                
 	                if (determinismLevel.isRestrictiveThan(Determinism.SESSION_DETERMINISTIC)) {
 	    				LogManager.logInfo(LogConstants.CTX_DQP, QueryPlugin.Util.getString("RequestWorkItem.cache_nondeterministic", originalCommand)); //$NON-NLS-1$
 	    			}

Modified: trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java	2010-12-06 14:40:09 UTC (rev 2758)
+++ trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java	2010-12-06 16:56:22 UTC (rev 2759)
@@ -178,7 +178,7 @@
         return hint;
 	}
 	
-	private static Pattern CACHE_HINT = Pattern.compile("/\\*\\+?\\s*cache(\\(\\s*(pref_mem)?\\s*(ttl:\\d{1,19})?\\s*(updatable)?[^\\)]*\\))?[^\\*]*\\*\\/.*", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); //$NON-NLS-1$
+	private static Pattern CACHE_HINT = Pattern.compile("/\\*\\+?\\s*cache(\\(\\s*(pref_mem)?\\s*(ttl:\\d{1,19})?\\s*(updatable)?\\s*(scope:(session|vdb|user))?[^\\)]*\\))?[^\\*]*\\*\\/.*", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); //$NON-NLS-1$
     
 	static CacheHint getQueryCacheOption(String query) {
     	Matcher match = CACHE_HINT.matcher(query);
@@ -194,6 +194,11 @@
     		if (match.group(4) != null) {
     			hint.setUpdatable(true);
     		}
+    		String scope =  match.group(5);
+    		if (scope != null) {
+    			scope = scope.substring(6);
+    			hint.setScope(scope);
+    		}    		
     		return hint;
     	}
     	return null;

Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/CacheHint.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/CacheHint.java	2010-12-06 14:40:09 UTC (rev 2758)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/CacheHint.java	2010-12-06 16:56:22 UTC (rev 2759)
@@ -25,6 +25,7 @@
 import java.io.Serializable;
 
 import org.teiid.core.util.EquivalenceUtil;
+import org.teiid.metadata.FunctionMethod.Determinism;
 import org.teiid.query.sql.visitor.SQLStringVisitor;
 
 public class CacheHint implements Serializable {
@@ -35,10 +36,16 @@
 	public static final String TTL = "ttl:"; //$NON-NLS-1$
 	public static final String UPDATABLE = "updatable"; //$NON-NLS-1$
 	public static final String CACHE = "cache"; //$NON-NLS-1$
+	public static final String SCOPE = "scope:"; //$NON-NLS-1$
 	
+	private static final String SESSION = "session"; //$NON-NLS-1$
+	private static final String VDB = "vdb"; //$NON-NLS-1$
+	private static final String USER = "user"; //$NON-NLS-1$
+	
 	private boolean prefersMemory;
 	private boolean updatable;
 	private Long ttl;
+	private String scope;
 	
 	public CacheHint() {
 	}
@@ -79,6 +86,31 @@
 		this.updatable = updatable;
 	}
 	
+	public Determinism getDeterminism() {
+		if (this.scope == null) {
+			return null;
+		}
+		
+		if (scope.equals(SESSION)) { 
+			return Determinism.SESSION_DETERMINISTIC;
+		}
+		else if (this.scope.equals(VDB)) {
+			return Determinism.VDB_DETERMINISTIC;
+		}
+		else if (this.scope.equals(USER)) { 
+			return  Determinism.USER_DETERMINISTIC;
+		}
+		return null;
+	}
+	
+	public String getScope() {
+		return this.scope;
+	}
+
+	public void setScope(String scope) {
+		this.scope = scope;
+	}
+	
 	@Override
 	public boolean equals(Object obj) {
 		if (obj == this) {
@@ -90,7 +122,8 @@
 		CacheHint other = (CacheHint)obj;
 		return this.prefersMemory == other.prefersMemory 
 		&& EquivalenceUtil.areEqual(this.ttl, other.ttl) 
-		&& this.updatable == other.updatable;
+		&& this.updatable == other.updatable
+		&& EquivalenceUtil.areEqual(this.scope, other.scope);
 	}
 
 }

Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java	2010-12-06 14:40:09 UTC (rev 2758)
+++ trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java	2010-12-06 16:56:22 UTC (rev 2759)
@@ -585,7 +585,7 @@
                 outputDisplayName((String)iter.next());
 
                 if (iter.hasNext()) {
-                    append(", ");
+                    append(", ");//$NON-NLS-1$
                 }
             }
         }
@@ -602,7 +602,7 @@
                 outputDisplayName((String)iter.next());
 
                 if (iter.hasNext()) {
-                    append(", ");
+                    append(", ");//$NON-NLS-1$
                 }
             }
         }
@@ -619,7 +619,7 @@
                 outputDisplayName((String)iter.next());
 
                 if (iter.hasNext()) {
-                    append(", ");
+                    append(", ");//$NON-NLS-1$
                 }
             }
         } else if (obj.isNoCache()) {
@@ -1011,6 +1011,16 @@
             }
             append(CacheHint.UPDATABLE);
         }
+        if (obj.getScope() != null) {
+            if (!addParens) {
+                append(Tokens.LPAREN);
+                addParens = true;
+            } else {
+                append(SPACE);
+            }     
+            append(CacheHint.SCOPE);
+            append(obj.getScope());            
+        }
         if (addParens) {
             append(Tokens.RPAREN);
         }

Modified: trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java	2010-12-06 14:40:09 UTC (rev 2758)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java	2010-12-06 16:56:22 UTC (rev 2759)
@@ -285,7 +285,12 @@
 		CachedResults cr = new CachedResults();
 		cr.setResults(tb);
 		cr.setHint(hint);
-		cache.put(cid, context.getDeterminismLevel(), cr, hint != null?hint.getTtl():null);
+		Determinism hintDeterminismLevel = null;
+		if (hint != null && hint.getDeterminism() != null) {
+			hintDeterminismLevel = hint.getDeterminism();
+			LogManager.logTrace(LogConstants.CTX_DQP, new Object[] { "Cache hint modified the query determinism from ",determinismLevel, " to ", hintDeterminismLevel }); //$NON-NLS-1$ //$NON-NLS-2$
+		}
+		cache.put(cid, hintDeterminismLevel != null?hintDeterminismLevel:context.getDeterminismLevel(), cr, hint != null?hint.getTtl():null);
 		context.setDeterminismLevel(determinismLevel);
 		return tb.createIndexedTupleSource();
 	}

Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java	2010-12-06 14:40:09 UTC (rev 2758)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java	2010-12-06 16:56:22 UTC (rev 2759)
@@ -22,7 +22,7 @@
 
 package org.teiid.query.parser;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -1053,6 +1053,25 @@
         TestParser.helpTest(sql, "/*+ cache */ SELECT * FROM t1", query);         //$NON-NLS-1$
     }
     
+    @Test public void testCacheScope() {
+        String sql = "/*+ cache(pref_mem scope:session) */ SELECT * FROM t1"; //$NON-NLS-1$
+        
+        Query query = new Query();
+        Select select = new Select();
+        select.addSymbol(new AllSymbol());
+        query.setSelect(select);
+        From from = new From();
+        UnaryFromClause ufc = new UnaryFromClause();
+        from.addClause(ufc);
+        ufc.setGroup(new GroupSymbol("t1")); //$NON-NLS-1$
+        query.setFrom(from);           
+        CacheHint hint = new CacheHint();
+        hint.setScope("session");
+        hint.setPrefersMemory(true);
+        query.setCacheHint(hint);
+        TestParser.helpTest(sql, "/*+ cache(pref_mem scope:session) */ SELECT * FROM t1", query);         //$NON-NLS-1$
+    }
+    
     @Test public void testCache1() {
         String sql = "/*+ cache */ execute foo()"; //$NON-NLS-1$
         



More information about the teiid-commits mailing list