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 dj...@apache.org on 2007/03/14 22:51:33 UTC

svn commit: r518343 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/sql/dictionary/ impl/sql/compile/ impl/sql/execute/

Author: djd
Date: Wed Mar 14 14:51:31 2007
New Revision: 518343

URL: http://svn.apache.org/viewvc?view=rev&rev=518343
Log:
DERBY-2397 (refactor) Move drop code for ConglomerateDescriptor into ConglomerateDescriptor.drop().
Add various comments from information gained while refactoring code and minor cleanup.
One more dropping of a ConglomerateDescriptor needs to be modified to use the drop() method
but requires some cleanup for DERBY-1343

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ConglomerateDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateIndexNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
    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/CreateConstraintConstantAction.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateIndexConstantAction.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropIndexConstantAction.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ConglomerateDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ConglomerateDescriptor.java?view=diff&rev=518343&r1=518342&r2=518343
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ConglomerateDescriptor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ConglomerateDescriptor.java Wed Mar 14 14:51:31 2007
@@ -21,12 +21,16 @@
 
 package org.apache.derby.iapi.sql.dictionary;
 
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
+import org.apache.derby.iapi.sql.depend.DependencyManager;
 import org.apache.derby.iapi.sql.depend.Provider;
 
 import org.apache.derby.catalog.UUID;
+import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.services.sanity.SanityManager;
 import org.apache.derby.iapi.sql.StatementType;
+import org.apache.derby.iapi.store.access.TransactionController;
 import org.apache.derby.catalog.DependableFinder;
 import org.apache.derby.catalog.Dependable;
 import org.apache.derby.iapi.services.io.StoredFormatIds;
@@ -37,12 +41,19 @@
 /**
  * The ConglomerateDescriptor class is used to get information about
  * conglomerates for the purpose of optimization.
+ * 
+ * A ConglomerateDescriptor can map to a base table, an index
+ * or a index backing a constraint. Multiple ConglomerateDescriptors
+ * can map to a single underlying store conglomerate, such as when
+ * multiple index definitions share a physical file.
  *
  * NOTE: The language module does not have to know much about conglomerates
  * with this architecture. To get the cost of using a conglomerate, all it
  * has to do is pass the ConglomerateDescriptor to the access methods, along
  * with the predicate. What the access methods need from a
  * ConglomerateDescriptor remains to be seen.
+ * 
+ * 
  *
  * @version 0.1
  */
@@ -53,7 +64,7 @@
 	// Implementation
 	private long	conglomerateNumber;
 	private String	name;
-	private String[]	columnNames;
+	private transient String[]	columnNames;
 	private final boolean	indexable;
 	private final boolean	forConstraint;
 	private final IndexRowGenerator	indexRowGenerator;
@@ -330,5 +341,38 @@
 
 	/** @see TupleDescriptor#getDescriptorName */
 	public String getDescriptorName() { return name; }
+    
+	public void drop(LanguageConnectionContext lcc,
+	        TableDescriptor td)
+	throws StandardException
+	{     
+        DataDictionary dd = getDataDictionary();
+        DependencyManager dm = dd.getDependencyManager();
+        TransactionController tc = lcc.getTransactionExecute();
+        
+        // invalidate any prepared statements that
+        // depended on the index (including this one)
+        dm.invalidateFor(this, DependencyManager.DROP_INDEX, lcc);
+	    
+        // only drop the conglomerate if no similar index but with different
+	    // name. Get from dd in case we drop other dup indexes with a cascade operation	    
+	    if (dd.getConglomerateDescriptors(getConglomerateNumber()).length == 1)
+	    {
+	        /* Drop statistics */
+	        dd.dropStatisticsDescriptors(td.getUUID(), getUUID(), tc);
+	        
+	        /* Drop the conglomerate */
+	        tc.dropConglomerate(getConglomerateNumber());
+        }	    
+	    
+	    /* Drop the conglomerate descriptor */
+	    dd.dropConglomerateDescriptor(this, tc);
+	    
+	    /* 
+	     ** Remove the conglomerate descriptor from the list hanging off of the
+	     ** table descriptor
+	     */
+	    td.removeConglomerateDescriptor(this);
+	}
 	
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateIndexNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateIndexNode.java?view=diff&rev=518343&r1=518342&r2=518343
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateIndexNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateIndexNode.java Wed Mar 14 14:51:31 2007
@@ -244,7 +244,6 @@
 	 */
 	public ConstantAction	makeConstantAction() throws StandardException
 	{
-        long 					conglomId = 0;
 		SchemaDescriptor		sd = getSchemaDescriptor();
 
 		int columnCount = columnNames.length;
@@ -295,7 +294,6 @@
 											  indexName.getTableName(),
 											  tableName.getTableName(),
 											  td.getUUID(),
-											  conglomId,
 											  columnNames,
 											  isAscending,
 											  false,

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java?view=diff&rev=518343&r1=518342&r2=518343
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java Wed Mar 14 14:51:31 2007
@@ -775,7 +775,6 @@
 									indexName,
 									tableName,
 									((td != null) ? td.getUUID() : (UUID) null),
-									0, // conglomId
 									columnNames,
 									isAscending,
 									isConstraint,

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?view=diff&rev=518343&r1=518342&r2=518343
==============================================================================
--- 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 Wed Mar 14 14:51:31 2007
@@ -1649,7 +1649,7 @@
 					 */
 					ConglomerateDescriptor cd = td.getConglomerateDescriptor
 												(indexConglomerateNumbers[i]);
-					DropIndexConstantAction.dropIndex(dm, dd, tc, cd, td, activation.getLanguageConnectionContext());
+					cd.drop(activation.getLanguageConnectionContext(), td);
 
 					compressIRGs[i] = null;		// mark it
 					continue;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateConstraintConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateConstraintConstantAction.java?view=diff&rev=518343&r1=518342&r2=518343
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateConstraintConstantAction.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateConstraintConstantAction.java Wed Mar 14 14:51:31 2007
@@ -127,7 +127,26 @@
 
 	/**
 	 *	This is the guts of the Execution-time logic for CREATE CONSTRAINT.
-	 *
+	 *  <P>
+	 *  A constraint is represented as:
+	 *  <UL>
+	 *  <LI> ConstraintDescriptor.
+	 *  </UL>
+	 *  If a backing index is required then the index will
+	 *  be created through an CreateIndexConstantAction setup
+	 *  by the compiler.
+	 *  <BR>
+	 *  Dependencies are created as:
+	 *  <UL>
+	 *  <LI> ConstraintDescriptor depends on all the providers collected
+     *  at compile time and passed into the constructor.
+	 *  <LI> For a FOREIGN KEY constraint ConstraintDescriptor depends
+     *  on the ConstraintDescriptor for the referenced constraints
+     *  and the privileges required to create the constraint.
+	 *  </UL>
+
+	 *  @see ConstraintDescriptor
+	 *  @see CreateIndexConstantAction
 	 *	@see ConstantAction#executeConstantAction
 	 *
 	 * @exception StandardException		Thrown on failure
@@ -214,7 +233,7 @@
 		 * constraint's name, if no name was specified.
 		 */
 		UUIDFactory uuidFactory = dd.getUUIDFactory();
-
+        
 		/* Create the index, if there's one for this constraint */
 		if (indexAction != null)
 		{
@@ -226,6 +245,7 @@
 			}
 			else { backingIndexName = indexAction.getIndexName(); }
 
+
 			/* Create the index */
 			indexAction.executeConstantAction(activation);
 
@@ -259,10 +279,6 @@
 			indexId = conglomDesc.getUUID();
 		}
 
-		// if no constraintId was specified, we should generate one. this handles
-		// the two cases of Source creation and Target replication. At the source
-		// database, we allocate a new UUID. At the Target, we just use the UUID that
-		// the Source sent along.
 		UUID constraintId = uuidFactory.createUUID();
 
 		/* Now, lets create the constraint descriptor */
@@ -417,7 +433,7 @@
 	 *
 	 * @return true/false
 	 */
-	public boolean isForeignKeyConstraint()
+	boolean isForeignKeyConstraint()
 	{ 
 		return (constraintType == DataDictionary.FOREIGNKEY_CONSTRAINT);
 	}
@@ -475,12 +491,6 @@
 	//
 	///////////////////////////////////////////////////////////////////////
 
-	/**
-	  *	Get the names of the columns touched by this constraint.
-	  *
-	  *	@return	the array of touched column names.
-	  */
-    public	String[]	getColumnNames() { return columnNames; }
 
 
 	/**
@@ -488,7 +498,7 @@
 	  *
 	  *	@return	constraint text
 	  */
-    public	String	getConstraintText() { return constraintText; }
+    String	getConstraintText() { return constraintText; }
 
 	public String toString()
 	{

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateIndexConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateIndexConstantAction.java?view=diff&rev=518343&r1=518342&r2=518343
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateIndexConstantAction.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateIndexConstantAction.java Wed Mar 14 14:51:31 2007
@@ -61,9 +61,9 @@
 import org.apache.derby.iapi.types.TypeId;
 
 /**
- *	This class  describes actions that are ALWAYS performed for a
- *	CREATE TABLE Statement at Execution time.
- *
+ * ConstantAction to create an index either through
+ * a CREATE INDEX statement or as a backing index to
+ * a constraint.
  */
 
 class CreateIndexConstantAction extends IndexConstantAction
@@ -71,7 +71,6 @@
 
 	private boolean			unique;
 	private String			indexType;
-	private long			conglomId;
 	private String[]		columnNames;
 	private boolean[]		isAscending;
 	private boolean			isConstraint;
@@ -83,7 +82,7 @@
 
 	// CONSTRUCTORS
 	/**
-	 *	Make the ConstantAction for a CREATE INDEX statement.
+	 *	Make the ConstantAction to create an index.
 	 *
 	 *  @param unique		True means it will be a unique index
 	 *  @param indexType	The type of index (BTREE, for example)
@@ -91,7 +90,6 @@
 	 *  @param indexName	Name of the index
 	 *  @param tableName	Name of table the index will be on
 	 *  @param tableId		UUID of table
-	 *  @param conglomId	Conglomerate ID of the index, if known in advance
 	 *  @param columnNames	Names of the columns in the index, in order
 	 *	@param isAscending	Array of booleans telling asc/desc on each column
 	 *  @param isConstraint	TRUE if index is backing up a constraint, else FALSE
@@ -105,7 +103,6 @@
 								String			indexName,
 								String			tableName,
 								UUID			tableId,
-								long			conglomId,
 								String[]		columnNames,
 								boolean[]		isAscending,
 								boolean			isConstraint,
@@ -115,7 +112,6 @@
 		super(tableId, indexName, tableName, schemaName);
 		this.unique = unique;
 		this.indexType = indexType;
-		this.conglomId= conglomId;
 		this.columnNames = columnNames;
 		this.isAscending = isAscending;
 		this.isConstraint = isConstraint;
@@ -140,8 +136,18 @@
 
 
 	/**
-	 *	This is the guts of the Execution-time logic for CREATE INDEX.
-	 *
+	 *	This is the guts of the Execution-time logic for 
+     *  creating an index.
+     *
+     *  <P>
+     *  A index is represented as:
+     *  <UL>
+     *  <LI> ConglomerateDescriptor.
+     *  </UL>
+     *  No dependencies are created.
+   	 *
+     *  @see ConglomerateDescriptor
+     *  @see SchemaDescriptor
 	 *	@see ConstantAction#executeConstantAction
 	 *
 	 * @exception StandardException		Thrown on failure
@@ -290,6 +296,7 @@
 		// check if we have similar indices already for this table
 		ConglomerateDescriptor[] congDescs = td.getConglomerateDescriptors();
 		boolean duplicate = false;
+        long conglomId = 0;
 
 		for (int i = 0; i < congDescs.length; i++)
 		{

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropIndexConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropIndexConstantAction.java?view=diff&rev=518343&r1=518342&r2=518343
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropIndexConstantAction.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropIndexConstantAction.java Wed Mar 14 14:51:31 2007
@@ -113,7 +113,6 @@
 
 		LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
 		DataDictionary dd = lcc.getDataDictionary();
-		DependencyManager dm = dd.getDependencyManager();
 		TransactionController tc = lcc.getTransactionExecute();
 
 		/*
@@ -172,13 +171,7 @@
 			throw StandardException.newException(SQLState.LANG_INDEX_NOT_FOUND_DURING_EXECUTION, fullIndexName);
 		}
 
-		/* Prepare all dependents to invalidate.  (This is there chance
-		 * to say that they can't be invalidated.)
-		 * We check for invalidation before we drop the conglomerate descriptor
-		 * since the conglomerate descriptor may be looked up as part of
-		 * decoding tuples in SYSDEPENDS.
-		 */
-		dropIndex(dm, dd, tc, cd, td, activation.getLanguageConnectionContext());
+		cd.drop(lcc, td);
 	}
 
 	public static void dropIndex(DependencyManager 	dm,

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?view=diff&rev=518343&r1=518342&r2=518343
==============================================================================
--- 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 Wed Mar 14 14:51:31 2007
@@ -198,7 +198,6 @@
 	 *  @param indexName	Name of the index
 	 *  @param tableName	Name of table the index will be on
 	 *	@param tableId		UUID of table.
-	 *  @param conglomId	Conglomerate ID of the index, if known in advance
 	 *  @param columnNames	Names of the columns in the index, in order
 	 *  @param isAscending	Array of booleans telling asc/desc on each column
 	 *  @param isConstraint	TRUE if index is backing up a constraint, else FALSE
@@ -213,7 +212,6 @@
 		String			indexName,
 		String			tableName,
 		UUID			tableId,
-		long			conglomId,
 		String[]		columnNames,
 		boolean[]		isAscending,
 		boolean			isConstraint,
@@ -223,7 +221,7 @@
 	{
 		return	new CreateIndexConstantAction
 			( unique, indexType, schemaName, indexName, tableName, tableId,
-			  conglomId, columnNames, isAscending, isConstraint,
+			  columnNames, isAscending, isConstraint,
 			  conglomerateUUID, properties );
 	}