db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r677998 - in /db/derby/code/trunk/java: engine/org/apache/derby/catalog/ engine/org/apache/derby/iapi/sql/dictionary/ engine/org/apache/derby/impl/sql/catalog/ engine/org/apache/derby/impl/sql/compile/ engine/org/apache/derby/impl/sql/execu...
Date Fri, 18 Jul 2008 18:53:23 GMT
Author: mamta
Date: Fri Jul 18 11:53:22 2008
New Revision: 677998

URL: http://svn.apache.org/viewvc?rev=677998&view=rev
Log:
DERBY-269

This patch will provide a manual way of updating the statistics of all or just one index on a table
using the new stored procedure SYSCS_UTIL.SYSCS_UPDATE_STATISTICS. The signature of the new procedure
is as follows
SYSCS_UTIL.SYSCS_UPDATE_STATISTICS(schemaname, tablename, indexname)
If the user provides null for indexname then statistics will be updated for all the indexes on
schemaname.tablename otherwise statistics will be updated only for schemaname.tablename.indexname.

We implement this functionality by intercepting the stored procedure call and converting it to an
internal to Derby only ALTER TABLE syntax. This allows us to use lot of basic code needed for
schema/table name validation, privilege checking etc. Other than this, the actual code for implementing
the functionality was obtained from exisiting unused class execute/UpdateStatisticsConstantAction.java
I have removed that class from the codeline since the code inside it has now been moved into
AlterTableConstantAction.java


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdateStatisticsTest.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_5.java   (with props)
Removed:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/UpdateStatisticsConstantAction.java
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/IndexRowGenerator.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DD_Version.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AlterTableNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GrantRevokeDDLTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_2.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/_Suite.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java?rev=677998&r1=677997&r2=677998&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java Fri Jul 18 11:53:22 2008
@@ -698,6 +698,52 @@
     }
 
     /**
+     * Update the statistics for
+     * 1)all the indexes or
+     * 2)a specific index on a table.
+     * <p>
+     * Calls either 
+     * "alter table tablename all update statistics " sql
+     * or
+     * "alter table tablename update statistics indexname" sql
+     * This routine will be called when an application calls:
+     *     SYSCS_UTIL.SYSCS_UPDATE_STATISTICS
+     * <p>
+     *
+     * @param schemaname    schema name of the index(es) whose statistics will
+     *                      be updated. Must be non-null, no default is used.
+     * @param tablename     table name of the index(es) whose statistics will
+     *                      be updated. Must be non-null.
+     * @param indexname     Can be null. If not null or emptry string then the
+     *                      user wants to update the statistics for only this
+     *                      index. If null, then update the statistics for all
+     *                      the indexes for the given table name.
+     *
+	 * @exception  StandardException  Standard exception policy.
+     **/
+    public static void SYSCS_UPDATE_STATISTICS(
+    	    String  schemaname,
+    	    String  tablename,
+    	    String  indexname)
+    throws SQLException
+    {
+        String escapedSchema = IdUtil.normalToDelimited(schemaname);
+        String escapedTableName = IdUtil.normalToDelimited(tablename);
+        String query = "alter table " + escapedSchema + "." + escapedTableName;
+        if (indexname == null)
+        	query = query + " all update statistics ";
+        else
+        	query = query + " update statistics " + IdUtil.normalToDelimited(indexname);
+        Connection conn = getDefaultConn();
+
+        PreparedStatement ps = conn.prepareStatement(query);
+        ps.executeUpdate();
+        ps.close();
+
+        conn.close();
+    }
+
+    /**
      * Compress the table.
      * <p>
      * Calls the "alter table compress {sequential}" sql.  This syntax

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java?rev=677998&r1=677997&r2=677998&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java Fri Jul 18 11:53:22 2008
@@ -113,6 +113,9 @@
 	/** Derby 10.4 System Catalog version */
 	public static final int DD_VERSION_DERBY_10_4		= 160;
 
+	/** Derby 10.5 System Catalog version */
+	public static final int DD_VERSION_DERBY_10_5		= 170;
+
 	// general info
 	public	static	final	String	DATABASE_ID = "derby.databaseID";
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/IndexRowGenerator.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/IndexRowGenerator.java?rev=677998&r1=677997&r2=677998&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/IndexRowGenerator.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/IndexRowGenerator.java Fri Jul 18 11:53:22 2008
@@ -39,6 +39,7 @@
 import org.apache.derby.iapi.sql.execute.ExecutionFactory;
 import org.apache.derby.iapi.types.RowLocation;
 import org.apache.derby.iapi.types.StringDataValue;
+import org.apache.derby.iapi.types.DataTypeDescriptor;
 
 /**
  * This class extends IndexDescriptor for internal use by the
@@ -144,6 +145,33 @@
 										id.baseColumnPositions().length + 1);
 	}
 
+    /**
+     * Get a NULL Index Row for this index. This is useful to create objects
+     * that need to be passed to ScanController.
+     *
+     * @param columnList ColumnDescriptors describing the base table.
+     * @param rowLocation   empty row location.
+     *
+     * @exception StandardException thrown on error.
+     */
+    public ExecIndexRow getNullIndexRow(ColumnDescriptorList columnList,
+    		RowLocation rowLocation)
+    throws StandardException
+    {
+            int[] baseColumnPositions = id.baseColumnPositions();
+            ExecIndexRow indexRow = getIndexRowTemplate();
+
+            for (int i = 0; i < baseColumnPositions.length; i++)
+            {
+                    DataTypeDescriptor dtd =
+                            columnList.elementAt(baseColumnPositions[i] - 1).getType();
+                    indexRow.setColumn(i + 1, dtd.getNull());
+            }
+
+            indexRow.setColumn(baseColumnPositions.length + 1, rowLocation);
+            return indexRow;
+    }
+
 	/**
 	 * Get an index row for this index given a row from the base table
 	 * and the RowLocation of the base row.  This method can be used

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DD_Version.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DD_Version.java?rev=677998&r1=677997&r2=677998&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DD_Version.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DD_Version.java Fri Jul 18 11:53:22 2008
@@ -151,6 +151,8 @@
 			return "10.3";
 		case DataDictionary.DD_VERSION_DERBY_10_4:
 			return "10.4";
+		case DataDictionary.DD_VERSION_DERBY_10_5:
+			return "10.5";
 		default:
 			return null;
 		}
@@ -394,6 +396,13 @@
                 bootingDictionary.getSystemUtilSchemaDescriptor().getUUID());
         }
 
+        if (fromMajorVersionNumber <= DataDictionary.DD_VERSION_DERBY_10_4)
+        {
+            // On ugrade from versions before 10.5, create system procedures
+            // added in 10.5.
+            bootingDictionary.create_10_5_system_procedures(tc);
+        }
+
         if (fromMajorVersionNumber <= DataDictionary.DD_VERSION_DERBY_10_1)
         {
             // On ugrade from versions before 10.2, create system procedures

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java?rev=677998&r1=677997&r2=677998&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java Fri Jul 18 11:53:22 2008
@@ -411,6 +411,7 @@
 												"SYSCS_SET_STATISTICS_TIMING", 
 												"SYSCS_INPLACE_COMPRESS_TABLE",
 												"SYSCS_COMPRESS_TABLE",
+												"SYSCS_UPDATE_STATISTICS",
 												};
 	
 	/**
@@ -471,7 +472,7 @@
 	public void boot(boolean create, Properties startParams) 
 			throws StandardException
 	{
-		softwareVersion = new DD_Version(this, DataDictionary.DD_VERSION_DERBY_10_4);
+		softwareVersion = new DD_Version(this, DataDictionary.DD_VERSION_DERBY_10_5);
 
 		startupParameters = startParams;
 
@@ -10141,6 +10142,8 @@
         create_10_2_system_procedures(tc, sysUtilUUID);
         // add 10.3 specific system procedures
         create_10_3_system_procedures(tc);
+        // add 10.5 specific system procedures
+        create_10_5_system_procedures(tc);
     }
 
     /**
@@ -11285,6 +11288,46 @@
     }
 
     /**
+     * Create the System procedures that are added to 10.5.
+     * 
+     * @param tc an instance of the TransactionController.
+     * @throws StandardException Standard exception policy.
+     */
+    void create_10_5_system_procedures(TransactionController tc)
+    throws StandardException
+    {
+        // Create the procedures in the SYSCS_UTIL schema.
+        UUID  sysUtilUUID = getSystemUtilSchemaDescriptor().getUUID();
+
+        // void SYSCS_UTIL.SYSCS_UPDATE_STATISTICS(varchar(128), varchar(128), varchar(128))
+        {
+            // procedure argument names
+            String[] arg_names = {"SCHEMANAME", "TABLENAME", "INDEXNAME"};
+
+            // procedure argument types
+            TypeDescriptor[] arg_types = {
+                    CATALOG_TYPE_SYSTEM_IDENTIFIER,
+                    CATALOG_TYPE_SYSTEM_IDENTIFIER,
+                    CATALOG_TYPE_SYSTEM_IDENTIFIER
+
+            };
+
+            UUID routine_uuid = createSystemProcedureOrFunction(
+                "SYSCS_UPDATE_STATISTICS",
+                sysUtilUUID,
+                arg_names,
+                arg_types,
+                0,
+                0,
+                RoutineAliasInfo.MODIFIES_SQL_DATA,
+                (TypeDescriptor) null,
+                tc);
+
+            createRoutinePermPublicDescriptor(routine_uuid, tc);
+        }
+    }
+
+    /**
      * Create the System procedures that are added in 10.3.
      *
      * @param tc an instance of the TransactionController.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AlterTableNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AlterTableNode.java?rev=677998&r1=677997&r2=677998&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AlterTableNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/AlterTableNode.java Fri Jul 18 11:53:22 2008
@@ -30,6 +30,7 @@
 
 import org.apache.derby.iapi.sql.compile.C_NodeTypes;
 
+import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
 import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
@@ -51,6 +52,25 @@
 	// The alter table action
 	public	TableElementList	tableElementList = null;
 	public  char				lockGranularity;
+
+	/**
+	 * updateStatistics will indicate that we are here for updating the
+	 * statistics. It could be statistics of just one index or all the
+	 * indexes on a given table. 
+	 */
+	private	boolean				updateStatistics = false;
+	/**
+	 * The flag updateStatisticsAll will tell if we are going to update the 
+	 * statistics of all indexes or just one index on a table. 
+	 */
+	private	boolean				updateStatisticsAll = false;
+	/**
+	 * If statistic is getting updated for just one index, then 
+	 * indexNameForUpdateStatistics will tell the name of the specific index 
+	 * whose statistics need to be updated.
+	 */
+	private	String				indexNameForUpdateStatistics;
+	
 	public	boolean				compressTable = false;
 	public	boolean				sequential = false;
 	//The following three (purge, defragment and truncateEndOfTable) apply for 
@@ -104,6 +124,33 @@
 	}
 
 	/**
+	 * Initializer for a AlterTableNode for updating the statistics. The user
+	 * can ask for update statistic of all the indexes or only a specific index
+	 *
+	 * @param objectName		The name of the table whose index(es) will have
+	 *                          their statistics updated.
+	 * @param updateStatisticsAll	If true then update the statistics of all 
+	 *                          the indexes on the table. If false, then update
+	 *                          the statistics of only the index provided as
+	 *                          3rd parameter here
+	 * @param indexName			Only used if updateStatisticsAll is set to 
+	 *                          false. 
+	 *
+	 * @exception StandardException		Thrown on error
+	 */
+	public void init(Object objectName,
+			Object updateStatisticsAll,
+			Object indexName)
+	throws StandardException
+	{
+		initAndCheck(objectName);
+		this.updateStatisticsAll = ((Boolean) updateStatisticsAll).booleanValue();
+		this.indexNameForUpdateStatistics = (String)indexName;
+		schemaDescriptor = getSchemaDescriptor();
+		updateStatistics = true;
+	}
+	
+	/**
 	 * Initializer for a AlterTableNode for COMPRESS using temporary tables
 	 * rather than inplace compress
 	 *
@@ -216,7 +263,10 @@
 				"truncateTable: " + "\n" + truncateTable + "\n" +
 				"purge: " + "\n" + purge + "\n" +
 				"defragment: " + "\n" + defragment + "\n" +
-				"truncateEndOfTable: " + "\n" + truncateEndOfTable + "\n";
+				"truncateEndOfTable: " + "\n" + truncateEndOfTable + "\n" +
+				"updateStatistics: " + "\n" + updateStatistics + "\n" +
+				"updateStatisticsAll: " + "\n" + updateStatisticsAll + "\n" +
+				"indexNameForUpdateStatistics: " + "\n" + indexNameForUpdateStatistics + "\n";
 		}
 		else
 		{
@@ -364,6 +414,23 @@
 
 		}
 
+		//Check if we are in alter table to update the statistics. If yes, then
+		//check if we are here to update the statistics of a specific index. If
+		//yes, then verify that the indexname provided is a valid one.
+		if (updateStatistics && !updateStatisticsAll)
+		{
+			ConglomerateDescriptor	cd = null;
+			if (schemaDescriptor.getUUID() != null) 
+				cd = dd.getConglomerateDescriptor(indexNameForUpdateStatistics, schemaDescriptor, false);
+
+			if (cd == null)
+			{
+				throw StandardException.newException(
+						SQLState.LANG_INDEX_NOT_FOUND, 
+						schemaDescriptor.getSchemaName() + "." + indexNameForUpdateStatistics);
+			}			
+		}
+
 		/* Unlike most other DDL, we will make this ALTER TABLE statement
 		 * dependent on the table being altered.  In general, we try to
 		 * avoid this for DDL, but we are already requiring the table to
@@ -411,7 +478,10 @@
  										     truncateTable,
  										     purge,
  										     defragment,
- 										     truncateEndOfTable );
+ 										     truncateEndOfTable,
+ 										     updateStatistics,
+ 										     updateStatisticsAll,
+ 										     indexNameForUpdateStatistics);
 	}
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=677998&r1=677997&r2=677998&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Fri Jul 18 11:53:22 2008
@@ -2311,6 +2311,7 @@
 |	<RETURNING: "returning">
 |   <RR: "rr">
 |   <RS: "rs">
+|	<STATISTICS: "statistics">
 |	<SEQUENCE: "sequence">
 |	<SEQUENTIAL: "sequential">
 |	<SETS: "sets">
@@ -12222,6 +12223,7 @@
 												getContextManager());
 	int[]				changeType = new int[1];
 	int[]				behavior = new int[1];
+        String indexName = null;
 }
 {
 //insert special key before compress so that only internal SP can know
@@ -12235,6 +12237,41 @@
 		return sn;
 	}
 |
+//This means update the statistics of all the indexes on the table
+	<ALL> <UPDATE> <STATISTICS>
+	{
+		checkVersion( DataDictionary.DD_VERSION_DERBY_10_5, "SYSCS_UPDATE_STATISTICS");
+		//This will make sure that this ALTER TABLE...syntax can't be called directly.
+		//This sql can only be generated internally (right now it is done for
+		//syscs_util.SYSCS_UPDATE_STATISTICS procedure
+		checkInternalFeature("UPDATE STATISTICS");
+		return (StatementNode) nodeFactory.getNode(
+							C_NodeTypes.ALTER_TABLE_NODE,
+							tableName,
+							Boolean.TRUE,
+							null,
+							getContextManager());
+	}
+|
+//This means update the statistics of the index name supplied for the table
+	<UPDATE> <STATISTICS>
+        (
+		indexName =  identifier(Limits.MAX_IDENTIFIER_LENGTH, true)
+        )
+	{
+		checkVersion( DataDictionary.DD_VERSION_DERBY_10_5, "SYSCS_UPDATE_STATISTICS");
+		//This will make sure that this ALTER TABLE...syntax can't be called directly.
+		//This sql can only be generated internally (right now it is done for
+		//syscs_util.SYSCS_UPDATE_STATISTICS procedure
+		checkInternalFeature("UPDATE STATISTICS");
+		return (StatementNode) nodeFactory.getNode(
+							C_NodeTypes.ALTER_TABLE_NODE,
+							tableName,
+							Boolean.FALSE,
+							indexName,
+							getContextManager());
+	}
+|
 	lockGranularity = alterTableAction( tableElementList, changeType, behavior )
 	{
 		return (StatementNode) nodeFactory.getNode(
@@ -13669,6 +13706,7 @@
     |       tok = <STABILITY>
 	|	tok = <START>
 	|	tok = <STATEMENT>
+	|	tok = <STATISTICS>
 	|	tok = <STRIP>
 	|	tok = <SYNONYM>
 	|	tok = <STYLE>

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java?rev=677998&r1=677997&r2=677998&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java Fri Jul 18 11:53:22 2008
@@ -115,6 +115,35 @@
     private	    boolean					    defragment;
     private	    boolean					    truncateEndOfTable;
 
+	/**
+	 * updateStatistics will indicate that we are here for updating the
+	 * statistics. It could be statistics of just one index or all the
+	 * indexes on a given table. 
+	 */
+    private	    boolean					    updateStatistics;
+	/**
+	 * The flag updateStatisticsAll will tell if we are going to update the 
+	 * statistics of all indexes or just one index on a table. 
+	 */
+    private	    boolean					    updateStatisticsAll;
+	/**
+	 * If statistic is getting updated for just one index, then 
+	 * indexNameForUpdateStatistics will tell the name of the specific index 
+	 * whose statistics need to be updated.
+	 */
+    private	    String						indexNameForUpdateStatistics;
+    /**
+     * RUNTIME state of the system is maintained in these objects.
+     * rowBufferOne simply reuses the index row prepared by
+     * makeConstantAction. rowBufferTwo is a clone (an extra copy) of
+     * objects. rowBufferCurrent just switches between rowBufferOne and
+     * rowBufferTwo. 
+     */
+    private DataValueDescriptor[][] rowBufferArray;
+    private DataValueDescriptor[] rowBuffer;
+    private DataValueDescriptor[] lastUniqueKey;
+    private static final int GROUP_FETCH_SIZE = 16;
+    
     // Alter table compress and Drop column
     private     boolean					    doneScan;
     private     boolean[]				    needToDropSort;
@@ -170,6 +199,12 @@
 	 *  @param purge				PURGE during INPLACE COMPRESS?
 	 *  @param defragment			DEFRAGMENT during INPLACE COMPRESS?
 	 *  @param truncateEndOfTable	TRUNCATE END during INPLACE COMPRESS?
+	 *  @param updateStatistics		TRUE means we are here to update statistics
+	 *  @param updateStatisticsAll	TRUE means we are here to update statistics
+	 *  	of all the indexes. False means we are here to update statistics of
+	 *  	only one index.
+	 *  @param indexNameForUpdateStatistics	Will name the index whose statistics
+	 *  	will be updated
 	 */
 	AlterTableConstantAction(
     SchemaDescriptor            sd,
@@ -186,7 +221,10 @@
     boolean                     truncateTable,
     boolean                     purge,
     boolean                     defragment,
-    boolean                     truncateEndOfTable)
+    boolean                     truncateEndOfTable,
+    boolean                     updateStatistics,
+    boolean                     updateStatisticsAll,
+    String	                    indexNameForUpdateStatistics)
 	{
 		super(tableId);
 		this.sd                     = sd;
@@ -203,6 +241,9 @@
 		this.purge          		= purge;
 		this.defragment          	= defragment;
 		this.truncateEndOfTable     = truncateEndOfTable;
+		this.updateStatistics     	= updateStatistics;
+		this.updateStatisticsAll    = updateStatisticsAll;
+		this.indexNameForUpdateStatistics = indexNameForUpdateStatistics;
 
 		if (SanityManager.DEBUG)
 		{
@@ -277,6 +318,10 @@
 			}
 		}
 
+		if (updateStatistics)
+		{
+			updateStatistics(activation);
+		}
 		/*
 		** Inform the data dictionary that we are about to write to it.
 		** There are several calls to data dictionary "get" methods here
@@ -580,6 +625,204 @@
 		}
 	}
 
+	/**
+	 * Update statistics of either all the indexes on the table or only one
+	 * specific index depending on what user has requested.
+	 * 
+	 * @param   activation  the current activation
+	 * @throws StandardException
+	 */
+	private void updateStatistics(Activation activation)
+	throws StandardException
+	{
+		LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
+		DataDictionary dd = lcc.getDataDictionary();
+		TransactionController tc = lcc.getTransactionCompile();
+		ConglomerateDescriptor[] cds;
+		long[] conglomerateNumber;
+		ExecIndexRow[] indexRow;
+		UUID[] objectUUID;
+		GroupFetchScanController gsc;
+		DependencyManager dm = dd.getDependencyManager();
+
+		td = dd.getTableDescriptor(tableId);
+		if (updateStatisticsAll)
+		{
+			cds = td.getConglomerateDescriptors();
+		}
+		else
+		{
+			cds = new ConglomerateDescriptor[1];
+			cds[0] = dd.getConglomerateDescriptor(indexNameForUpdateStatistics, sd, false);
+		}
+
+		conglomerateNumber = new long[cds.length];
+		indexRow = new ExecIndexRow[cds.length];
+		objectUUID = new UUID[cds.length];
+		ConglomerateController heapCC =
+			tc.openConglomerate(td.getHeapConglomerateId(), false, 0,
+					TransactionController.MODE_RECORD,
+					TransactionController.ISOLATION_REPEATABLE_READ);
+
+		//= null;
+		try
+		{
+/*			 heapCC = 
+				tc.openConglomerate(td.getHeapConglomerateId(), false, 0,
+					TransactionController.MODE_RECORD,
+					TransactionController.ISOLATION_REPEATABLE_READ);*/
+
+			for (int i = 0; i < cds.length; i++)
+			{
+				if (!cds[i].isIndex())
+				{
+					conglomerateNumber[i] = -1;
+					continue;
+				}
+
+				conglomerateNumber[i] = cds[i].getConglomerateNumber();
+
+				objectUUID[i] = cds[i].getUUID();
+
+				indexRow[i] =
+					cds[i].getIndexDescriptor().getNullIndexRow(
+						td.getColumnDescriptorList(),
+						heapCC.newRowLocationTemplate());
+			}
+		}
+		finally
+		{
+//			if (heapCC != null)
+				heapCC.close();
+		}
+
+		dd.startWriting(lcc);
+
+		dm.invalidateFor(td, DependencyManager.UPDATE_STATISTICS, lcc);
+
+		for (int indexNumber = 0; indexNumber < conglomerateNumber.length;
+			 indexNumber++)
+		{
+			if (conglomerateNumber[indexNumber] == -1)
+				continue;
+
+			int numCols = indexRow[indexNumber].nColumns() - 1;
+			long[] cardinality = new long[numCols];
+			long numRows = 0;
+			initializeRowBuffers(indexRow[indexNumber]);
+
+			/* Read uncommited, with record locking. Actually CS store may
+			   not hold record locks */
+			gsc = 
+				tc.openGroupFetchScan(
+						conglomerateNumber[indexNumber],
+						false,  // hold
+						0,      // openMode: for read
+						TransactionController.MODE_RECORD, // locking
+						TransactionController.ISOLATION_READ_UNCOMMITTED, //isolation level
+						null,   // scancolumnlist-- want everything.
+						null,   // startkeyvalue-- start from the beginning.
+						0,
+						null,   // qualifiers, none!
+						null,   // stopkeyvalue,
+						0);
+
+			try
+			{
+				boolean firstRow = true;
+				int rowsFetched = 0;
+				while ((rowsFetched = gsc.fetchNextGroup(rowBufferArray, null)) > 0)
+				{
+					for (int i = 0; i < rowsFetched; i++)
+					{
+						int whichPositionChanged = compareWithPrevKey(i, firstRow);
+						firstRow = false;
+						if (whichPositionChanged >= 0)
+						{
+							for (int j = whichPositionChanged; j < cardinality.length; j++)
+								cardinality[j]++;
+						}
+						numRows++;
+					}
+
+					DataValueDescriptor[] tmp;
+					tmp = rowBufferArray[GROUP_FETCH_SIZE - 1];
+					rowBufferArray[GROUP_FETCH_SIZE - 1] = lastUniqueKey;
+					lastUniqueKey = tmp;
+				} // while
+			} // try
+			finally
+			{
+//				if (gsc != null)
+				{
+					gsc.close();
+					gsc = null;
+				}
+			}
+
+			if (numRows == 0)
+			{
+				/* if there is no data in the table: no need to write anything
+				 * to sys.systatstics.
+				 */
+				break;			
+			}
+
+			StatisticsDescriptor statDesc;
+
+			dd.dropStatisticsDescriptors(tableId, objectUUID[indexNumber],
+										 tc);
+
+			for (int i = 0; i < indexRow[indexNumber].nColumns() - 1; i++)
+			{
+				statDesc = new StatisticsDescriptor(dd, dd.getUUIDFactory().createUUID(),
+						objectUUID[indexNumber],
+						tableId,
+						"I",
+						new StatisticsImpl(numRows,
+								cardinality[i]),
+								i + 1);
+				dd.addDescriptor(statDesc, null,
+						DataDictionary.SYSSTATISTICS_CATALOG_NUM,
+								 true, tc);
+			} // for each leading column (c1) (c1,c2)....
+
+		} // for each index.
+	}
+
+	private void initializeRowBuffers(ExecIndexRow ir)
+	{
+
+		rowBufferArray = new DataValueDescriptor[GROUP_FETCH_SIZE][];
+		lastUniqueKey = ir.getRowArrayClone();
+		rowBufferArray[0] = ir.getRowArray(); // 1 gets old objects.
+	}
+
+  	private int compareWithPrevKey(int index, boolean firstRow)
+  		throws StandardException
+  	{
+  		if (firstRow)
+  			return 0;
+
+  		DataValueDescriptor[] prev = (index == 0) ? lastUniqueKey : rowBufferArray[index - 1];
+  		DataValueDescriptor[] curr = rowBufferArray[index];
+  		// no point trying to do rowlocation; hence - 1
+  		for (int i = 0; i < (prev.length - 1); i++)
+  		{
+			DataValueDescriptor dvd = (DataValueDescriptor)prev[i];
+
+			if (dvd.isNull())
+				return i;// nulls are counted as unique values.
+
+  			if (prev[i].compare(curr[i]) != 0)
+  			{
+  				return i;
+  			}
+  		}
+
+  		return -1;
+  	}
+
     /**
      * Truncate end of conglomerate.
      * <p>
@@ -1674,7 +1917,7 @@
 		} 
 		// else we are simply changing the default value
 	}
-
+	
     /**
      * routine to process compress table or ALTER TABLE <t> DROP COLUMN <c>;
      * <p>

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java?rev=677998&r1=677997&r2=677998&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java Fri Jul 18 11:53:22 2008
@@ -131,6 +131,13 @@
 	 *  @param purge				PURGE during INPLACE COMPRESS?
 	 *  @param defragment			DEFRAGMENT during INPLACE COMPRESS?
 	 *  @param truncateEndOfTable	TRUNCATE END during INPLACE COMPRESS?
+	 *  @param updateStatistics		TRUE means we are here to update statistics
+	 *  @param updateStatisticsAll	TRUE means we are here to update statistics
+	 *  	of all the indexes. False means we are here to update statistics of
+	 *  	only one index.
+	 *  @param indexNameForUpdateStatistics	Will name the index whose statistics
+	 *  	will be updated. This param is looked at only if updateStatisticsAll
+	 *  	is set to false.
 	 */
 	public	ConstantAction	getAlterTableConstantAction
 	(
@@ -149,14 +156,20 @@
 		boolean                     truncateTable,
 		boolean						purge,
 		boolean						defragment,
-		boolean						truncateEndOfTable 
+		boolean						truncateEndOfTable,
+		boolean						updateStatistics,
+		boolean						updateStatisticsAll,
+		String						indexNameForUpdateStatistics
     )
 	{
 		return new	AlterTableConstantAction( sd, tableName, tableId, tableConglomerateId, 
 											  tableType, columnInfo, constraintActions, 
 											  lockGranularity, compressTable,
 											  behavior, sequential, truncateTable,
-											  purge, defragment, truncateEndOfTable);
+											  purge, defragment, truncateEndOfTable,
+											  updateStatistics, 
+											  updateStatisticsAll,
+											  indexNameForUpdateStatistics);
 	}
 
 	/**
@@ -946,39 +959,6 @@
 	{
 		return new DropTriggerConstantAction(sd, triggerName, tableId);
 	}
-	
-	/**
-	 * Make the constant action for a UPDATE STATISTICS statement.
-	 *
-	 * @param forTable		whether for an index or table.
-	 * @param objectName	name of the object (either table or index) for which
-	 * this statistic is being created.
-	 * @param tableUUID		UUID of the table for which statistics are being
-	 * created.
-	 * @param objectUUID    array of UUID's, one for each index conglomerate for
-	 * which statistics are being created. 
-	 * @param conglomerateNumber array of conglomerate numbers, one for each
-	 * index conglomerate for which statistics are being created.
-	 * @param indexRow		array of index rows, one for each index. This row is
-	 * used by the constant action to read data from the indices.
-	 */
-	public ConstantAction getUpdateStatisticsConstantAction
-	(
-	 boolean forTable,
-	 String objectName,
-	 UUID tableUUID,
-	 UUID[] objectUUID,
-	 long[] conglomerateNumber,
-	 ExecIndexRow[] indexRow
-	)
-	{
-		return new UpdateStatisticsConstantAction(forTable, 
-												  objectName,
-												  tableUUID,
-												  objectUUID,
-												  conglomerateNumber,
-												  indexRow);
-	}
 
 	/**
 	 * Make the constant action for Drop Statistics statement.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GrantRevokeDDLTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GrantRevokeDDLTest.java?rev=677998&r1=677997&r2=677998&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GrantRevokeDDLTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GrantRevokeDDLTest.java Fri Jul 18 11:53:22 2008
@@ -1033,6 +1033,11 @@
         JDBC.assertColumnNames(rs, expColNames);
         
         JDBC.assertDrainResults(rs, 1);
+
+        cSt = samConnection.prepareCall(
+            " call SYSCS_UTIL.SYSCS_UPDATE_STATISTICS('SAM','SAMTABLE',null)");
+        assertUpdateCount(cSt, 0);
+        cSt.close();
         
         cSt = samConnection.prepareCall(
             " call SYSCS_UTIL.SYSCS_COMPRESS_TABLE('SAM', 'SAMTABLE', 1)");
@@ -1059,6 +1064,12 @@
             + "'MYTAB', 1, 1, 1)");
         assertStatementError("38000", cSt);
         cSt.close();
+
+        // Try updating statistics of table not owned.
+        cSt = samConnection.prepareCall(
+        " call SYSCS_UTIL.SYSCS_UPDATE_STATISTICS('SWIPER','MYTAB',null)");
+        assertStatementError("38000", cSt);
+        cSt.close();
         
         // Try other system routines. All should fail
         
@@ -7127,7 +7138,7 @@
         expColNames = new String [] {"COLPERMSID", "GRANTEE", "GRANTOR", "TABLEID", "TYPE", "COLUMNS"};
         JDBC.assertColumnNames(rs, expColNames);
         JDBC.assertDrainResults(rs, 0);
-        
+
         rs = st_user1.executeQuery(
             " select GRANTEE, GRANTOR, GRANTOPTION from sys.sysroutineperms");
         
@@ -7140,6 +7151,7 @@
             {"PUBLIC", "TEST_DBO", "N"},
             {"PUBLIC", "TEST_DBO", "N"},
             {"PUBLIC", "TEST_DBO", "N"},
+            {"PUBLIC", "TEST_DBO", "N"},
             {"PUBLIC", "TEST_DBO", "N"}
         };
         
@@ -7171,7 +7183,7 @@
         expColNames = new String [] {"COLPERMSID", "GRANTEE", "GRANTOR", "TABLEID", "TYPE", "COLUMNS"};
         JDBC.assertColumnNames(rs, expColNames);
         JDBC.assertDrainResults(rs, 0);
-        
+
         rs = st_user1.executeQuery(
             " select GRANTEE, GRANTOR, GRANTOPTION from sys.sysroutineperms");
         
@@ -7185,6 +7197,7 @@
             {"PUBLIC", "TEST_DBO", "N"},
             {"PUBLIC", "TEST_DBO", "N"},
             {"PUBLIC", "TEST_DBO", "N"},
+            {"PUBLIC", "TEST_DBO", "N"},
             {"USER2", "USER1", "N"}
         };
         

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesTest.java?rev=677998&r1=677997&r2=677998&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesTest.java Fri Jul 18 11:53:22 2008
@@ -577,9 +577,9 @@
 
         assertSysColPermsRowCount(0, 2, 2);
 
-        assertSysRoutinePermsRowCount(5, // 5 pre-existing grants to PUBLIC
-                                      6,
-                                      6);
+        assertSysRoutinePermsRowCount(6, // 5 pre-existing grants to PUBLIC
+                                      7,
+                                      7);
 
         /*
          * DROP ROLE
@@ -607,12 +607,12 @@
                                   // to admin is de facto to a user
                                   // named admin:
                                   2);
-        assertSysRoutinePermsRowCount(5, 5,
+        assertSysRoutinePermsRowCount(6, 6,
                                       //  nonDbo run: role admin
                                       // has been dropped, so this
                                       // run's grant to admin is de
                                       // facto to a user named admin:
-                                      6);
+                                      7);
 
         doStmt("drop role \"NONE\"",
                sqlAuthorizationRequired, null , roleDboOnly);
@@ -634,7 +634,7 @@
                                     1,
                                     0);
         assertSysColPermsRowCount(0,0,0);
-        assertSysRoutinePermsRowCount(5,5,5);
+        assertSysRoutinePermsRowCount(6,6,6);
 
         // roles foo and bar survive to nonDbo run and beyond:
         assertSysRolesRowCount(0, 4, 4);

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdateStatisticsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdateStatisticsTest.java?rev=677998&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdateStatisticsTest.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdateStatisticsTest.java Fri Jul 18 11:53:22 2008
@@ -0,0 +1,107 @@
+/*
+ * Class org.apache.derbyTesting.functionTests.tests.lang.UpdateStatisticsTest
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.derbyTesting.functionTests.tests.lang;
+
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.ResultSet;
+import junit.framework.Test;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+/**
+ * Tests for updating the statistics of one index or all the indexes on a
+ * table DERBY-269.
+ */
+public class UpdateStatisticsTest extends BaseJDBCTestCase {
+
+    public UpdateStatisticsTest(String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+        return TestConfiguration.defaultSuite(UpdateStatisticsTest.class);
+    }
+
+    /**
+     * Test for update statistics
+     */
+    public void testUpdateStatistics() throws SQLException {
+        Statement s = createStatement();
+        //following should fail because table APP.T1 does not exist
+        assertStatementError("42Y55", s, 
+            "CALL SYSCS_UTIL.SYSCS_UPDATE_STATISTICS('APP','T1',null)");
+        s.execute("CREATE TABLE t1 (c11 int, c12 varchar(128))");
+        //following will pass now because we have created APP.T1
+        s.execute("CALL SYSCS_UTIL.SYSCS_UPDATE_STATISTICS('APP','T1',null)");
+        //following should fail because index I1 does not exist on table APP.T1
+        assertStatementError("42X65", s, 
+            "CALL SYSCS_UTIL.SYSCS_UPDATE_STATISTICS('APP','T1','I1')");
+        s.execute("CREATE INDEX i1 on t1(c12)");
+        //following will pass now because we have created index I1 on APP.T1
+        s.execute("CALL SYSCS_UTIL.SYSCS_UPDATE_STATISTICS('APP','T1','I1')");
+
+        //The following set of subtest will ensure that when an index is
+        //created on a table when there is no data in the table, then Derby
+        //will not generate a row for it in sysstatistics table. If the index
+        //is created after the table has data on it, there will be a row for
+        //it in sysstatistics table. In order to generate statistics for the
+        //first index, users can run the stored procedure 
+        //SYSCS_UPDATE_STATISTICS
+        //So far the table t1 is empty and we have already created index I1 on 
+        //it. Since three was no data in the table when index I1 was created,
+        //there will be no row in sysstatistics table
+        ResultSet rs = s.executeQuery("SELECT * FROM SYS.SYSSTATISTICS");
+        JDBC.assertEmpty(rs);
+        //Now insert some data into t1 and then create a new index on the 
+        //table. This will cause sysstatistics table to have one row for this
+        //new index. Old index will still not have a row for it in
+        //sysstatistics table
+        s.executeUpdate("INSERT INTO T1 VALUES(1,'a'),(2,'b'),(3,'c'),(4,'d')");
+        s.execute("CREATE INDEX i2 on t1(c11)");
+        rs = s.executeQuery("SELECT * FROM SYS.SYSSTATISTICS");
+        JDBC.assertDrainResults(rs, 1);
+        //Now update the statistics for the old index I1 using the new stored
+        //procedure. Doing this should add a row for it in sysstatistics table
+        s.execute("CALL SYSCS_UTIL.SYSCS_UPDATE_STATISTICS('APP','T1','I1')");
+        rs = s.executeQuery("SELECT * FROM SYS.SYSSTATISTICS");
+        JDBC.assertDrainResults(rs, 2);
+
+        //calls to system procedure for update statisitcs is internally
+        //converted into ALTER TABLE ... sql but that generated sql format
+        //is not available to end user to issue directly. Write a test case
+        //for that sql syntax
+        assertStatementError("42X01", s, 
+            "ALTER TABLE APP.T1 ALL UPDATE STATISTICS");
+        assertStatementError("42X01", s, 
+            "ALTER TABLE APP.T1 UPDATE STATISTICS I1");
+
+        //Try update statistics on global temporary table
+		s.executeUpdate("declare global temporary table SESSION.t1(c11 int, c12 int) on commit delete rows not logged");
+		s.executeUpdate("insert into session.t1 values(11, 1)");
+        //following should fail because update statistics can't be issued on
+		//global temporary tables
+        assertStatementError("42995", s, 
+            "CALL SYSCS_UTIL.SYSCS_UPDATE_STATISTICS('SESSION','T1',null)");
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdateStatisticsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java?rev=677998&r1=677997&r2=677998&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java Fri Jul 18 11:53:22 2008
@@ -169,10 +169,11 @@
         
         suite.addTest(BigDataTest.suite());
         suite.addTest(MixedCaseExpressionTest.suite());
+        suite.addTest(UpdateStatisticsTest.suite());
         suite.addTest(MiscErrorsTest.suite());
         suite.addTest(ArithmeticTest.suite());
         suite.addTest(ConstantExpressionTest.suite());
-        
+
         return suite;
 	}
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_2.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_2.java?rev=677998&r1=677997&r2=677998&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_2.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_2.java Fri Jul 18 11:53:22 2008
@@ -335,7 +335,8 @@
                     {"SYSCS_GET_RUNTIMESTATISTICS"},
                     {"SYSCS_INPLACE_COMPRESS_TABLE"},
                     {"SYSCS_SET_RUNTIMESTATISTICS"},
-                    {"SYSCS_SET_STATISTICS_TIMING"}}
+                    {"SYSCS_SET_STATISTICS_TIMING"},
+                    {"SYSCS_UPDATE_STATISTICS"}}
                     );
 
             rs.close();

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_5.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_5.java?rev=677998&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_5.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_5.java Fri Jul 18 11:53:22 2008
@@ -0,0 +1,111 @@
+/*
+
+Derby - Class org.apache.derbyTesting.functionTests.tests.upgradeTests.Changes10_5
+
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+*/
+package org.apache.derbyTesting.functionTests.tests.upgradeTests;
+
+import org.apache.derbyTesting.junit.SupportFilesSetup;
+
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Upgrade test cases for 10.5.
+ * If the old version is 10.5 or later then these tests
+ * will not be run.
+ * <BR>
+    10.5 Upgrade issues
+
+    <UL>
+    <LI> testUpdateStatisticsProcdure - DERBY-269
+    Make sure that SYSCS_UTIL.SYSCS_UPDATE_STATISTICS can only be run in Derby
+    10.5 and higher.
+    </UL>
+
+ */
+public class Changes10_5 extends UpgradeChange {
+
+    public Changes10_5(String name) {
+        super(name);
+    }
+
+    /**
+     * Return the suite of tests to test the changes made in 10.5.
+     * @param phase an integer that indicates the current phase in
+     *              the upgrade test.
+     * @return the test suite created.
+     */
+    public static Test suite(int phase) {
+        TestSuite suite = new TestSuite("Upgrade test for 10.5");
+
+        suite.addTestSuite(Changes10_5.class);
+        return new SupportFilesSetup((Test) suite);
+    }
+
+    /**
+     * Make sure that SYSCS_UTIL.SYSCS_UPDATE_STATISTICS can only be run in 
+     * Derby 10.5 and higher. 
+     * DERBY-269
+     * Test added for 10.5.
+     * @throws SQLException
+     *
+     */
+    public void testUpdateStatisticsProcdure() throws SQLException
+    {
+    	Statement s;
+        switch (getPhase())
+        {
+        case PH_CREATE:
+            s = createStatement();
+            s.execute("CREATE TABLE DERBY_269(c11 int, c12 char(20))");
+            s.execute("INSERT INTO DERBY_269 VALUES(1, 'DERBY-269')");
+            s.execute("CREATE INDEX I1 ON DERBY_269(c12)");
+            s.close();
+            break;
+
+        case PH_SOFT_UPGRADE:
+        case PH_POST_SOFT_UPGRADE:
+            // new update statistics procedure should not be found
+            // on soft-upgrade.
+            s = createStatement();
+            assertStatementError("42Y03", s,
+                    "call SYSCS_UTIL.SYSCS_UPDATE_STATISTICS" +
+                    "('APP', 'DERBY_269', null)");
+            assertStatementError("42Y03", s,
+                    "call SYSCS_UTIL.SYSCS_UPDATE_STATISTICS" +
+                    "('APP', 'DERBY_269', 'I1')");
+            s.close();
+            break;
+
+        case PH_HARD_UPGRADE:
+        	//We are at Derby 10.5 release and hence should find the
+        	//update statistics procedure
+            s = createStatement();
+            s.execute("call SYSCS_UTIL.SYSCS_UPDATE_STATISTICS" +
+            		"('APP', 'DERBY_269', null)");
+            s.execute("call SYSCS_UTIL.SYSCS_UPDATE_STATISTICS" +
+            		"('APP', 'DERBY_269', 'I1')");
+            s.close();
+            break;
+        }
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_5.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java?rev=677998&r1=677997&r2=677998&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java Fri Jul 18 11:53:22 2008
@@ -222,6 +222,8 @@
                 }
                 if (oldMinor < 4)
                 	suite.addTest(Changes10_4.suite(phase));
+                if (oldMinor < 5)
+                	suite.addTest(Changes10_5.suite(phase));
             }
             
             // Add DatabaseMetaData tests. Since metadata

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/_Suite.java?rev=677998&r1=677997&r2=677998&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/_Suite.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/_Suite.java Fri Jul 18 11:53:22 2008
@@ -115,6 +115,7 @@
         {10, 2, 1, 6}, // 10.2.1.6 (Oct 02, 2006 / SVN 452058)
         {10, 2, 2, 0}, // 10.2.2.0 (Dec 12, 2006 / SVN 485682)
         {10, 3, 1, 4}, // 10.3.1.4 (Aug 1, 2007 / SVN 561794)
+        {10, 4, 1, 3}, // 10.4.1.3 (April 24, 2008 / SVN 648739)
     };
 
     /**



Mime
View raw message