1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* indexing.c
|
1997-09-07 07:04:48 +02:00
|
|
|
* This file contains routines to support indices defined on system
|
|
|
|
* catalogs.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2002-06-20 22:29:54 +02:00
|
|
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2002-07-22 22:23:19 +02:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.99 2002/07/22 20:23:19 petere Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-01-10 21:19:49 +01:00
|
|
|
|
1998-04-27 06:08:07 +02:00
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include "access/genam.h"
|
|
|
|
#include "access/heapam.h"
|
|
|
|
#include "catalog/catalog.h"
|
|
|
|
#include "catalog/catname.h"
|
|
|
|
#include "catalog/index.h"
|
|
|
|
#include "catalog/indexing.h"
|
2000-06-15 05:33:12 +02:00
|
|
|
#include "catalog/pg_index.h"
|
1998-04-27 06:08:07 +02:00
|
|
|
#include "miscadmin.h"
|
2000-05-28 19:56:29 +02:00
|
|
|
#include "utils/fmgroids.h"
|
1998-04-27 06:08:07 +02:00
|
|
|
#include "utils/syscache.h"
|
1996-11-04 00:27:08 +01:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
2001-06-12 07:55:50 +02:00
|
|
|
* Names of indices for each system catalog.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
|
1999-11-22 18:56:41 +01:00
|
|
|
char *Name_pg_aggregate_indices[Num_pg_aggregate_indices] =
|
2002-04-11 22:00:18 +02:00
|
|
|
{AggregateFnoidIndex};
|
1999-11-22 18:56:41 +01:00
|
|
|
char *Name_pg_am_indices[Num_pg_am_indices] =
|
2001-06-12 07:55:50 +02:00
|
|
|
{AmNameIndex, AmOidIndex};
|
1999-11-22 18:56:41 +01:00
|
|
|
char *Name_pg_amop_indices[Num_pg_amop_indices] =
|
2001-08-21 18:36:06 +02:00
|
|
|
{AccessMethodOperatorIndex, AccessMethodStrategyIndex};
|
2001-06-12 07:55:50 +02:00
|
|
|
char *Name_pg_amproc_indices[Num_pg_amproc_indices] =
|
2001-08-21 18:36:06 +02:00
|
|
|
{AccessMethodProcedureIndex};
|
1999-11-22 18:56:41 +01:00
|
|
|
char *Name_pg_attr_indices[Num_pg_attr_indices] =
|
2000-04-12 19:17:23 +02:00
|
|
|
{AttributeRelidNameIndex, AttributeRelidNumIndex};
|
1999-11-22 18:56:41 +01:00
|
|
|
char *Name_pg_attrdef_indices[Num_pg_attrdef_indices] =
|
2002-07-15 18:33:32 +02:00
|
|
|
{AttrDefaultIndex, AttrDefaultOidIndex};
|
2002-07-19 01:11:32 +02:00
|
|
|
char *Name_pg_cast_indices[Num_pg_cast_indices] =
|
2002-07-22 22:23:19 +02:00
|
|
|
{CastOidIndex, CastSourceTargetIndex};
|
1999-11-22 18:56:41 +01:00
|
|
|
char *Name_pg_class_indices[Num_pg_class_indices] =
|
2002-03-26 20:17:02 +01:00
|
|
|
{ClassNameNspIndex, ClassOidIndex};
|
2002-07-12 20:43:19 +02:00
|
|
|
char *Name_pg_constraint_indices[Num_pg_constraint_indices] =
|
|
|
|
{ConstraintNameNspIndex, ConstraintOidIndex, ConstraintRelidIndex};
|
2002-07-11 09:39:28 +02:00
|
|
|
char *Name_pg_conversion_indices[Num_pg_conversion_indices] =
|
2002-07-15 18:33:32 +02:00
|
|
|
{ConversionDefaultIndex, ConversionNameNspIndex, ConversionOidIndex};
|
2001-06-12 07:55:50 +02:00
|
|
|
char *Name_pg_database_indices[Num_pg_database_indices] =
|
|
|
|
{DatabaseNameIndex, DatabaseOidIndex};
|
2002-07-12 20:43:19 +02:00
|
|
|
char *Name_pg_depend_indices[Num_pg_depend_indices] =
|
|
|
|
{DependDependerIndex, DependReferenceIndex};
|
1999-11-22 18:56:41 +01:00
|
|
|
char *Name_pg_group_indices[Num_pg_group_indices] =
|
2000-04-12 19:17:23 +02:00
|
|
|
{GroupNameIndex, GroupSysidIndex};
|
1999-11-22 18:56:41 +01:00
|
|
|
char *Name_pg_index_indices[Num_pg_index_indices] =
|
2000-06-07 04:44:40 +02:00
|
|
|
{IndexRelidIndex, IndexIndrelidIndex};
|
1999-11-22 18:56:41 +01:00
|
|
|
char *Name_pg_inherits_indices[Num_pg_inherits_indices] =
|
2000-04-12 19:17:23 +02:00
|
|
|
{InheritsRelidSeqnoIndex};
|
1999-11-22 18:56:41 +01:00
|
|
|
char *Name_pg_language_indices[Num_pg_language_indices] =
|
2000-04-12 19:17:23 +02:00
|
|
|
{LanguageOidIndex, LanguageNameIndex};
|
2000-10-24 03:38:44 +02:00
|
|
|
char *Name_pg_largeobject_indices[Num_pg_largeobject_indices] =
|
|
|
|
{LargeObjectLOidPNIndex};
|
2002-03-22 22:34:44 +01:00
|
|
|
char *Name_pg_namespace_indices[Num_pg_namespace_indices] =
|
|
|
|
{NamespaceNameIndex, NamespaceOidIndex};
|
1999-11-22 18:56:41 +01:00
|
|
|
char *Name_pg_opclass_indices[Num_pg_opclass_indices] =
|
2002-04-17 22:57:57 +02:00
|
|
|
{OpclassAmNameNspIndex, OpclassOidIndex};
|
1999-11-22 18:56:41 +01:00
|
|
|
char *Name_pg_operator_indices[Num_pg_operator_indices] =
|
2002-04-17 01:08:12 +02:00
|
|
|
{OperatorOidIndex, OperatorNameNspIndex};
|
1999-11-22 18:56:41 +01:00
|
|
|
char *Name_pg_proc_indices[Num_pg_proc_indices] =
|
2002-04-05 02:31:36 +02:00
|
|
|
{ProcedureOidIndex, ProcedureNameNspIndex};
|
1999-11-22 18:56:41 +01:00
|
|
|
char *Name_pg_rewrite_indices[Num_pg_rewrite_indices] =
|
2002-04-18 22:01:11 +02:00
|
|
|
{RewriteOidIndex, RewriteRelRulenameIndex};
|
1999-11-22 18:56:41 +01:00
|
|
|
char *Name_pg_shadow_indices[Num_pg_shadow_indices] =
|
2000-04-12 19:17:23 +02:00
|
|
|
{ShadowNameIndex, ShadowSysidIndex};
|
1999-11-25 01:15:57 +01:00
|
|
|
char *Name_pg_statistic_indices[Num_pg_statistic_indices] =
|
2000-04-12 19:17:23 +02:00
|
|
|
{StatisticRelidAttnumIndex};
|
1999-11-22 18:56:41 +01:00
|
|
|
char *Name_pg_trigger_indices[Num_pg_trigger_indices] =
|
2002-04-19 18:36:08 +02:00
|
|
|
{TriggerRelidNameIndex, TriggerConstrNameIndex, TriggerConstrRelidIndex, TriggerOidIndex};
|
1999-11-22 18:56:41 +01:00
|
|
|
char *Name_pg_type_indices[Num_pg_type_indices] =
|
2002-03-29 20:06:29 +01:00
|
|
|
{TypeNameNspIndex, TypeOidIndex};
|
2000-04-12 19:17:23 +02:00
|
|
|
char *Name_pg_description_indices[Num_pg_description_indices] =
|
|
|
|
{DescriptionObjIndex};
|
This patch implements ORACLE's COMMENT SQL command.
>From the ORACLE 7 SQL Language Reference Manual:
-----------------------------------------------------
COMMENT
Purpose:
To add a comment about a table, view, snapshot, or
column into the data dictionary.
Prerequisites:
The table, view, or snapshot must be in your own
schema
or you must have COMMENT ANY TABLE system privilege.
Syntax:
COMMENT ON [ TABLE table ] |
[ COLUMN table.column] IS 'text'
You can effectively drop a comment from the database
by setting it to the empty string ''.
-----------------------------------------------------
Example:
COMMENT ON TABLE workorders IS
'Maintains base records for workorder information';
COMMENT ON COLUMN workorders.hours IS
'Number of hours the engineer worked on the task';
to drop a comment:
COMMENT ON COLUMN workorders.hours IS '';
The current patch will simply perform the insert into
pg_description, as per the TODO. And, of course, when
the table is dropped, any comments relating to it
or any of its attributes are also dropped. I haven't
looked at the ODBC source yet, but I do know from
an ODBC client standpoint that the standard does
support the notion of table and column comments.
Hopefully the ODBC driver is already fetching these
values from pg_description, but if not, it should be
trivial.
Hope this makes the grade,
Mike Mascari
(mascarim@yahoo.com)
1999-10-15 03:49:49 +02:00
|
|
|
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/*
|
2000-07-15 00:18:02 +02:00
|
|
|
* Changes (appends) to catalogs can and do happen at various places
|
1996-07-09 08:22:35 +02:00
|
|
|
* throughout the code. We need a generic routine that will open all of
|
2000-07-15 00:18:02 +02:00
|
|
|
* the indices defined on a given catalog and return the relation descriptors
|
1996-07-09 08:22:35 +02:00
|
|
|
* associated with them.
|
|
|
|
*/
|
|
|
|
void
|
1998-09-01 05:29:17 +02:00
|
|
|
CatalogOpenIndices(int nIndices, char **names, Relation *idescs)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
int i;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-02-18 10:30:20 +01:00
|
|
|
if (IsIgnoringSystemIndexes())
|
|
|
|
return;
|
1997-09-07 07:04:48 +02:00
|
|
|
for (i = 0; i < nIndices; i++)
|
|
|
|
idescs[i] = index_openr(names[i]);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the inverse routine to CatalogOpenIndices()
|
|
|
|
*/
|
|
|
|
void
|
1997-09-08 23:56:23 +02:00
|
|
|
CatalogCloseIndices(int nIndices, Relation *idescs)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
int i;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-02-18 10:30:20 +01:00
|
|
|
if (IsIgnoringSystemIndexes())
|
|
|
|
return;
|
1997-09-07 07:04:48 +02:00
|
|
|
for (i = 0; i < nIndices; i++)
|
|
|
|
index_close(idescs[i]);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2000-07-15 00:18:02 +02:00
|
|
|
* For the same reasons outlined above for CatalogOpenIndices(), we need a
|
|
|
|
* routine that takes a new catalog tuple and inserts an associated index
|
|
|
|
* tuple into each catalog index.
|
|
|
|
*
|
|
|
|
* NOTE: since this routine looks up all the pg_index data on each call,
|
|
|
|
* it's relatively inefficient for inserting a large number of tuples into
|
|
|
|
* the same catalog. We use it only for inserting one or a few tuples
|
2001-03-22 05:01:46 +01:00
|
|
|
* in a given command. See ExecOpenIndices() and related routines if you
|
2000-07-15 00:18:02 +02:00
|
|
|
* are inserting tuples in bulk.
|
|
|
|
*
|
|
|
|
* NOTE: we do not bother to handle partial indices. Nor do we try to
|
|
|
|
* be efficient for functional indices (the code should work for them,
|
|
|
|
* but may leak memory intraquery). This should be OK for system catalogs,
|
|
|
|
* but don't use this routine for user tables!
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
void
|
1997-09-08 23:56:23 +02:00
|
|
|
CatalogIndexInsert(Relation *idescs,
|
1997-09-07 07:04:48 +02:00
|
|
|
int nIndices,
|
|
|
|
Relation heapRelation,
|
|
|
|
HeapTuple heapTuple)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
TupleDesc heapDescriptor;
|
1998-09-03 01:05:37 +02:00
|
|
|
Datum datum[INDEX_MAX_KEYS];
|
2000-07-15 00:18:02 +02:00
|
|
|
char nullv[INDEX_MAX_KEYS];
|
1997-09-08 04:41:22 +02:00
|
|
|
int i;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-12-14 08:02:42 +01:00
|
|
|
if (IsIgnoringSystemIndexes() || (!heapRelation->rd_rel->relhasindex))
|
2000-02-18 10:30:20 +01:00
|
|
|
return;
|
1998-09-01 05:29:17 +02:00
|
|
|
heapDescriptor = RelationGetDescr(heapRelation);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
for (i = 0; i < nIndices; i++)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-07-15 00:18:02 +02:00
|
|
|
IndexInfo *indexInfo;
|
1997-09-07 07:04:48 +02:00
|
|
|
InsertIndexResult indexRes;
|
|
|
|
|
2002-02-19 21:11:20 +01:00
|
|
|
indexInfo = BuildIndexInfo(idescs[i]->rd_index);
|
1999-05-25 18:15:34 +02:00
|
|
|
|
2000-07-15 00:18:02 +02:00
|
|
|
FormIndexDatum(indexInfo,
|
1997-09-07 07:04:48 +02:00
|
|
|
heapTuple,
|
|
|
|
heapDescriptor,
|
2000-07-15 00:18:02 +02:00
|
|
|
CurrentMemoryContext,
|
1998-09-03 01:05:37 +02:00
|
|
|
datum,
|
2000-07-15 00:18:02 +02:00
|
|
|
nullv);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-07-15 00:18:02 +02:00
|
|
|
indexRes = index_insert(idescs[i], datum, nullv,
|
2002-05-24 20:57:57 +02:00
|
|
|
&heapTuple->t_self, heapRelation,
|
|
|
|
idescs[i]->rd_uniqueindex);
|
1997-09-07 07:04:48 +02:00
|
|
|
if (indexRes)
|
|
|
|
pfree(indexRes);
|
2000-07-15 00:18:02 +02:00
|
|
|
pfree(indexInfo);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
}
|