Skip to content

Commit 34f8ee9

Browse files
committed
Add selectivity-calculation code for RowCompareExpr nodes. Simplistic,
but a lot better than nothing at all ...
1 parent 39fc1fb commit 34f8ee9

File tree

3 files changed

+73
-3
lines changed

3 files changed

+73
-3
lines changed

src/backend/optimizer/path/clausesel.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/path/clausesel.c,v 1.76 2005/11/25 19:47:49 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/path/clausesel.c,v 1.77 2006/01/14 00:14:11 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -663,6 +663,14 @@ clause_selectivity(PlannerInfo *root,
663663
varRelid,
664664
jointype);
665665
}
666+
else if (IsA(clause, RowCompareExpr))
667+
{
668+
/* Use node specific selectivity calculation function */
669+
s1 = rowcomparesel(root,
670+
(RowCompareExpr *) clause,
671+
varRelid,
672+
jointype);
673+
}
666674
else if (IsA(clause, NullTest))
667675
{
668676
/* Use node specific selectivity calculation function */

src/backend/utils/adt/selfuncs.c

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.195 2006/01/10 17:35:52 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.196 2006/01/14 00:14:11 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -1566,6 +1566,65 @@ scalararraysel(PlannerInfo *root,
15661566
return s1;
15671567
}
15681568

1569+
/*
1570+
* rowcomparesel - Selectivity of RowCompareExpr Node.
1571+
*
1572+
* We estimate RowCompare selectivity by considering just the first (high
1573+
* order) columns, which makes it equivalent to an ordinary OpExpr. While
1574+
* this estimate could be refined by considering additional columns, it
1575+
* seems unlikely that we could do a lot better without multi-column
1576+
* statistics.
1577+
*/
1578+
Selectivity
1579+
rowcomparesel(PlannerInfo *root,
1580+
RowCompareExpr *clause,
1581+
int varRelid, JoinType jointype)
1582+
{
1583+
Selectivity s1;
1584+
Oid opno = linitial_oid(clause->opnos);
1585+
List *opargs;
1586+
bool is_join_clause;
1587+
1588+
/* Build equivalent arg list for single operator */
1589+
opargs = list_make2(linitial(clause->largs), linitial(clause->rargs));
1590+
1591+
/* Decide if it's a join clause, same as for OpExpr */
1592+
if (varRelid != 0)
1593+
{
1594+
/*
1595+
* If we are considering a nestloop join then all clauses are
1596+
* restriction clauses, since we are only interested in the one
1597+
* relation.
1598+
*/
1599+
is_join_clause = false;
1600+
}
1601+
else
1602+
{
1603+
/*
1604+
* Otherwise, it's a join if there's more than one relation used.
1605+
* Notice we ignore the low-order columns here.
1606+
*/
1607+
is_join_clause = (NumRelids((Node *) opargs) > 1);
1608+
}
1609+
1610+
if (is_join_clause)
1611+
{
1612+
/* Estimate selectivity for a join clause. */
1613+
s1 = join_selectivity(root, opno,
1614+
opargs,
1615+
jointype);
1616+
}
1617+
else
1618+
{
1619+
/* Estimate selectivity for a restriction clause. */
1620+
s1 = restriction_selectivity(root, opno,
1621+
opargs,
1622+
varRelid);
1623+
}
1624+
1625+
return s1;
1626+
}
1627+
15691628
/*
15701629
* eqjoinsel - Join selectivity of "="
15711630
*/

src/include/utils/selfuncs.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/utils/selfuncs.h,v 1.26 2005/11/25 19:47:50 tgl Exp $
11+
* $PostgreSQL: pgsql/src/include/utils/selfuncs.h,v 1.27 2006/01/14 00:14:12 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -116,6 +116,9 @@ extern Selectivity scalararraysel(PlannerInfo *root,
116116
ScalarArrayOpExpr *clause,
117117
bool is_join_clause,
118118
int varRelid, JoinType jointype);
119+
extern Selectivity rowcomparesel(PlannerInfo *root,
120+
RowCompareExpr *clause,
121+
int varRelid, JoinType jointype);
119122

120123
extern void mergejoinscansel(PlannerInfo *root, Node *clause,
121124
Selectivity *leftscan,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy