mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	If an index depends on no columns of its table, give it a dependency on the
whole table instead, to ensure that it goes away when the table is dropped. Per bug #3723 from Sam Mason. Backpatch as far as 7.4; AFAICT 7.3 does not have the issue, because it doesn't have general-purpose expression indexes and so there must be at least one column referenced by an index.
This commit is contained in:
		@@ -8,7 +8,7 @@
 | 
				
			|||||||
 *
 | 
					 *
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * IDENTIFICATION
 | 
					 * IDENTIFICATION
 | 
				
			||||||
 *	  $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.261.2.2 2006/03/24 23:02:23 tgl Exp $
 | 
					 *	  $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.261.2.3 2007/11/08 23:23:07 tgl Exp $
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * INTERFACE ROUTINES
 | 
					 * INTERFACE ROUTINES
 | 
				
			||||||
@@ -37,6 +37,7 @@
 | 
				
			|||||||
#include "executor/executor.h"
 | 
					#include "executor/executor.h"
 | 
				
			||||||
#include "miscadmin.h"
 | 
					#include "miscadmin.h"
 | 
				
			||||||
#include "optimizer/clauses.h"
 | 
					#include "optimizer/clauses.h"
 | 
				
			||||||
 | 
					#include "optimizer/var.h"
 | 
				
			||||||
#include "parser/parse_expr.h"
 | 
					#include "parser/parse_expr.h"
 | 
				
			||||||
#include "storage/procarray.h"
 | 
					#include "storage/procarray.h"
 | 
				
			||||||
#include "storage/smgr.h"
 | 
					#include "storage/smgr.h"
 | 
				
			||||||
@@ -667,6 +668,8 @@ index_create(Oid heapRelationId,
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
 | 
								bool	have_simple_col = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			/* Create auto dependencies on simply-referenced columns */
 | 
								/* Create auto dependencies on simply-referenced columns */
 | 
				
			||||||
			for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
 | 
								for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
@@ -677,8 +680,29 @@ index_create(Oid heapRelationId,
 | 
				
			|||||||
					referenced.objectSubId = indexInfo->ii_KeyAttrNumbers[i];
 | 
										referenced.objectSubId = indexInfo->ii_KeyAttrNumbers[i];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					recordDependencyOn(&myself, &referenced, DEPENDENCY_AUTO);
 | 
										recordDependencyOn(&myself, &referenced, DEPENDENCY_AUTO);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										have_simple_col = true;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								/*
 | 
				
			||||||
 | 
								 * It's possible for an index to not depend on any columns of
 | 
				
			||||||
 | 
								 * the table at all, in which case we need to give it a dependency
 | 
				
			||||||
 | 
								 * on the table as a whole; else it won't get dropped when the
 | 
				
			||||||
 | 
								 * table is dropped.  This edge case is not totally useless;
 | 
				
			||||||
 | 
								 * for example, a unique index on a constant expression can serve
 | 
				
			||||||
 | 
								 * to prevent a table from containing more than one row.
 | 
				
			||||||
 | 
								 */
 | 
				
			||||||
 | 
								if (!have_simple_col &&
 | 
				
			||||||
 | 
									!contain_vars_of_level((Node *) indexInfo->ii_Expressions, 0) &&
 | 
				
			||||||
 | 
									!contain_vars_of_level((Node *) indexInfo->ii_Predicate, 0))
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									referenced.classId = RelationRelationId;
 | 
				
			||||||
 | 
									referenced.objectId = heapRelationId;
 | 
				
			||||||
 | 
									referenced.objectSubId = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									recordDependencyOn(&myself, &referenced, DEPENDENCY_AUTO);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* Store dependency on operator classes */
 | 
							/* Store dependency on operator classes */
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user