UpdateRangeTableOfViewParse(Oid viewOid, Query *viewParse)
{
	Relation	viewRel;
	List	   *new_rt;
	RangeTblEntry *rt_entry1,
			   *rt_entry2;
	ParseState *pstate;

	/*
	 * Make a copy of the given parsetree.  It's not so much that we don't
	 * want to scribble on our input, it's that the parser has a bad habit of
	 * outputting multiple links to the same subtree for constructs like
	 * BETWEEN, and we mustn't have OffsetVarNodes increment the varno of a
	 * Var node twice.  copyObject will expand any multiply-referenced subtree
	 * into multiple copies.
	 */
	viewParse = copyObject(viewParse);

	/* Create a dummy ParseState for addRangeTableEntryForRelation */
	pstate = make_parsestate(NULL);

	/* need to open the rel for addRangeTableEntryForRelation */
	viewRel = relation_open(viewOid, AccessShareLock);

	/*
	 * Create the 2 new range table entries and form the new range table...
	 * OLD first, then NEW....
	 */
	rt_entry1 = addRangeTableEntryForRelation(pstate, viewRel,
											  AccessShareLock,
											  makeAlias("old", NIL),
											  false, false);
	rt_entry2 = addRangeTableEntryForRelation(pstate, viewRel,
											  AccessShareLock,
											  makeAlias("new", NIL),
											  false, false);
	/* Must override addRangeTableEntry's default access-check flags */
	rt_entry1->requiredPerms = 0;
	rt_entry2->requiredPerms = 0;

	new_rt = lcons(rt_entry1, lcons(rt_entry2, viewParse->rtable));

	viewParse->rtable = new_rt;

	/*
	 * Now offset all var nodes by 2, and jointree RT indexes too.
	 */
	OffsetVarNodes((Node *) viewParse, 2, 0);

	relation_close(viewRel, AccessShareLock);

	return viewParse;
}
UpdateRangeTableOfViewParse(Oid viewOid, Query *viewParse)
{
	Relation	viewRel;
	List	   *new_rt;
	RangeTblEntry *rt_entry1,
			   *rt_entry2;
	ParseState *pstate;

	 
	viewParse = copyObject(viewParse);

	 
	pstate = make_parsestate(NULL);

	 
	viewRel = relation_open(viewOid, AccessShareLock);

	 
	rt_entry1 = addRangeTableEntryForRelation(pstate, viewRel,
											  AccessShareLock,
											  makeAlias("old", NIL),
											  false, false);
	rt_entry2 = addRangeTableEntryForRelation(pstate, viewRel,
											  AccessShareLock,
											  makeAlias("new", NIL),
											  false, false);
	 
	rt_entry1->requiredPerms = 0;
	rt_entry2->requiredPerms = 0;

	new_rt = lcons(rt_entry1, lcons(rt_entry2, viewParse->rtable));

	viewParse->rtable = new_rt;

	 
	OffsetVarNodes((Node *) viewParse, 2, 0);

	relation_close(viewRel, AccessShareLock);

	return viewParse;
}