Commit 610dfa6d authored by Tom Lane's avatar Tom Lane

Combine index_info and find_secondary_indexes into a single routine that

returns a list of RelOptInfos, eliminating the need for static state
in index_info.  That static state was a direct cause of coredumps; if
anything decided to elog(ERROR) partway through an index_info search of
pg_index, the next query would try to close a scan pointer that was
pointing at no-longer-valid memory.  Another example of the reasons to
avoid static state variables...
parent 40d3e925
......@@ -7,21 +7,16 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/indexnode.c,v 1.20 1999/08/16 02:17:57 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/indexnode.c,v 1.21 1999/11/21 23:25:47 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include <sys/types.h>
#include "postgres.h"
#include "optimizer/pathnode.h"
#include "optimizer/plancat.h"
static List *find_secondary_index(Query *root, Oid relid);
/*
* find_relation_indices
* Returns a list of index nodes containing appropriate information for
......@@ -32,56 +27,7 @@ List *
find_relation_indices(Query *root, RelOptInfo *rel)
{
if (rel->indexed)
return find_secondary_index(root, lfirsti(rel->relids));
return find_secondary_indexes(root, lfirsti(rel->relids));
else
return NIL;
}
/*
* find_secondary_index
* Creates a list of RelOptInfo nodes containing information for each
* secondary index defined on a relation by searching through the index
* catalog.
*
* 'relid' is the OID of the relation for which indices are being located
*
* Returns a list of new index RelOptInfo nodes.
*/
static List *
find_secondary_index(Query *root, Oid relid)
{
IdxInfoRetval indexinfo;
List *indexes = NIL;
bool first = true;
while (index_info(root, first, relid, &indexinfo))
{
RelOptInfo *indexnode = makeNode(RelOptInfo);
indexnode->relids = lconsi(indexinfo.relid, NIL);
indexnode->relam = indexinfo.relam;
indexnode->pages = indexinfo.pages;
indexnode->tuples = indexinfo.tuples;
indexnode->classlist = indexinfo.classlist;
indexnode->indexkeys = indexinfo.indexkeys;
indexnode->ordering = indexinfo.orderOprs;
indexnode->indproc = indexinfo.indproc;
indexnode->indpred = (List *) indexinfo.indpred;
indexnode->indexed = false; /* not indexed itself */
indexnode->size = 0;
indexnode->width = 0;
indexnode->targetlist = NIL;
indexnode->pathlist = NIL;
indexnode->cheapestpath = NULL;
indexnode->pruneable = true;
indexnode->restrictinfo = NIL;
indexnode->joininfo = NIL;
indexnode->innerjoin = NIL;
indexes = lcons(indexnode, indexes);
first = false;
}
return indexes;
}
This diff is collapsed.
......@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: plancat.h,v 1.13 1999/07/25 23:07:23 tgl Exp $
* $Id: plancat.h,v 1.14 1999/11/21 23:25:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -15,32 +15,11 @@
#include "nodes/parsenodes.h"
/*
* transient data structure to hold return value of index_info. Note that
* indexkeys, orderOprs and classlist is "null-terminated".
*/
typedef struct IdxInfoRetval
{
Oid relid; /* OID of the index relation (not the OID
* of the relation being indexed) */
Oid relam; /* OID of the pg_am of this index */
int pages; /* number of pages in the index relation */
int tuples; /* number of tuples in the index relation */
int *indexkeys; /* keys over which we're indexing */
Oid *orderOprs; /* operators used for ordering purposes */
Oid *classlist; /* classes of AM operators */
Oid indproc;
Node *indpred;
} IdxInfoRetval;
extern void relation_info(Query *root,
Oid relid,
bool *hashindex, int *pages,
int *tuples);
extern bool index_info(Query *root,
bool first, int relid, IdxInfoRetval *info);
extern void relation_info(Query *root, Index relid,
bool *hasindex, int *pages, int *tuples);
extern List *find_secondary_indexes(Query *root, Index relid);
extern Cost restriction_selectivity(Oid functionObjectId,
Oid operatorObjectId,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment