Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 77C551539070 for ; Wed, 13 Jun 2012 15:08:51 -0300 (ADT) Received: from mahout.postgresql.org ([98.129.198.123]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Serzt-0008PR-S5 for pgsql-bugs@postgresql.org; Wed, 13 Jun 2012 18:08:50 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Serzh-0003UU-Ey for pgsql-bugs@postgresql.org; Wed, 13 Jun 2012 18:08:37 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1Serzh-0008Qv-6o for pgsql-bugs@postgresql.org; Wed, 13 Jun 2012 18:08:37 +0000 Date: Wed, 13 Jun 2012 18:08:37 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #6693: Potential Bug in rewriteManip.c To: pgsql-bugs@postgresql.org From: msrbugzilla@gmail.com X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201206/134 X-Sequence-Number: 33361 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 =3D rt_index; context.new_index =3D new_index; context.sublevels_up =3D 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 =3D (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 =3D=3D 0) { ListCell *l; if (qry->resultRelation =3D=3D rt_index) qry->resultRelation =3D new_index; foreach(l, qry->rowMarks) { RowMarkClause *rc =3D (RowMarkClause *) lfirst(l); if (rc->rti =3D=3D rt_index) rc->rti =3D 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 =3D offset; context.sublevels_up =3D 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 =3D (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 =3D=3D 0) { ListCell *l; if (qry->resultRelation) qry->resultRelation +=3D offset; foreach(l, qry->rowMarks) { RowMarkClause *rc =3D (RowMarkClause *) lfirst(l); rc->rti +=3D offset; } } query_tree_walker(qry, OffsetVarNodes_walker, (void *) &context, 0); } else OffsetVarNodes_walker(node, &context);