]> granicus.if.org Git - postgresql/commitdiff
Rename same() to sameseti() to have a slightly less generic name. Move
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 6 Feb 2000 03:27:35 +0000 (03:27 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 6 Feb 2000 03:27:35 +0000 (03:27 +0000)
nonoverlap_sets() and is_subset() to list.c, where they should have lived
to begin with, and rename to nonoverlap_setsi and is_subseti since they
only work on integer lists.

src/backend/nodes/list.c
src/backend/optimizer/path/joinpath.c
src/backend/optimizer/path/joinrels.c
src/backend/optimizer/path/prune.c
src/backend/optimizer/util/joininfo.c
src/backend/optimizer/util/relnode.c
src/include/nodes/pg_list.h
src/include/optimizer/paths.h

index 3a8ecf358678e87c15406cc203bc153181b62178..723930f36a8f0011b29d82a80863750f0cf64fe6 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/nodes/list.c,v 1.28 2000/01/26 05:56:31 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/nodes/list.c,v 1.29 2000/02/06 03:27:32 tgl Exp $
  *
  * NOTES
  *       XXX a few of the following functions are duplicated to handle
@@ -264,34 +264,32 @@ freeList(List *list)
 }
 
 /*
- *             same
+ *             sameseti
  *
- *             Returns t if two lists contain the same elements
+ *             Returns t if two integer lists contain the same elements
  *             (but unlike equal(), they need not be in the same order)
- *         
  *
- * XXX should be called samei() --- only good for IntList      -ay
+ *             Caution: this routine could be fooled if list1 contains
+ *             duplicate elements.  It is intended to be used on lists
+ *             containing only nonduplicate elements, eg Relids lists.
  */
 bool
-same(List *l1, List *l2)
+sameseti(List *list1, List *list2)
 {
        List       *temp;
 
-       if (l1 == NIL)
-               return l2 == NIL;
-       if (l2 == NIL)
-               return l1 == NIL;
-       if (length(l1) == length(l2))
+       if (list1 == NIL)
+               return list2 == NIL;
+       if (list2 == NIL)
+               return false;
+       if (length(list1) != length(list2))
+               return false;
+       foreach(temp, list1)
        {
-               foreach(temp, l1)
-               {
-                       if (!intMember(lfirsti(temp), l2))
-                               return false;
-               }
-               return true;
+               if (!intMember(lfirsti(temp), list2))
+                       return false;
        }
-       return false;
-
+       return true;
 }
 
 /*
@@ -519,3 +517,39 @@ set_differencei(List *l1, List *l2)
        }
        return result;
 }
+
+/*
+ * Return t if two integer lists have no members in common.
+ */
+bool
+nonoverlap_setsi(List *list1, List *list2)
+{
+       List       *x;
+
+       foreach(x, list1)
+       {
+               int                     e = lfirsti(x);
+
+               if (intMember(e, list2))
+                       return false;
+       }
+       return true;
+}
+
+/*
+ * Return t if all members of integer list list1 appear in list2.
+ */
+bool
+is_subseti(List *list1, List *list2)
+{
+       List       *x;
+
+       foreach(x, list1)
+       {
+               int                     e = lfirsti(x);
+
+               if (!intMember(e, list2))
+                       return false;
+       }
+       return true;
+}
index 1d63d9a564269517f392e5dcaafa7ac7910bf2b9..371dd2b7b56c2f5bdb7b5f08b05c7257705cd1ca 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.49 2000/01/26 05:56:34 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.50 2000/02/06 03:27:32 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -181,7 +181,7 @@ best_innerjoin(List *join_paths, Relids outer_relids)
                 * outer_relids in order to use this inner path, because those
                 * rels are used in the index join quals of this inner path.
                 */
-               if (is_subset(((IndexPath *) path)->joinrelids, outer_relids) &&
+               if (is_subseti(((IndexPath *) path)->joinrelids, outer_relids) &&
                        (cheapest == NULL ||
                         path_is_cheaper(path, cheapest)))
                        cheapest = path;
index 801127434a3c3ba6c9caa51a38c20f32491d6c91..5fc673e5dbadf523be4c677b20ecbd7bd77a4945 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinrels.c,v 1.41 2000/01/26 05:56:34 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinrels.c,v 1.42 2000/02/06 03:27:32 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -144,8 +144,8 @@ make_rels_by_clause_joins(Query *root, RelOptInfo *old_rel,
                                RelOptInfo *join_rel = lfirst(r);
 
                                Assert(length(join_rel->relids) > 1);
-                               if (is_subset(unjoined_relids, join_rel->relids) &&
-                                       nonoverlap_sets(old_rel->relids, join_rel->relids))
+                               if (is_subseti(unjoined_relids, join_rel->relids) &&
+                                       nonoverlap_setsi(old_rel->relids, join_rel->relids))
                                {
                                        joined_rel = make_join_rel(old_rel, join_rel);
                                        join_list = lappend(join_list, joined_rel);
@@ -175,7 +175,7 @@ make_rels_by_clauseless_joins(RelOptInfo *old_rel, List *inner_rels)
        {
                RelOptInfo *inner_rel = (RelOptInfo *) lfirst(i);
 
-               if (nonoverlap_sets(inner_rel->relids, old_rel->relids))
+               if (nonoverlap_setsi(inner_rel->relids, old_rel->relids))
                {
                        join_list = lappend(join_list,
                                                                make_join_rel(old_rel, inner_rel));
@@ -404,39 +404,3 @@ get_cheapest_complete_rel(List *join_rel_list)
 
        return final_rel;
 }
-
-/*
- * Subset-inclusion tests on integer lists.
- *
- * XXX these probably ought to be in nodes/list.c or some such place.
- */
-
-bool
-nonoverlap_sets(List *s1, List *s2)
-{
-       List       *x;
-
-       foreach(x, s1)
-       {
-               int                     e = lfirsti(x);
-
-               if (intMember(e, s2))
-                       return false;
-       }
-       return true;
-}
-
-bool
-is_subset(List *s1, List *s2)
-{
-       List       *x;
-
-       foreach(x, s1)
-       {
-               int                     e = lfirsti(x);
-
-               if (!intMember(e, s2))
-                       return false;
-       }
-       return true;
-}
index 2554f8af1e5b3505404189fda50b6186ddbe99d3..f2dc6d90dfcff8e5e0c6b83439499565e6e966e0 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/prune.c,v 1.45 2000/01/26 05:56:34 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/prune.c,v 1.46 2000/02/06 03:27:32 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -67,7 +67,7 @@ merge_rel_with_same_relids(RelOptInfo *rel, List *unmerged_rels)
        {
                RelOptInfo *unmerged_rel = (RelOptInfo *) lfirst(i);
 
-               if (same(rel->relids, unmerged_rel->relids))
+               if (sameseti(rel->relids, unmerged_rel->relids))
                {
                        /*
                         * These rels are for the same set of base relations,
index 86837ebf403911cca14a2b14d6fba8a2ff5eec3c..d29fcc2f480f32f808662888b9828cfaf585a7d5 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/optimizer/util/joininfo.c,v 1.25 2000/01/26 05:56:40 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/optimizer/util/joininfo.c,v 1.26 2000/02/06 03:27:33 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -41,7 +41,7 @@ joininfo_member(List *join_relids, List *joininfo_list)
        {
                JoinInfo   *joininfo = (JoinInfo *) lfirst(i);
 
-               if (same(join_relids, joininfo->unjoined_relids))
+               if (sameseti(join_relids, joininfo->unjoined_relids))
                        return joininfo;
        }
        return NULL;
index 4d62f7b45aa49c39bb747cb6b57160fca6897748..23ee8ba811166af2564939074463468748cebb7f 100644 (file)
@@ -8,13 +8,12 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/optimizer/util/relnode.c,v 1.21 2000/01/26 05:56:40 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/optimizer/util/relnode.c,v 1.22 2000/02/06 03:27:33 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 #include "postgres.h"
 
-
 #include "optimizer/internal.h"
 #include "optimizer/pathnode.h"
 #include "optimizer/plancat.h"
@@ -97,17 +96,14 @@ get_join_rel(Query *root, Relids relid)
 RelOptInfo *
 rel_member(Relids relids, List *rels)
 {
-       if (relids != NIL && rels != NIL)
-       {
-               List       *temp;
+       List       *temp;
 
-               foreach(temp, rels)
-               {
-                       RelOptInfo *rel = (RelOptInfo *) lfirst(temp);
+       foreach(temp, rels)
+       {
+               RelOptInfo *rel = (RelOptInfo *) lfirst(temp);
 
-                       if (same(rel->relids, relids))
-                               return rel;
-               }
+               if (sameseti(rel->relids, relids))
+                       return rel;
        }
        return NULL;
 }
index 9e96cef956b38540e3b9e83c614309071f8c7e07..94aa8d58c6b91882290c15366698695447a9dc3d 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: pg_list.h,v 1.14 2000/01/26 05:58:16 momjian Exp $
+ * $Id: pg_list.h,v 1.15 2000/02/06 03:27:35 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -106,7 +106,10 @@ extern List *set_difference(List *list1, List *list2);
 extern List *set_differencei(List *list1, List *list2);
 extern List *LispUnion(List *list1, List *list2);
 extern List *LispUnioni(List *list1, List *list2);
-extern bool same(List *list1, List *list2);
+
+extern bool sameseti(List *list1, List *list2);
+extern bool nonoverlap_setsi(List *list1, List *list2);
+extern bool is_subseti(List *list1, List *list2);
 
 extern void freeList(List *list);
 
index c422654c5ad7becded27905bab2852e504789dd1..bcecd4c923c5ac18f02823ff49588b7af8bdfe6d 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: paths.h,v 1.40 2000/02/05 18:26:07 tgl Exp $
+ * $Id: paths.h,v 1.41 2000/02/06 03:27:35 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -100,8 +100,6 @@ extern List *make_rels_by_clause_joins(Query *root, RelOptInfo *old_rel,
 extern List *make_rels_by_clauseless_joins(RelOptInfo *old_rel,
                                                          List *inner_rels);
 extern RelOptInfo *get_cheapest_complete_rel(List *join_rel_list);
-extern bool nonoverlap_sets(List *s1, List *s2);
-extern bool is_subset(List *s1, List *s2);
 
 /*
  * prune.c