pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #6693: Potential Bug in rewriteManip.c
2+ messages / 2 participants
[nested] [flat]

* BUG #6693: Potential Bug in rewriteManip.c
@ 2012-06-13 18:08 msrbugzilla@gmail.com
  2012-06-16 16:34 ` Re: BUG #6693: Potential Bug in rewriteManip.c Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: msrbugzilla@gmail.com @ 2012-06-13 18:08 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      6693
Logged by:          Ken Cheung
Email address:      msrbugzilla@gmail.com
PostgreSQL version: 9.1.3
Operating system:   Linux
Description:        

I observed a code clone in the following files. In these functions,
qry->resultRelation is computed differently but the comment above mentions
the same functionality. I wonder if this is a bug. Hope it helps.

function : ChangeVarNodes @ (file:
"postgresql-9.1.3/src/backend/rewrite/rewriteManip.c", line: 570)~608
	context.rt_index = rt_index;
	context.new_index = new_index;
	context.sublevels_up = sublevels_up;

	/*
	 * Must be prepared to start with a Query or a bare expression tree; if
	 * it's a Query, go straight to query_tree_walker to make sure that
	 * sublevels_up doesn't get incremented prematurely.
	 */
	if (node && IsA(node, Query))
	{
		Query	   *qry = (Query *) node;

		/*
		 * If we are starting at a Query, and sublevels_up is zero, then we
		 * must also fix rangetable indexes in the Query itself --- namely
		 * resultRelation and rowMarks entries.  sublevels_up cannot be zero
		 * when recursing into a subquery, so there's no need to have the same
		 * logic inside ChangeVarNodes_walker.
		 */
		if (sublevels_up == 0)
		{
			ListCell   *l;

			if (qry->resultRelation == rt_index)
				qry->resultRelation = new_index;
			foreach(l, qry->rowMarks)
			{
				RowMarkClause *rc = (RowMarkClause *) lfirst(l);

				if (rc->rti == rt_index)
					rc->rti = new_index;
			}
		}
		query_tree_walker(qry, ChangeVarNodes_walker,
						  (void *) &context, 0);
	}
	else
		ChangeVarNodes_walker(node, &context);

function : OffsetVarNodes @ (file:
"postgresql-9.1.3/src/backend/rewrite/rewriteManip.c", line: 402)~438
	context.offset = offset;
	context.sublevels_up = sublevels_up;

	/*
	 * Must be prepared to start with a Query or a bare expression tree; if
	 * it's a Query, go straight to query_tree_walker to make sure that
	 * sublevels_up doesn't get incremented prematurely.
	 */
	if (node && IsA(node, Query))
	{
		Query	   *qry = (Query *) node;

		/*
		 * If we are starting at a Query, and sublevels_up is zero, then we
		 * must also fix rangetable indexes in the Query itself --- namely
		 * resultRelation and rowMarks entries.  sublevels_up cannot be zero
		 * when recursing into a subquery, so there's no need to have the same
		 * logic inside OffsetVarNodes_walker.
		 */
		if (sublevels_up == 0)
		{
			ListCell   *l;

			if (qry->resultRelation)
				qry->resultRelation += offset;
			foreach(l, qry->rowMarks)
			{
				RowMarkClause *rc = (RowMarkClause *) lfirst(l);

				rc->rti += offset;
			}
		}
		query_tree_walker(qry, OffsetVarNodes_walker,
						  (void *) &context, 0);
	}
	else
		OffsetVarNodes_walker(node, &context);




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #6693: Potential Bug in rewriteManip.c
  2012-06-13 18:08 BUG #6693: Potential Bug in rewriteManip.c msrbugzilla@gmail.com
@ 2012-06-16 16:34 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2012-06-16 16:34 UTC (permalink / raw)
  To: msrbugzilla@gmail.com; +Cc: pgsql-bugs

msrbugzilla@gmail.com writes:
> I observed a code clone in the following files. In these functions,
> qry->resultRelation is computed differently but the comment above mentions
> the same functionality. I wonder if this is a bug. Hope it helps.

No, it isn't.  You might gain some insight if you read the header
comments for ChangeVarNodes and OffsetVarNodes.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2012-06-16 16:34 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-06-13 18:08 BUG #6693: Potential Bug in rewriteManip.c msrbugzilla@gmail.com
2012-06-16 16:34 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox