1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-24 09:27:52 +03:00

Modify optimizer data structures so that IndexOptInfo lists built for

create_index_paths are not immediately discarded, but are available for
subsequent planner work.  This allows avoiding redundant syscache lookups
in several places.  Change interface to operator selectivity estimation
procedures to allow faster and more flexible estimation.
Initdb forced due to change of pg_proc entries for selectivity functions!
This commit is contained in:
Tom Lane
2001-05-20 20:28:20 +00:00
parent 5d53389cfe
commit be03eb25f3
32 changed files with 1147 additions and 1218 deletions

View File

@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.141 2001/05/07 00:43:18 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.142 2001/05/20 20:28:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1071,7 +1071,7 @@ _copyRelOptInfo(RelOptInfo *from)
newnode->pruneable = from->pruneable;
newnode->issubquery = from->issubquery;
newnode->indexed = from->indexed;
Node_Copy(from, newnode, indexlist);
newnode->pages = from->pages;
newnode->tuples = from->tuples;
Node_Copy(from, newnode, subplan);
@@ -1093,47 +1093,44 @@ static IndexOptInfo *
_copyIndexOptInfo(IndexOptInfo *from)
{
IndexOptInfo *newnode = makeNode(IndexOptInfo);
int i,
len;
Size len;
newnode->indexoid = from->indexoid;
newnode->pages = from->pages;
newnode->tuples = from->tuples;
newnode->ncolumns = from->ncolumns;
newnode->nkeys = from->nkeys;
if (from->classlist)
{
for (len = 0; from->classlist[len] != 0; len++)
;
newnode->classlist = (Oid *) palloc(sizeof(Oid) * (len + 1));
for (i = 0; i < len; i++)
newnode->classlist[i] = from->classlist[i];
newnode->classlist[len] = 0;
/* copy the trailing zero too */
len = (from->ncolumns + 1) * sizeof(Oid);
newnode->classlist = (Oid *) palloc(len);
memcpy(newnode->classlist, from->classlist, len);
}
if (from->indexkeys)
{
for (len = 0; from->indexkeys[len] != 0; len++)
;
newnode->indexkeys = (int *) palloc(sizeof(int) * (len + 1));
for (i = 0; i < len; i++)
newnode->indexkeys[i] = from->indexkeys[i];
newnode->indexkeys[len] = 0;
/* copy the trailing zero too */
len = (from->nkeys + 1) * sizeof(int);
newnode->indexkeys = (int *) palloc(len);
memcpy(newnode->indexkeys, from->indexkeys, len);
}
if (from->ordering)
{
for (len = 0; from->ordering[len] != 0; len++)
;
newnode->ordering = (Oid *) palloc(sizeof(Oid) * (len + 1));
for (i = 0; i < len; i++)
newnode->ordering[i] = from->ordering[i];
newnode->ordering[len] = 0;
/* copy the trailing zero too */
len = (from->ncolumns + 1) * sizeof(Oid);
newnode->ordering = (Oid *) palloc(len);
memcpy(newnode->ordering, from->ordering, len);
}
newnode->relam = from->relam;
newnode->amcostestimate = from->amcostestimate;
newnode->indproc = from->indproc;
Node_Copy(from, newnode, indpred);
newnode->unique = from->unique;
newnode->lossy = from->lossy;
return newnode;
@@ -1196,7 +1193,7 @@ _copyIndexPath(IndexPath *from)
/*
* copy remainder of node
*/
newnode->indexid = listCopy(from->indexid);
Node_Copy(from, newnode, indexinfo);
Node_Copy(from, newnode, indexqual);
newnode->indexscandir = from->indexscandir;
newnode->joinrelids = listCopy(from->joinrelids);
@@ -1749,8 +1746,8 @@ _copyQuery(Query *from)
/*
* We do not copy the planner internal fields: base_rel_list,
* join_rel_list, equi_key_list, query_pathkeys. Not entirely clear if
* this is right?
* other_rel_list, join_rel_list, equi_key_list, query_pathkeys.
* Not entirely clear if this is right?
*/
return newnode;

View File

@@ -20,7 +20,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.89 2001/05/07 00:43:19 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.90 2001/05/20 20:28:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -405,7 +405,7 @@ _equalIndexPath(IndexPath *a, IndexPath *b)
{
if (!_equalPath((Path *) a, (Path *) b))
return false;
if (!equali(a->indexid, b->indexid))
if (!equal(a->indexinfo, b->indexinfo))
return false;
if (!equal(a->indexqual, b->indexqual))
return false;
@@ -623,9 +623,9 @@ _equalQuery(Query *a, Query *b)
/*
* We do not check the internal-to-the-planner fields: base_rel_list,
* join_rel_list, equi_key_list, query_pathkeys. They might not be set
* yet, and in any case they should be derivable from the other
* fields.
* other_rel_list, join_rel_list, equi_key_list, query_pathkeys.
* They might not be set yet, and in any case they should be derivable
* from the other fields.
*/
return true;
}

View File

@@ -5,7 +5,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.140 2001/03/22 03:59:32 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.141 2001/05/20 20:28:18 tgl Exp $
*
* NOTES
* Every (plan) node in POSTGRES has an associated "out" routine which
@@ -952,56 +952,6 @@ _outJoinExpr(StringInfo str, JoinExpr *node)
_outNode(str, node->colvars);
}
/*
* Stuff from relation.h
*/
static void
_outRelOptInfo(StringInfo str, RelOptInfo *node)
{
appendStringInfo(str, " RELOPTINFO :relids ");
_outIntList(str, node->relids);
appendStringInfo(str, " :rows %.0f :width %d :targetlist ",
node->rows,
node->width);
_outNode(str, node->targetlist);
appendStringInfo(str, " :pathlist ");
_outNode(str, node->pathlist);
appendStringInfo(str, " :cheapest_startup_path ");
_outNode(str, node->cheapest_startup_path);
appendStringInfo(str, " :cheapest_total_path ");
_outNode(str, node->cheapest_total_path);
appendStringInfo(str, " :pruneable %s :issubquery %s :indexed %s :pages %ld :tuples %.0f :subplan ",
booltostr(node->pruneable),
booltostr(node->issubquery),
booltostr(node->indexed),
node->pages,
node->tuples);
_outNode(str, node->subplan);
appendStringInfo(str, " :baserestrictinfo ");
_outNode(str, node->baserestrictinfo);
appendStringInfo(str, " :baserestrictcost %.2f :outerjoinset ",
node->baserestrictcost);
_outIntList(str, node->outerjoinset);
appendStringInfo(str, " :joininfo ");
_outNode(str, node->joininfo);
appendStringInfo(str, " :innerjoin ");
_outNode(str, node->innerjoin);
}
static void
_outIndexOptInfo(StringInfo str, IndexOptInfo *node)
{
appendStringInfo(str, " INDEXOPTINFO :indexoid %u :pages %ld :tuples %g ",
node->indexoid,
node->pages,
node->tuples);
}
/*
* TargetEntry is a subclass of Node.
*/
@@ -1064,8 +1014,8 @@ _outIndexPath(StringInfo str, IndexPath *node)
node->path.total_cost);
_outNode(str, node->path.pathkeys);
appendStringInfo(str, " :indexid ");
_outOidList(str, node->indexid);
appendStringInfo(str, " :indexinfo ");
_outNode(str, node->indexinfo);
appendStringInfo(str, " :indexqual ");
_outNode(str, node->indexqual);
@@ -1629,12 +1579,6 @@ _outNode(StringInfo str, void *obj)
case T_JoinExpr:
_outJoinExpr(str, obj);
break;
case T_RelOptInfo:
_outRelOptInfo(str, obj);
break;
case T_IndexOptInfo:
_outIndexOptInfo(str, obj);
break;
case T_TargetEntry:
_outTargetEntry(str, obj);
break;

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.108 2001/05/07 00:43:19 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.109 2001/05/20 20:28:18 tgl Exp $
*
* NOTES
* Most of the read functions for plan nodes are tested. (In fact, they
@@ -1318,88 +1318,6 @@ _readJoinExpr(void)
return local_node;
}
/*
* Stuff from relation.h
*/
/* ----------------
* _readRelOptInfo
* ----------------
*/
static RelOptInfo *
_readRelOptInfo(void)
{
RelOptInfo *local_node;
char *token;
int length;
local_node = makeNode(RelOptInfo);
token = pg_strtok(&length); /* get :relids */
local_node->relids = toIntList(nodeRead(true)); /* now read it */
token = pg_strtok(&length); /* get :rows */
token = pg_strtok(&length); /* now read it */
local_node->rows = atof(token);
token = pg_strtok(&length); /* get :width */
token = pg_strtok(&length); /* now read it */
local_node->width = atoi(token);
token = pg_strtok(&length); /* get :targetlist */
local_node->targetlist = nodeRead(true); /* now read it */
token = pg_strtok(&length); /* get :pathlist */
local_node->pathlist = nodeRead(true); /* now read it */
token = pg_strtok(&length); /* get :cheapest_startup_path */
local_node->cheapest_startup_path = nodeRead(true); /* now read it */
token = pg_strtok(&length); /* get :cheapest_total_path */
local_node->cheapest_total_path = nodeRead(true); /* now read it */
token = pg_strtok(&length); /* eat :pruneable */
token = pg_strtok(&length); /* get :pruneable */
local_node->pruneable = strtobool(token);
token = pg_strtok(&length); /* get :issubquery */
token = pg_strtok(&length); /* now read it */
local_node->issubquery = strtobool(token);
token = pg_strtok(&length); /* get :indexed */
token = pg_strtok(&length); /* now read it */
local_node->indexed = strtobool(token);
token = pg_strtok(&length); /* get :pages */
token = pg_strtok(&length); /* now read it */
local_node->pages = atol(token);
token = pg_strtok(&length); /* get :tuples */
token = pg_strtok(&length); /* now read it */
local_node->tuples = atof(token);
token = pg_strtok(&length); /* get :subplan */
local_node->subplan = nodeRead(true); /* now read it */
token = pg_strtok(&length); /* get :baserestrictinfo */
local_node->baserestrictinfo = nodeRead(true); /* now read it */
token = pg_strtok(&length); /* get :baserestrictcost */
token = pg_strtok(&length); /* now read it */
local_node->baserestrictcost = (Cost) atof(token);
token = pg_strtok(&length); /* get :outerjoinset */
local_node->outerjoinset = toIntList(nodeRead(true)); /* now read it */
token = pg_strtok(&length); /* get :joininfo */
local_node->joininfo = nodeRead(true); /* now read it */
token = pg_strtok(&length); /* get :innerjoin */
local_node->innerjoin = nodeRead(true); /* now read it */
return local_node;
}
/* ----------------
* _readTargetEntry
* ----------------
@@ -1557,8 +1475,8 @@ _readIndexPath(void)
token = pg_strtok(&length); /* get :pathkeys */
local_node->path.pathkeys = nodeRead(true); /* now read it */
token = pg_strtok(&length); /* get :indexid */
local_node->indexid = toOidList(nodeRead(true));
token = pg_strtok(&length); /* get :indexinfo */
local_node->indexinfo = nodeRead(true); /* now read it */
token = pg_strtok(&length); /* get :indexqual */
local_node->indexqual = nodeRead(true); /* now read it */
@@ -2008,8 +1926,6 @@ parsePlanString(void)
return_value = _readOper();
else if (length == 5 && strncmp(token, "PARAM", length) == 0)
return_value = _readParam();
else if (length == 10 && strncmp(token, "RELOPTINFO", length) == 0)
return_value = _readRelOptInfo();
else if (length == 11 && strncmp(token, "TARGETENTRY", length) == 0)
return_value = _readTargetEntry();
else if (length == 3 && strncmp(token, "RTE", length) == 0)