Skip to content

Commit 43ba1b4

Browse files
committed
Add test code to copy all parse/plan trees. Repair essential omissions
in copyfuncs and equalfuncs exposed by regression tests. We still have some work to do: these modules really ought to handle most or all of the utility statement node types. But it's better than it was.
1 parent 6a7b40d commit 43ba1b4

File tree

3 files changed

+200
-169
lines changed

3 files changed

+200
-169
lines changed

src/backend/nodes/copyfuncs.c

Lines changed: 82 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,23 @@
33
* copyfuncs.c
44
* Copy functions for Postgres tree nodes.
55
*
6+
* NOTE: a general convention when copying or comparing plan nodes is
7+
* that we ignore the executor state subnode. We do not need to look
8+
* at it because no current uses of copyObject() or equal() need to
9+
* deal with already-executing plan trees. By leaving the state subnodes
10+
* out, we avoid needing to write copy/compare routines for all the
11+
* different executor state node types.
12+
*
13+
* Another class of nodes not currently handled is nodes that appear
14+
* only in "raw" parsetrees (gram.y output not yet analyzed by the parser).
15+
* Perhaps some day that will need to be supported.
16+
*
17+
*
618
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
719
* Portions Copyright (c) 1994, Regents of the University of California
820
*
9-
*
1021
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.114 2000/06/18 22:44:05 tgl Exp $
22+
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.115 2000/06/29 07:35:56 tgl Exp $
1223
*
1324
*-------------------------------------------------------------------------
1425
*/
@@ -1671,9 +1682,6 @@ copyObject(void *from)
16711682
case T_Agg:
16721683
retval = _copyAgg(from);
16731684
break;
1674-
case T_GroupClause:
1675-
retval = _copyGroupClause(from);
1676-
break;
16771685
case T_Unique:
16781686
retval = _copyUnique(from);
16791687
break;
@@ -1699,9 +1707,6 @@ copyObject(void *from)
16991707
case T_Var:
17001708
retval = _copyVar(from);
17011709
break;
1702-
case T_Attr:
1703-
retval = _copyAttr(from);
1704-
break;
17051710
case T_Oper:
17061711
retval = _copyOper(from);
17071712
break;
@@ -1711,6 +1716,12 @@ copyObject(void *from)
17111716
case T_Param:
17121717
retval = _copyParam(from);
17131718
break;
1719+
case T_Aggref:
1720+
retval = _copyAggref(from);
1721+
break;
1722+
case T_SubLink:
1723+
retval = _copySubLink(from);
1724+
break;
17141725
case T_Func:
17151726
retval = _copyFunc(from);
17161727
break;
@@ -1720,21 +1731,12 @@ copyObject(void *from)
17201731
case T_ArrayRef:
17211732
retval = _copyArrayRef(from);
17221733
break;
1723-
case T_Aggref:
1724-
retval = _copyAggref(from);
1725-
break;
1726-
case T_SubLink:
1727-
retval = _copySubLink(from);
1734+
case T_Iter:
1735+
retval = _copyIter(from);
17281736
break;
17291737
case T_RelabelType:
17301738
retval = _copyRelabelType(from);
17311739
break;
1732-
case T_CaseExpr:
1733-
retval = _copyCaseExpr(from);
1734-
break;
1735-
case T_CaseWhen:
1736-
retval = _copyCaseWhen(from);
1737-
break;
17381740

17391741
/*
17401742
* RELATION NODES
@@ -1769,9 +1771,6 @@ copyObject(void *from)
17691771
case T_JoinInfo:
17701772
retval = _copyJoinInfo(from);
17711773
break;
1772-
case T_Iter:
1773-
retval = _copyIter(from);
1774-
break;
17751774
case T_Stream:
17761775
retval = _copyStream(from);
17771776
break;
@@ -1780,29 +1779,35 @@ copyObject(void *from)
17801779
break;
17811780

17821781
/*
1783-
* PARSE NODES
1782+
* VALUE NODES
17841783
*/
1785-
case T_TargetEntry:
1786-
retval = _copyTargetEntry(from);
1787-
break;
1788-
case T_RangeTblEntry:
1789-
retval = _copyRangeTblEntry(from);
1790-
break;
1791-
case T_RowMark:
1792-
retval = _copyRowMark(from);
1793-
break;
1794-
case T_SortClause:
1795-
retval = _copySortClause(from);
1796-
break;
1797-
case T_A_Const:
1798-
retval = _copyAConst(from);
1799-
break;
1800-
case T_TypeName:
1801-
retval = _copyTypeName(from);
1784+
case T_Integer:
1785+
case T_Float:
1786+
case T_String:
1787+
retval = _copyValue(from);
18021788
break;
1803-
case T_TypeCast:
1804-
retval = _copyTypeCast(from);
1789+
case T_List:
1790+
{
1791+
List *list = from,
1792+
*l,
1793+
*nl;
1794+
1795+
/* rather ugly coding for speed... */
1796+
/* Note the input list cannot be NIL if we got here. */
1797+
nl = lcons(copyObject(lfirst(list)), NIL);
1798+
retval = nl;
1799+
1800+
foreach(l, lnext(list))
1801+
{
1802+
lnext(nl) = lcons(copyObject(lfirst(l)), NIL);
1803+
nl = lnext(nl);
1804+
}
1805+
}
18051806
break;
1807+
1808+
/*
1809+
* PARSE NODES
1810+
*/
18061811
case T_Query:
18071812
retval = _copyQuery(from);
18081813
break;
@@ -1837,35 +1842,44 @@ copyObject(void *from)
18371842
retval = _copyLockStmt(from);
18381843
break;
18391844

1840-
/*
1841-
* VALUE NODES
1842-
*/
1843-
case T_Integer:
1844-
case T_Float:
1845-
case T_String:
1846-
retval = _copyValue(from);
1845+
case T_Attr:
1846+
retval = _copyAttr(from);
18471847
break;
1848-
case T_List:
1849-
{
1850-
List *list = from,
1851-
*l,
1852-
*nl;
1853-
1854-
/* rather ugly coding for speed... */
1855-
/* Note the input list cannot be NIL if we got here. */
1856-
nl = lcons(copyObject(lfirst(list)), NIL);
1857-
retval = nl;
1858-
1859-
foreach(l, lnext(list))
1860-
{
1861-
lnext(nl) = lcons(copyObject(lfirst(l)), NIL);
1862-
nl = lnext(nl);
1863-
}
1864-
}
1848+
case T_A_Const:
1849+
retval = _copyAConst(from);
1850+
break;
1851+
case T_TypeCast:
1852+
retval = _copyTypeCast(from);
1853+
break;
1854+
case T_TypeName:
1855+
retval = _copyTypeName(from);
1856+
break;
1857+
case T_TargetEntry:
1858+
retval = _copyTargetEntry(from);
1859+
break;
1860+
case T_RangeTblEntry:
1861+
retval = _copyRangeTblEntry(from);
18651862
break;
1863+
case T_SortClause:
1864+
retval = _copySortClause(from);
1865+
break;
1866+
case T_GroupClause:
1867+
retval = _copyGroupClause(from);
1868+
break;
1869+
case T_CaseExpr:
1870+
retval = _copyCaseExpr(from);
1871+
break;
1872+
case T_CaseWhen:
1873+
retval = _copyCaseWhen(from);
1874+
break;
1875+
case T_RowMark:
1876+
retval = _copyRowMark(from);
1877+
break;
1878+
18661879
default:
1867-
elog(ERROR, "copyObject: don't know how to copy %d", nodeTag(from));
1868-
retval = from;
1880+
elog(ERROR, "copyObject: don't know how to copy node type %d",
1881+
nodeTag(from));
1882+
retval = from; /* keep compiler quiet */
18691883
break;
18701884
}
18711885
return retval;

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