aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/selfuncs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils/adt/selfuncs.c')
-rw-r--r--src/backend/utils/adt/selfuncs.c61
1 files changed, 60 insertions, 1 deletions
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 20ae7ddc1c4..336c1deaeaa 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -15,7 +15,7 @@
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
@@ -1567,6 +1567,65 @@ scalararraysel(PlannerInfo *root,
}
/*
+ * 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 "="
*/
Datum