You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2012/07/05 17:41:16 UTC

svn commit: r1357692 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/FromVTI.java testing/org/apache/derbyTesting/functionTests/tests/lang/SysDiagVTIMappingTest.java

Author: rhillegas
Date: Thu Jul  5 15:41:16 2012
New Revision: 1357692

URL: http://svn.apache.org/viewvc?rev=1357692&view=rev
Log:
DERBY-5554: Forbid the joining of VTIs to one another in the FROM list.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SysDiagVTIMappingTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java?rev=1357692&r1=1357691&r2=1357692&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java Thu Jul  5 15:41:16 2012
@@ -881,17 +881,18 @@ public class FromVTI extends FromTable i
 
             //
             // Table Function parameters may not reference columns from other tables in the
-            // FROM list of the current query block. See DERBY-5579.
+            // FROM list of the current query block. See DERBY-5579. We also do not allow
+            // VTI parameters to refer to other VTIs.
             //
-            if ( isDerbyStyleTableFunction )
-            {
-                int referencedTableNumber = ref.getTableNumber();
+            int referencedTableNumber = ref.getTableNumber();
                 
-                for ( int i = 0; i < fromListParam.size(); i++ )
-                {
-                    FromTable   fromTable = (FromTable) fromListParam.elementAt( i );
+            for ( int i = 0; i < fromListParam.size(); i++ )
+            {
+                FromTable   fromTable = (FromTable) fromListParam.elementAt( i );
 
-                    if ( referencedTableNumber == fromTable.getTableNumber() )
+                if ( referencedTableNumber == fromTable.getTableNumber() )
+                {
+                    if ( isDerbyStyleTableFunction || (fromTable instanceof FromVTI) )
                     {
                         throw StandardException.newException
                             ( SQLState.LANG_BAD_TABLE_FUNCTION_PARAM_REF, ref.getSQLColumnName() );

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SysDiagVTIMappingTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SysDiagVTIMappingTest.java?rev=1357692&r1=1357691&r2=1357692&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SysDiagVTIMappingTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SysDiagVTIMappingTest.java Thu Jul  5 15:41:16 2012
@@ -29,6 +29,7 @@ import org.apache.derbyTesting.junit.Sup
 import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
+import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.Statement;
 import java.sql.CallableStatement;
@@ -50,6 +51,8 @@ public final class SysDiagVTIMappingTest
         "NUMUNFILLEDPAGES", "PAGESIZE", "ESTIMSPACESAVING", "TABLEID"
     };
 
+    private static  final   String  BAD_FROM_LIST_JOIN = "42ZB7";
+
     /**
      * Public constructor required for running test as standalone JUnit.
      */
@@ -477,6 +480,58 @@ public final class SysDiagVTIMappingTest
     }
     
     /**
+     * Verify that you can't join diagnostic VTIs to one another in the FROM list. See DERBY-5554.
+     */
+    public void test_vti2vtiJoinInFromList() throws Exception
+    {
+        Connection  conn = getConnection();
+        Statement st = createStatement();
+
+        // joins to real tables are ok
+        conn.prepareStatement
+            (
+             "select t1.*\n" +
+             "from \n" +
+             "    sys.systables systabs,\n" +
+             "    table ( syscs_diag.space_table( systabs.tablename ) ) as t1\n" +
+             "where systabs.tabletype = 'T'\n"
+             );
+        conn.prepareStatement
+            (
+             "select t1.*\n" +
+             "from \n" +
+             "    table ( syscs_diag.space_table( systabs.tablename ) ) as t1,\n" +
+             "    sys.systables systabs\n" +
+             "where systabs.tabletype = 'T'\n"
+             );
+
+        // can't join VTIs to one another in the FROM list
+        assertStatementError
+            (
+             BAD_FROM_LIST_JOIN,
+             st,
+             "select t1.*, t2.*\n" +
+             "from \n" +
+             "    sys.systables systabs,\n" +
+             "    table ( syscs_diag.space_table( systabs.tablename ) ) as t1,\n" +
+             "    table ( syscs_diag.space_table( t1.conglomeratename ) ) as t2\n" +
+             "where systabs.tabletype = 'T'\n"
+             );
+        assertStatementError
+            (
+             "42X04",
+             st,
+             "select t1.*, t2.*\n" +
+             "from \n" +
+             "    sys.systables systabs,\n" +
+             "    table ( syscs_diag.space_table( t1.conglomeratename ) ) as t2,\n" +
+             "    table ( syscs_diag.space_table( systabs.tablename ) ) as t1\n" +
+             "where systabs.tabletype = 'T'\n"
+             );
+
+    }
+    
+    /**
      * Just run a couple of sanity checks to makes sure the table
      * mapping for org.apache.derby.diag.StatementDuration() works
      * correctly and fails where it is supposed to.