Add selectivity-calculation code for RowCompareExpr nodes. Simplistic,
but a lot better than nothing at all ...
This commit is contained in:
parent
39fc1fb07a
commit
34f8ee9737
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/clausesel.c,v 1.76 2005/11/25 19:47:49 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/optimizer/path/clausesel.c,v 1.77 2006/01/14 00:14:11 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -663,6 +663,14 @@ clause_selectivity(PlannerInfo *root,
|
|||||||
varRelid,
|
varRelid,
|
||||||
jointype);
|
jointype);
|
||||||
}
|
}
|
||||||
|
else if (IsA(clause, RowCompareExpr))
|
||||||
|
{
|
||||||
|
/* Use node specific selectivity calculation function */
|
||||||
|
s1 = rowcomparesel(root,
|
||||||
|
(RowCompareExpr *) clause,
|
||||||
|
varRelid,
|
||||||
|
jointype);
|
||||||
|
}
|
||||||
else if (IsA(clause, NullTest))
|
else if (IsA(clause, NullTest))
|
||||||
{
|
{
|
||||||
/* Use node specific selectivity calculation function */
|
/* Use node specific selectivity calculation function */
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.195 2006/01/10 17:35:52 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.196 2006/01/14 00:14:11 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -1566,6 +1566,65 @@ scalararraysel(PlannerInfo *root,
|
|||||||
return s1;
|
return s1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* rowcomparesel - Selectivity of RowCompareExpr Node.
|
||||||
|
*
|
||||||
|
* We estimate RowCompare selectivity by considering just the first (high
|
||||||
|
* order) columns, which makes it equivalent to an ordinary OpExpr. While
|
||||||
|
* this estimate could be refined by considering additional columns, it
|
||||||
|
* seems unlikely that we could do a lot better without multi-column
|
||||||
|
* statistics.
|
||||||
|
*/
|
||||||
|
Selectivity
|
||||||
|
rowcomparesel(PlannerInfo *root,
|
||||||
|
RowCompareExpr *clause,
|
||||||
|
int varRelid, JoinType jointype)
|
||||||
|
{
|
||||||
|
Selectivity s1;
|
||||||
|
Oid opno = linitial_oid(clause->opnos);
|
||||||
|
List *opargs;
|
||||||
|
bool is_join_clause;
|
||||||
|
|
||||||
|
/* Build equivalent arg list for single operator */
|
||||||
|
opargs = list_make2(linitial(clause->largs), linitial(clause->rargs));
|
||||||
|
|
||||||
|
/* Decide if it's a join clause, same as for OpExpr */
|
||||||
|
if (varRelid != 0)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* If we are considering a nestloop join then all clauses are
|
||||||
|
* restriction clauses, since we are only interested in the one
|
||||||
|
* relation.
|
||||||
|
*/
|
||||||
|
is_join_clause = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Otherwise, it's a join if there's more than one relation used.
|
||||||
|
* Notice we ignore the low-order columns here.
|
||||||
|
*/
|
||||||
|
is_join_clause = (NumRelids((Node *) opargs) > 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_join_clause)
|
||||||
|
{
|
||||||
|
/* Estimate selectivity for a join clause. */
|
||||||
|
s1 = join_selectivity(root, opno,
|
||||||
|
opargs,
|
||||||
|
jointype);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Estimate selectivity for a restriction clause. */
|
||||||
|
s1 = restriction_selectivity(root, opno,
|
||||||
|
opargs,
|
||||||
|
varRelid);
|
||||||
|
}
|
||||||
|
|
||||||
|
return s1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* eqjoinsel - Join selectivity of "="
|
* eqjoinsel - Join selectivity of "="
|
||||||
*/
|
*/
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/include/utils/selfuncs.h,v 1.26 2005/11/25 19:47:50 tgl Exp $
|
* $PostgreSQL: pgsql/src/include/utils/selfuncs.h,v 1.27 2006/01/14 00:14:12 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -116,6 +116,9 @@ extern Selectivity scalararraysel(PlannerInfo *root,
|
|||||||
ScalarArrayOpExpr *clause,
|
ScalarArrayOpExpr *clause,
|
||||||
bool is_join_clause,
|
bool is_join_clause,
|
||||||
int varRelid, JoinType jointype);
|
int varRelid, JoinType jointype);
|
||||||
|
extern Selectivity rowcomparesel(PlannerInfo *root,
|
||||||
|
RowCompareExpr *clause,
|
||||||
|
int varRelid, JoinType jointype);
|
||||||
|
|
||||||
extern void mergejoinscansel(PlannerInfo *root, Node *clause,
|
extern void mergejoinscansel(PlannerInfo *root, Node *clause,
|
||||||
Selectivity *leftscan,
|
Selectivity *leftscan,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user