Add selectivity-calculation code for RowCompareExpr nodes. Simplistic,
authorTom Lane
Sat, 14 Jan 2006 00:14:12 +0000 (00:14 +0000)
committerTom Lane
Sat, 14 Jan 2006 00:14:12 +0000 (00:14 +0000)
but a lot better than nothing at all ...

src/backend/optimizer/path/clausesel.c
src/backend/utils/adt/selfuncs.c
src/include/utils/selfuncs.h

index eba6bf1d148622e815f43cbfc3d8724396de2455..d3e28dc9650d65c6c25a387240ae67d52db1ebf2 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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,
                            jointype);
    }
+   else if (IsA(clause, RowCompareExpr))
+   {
+       /* Use node specific selectivity calculation function */
+       s1 = rowcomparesel(root,
+                          (RowCompareExpr *) clause,
+                          varRelid,
+                          jointype);
+   }
    else if (IsA(clause, NullTest))
    {
        /* Use node specific selectivity calculation function */
index 20ae7ddc1c4dd7428b199e8a729e1782cd81497e..336c1deaeaa8ddb3f2c3b1354bc56e887301f91d 100644 (file)
@@ -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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -1566,6 +1566,65 @@ scalararraysel(PlannerInfo *root,
    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 "="
  */
index 2c021ad25022881f64594f190dd36c0592c2d54a..541b58e5467f0d40db3561a95c21220b2af65ed6 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * 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,
                                  bool is_join_clause,
                                  int varRelid, JoinType jointype);
+extern Selectivity rowcomparesel(PlannerInfo *root,
+                                RowCompareExpr *clause,
+                                int varRelid, JoinType jointype);
 
 extern void mergejoinscansel(PlannerInfo *root, Node *clause,
                 Selectivity *leftscan,