Skip to content

Commit 81fc1d5

Browse files
committed
Rename same() to sameseti() to have a slightly less generic name. Move
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.
1 parent 418b270 commit 81fc1d5

File tree

8 files changed

+76
-81
lines changed

8 files changed

+76
-81
lines changed

src/backend/nodes/list.c

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/nodes/list.c,v 1.28 2000/01/26 05:56:31 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/nodes/list.c,v 1.29 2000/02/06 03:27:32 tgl Exp $
1212
*
1313
* NOTES
1414
* XXX a few of the following functions are duplicated to handle
@@ -264,34 +264,32 @@ freeList(List *list)
264264
}
265265

266266
/*
267-
* same
267+
* sameseti
268268
*
269-
* Returns t if two lists contain the same elements
269+
* Returns t if two integer lists contain the same elements
270270
* (but unlike equal(), they need not be in the same order)
271-
*
272271
*
273-
* XXX should be called samei() --- only good for IntList -ay
272+
* Caution: this routine could be fooled if list1 contains
273+
* duplicate elements. It is intended to be used on lists
274+
* containing only nonduplicate elements, eg Relids lists.
274275
*/
275276
bool
276-
same(List *l1, List *l2)
277+
sameseti(List *list1, List *list2)
277278
{
278279
List *temp;
279280

280-
if (l1 == NIL)
281-
return l2 == NIL;
282-
if (l2 == NIL)
283-
return l1 == NIL;
284-
if (length(l1) == length(l2))
281+
if (list1 == NIL)
282+
return list2 == NIL;
283+
if (list2 == NIL)
284+
return false;
285+
if (length(list1) != length(list2))
286+
return false;
287+
foreach(temp, list1)
285288
{
286-
foreach(temp, l1)
287-
{
288-
if (!intMember(lfirsti(temp), l2))
289-
return false;
290-
}
291-
return true;
289+
if (!intMember(lfirsti(temp), list2))
290+
return false;
292291
}
293-
return false;
294-
292+
return true;
295293
}
296294

297295
/*
@@ -519,3 +517,39 @@ set_differencei(List *l1, List *l2)
519517
}
520518
return result;
521519
}
520+
521+
/*
522+
* Return t if two integer lists have no members in common.
523+
*/
524+
bool
525+
nonoverlap_setsi(List *list1, List *list2)
526+
{
527+
List *x;
528+
529+
foreach(x, list1)
530+
{
531+
int e = lfirsti(x);
532+
533+
if (intMember(e, list2))
534+
return false;
535+
}
536+
return true;
537+
}
538+
539+
/*
540+
* Return t if all members of integer list list1 appear in list2.
541+
*/
542+
bool
543+
is_subseti(List *list1, List *list2)
544+
{
545+
List *x;
546+
547+
foreach(x, list1)
548+
{
549+
int e = lfirsti(x);
550+
551+
if (!intMember(e, list2))
552+
return false;
553+
}
554+
return true;
555+
}

src/backend/optimizer/path/joinpath.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.49 2000/01/26 05:56:34 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.50 2000/02/06 03:27:32 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -181,7 +181,7 @@ best_innerjoin(List *join_paths, Relids outer_relids)
181181
* outer_relids in order to use this inner path, because those
182182
* rels are used in the index join quals of this inner path.
183183
*/
184-
if (is_subset(((IndexPath *) path)->joinrelids, outer_relids) &&
184+
if (is_subseti(((IndexPath *) path)->joinrelids, outer_relids) &&
185185
(cheapest == NULL ||
186186
path_is_cheaper(path, cheapest)))
187187
cheapest = path;

src/backend/optimizer/path/joinrels.c

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinrels.c,v 1.41 2000/01/26 05:56:34 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinrels.c,v 1.42 2000/02/06 03:27:32 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -144,8 +144,8 @@ make_rels_by_clause_joins(Query *root, RelOptInfo *old_rel,
144144
RelOptInfo *join_rel = lfirst(r);
145145

146146
Assert(length(join_rel->relids) > 1);
147-
if (is_subset(unjoined_relids, join_rel->relids) &&
148-
nonoverlap_sets(old_rel->relids, join_rel->relids))
147+
if (is_subseti(unjoined_relids, join_rel->relids) &&
148+
nonoverlap_setsi(old_rel->relids, join_rel->relids))
149149
{
150150
joined_rel = make_join_rel(old_rel, join_rel);
151151
join_list = lappend(join_list, joined_rel);
@@ -175,7 +175,7 @@ make_rels_by_clauseless_joins(RelOptInfo *old_rel, List *inner_rels)
175175
{
176176
RelOptInfo *inner_rel = (RelOptInfo *) lfirst(i);
177177

178-
if (nonoverlap_sets(inner_rel->relids, old_rel->relids))
178+
if (nonoverlap_setsi(inner_rel->relids, old_rel->relids))
179179
{
180180
join_list = lappend(join_list,
181181
make_join_rel(old_rel, inner_rel));
@@ -404,39 +404,3 @@ get_cheapest_complete_rel(List *join_rel_list)
404404

405405
return final_rel;
406406
}
407-
408-
/*
409-
* Subset-inclusion tests on integer lists.
410-
*
411-
* XXX these probably ought to be in nodes/list.c or some such place.
412-
*/
413-
414-
bool
415-
nonoverlap_sets(List *s1, List *s2)
416-
{
417-
List *x;
418-
419-
foreach(x, s1)
420-
{
421-
int e = lfirsti(x);
422-
423-
if (intMember(e, s2))
424-
return false;
425-
}
426-
return true;
427-
}
428-
429-
bool
430-
is_subset(List *s1, List *s2)
431-
{
432-
List *x;
433-
434-
foreach(x, s1)
435-
{
436-
int e = lfirsti(x);
437-
438-
if (!intMember(e, s2))
439-
return false;
440-
}
441-
return true;
442-
}

src/backend/optimizer/path/prune.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/prune.c,v 1.45 2000/01/26 05:56:34 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/prune.c,v 1.46 2000/02/06 03:27:32 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -67,7 +67,7 @@ merge_rel_with_same_relids(RelOptInfo *rel, List *unmerged_rels)
6767
{
6868
RelOptInfo *unmerged_rel = (RelOptInfo *) lfirst(i);
6969

70-
if (same(rel->relids, unmerged_rel->relids))
70+
if (sameseti(rel->relids, unmerged_rel->relids))
7171
{
7272
/*
7373
* These rels are for the same set of base relations,

src/backend/optimizer/util/joininfo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/joininfo.c,v 1.25 2000/01/26 05:56:40 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/joininfo.c,v 1.26 2000/02/06 03:27:33 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -41,7 +41,7 @@ joininfo_member(List *join_relids, List *joininfo_list)
4141
{
4242
JoinInfo *joininfo = (JoinInfo *) lfirst(i);
4343

44-
if (same(join_relids, joininfo->unjoined_relids))
44+
if (sameseti(join_relids, joininfo->unjoined_relids))
4545
return joininfo;
4646
}
4747
return NULL;

src/backend/optimizer/util/relnode.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/relnode.c,v 1.21 2000/01/26 05:56:40 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/relnode.c,v 1.22 2000/02/06 03:27:33 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
1515
#include "postgres.h"
1616

17-
1817
#include "optimizer/internal.h"
1918
#include "optimizer/pathnode.h"
2019
#include "optimizer/plancat.h"
@@ -97,17 +96,14 @@ get_join_rel(Query *root, Relids relid)
9796
RelOptInfo *
9897
rel_member(Relids relids, List *rels)
9998
{
100-
if (relids != NIL && rels != NIL)
101-
{
102-
List *temp;
99+
List *temp;
103100

104-
foreach(temp, rels)
105-
{
106-
RelOptInfo *rel = (RelOptInfo *) lfirst(temp);
101+
foreach(temp, rels)
102+
{
103+
RelOptInfo *rel = (RelOptInfo *) lfirst(temp);
107104

108-
if (same(rel->relids, relids))
109-
return rel;
110-
}
105+
if (sameseti(rel->relids, relids))
106+
return rel;
111107
}
112108
return NULL;
113109
}

src/include/nodes/pg_list.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_list.h,v 1.14 2000/01/26 05:58:16 momjian Exp $
10+
* $Id: pg_list.h,v 1.15 2000/02/06 03:27:35 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -106,7 +106,10 @@ extern List *set_difference(List *list1, List *list2);
106106
extern List *set_differencei(List *list1, List *list2);
107107
extern List *LispUnion(List *list1, List *list2);
108108
extern List *LispUnioni(List *list1, List *list2);
109-
extern bool same(List *list1, List *list2);
109+
110+
extern bool sameseti(List *list1, List *list2);
111+
extern bool nonoverlap_setsi(List *list1, List *list2);
112+
extern bool is_subseti(List *list1, List *list2);
110113

111114
extern void freeList(List *list);
112115

src/include/optimizer/paths.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $Id: paths.h,v 1.40 2000/02/05 18:26:07 tgl Exp $
11+
* $Id: paths.h,v 1.41 2000/02/06 03:27:35 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -100,8 +100,6 @@ extern List *make_rels_by_clause_joins(Query *root, RelOptInfo *old_rel,
100100
extern List *make_rels_by_clauseless_joins(RelOptInfo *old_rel,
101101
List *inner_rels);
102102
extern RelOptInfo *get_cheapest_complete_rel(List *join_rel_list);
103-
extern bool nonoverlap_sets(List *s1, List *s2);
104-
extern bool is_subset(List *s1, List *s2);
105103

106104
/*
107105
* prune.c

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