⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 joininfo.c

📁 PostgreSQL 8.1.4的源码 适用于Linux下的开源数据库系统
💻 C
字号:
/*------------------------------------------------------------------------- * * joininfo.c *	  joininfo list manipulation routines * * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * * IDENTIFICATION *	  $PostgreSQL: pgsql/src/backend/optimizer/util/joininfo.c,v 1.43 2005/06/09 04:19:00 tgl Exp $ * *------------------------------------------------------------------------- */#include "postgres.h"#include "optimizer/joininfo.h"#include "optimizer/pathnode.h"/* * have_relevant_joinclause *		Detect whether there is a joinclause that can be used to join *		the two given relations. */boolhave_relevant_joinclause(RelOptInfo *rel1, RelOptInfo *rel2){	bool		result = false;	Relids		join_relids;	List	   *joininfo;	ListCell   *l;	join_relids = bms_union(rel1->relids, rel2->relids);	/*	 * We could scan either relation's joininfo list; may as well use the	 * shorter one.	 */	if (list_length(rel1->joininfo) <= list_length(rel2->joininfo))		joininfo = rel1->joininfo;	else		joininfo = rel2->joininfo;	foreach(l, joininfo)	{		RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);		if (bms_is_subset(rinfo->required_relids, join_relids))		{			result = true;			break;		}	}	bms_free(join_relids);	return result;}/* * add_join_clause_to_rels *	  Add 'restrictinfo' to the joininfo list of each relation it requires. * * Note that the same copy of the restrictinfo node is linked to by all the * lists it is in.	This allows us to exploit caching of information about * the restriction clause (but we must be careful that the information does * not depend on context). * * 'restrictinfo' describes the join clause * 'join_relids' is the list of relations participating in the join clause *				 (there must be more than one) */voidadd_join_clause_to_rels(PlannerInfo *root,						RestrictInfo *restrictinfo,						Relids join_relids){	Relids		tmprelids;	int			cur_relid;	tmprelids = bms_copy(join_relids);	while ((cur_relid = bms_first_member(tmprelids)) >= 0)	{		RelOptInfo *rel = find_base_rel(root, cur_relid);		rel->joininfo = lappend(rel->joininfo, restrictinfo);	}	bms_free(tmprelids);}/* * remove_join_clause_from_rels *	  Delete 'restrictinfo' from all the joininfo lists it is in * * This reverses the effect of add_join_clause_to_rels.  It's used when we * discover that a join clause is redundant. * * 'restrictinfo' describes the join clause * 'join_relids' is the list of relations participating in the join clause *				 (there must be more than one) */voidremove_join_clause_from_rels(PlannerInfo *root,							 RestrictInfo *restrictinfo,							 Relids join_relids){	Relids		tmprelids;	int			cur_relid;	tmprelids = bms_copy(join_relids);	while ((cur_relid = bms_first_member(tmprelids)) >= 0)	{		RelOptInfo *rel = find_base_rel(root, cur_relid);		/*		 * Remove the restrictinfo from the list.  Pointer comparison is		 * sufficient.		 */		Assert(list_member_ptr(rel->joininfo, restrictinfo));		rel->joininfo = list_delete_ptr(rel->joininfo, restrictinfo);	}	bms_free(tmprelids);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -