1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* indexing.c
|
2002-08-05 05:29:17 +02:00
|
|
|
* This file contains routines to support indexes defined on system
|
1997-09-07 07:04:48 +02:00
|
|
|
* catalogs.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2008-01-01 20:46:01 +01:00
|
|
|
* Portions Copyright (c) 1996-2008, 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
|
2008-01-01 20:46:01 +01:00
|
|
|
* $PostgreSQL: pgsql/src/backend/catalog/indexing.c,v 1.116 2008/01/01 19:45:48 momjian Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1998-04-27 06:08:07 +02:00
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include "access/genam.h"
|
|
|
|
#include "catalog/index.h"
|
|
|
|
#include "catalog/indexing.h"
|
2002-08-05 05:29:17 +02:00
|
|
|
#include "executor/executor.h"
|
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
|
|
|
|
|
|
|
/*
|
2002-08-05 05:29:17 +02:00
|
|
|
* CatalogOpenIndexes - open the indexes on a system catalog.
|
|
|
|
*
|
|
|
|
* When inserting or updating tuples in a system catalog, call this
|
|
|
|
* to prepare to update the indexes for the catalog.
|
|
|
|
*
|
|
|
|
* In the current implementation, we share code for opening/closing the
|
|
|
|
* indexes with execUtils.c. But we do not use ExecInsertIndexTuples,
|
|
|
|
* because we don't want to create an EState. This implies that we
|
2003-05-28 18:04:02 +02:00
|
|
|
* do not support partial or expressional indexes on system catalogs.
|
|
|
|
* This could be fixed with localized changes here if we wanted to pay
|
|
|
|
* the extra overhead of building an EState.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2002-08-05 05:29:17 +02:00
|
|
|
CatalogIndexState
|
|
|
|
CatalogOpenIndexes(Relation heapRel)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2002-08-05 05:29:17 +02:00
|
|
|
ResultRelInfo *resultRelInfo;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-08-05 05:29:17 +02:00
|
|
|
resultRelInfo = makeNode(ResultRelInfo);
|
|
|
|
resultRelInfo->ri_RangeTableIndex = 1; /* dummy */
|
|
|
|
resultRelInfo->ri_RelationDesc = heapRel;
|
2002-09-04 22:31:48 +02:00
|
|
|
resultRelInfo->ri_TrigDesc = NULL; /* we don't fire triggers */
|
2002-08-05 05:29:17 +02:00
|
|
|
|
|
|
|
ExecOpenIndices(resultRelInfo);
|
|
|
|
|
|
|
|
return resultRelInfo;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-08-05 05:29:17 +02:00
|
|
|
* CatalogCloseIndexes - clean up resources allocated by CatalogOpenIndexes
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
void
|
2002-08-05 05:29:17 +02:00
|
|
|
CatalogCloseIndexes(CatalogIndexState indstate)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2002-08-05 05:29:17 +02:00
|
|
|
ExecCloseIndices(indstate);
|
|
|
|
pfree(indstate);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-08-05 05:29:17 +02:00
|
|
|
* CatalogIndexInsert - insert index entries for one catalog tuple
|
2000-07-15 00:18:02 +02:00
|
|
|
*
|
2002-08-05 05:29:17 +02:00
|
|
|
* This should be called for each inserted or updated catalog tuple.
|
2000-07-15 00:18:02 +02:00
|
|
|
*
|
2002-08-05 05:29:17 +02:00
|
|
|
* This is effectively a cut-down version of ExecInsertIndexTuples.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
void
|
2002-08-05 05:29:17 +02:00
|
|
|
CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2002-08-05 05:29:17 +02:00
|
|
|
int i;
|
|
|
|
int numIndexes;
|
|
|
|
RelationPtr relationDescs;
|
|
|
|
Relation heapRelation;
|
2005-03-16 22:38:10 +01:00
|
|
|
TupleTableSlot *slot;
|
2002-08-05 05:29:17 +02:00
|
|
|
IndexInfo **indexInfoArray;
|
2005-03-21 02:24:04 +01:00
|
|
|
Datum values[INDEX_MAX_KEYS];
|
|
|
|
bool isnull[INDEX_MAX_KEYS];
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2007-09-20 19:56:33 +02:00
|
|
|
/* HOT update does not require index inserts */
|
|
|
|
if (HeapTupleIsHeapOnly(heapTuple))
|
|
|
|
return;
|
|
|
|
|
2002-08-05 05:29:17 +02:00
|
|
|
/*
|
2005-03-16 22:38:10 +01:00
|
|
|
* Get information from the state structure. Fall out if nothing to do.
|
2002-08-05 05:29:17 +02:00
|
|
|
*/
|
|
|
|
numIndexes = indstate->ri_NumIndices;
|
2005-03-16 22:38:10 +01:00
|
|
|
if (numIndexes == 0)
|
|
|
|
return;
|
2002-08-05 05:29:17 +02:00
|
|
|
relationDescs = indstate->ri_IndexRelationDescs;
|
|
|
|
indexInfoArray = indstate->ri_IndexRelationInfo;
|
|
|
|
heapRelation = indstate->ri_RelationDesc;
|
2005-03-16 22:38:10 +01:00
|
|
|
|
|
|
|
/* Need a slot to hold the tuple being examined */
|
|
|
|
slot = MakeSingleTupleTableSlot(RelationGetDescr(heapRelation));
|
|
|
|
ExecStoreTuple(heapTuple, slot, InvalidBuffer, false);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-08-05 05:29:17 +02:00
|
|
|
/*
|
|
|
|
* for each index, form and insert the index tuple
|
|
|
|
*/
|
|
|
|
for (i = 0; i < numIndexes; 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
|
|
|
|
2002-08-05 05:29:17 +02:00
|
|
|
indexInfo = indexInfoArray[i];
|
1999-05-25 18:15:34 +02:00
|
|
|
|
2007-09-20 19:56:33 +02:00
|
|
|
/* If the index is marked as read-only, ignore it */
|
|
|
|
if (!indexInfo->ii_ReadyForInserts)
|
|
|
|
continue;
|
|
|
|
|
2003-05-28 18:04:02 +02:00
|
|
|
/*
|
|
|
|
* Expressional and partial indexes on system catalogs are not
|
|
|
|
* supported
|
|
|
|
*/
|
|
|
|
Assert(indexInfo->ii_Expressions == NIL);
|
2002-08-05 05:29:17 +02:00
|
|
|
Assert(indexInfo->ii_Predicate == NIL);
|
|
|
|
|
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* FormIndexDatum fills in its values and isnull parameters with the
|
|
|
|
* appropriate values for the column(s) of the index.
|
2002-08-05 05:29:17 +02:00
|
|
|
*/
|
2000-07-15 00:18:02 +02:00
|
|
|
FormIndexDatum(indexInfo,
|
2005-03-16 22:38:10 +01:00
|
|
|
slot,
|
2003-05-28 18:04:02 +02:00
|
|
|
NULL, /* no expression eval to do */
|
2005-03-21 02:24:04 +01:00
|
|
|
values,
|
|
|
|
isnull);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-08-05 05:29:17 +02:00
|
|
|
/*
|
|
|
|
* The index AM does the rest.
|
|
|
|
*/
|
2005-03-21 02:24:04 +01:00
|
|
|
index_insert(relationDescs[i], /* index relation */
|
2005-10-15 04:49:52 +02:00
|
|
|
values, /* array of index Datums */
|
|
|
|
isnull, /* is-null flags */
|
2005-03-21 02:24:04 +01:00
|
|
|
&(heapTuple->t_self), /* tid of heap tuple */
|
|
|
|
heapRelation,
|
|
|
|
relationDescs[i]->rd_index->indisunique);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
2005-03-16 22:38:10 +01:00
|
|
|
|
|
|
|
ExecDropSingleTupleTableSlot(slot);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
2002-08-05 05:29:17 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CatalogUpdateIndexes - do all the indexing work for a new catalog tuple
|
|
|
|
*
|
|
|
|
* This is a convenience routine for the common case where we only need
|
2002-09-04 22:31:48 +02:00
|
|
|
* to insert or update a single tuple in a system catalog. Avoid using it for
|
2002-08-05 05:29:17 +02:00
|
|
|
* multiple tuples, since opening the indexes and building the index info
|
|
|
|
* structures is moderately expensive.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
CatalogUpdateIndexes(Relation heapRel, HeapTuple heapTuple)
|
|
|
|
{
|
2002-09-04 22:31:48 +02:00
|
|
|
CatalogIndexState indstate;
|
2002-08-05 05:29:17 +02:00
|
|
|
|
|
|
|
indstate = CatalogOpenIndexes(heapRel);
|
|
|
|
CatalogIndexInsert(indstate, heapTuple);
|
|
|
|
CatalogCloseIndexes(indstate);
|
|
|
|
}
|