Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit be03eb2

Browse files
committed
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!
1 parent 5d53389 commit be03eb2

32 files changed

+1150
-1221
lines changed

src/backend/catalog/pg_operator.c

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.57 2001/03/22 06:16:10 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.58 2001/05/20 20:28:17 tgl Exp $
1212
*
1313
* NOTES
1414
* these routines moved here from commands/define.c and somewhat cleaned up.
@@ -69,7 +69,7 @@ static void OperatorUpd(Oid baseId, Oid commId, Oid negId);
6969
/* ----------------------------------------------------------------
7070
* OperatorGetWithOpenRelation
7171
*
72-
* preforms a scan on pg_operator for an operator tuple
72+
* performs a scan on pg_operator for an operator tuple
7373
* with given name and left/right type oids.
7474
* ----------------------------------------------------------------
7575
* pg_operator_desc -- reldesc for pg_operator
@@ -570,53 +570,50 @@ OperatorDef(char *operatorName,
570570
ReleaseSysCache(tup);
571571

572572
/*
573-
* find restriction
573+
* find restriction estimator
574574
*/
575575
if (restrictionName)
576576
{ /* optional */
577577
Oid restOid;
578578

579579
MemSet(typeId, 0, FUNC_MAX_ARGS * sizeof(Oid));
580-
typeId[0] = OIDOID; /* operator OID */
581-
typeId[1] = OIDOID; /* relation OID */
582-
typeId[2] = INT2OID; /* attribute number */
583-
typeId[3] = 0; /* value - can be any type */
584-
typeId[4] = INT4OID; /* flags - left or right selectivity */
580+
typeId[0] = 0; /* Query (opaque type) */
581+
typeId[1] = OIDOID; /* operator OID */
582+
typeId[2] = 0; /* args list (opaque type) */
583+
typeId[3] = INT4OID; /* varRelid */
585584

586585
restOid = GetSysCacheOid(PROCNAME,
587586
PointerGetDatum(restrictionName),
588-
Int32GetDatum(5),
587+
Int32GetDatum(4),
589588
PointerGetDatum(typeId),
590589
0);
591590
if (!OidIsValid(restOid))
592-
func_error("OperatorDef", restrictionName, 5, typeId, NULL);
591+
func_error("OperatorDef", restrictionName, 4, typeId, NULL);
593592

594593
values[Anum_pg_operator_oprrest - 1] = ObjectIdGetDatum(restOid);
595594
}
596595
else
597596
values[Anum_pg_operator_oprrest - 1] = ObjectIdGetDatum(InvalidOid);
598597

599598
/*
600-
* find join - only valid for binary operators
599+
* find join estimator
601600
*/
602601
if (joinName)
603602
{ /* optional */
604603
Oid joinOid;
605604

606605
MemSet(typeId, 0, FUNC_MAX_ARGS * sizeof(Oid));
607-
typeId[0] = OIDOID; /* operator OID */
608-
typeId[1] = OIDOID; /* relation OID 1 */
609-
typeId[2] = INT2OID; /* attribute number 1 */
610-
typeId[3] = OIDOID; /* relation OID 2 */
611-
typeId[4] = INT2OID; /* attribute number 2 */
606+
typeId[0] = 0; /* Query (opaque type) */
607+
typeId[1] = OIDOID; /* operator OID */
608+
typeId[2] = 0; /* args list (opaque type) */
612609

613610
joinOid = GetSysCacheOid(PROCNAME,
614611
PointerGetDatum(joinName),
615-
Int32GetDatum(5),
612+
Int32GetDatum(3),
616613
PointerGetDatum(typeId),
617614
0);
618615
if (!OidIsValid(joinOid))
619-
func_error("OperatorDef", joinName, 5, typeId, NULL);
616+
func_error("OperatorDef", joinName, 3, typeId, NULL);
620617

621618
values[Anum_pg_operator_oprjoin - 1] = ObjectIdGetDatum(joinOid);
622619
}
@@ -1044,10 +1041,8 @@ OperatorCreate(char *operatorName,
10441041
/* If it's not a binary op, these things mustn't be set: */
10451042
if (commutatorName)
10461043
elog(ERROR, "OperatorCreate: only binary operators can have commutators");
1047-
if (negatorName)
1048-
elog(ERROR, "OperatorCreate: only binary operators can have negators");
1049-
if (restrictionName || joinName)
1050-
elog(ERROR, "OperatorCreate: only binary operators can have selectivity");
1044+
if (joinName)
1045+
elog(ERROR, "OperatorCreate: only binary operators can have join selectivity");
10511046
if (canHash)
10521047
elog(ERROR, "OperatorCreate: only binary operators can hash");
10531048
if (leftSortName || rightSortName)

src/backend/nodes/copyfuncs.c

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.141 2001/05/07 00:43:18 tgl Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.142 2001/05/20 20:28:17 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -1071,7 +1071,7 @@ _copyRelOptInfo(RelOptInfo *from)
10711071
newnode->pruneable = from->pruneable;
10721072

10731073
newnode->issubquery = from->issubquery;
1074-
newnode->indexed = from->indexed;
1074+
Node_Copy(from, newnode, indexlist);
10751075
newnode->pages = from->pages;
10761076
newnode->tuples = from->tuples;
10771077
Node_Copy(from, newnode, subplan);
@@ -1093,47 +1093,44 @@ static IndexOptInfo *
10931093
_copyIndexOptInfo(IndexOptInfo *from)
10941094
{
10951095
IndexOptInfo *newnode = makeNode(IndexOptInfo);
1096-
int i,
1097-
len;
1096+
Size len;
10981097

10991098
newnode->indexoid = from->indexoid;
11001099
newnode->pages = from->pages;
11011100
newnode->tuples = from->tuples;
11021101

1102+
newnode->ncolumns = from->ncolumns;
1103+
newnode->nkeys = from->nkeys;
1104+
11031105
if (from->classlist)
11041106
{
1105-
for (len = 0; from->classlist[len] != 0; len++)
1106-
;
1107-
newnode->classlist = (Oid *) palloc(sizeof(Oid) * (len + 1));
1108-
for (i = 0; i < len; i++)
1109-
newnode->classlist[i] = from->classlist[i];
1110-
newnode->classlist[len] = 0;
1107+
/* copy the trailing zero too */
1108+
len = (from->ncolumns + 1) * sizeof(Oid);
1109+
newnode->classlist = (Oid *) palloc(len);
1110+
memcpy(newnode->classlist, from->classlist, len);
11111111
}
11121112

11131113
if (from->indexkeys)
11141114
{
1115-
for (len = 0; from->indexkeys[len] != 0; len++)
1116-
;
1117-
newnode->indexkeys = (int *) palloc(sizeof(int) * (len + 1));
1118-
for (i = 0; i < len; i++)
1119-
newnode->indexkeys[i] = from->indexkeys[i];
1120-
newnode->indexkeys[len] = 0;
1115+
/* copy the trailing zero too */
1116+
len = (from->nkeys + 1) * sizeof(int);
1117+
newnode->indexkeys = (int *) palloc(len);
1118+
memcpy(newnode->indexkeys, from->indexkeys, len);
11211119
}
11221120

11231121
if (from->ordering)
11241122
{
1125-
for (len = 0; from->ordering[len] != 0; len++)
1126-
;
1127-
newnode->ordering = (Oid *) palloc(sizeof(Oid) * (len + 1));
1128-
for (i = 0; i < len; i++)
1129-
newnode->ordering[i] = from->ordering[i];
1130-
newnode->ordering[len] = 0;
1123+
/* copy the trailing zero too */
1124+
len = (from->ncolumns + 1) * sizeof(Oid);
1125+
newnode->ordering = (Oid *) palloc(len);
1126+
memcpy(newnode->ordering, from->ordering, len);
11311127
}
11321128

11331129
newnode->relam = from->relam;
11341130
newnode->amcostestimate = from->amcostestimate;
11351131
newnode->indproc = from->indproc;
11361132
Node_Copy(from, newnode, indpred);
1133+
newnode->unique = from->unique;
11371134
newnode->lossy = from->lossy;
11381135

11391136
return newnode;
@@ -1196,7 +1193,7 @@ _copyIndexPath(IndexPath *from)
11961193
/*
11971194
* copy remainder of node
11981195
*/
1199-
newnode->indexid = listCopy(from->indexid);
1196+
Node_Copy(from, newnode, indexinfo);
12001197
Node_Copy(from, newnode, indexqual);
12011198
newnode->indexscandir = from->indexscandir;
12021199
newnode->joinrelids = listCopy(from->joinrelids);
@@ -1749,8 +1746,8 @@ _copyQuery(Query *from)
17491746

17501747
/*
17511748
* We do not copy the planner internal fields: base_rel_list,
1752-
* join_rel_list, equi_key_list, query_pathkeys. Not entirely clear if
1753-
* this is right?
1749+
* other_rel_list, join_rel_list, equi_key_list, query_pathkeys.
1750+
* Not entirely clear if this is right?
17541751
*/
17551752

17561753
return newnode;

src/backend/nodes/equalfuncs.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* Portions Copyright (c) 1994, Regents of the University of California
2121
*
2222
* IDENTIFICATION
23-
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.89 2001/05/07 00:43:19 tgl Exp $
23+
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.90 2001/05/20 20:28:18 tgl Exp $
2424
*
2525
*-------------------------------------------------------------------------
2626
*/
@@ -405,7 +405,7 @@ _equalIndexPath(IndexPath *a, IndexPath *b)
405405
{
406406
if (!_equalPath((Path *) a, (Path *) b))
407407
return false;
408-
if (!equali(a->indexid, b->indexid))
408+
if (!equal(a->indexinfo, b->indexinfo))
409409
return false;
410410
if (!equal(a->indexqual, b->indexqual))
411411
return false;
@@ -623,9 +623,9 @@ _equalQuery(Query *a, Query *b)
623623

624624
/*
625625
* We do not check the internal-to-the-planner fields: base_rel_list,
626-
* join_rel_list, equi_key_list, query_pathkeys. They might not be set
627-
* yet, and in any case they should be derivable from the other
628-
* fields.
626+
* other_rel_list, join_rel_list, equi_key_list, query_pathkeys.
627+
* They might not be set yet, and in any case they should be derivable
628+
* from the other fields.
629629
*/
630630
return true;
631631
}

src/backend/nodes/outfuncs.c

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.140 2001/03/22 03:59:32 momjian Exp $
8+
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.141 2001/05/20 20:28:18 tgl Exp $
99
*
1010
* NOTES
1111
* Every (plan) node in POSTGRES has an associated "out" routine which
@@ -952,56 +952,6 @@ _outJoinExpr(StringInfo str, JoinExpr *node)
952952
_outNode(str, node->colvars);
953953
}
954954

955-
/*
956-
* Stuff from relation.h
957-
*/
958-
959-
static void
960-
_outRelOptInfo(StringInfo str, RelOptInfo *node)
961-
{
962-
appendStringInfo(str, " RELOPTINFO :relids ");
963-
_outIntList(str, node->relids);
964-
965-
appendStringInfo(str, " :rows %.0f :width %d :targetlist ",
966-
node->rows,
967-
node->width);
968-
_outNode(str, node->targetlist);
969-
970-
appendStringInfo(str, " :pathlist ");
971-
_outNode(str, node->pathlist);
972-
appendStringInfo(str, " :cheapest_startup_path ");
973-
_outNode(str, node->cheapest_startup_path);
974-
appendStringInfo(str, " :cheapest_total_path ");
975-
_outNode(str, node->cheapest_total_path);
976-
977-
appendStringInfo(str, " :pruneable %s :issubquery %s :indexed %s :pages %ld :tuples %.0f :subplan ",
978-
booltostr(node->pruneable),
979-
booltostr(node->issubquery),
980-
booltostr(node->indexed),
981-
node->pages,
982-
node->tuples);
983-
_outNode(str, node->subplan);
984-
985-
appendStringInfo(str, " :baserestrictinfo ");
986-
_outNode(str, node->baserestrictinfo);
987-
appendStringInfo(str, " :baserestrictcost %.2f :outerjoinset ",
988-
node->baserestrictcost);
989-
_outIntList(str, node->outerjoinset);
990-
appendStringInfo(str, " :joininfo ");
991-
_outNode(str, node->joininfo);
992-
appendStringInfo(str, " :innerjoin ");
993-
_outNode(str, node->innerjoin);
994-
}
995-
996-
static void
997-
_outIndexOptInfo(StringInfo str, IndexOptInfo *node)
998-
{
999-
appendStringInfo(str, " INDEXOPTINFO :indexoid %u :pages %ld :tuples %g ",
1000-
node->indexoid,
1001-
node->pages,
1002-
node->tuples);
1003-
}
1004-
1005955
/*
1006956
* TargetEntry is a subclass of Node.
1007957
*/
@@ -1064,8 +1014,8 @@ _outIndexPath(StringInfo str, IndexPath *node)
10641014
node->path.total_cost);
10651015
_outNode(str, node->path.pathkeys);
10661016

1067-
appendStringInfo(str, " :indexid ");
1068-
_outOidList(str, node->indexid);
1017+
appendStringInfo(str, " :indexinfo ");
1018+
_outNode(str, node->indexinfo);
10691019

10701020
appendStringInfo(str, " :indexqual ");
10711021
_outNode(str, node->indexqual);
@@ -1629,12 +1579,6 @@ _outNode(StringInfo str, void *obj)
16291579
case T_JoinExpr:
16301580
_outJoinExpr(str, obj);
16311581
break;
1632-
case T_RelOptInfo:
1633-
_outRelOptInfo(str, obj);
1634-
break;
1635-
case T_IndexOptInfo:
1636-
_outIndexOptInfo(str, obj);
1637-
break;
16381582
case T_TargetEntry:
16391583
_outTargetEntry(str, obj);
16401584
break;

0 commit comments

Comments
 (0)