PageRenderTime 61ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/src/backend/nodes/copyfuncs.c

https://github.com/bbt123/postgres
C | 4644 lines | 3299 code | 759 blank | 586 comment | 14 complexity | 52454c2b24489e3b9b1e6368764e2ef8 MD5 | raw file
Possible License(s): AGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. /*-------------------------------------------------------------------------
  2. *
  3. * copyfuncs.c
  4. * Copy functions for Postgres tree nodes.
  5. *
  6. * NOTE: we currently support copying all node types found in parse and
  7. * plan trees. We do not support copying executor state trees; there
  8. * is no need for that, and no point in maintaining all the code that
  9. * would be needed. We also do not support copying Path trees, mainly
  10. * because the circular linkages between RelOptInfo and Path nodes can't
  11. * be handled easily in a simple depth-first traversal.
  12. *
  13. *
  14. * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
  15. * Portions Copyright (c) 1994, Regents of the University of California
  16. *
  17. * IDENTIFICATION
  18. * src/backend/nodes/copyfuncs.c
  19. *
  20. *-------------------------------------------------------------------------
  21. */
  22. #include "postgres.h"
  23. #include "miscadmin.h"
  24. #include "nodes/plannodes.h"
  25. #include "nodes/relation.h"
  26. #include "utils/datum.h"
  27. /*
  28. * Macros to simplify copying of different kinds of fields. Use these
  29. * wherever possible to reduce the chance for silly typos. Note that these
  30. * hard-wire the convention that the local variables in a Copy routine are
  31. * named 'newnode' and 'from'.
  32. */
  33. /* Copy a simple scalar field (int, float, bool, enum, etc) */
  34. #define COPY_SCALAR_FIELD(fldname) \
  35. (newnode->fldname = from->fldname)
  36. /* Copy a field that is a pointer to some kind of Node or Node tree */
  37. #define COPY_NODE_FIELD(fldname) \
  38. (newnode->fldname = copyObject(from->fldname))
  39. /* Copy a field that is a pointer to a Bitmapset */
  40. #define COPY_BITMAPSET_FIELD(fldname) \
  41. (newnode->fldname = bms_copy(from->fldname))
  42. /* Copy a field that is a pointer to a C string, or perhaps NULL */
  43. #define COPY_STRING_FIELD(fldname) \
  44. (newnode->fldname = from->fldname ? pstrdup(from->fldname) : (char *) NULL)
  45. /* Copy a field that is a pointer to a simple palloc'd object of size sz */
  46. #define COPY_POINTER_FIELD(fldname, sz) \
  47. do { \
  48. Size _size = (sz); \
  49. newnode->fldname = palloc(_size); \
  50. memcpy(newnode->fldname, from->fldname, _size); \
  51. } while (0)
  52. /* Copy a parse location field (for Copy, this is same as scalar case) */
  53. #define COPY_LOCATION_FIELD(fldname) \
  54. (newnode->fldname = from->fldname)
  55. /* ****************************************************************
  56. * plannodes.h copy functions
  57. * ****************************************************************
  58. */
  59. /*
  60. * _copyPlannedStmt
  61. */
  62. static PlannedStmt *
  63. _copyPlannedStmt(const PlannedStmt *from)
  64. {
  65. PlannedStmt *newnode = makeNode(PlannedStmt);
  66. COPY_SCALAR_FIELD(commandType);
  67. COPY_SCALAR_FIELD(queryId);
  68. COPY_SCALAR_FIELD(hasReturning);
  69. COPY_SCALAR_FIELD(hasModifyingCTE);
  70. COPY_SCALAR_FIELD(canSetTag);
  71. COPY_SCALAR_FIELD(transientPlan);
  72. COPY_NODE_FIELD(planTree);
  73. COPY_NODE_FIELD(rtable);
  74. COPY_NODE_FIELD(resultRelations);
  75. COPY_NODE_FIELD(utilityStmt);
  76. COPY_NODE_FIELD(subplans);
  77. COPY_BITMAPSET_FIELD(rewindPlanIDs);
  78. COPY_NODE_FIELD(rowMarks);
  79. COPY_NODE_FIELD(relationOids);
  80. COPY_NODE_FIELD(invalItems);
  81. COPY_SCALAR_FIELD(nParamExec);
  82. return newnode;
  83. }
  84. /*
  85. * CopyPlanFields
  86. *
  87. * This function copies the fields of the Plan node. It is used by
  88. * all the copy functions for classes which inherit from Plan.
  89. */
  90. static void
  91. CopyPlanFields(const Plan *from, Plan *newnode)
  92. {
  93. COPY_SCALAR_FIELD(startup_cost);
  94. COPY_SCALAR_FIELD(total_cost);
  95. COPY_SCALAR_FIELD(plan_rows);
  96. COPY_SCALAR_FIELD(plan_width);
  97. COPY_NODE_FIELD(targetlist);
  98. COPY_NODE_FIELD(qual);
  99. COPY_NODE_FIELD(lefttree);
  100. COPY_NODE_FIELD(righttree);
  101. COPY_NODE_FIELD(initPlan);
  102. COPY_BITMAPSET_FIELD(extParam);
  103. COPY_BITMAPSET_FIELD(allParam);
  104. }
  105. /*
  106. * _copyPlan
  107. */
  108. static Plan *
  109. _copyPlan(const Plan *from)
  110. {
  111. Plan *newnode = makeNode(Plan);
  112. /*
  113. * copy node superclass fields
  114. */
  115. CopyPlanFields(from, newnode);
  116. return newnode;
  117. }
  118. /*
  119. * _copyResult
  120. */
  121. static Result *
  122. _copyResult(const Result *from)
  123. {
  124. Result *newnode = makeNode(Result);
  125. /*
  126. * copy node superclass fields
  127. */
  128. CopyPlanFields((const Plan *) from, (Plan *) newnode);
  129. /*
  130. * copy remainder of node
  131. */
  132. COPY_NODE_FIELD(resconstantqual);
  133. return newnode;
  134. }
  135. /*
  136. * _copyModifyTable
  137. */
  138. static ModifyTable *
  139. _copyModifyTable(const ModifyTable *from)
  140. {
  141. ModifyTable *newnode = makeNode(ModifyTable);
  142. /*
  143. * copy node superclass fields
  144. */
  145. CopyPlanFields((const Plan *) from, (Plan *) newnode);
  146. /*
  147. * copy remainder of node
  148. */
  149. COPY_SCALAR_FIELD(operation);
  150. COPY_SCALAR_FIELD(canSetTag);
  151. COPY_NODE_FIELD(resultRelations);
  152. COPY_SCALAR_FIELD(resultRelIndex);
  153. COPY_NODE_FIELD(plans);
  154. COPY_NODE_FIELD(withCheckOptionLists);
  155. COPY_NODE_FIELD(returningLists);
  156. COPY_NODE_FIELD(fdwPrivLists);
  157. COPY_NODE_FIELD(rowMarks);
  158. COPY_SCALAR_FIELD(epqParam);
  159. return newnode;
  160. }
  161. /*
  162. * _copyAppend
  163. */
  164. static Append *
  165. _copyAppend(const Append *from)
  166. {
  167. Append *newnode = makeNode(Append);
  168. /*
  169. * copy node superclass fields
  170. */
  171. CopyPlanFields((const Plan *) from, (Plan *) newnode);
  172. /*
  173. * copy remainder of node
  174. */
  175. COPY_NODE_FIELD(appendplans);
  176. return newnode;
  177. }
  178. /*
  179. * _copyMergeAppend
  180. */
  181. static MergeAppend *
  182. _copyMergeAppend(const MergeAppend *from)
  183. {
  184. MergeAppend *newnode = makeNode(MergeAppend);
  185. /*
  186. * copy node superclass fields
  187. */
  188. CopyPlanFields((const Plan *) from, (Plan *) newnode);
  189. /*
  190. * copy remainder of node
  191. */
  192. COPY_NODE_FIELD(mergeplans);
  193. COPY_SCALAR_FIELD(numCols);
  194. COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
  195. COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
  196. COPY_POINTER_FIELD(collations, from->numCols * sizeof(Oid));
  197. COPY_POINTER_FIELD(nullsFirst, from->numCols * sizeof(bool));
  198. return newnode;
  199. }
  200. /*
  201. * _copyRecursiveUnion
  202. */
  203. static RecursiveUnion *
  204. _copyRecursiveUnion(const RecursiveUnion *from)
  205. {
  206. RecursiveUnion *newnode = makeNode(RecursiveUnion);
  207. /*
  208. * copy node superclass fields
  209. */
  210. CopyPlanFields((const Plan *) from, (Plan *) newnode);
  211. /*
  212. * copy remainder of node
  213. */
  214. COPY_SCALAR_FIELD(wtParam);
  215. COPY_SCALAR_FIELD(numCols);
  216. if (from->numCols > 0)
  217. {
  218. COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
  219. COPY_POINTER_FIELD(dupOperators, from->numCols * sizeof(Oid));
  220. }
  221. COPY_SCALAR_FIELD(numGroups);
  222. return newnode;
  223. }
  224. /*
  225. * _copyBitmapAnd
  226. */
  227. static BitmapAnd *
  228. _copyBitmapAnd(const BitmapAnd *from)
  229. {
  230. BitmapAnd *newnode = makeNode(BitmapAnd);
  231. /*
  232. * copy node superclass fields
  233. */
  234. CopyPlanFields((const Plan *) from, (Plan *) newnode);
  235. /*
  236. * copy remainder of node
  237. */
  238. COPY_NODE_FIELD(bitmapplans);
  239. return newnode;
  240. }
  241. /*
  242. * _copyBitmapOr
  243. */
  244. static BitmapOr *
  245. _copyBitmapOr(const BitmapOr *from)
  246. {
  247. BitmapOr *newnode = makeNode(BitmapOr);
  248. /*
  249. * copy node superclass fields
  250. */
  251. CopyPlanFields((const Plan *) from, (Plan *) newnode);
  252. /*
  253. * copy remainder of node
  254. */
  255. COPY_NODE_FIELD(bitmapplans);
  256. return newnode;
  257. }
  258. /*
  259. * CopyScanFields
  260. *
  261. * This function copies the fields of the Scan node. It is used by
  262. * all the copy functions for classes which inherit from Scan.
  263. */
  264. static void
  265. CopyScanFields(const Scan *from, Scan *newnode)
  266. {
  267. CopyPlanFields((const Plan *) from, (Plan *) newnode);
  268. COPY_SCALAR_FIELD(scanrelid);
  269. }
  270. /*
  271. * _copyScan
  272. */
  273. static Scan *
  274. _copyScan(const Scan *from)
  275. {
  276. Scan *newnode = makeNode(Scan);
  277. /*
  278. * copy node superclass fields
  279. */
  280. CopyScanFields((const Scan *) from, (Scan *) newnode);
  281. return newnode;
  282. }
  283. /*
  284. * _copySeqScan
  285. */
  286. static SeqScan *
  287. _copySeqScan(const SeqScan *from)
  288. {
  289. SeqScan *newnode = makeNode(SeqScan);
  290. /*
  291. * copy node superclass fields
  292. */
  293. CopyScanFields((const Scan *) from, (Scan *) newnode);
  294. return newnode;
  295. }
  296. /*
  297. * _copyIndexScan
  298. */
  299. static IndexScan *
  300. _copyIndexScan(const IndexScan *from)
  301. {
  302. IndexScan *newnode = makeNode(IndexScan);
  303. /*
  304. * copy node superclass fields
  305. */
  306. CopyScanFields((const Scan *) from, (Scan *) newnode);
  307. /*
  308. * copy remainder of node
  309. */
  310. COPY_SCALAR_FIELD(indexid);
  311. COPY_NODE_FIELD(indexqual);
  312. COPY_NODE_FIELD(indexqualorig);
  313. COPY_NODE_FIELD(indexorderby);
  314. COPY_NODE_FIELD(indexorderbyorig);
  315. COPY_SCALAR_FIELD(indexorderdir);
  316. return newnode;
  317. }
  318. /*
  319. * _copyIndexOnlyScan
  320. */
  321. static IndexOnlyScan *
  322. _copyIndexOnlyScan(const IndexOnlyScan *from)
  323. {
  324. IndexOnlyScan *newnode = makeNode(IndexOnlyScan);
  325. /*
  326. * copy node superclass fields
  327. */
  328. CopyScanFields((const Scan *) from, (Scan *) newnode);
  329. /*
  330. * copy remainder of node
  331. */
  332. COPY_SCALAR_FIELD(indexid);
  333. COPY_NODE_FIELD(indexqual);
  334. COPY_NODE_FIELD(indexorderby);
  335. COPY_NODE_FIELD(indextlist);
  336. COPY_SCALAR_FIELD(indexorderdir);
  337. return newnode;
  338. }
  339. /*
  340. * _copyBitmapIndexScan
  341. */
  342. static BitmapIndexScan *
  343. _copyBitmapIndexScan(const BitmapIndexScan *from)
  344. {
  345. BitmapIndexScan *newnode = makeNode(BitmapIndexScan);
  346. /*
  347. * copy node superclass fields
  348. */
  349. CopyScanFields((const Scan *) from, (Scan *) newnode);
  350. /*
  351. * copy remainder of node
  352. */
  353. COPY_SCALAR_FIELD(indexid);
  354. COPY_NODE_FIELD(indexqual);
  355. COPY_NODE_FIELD(indexqualorig);
  356. return newnode;
  357. }
  358. /*
  359. * _copyBitmapHeapScan
  360. */
  361. static BitmapHeapScan *
  362. _copyBitmapHeapScan(const BitmapHeapScan *from)
  363. {
  364. BitmapHeapScan *newnode = makeNode(BitmapHeapScan);
  365. /*
  366. * copy node superclass fields
  367. */
  368. CopyScanFields((const Scan *) from, (Scan *) newnode);
  369. /*
  370. * copy remainder of node
  371. */
  372. COPY_NODE_FIELD(bitmapqualorig);
  373. return newnode;
  374. }
  375. /*
  376. * _copyTidScan
  377. */
  378. static TidScan *
  379. _copyTidScan(const TidScan *from)
  380. {
  381. TidScan *newnode = makeNode(TidScan);
  382. /*
  383. * copy node superclass fields
  384. */
  385. CopyScanFields((const Scan *) from, (Scan *) newnode);
  386. /*
  387. * copy remainder of node
  388. */
  389. COPY_NODE_FIELD(tidquals);
  390. return newnode;
  391. }
  392. /*
  393. * _copySubqueryScan
  394. */
  395. static SubqueryScan *
  396. _copySubqueryScan(const SubqueryScan *from)
  397. {
  398. SubqueryScan *newnode = makeNode(SubqueryScan);
  399. /*
  400. * copy node superclass fields
  401. */
  402. CopyScanFields((const Scan *) from, (Scan *) newnode);
  403. /*
  404. * copy remainder of node
  405. */
  406. COPY_NODE_FIELD(subplan);
  407. return newnode;
  408. }
  409. /*
  410. * _copyFunctionScan
  411. */
  412. static FunctionScan *
  413. _copyFunctionScan(const FunctionScan *from)
  414. {
  415. FunctionScan *newnode = makeNode(FunctionScan);
  416. /*
  417. * copy node superclass fields
  418. */
  419. CopyScanFields((const Scan *) from, (Scan *) newnode);
  420. /*
  421. * copy remainder of node
  422. */
  423. COPY_NODE_FIELD(functions);
  424. COPY_SCALAR_FIELD(funcordinality);
  425. return newnode;
  426. }
  427. /*
  428. * _copyValuesScan
  429. */
  430. static ValuesScan *
  431. _copyValuesScan(const ValuesScan *from)
  432. {
  433. ValuesScan *newnode = makeNode(ValuesScan);
  434. /*
  435. * copy node superclass fields
  436. */
  437. CopyScanFields((const Scan *) from, (Scan *) newnode);
  438. /*
  439. * copy remainder of node
  440. */
  441. COPY_NODE_FIELD(values_lists);
  442. return newnode;
  443. }
  444. /*
  445. * _copyCteScan
  446. */
  447. static CteScan *
  448. _copyCteScan(const CteScan *from)
  449. {
  450. CteScan *newnode = makeNode(CteScan);
  451. /*
  452. * copy node superclass fields
  453. */
  454. CopyScanFields((const Scan *) from, (Scan *) newnode);
  455. /*
  456. * copy remainder of node
  457. */
  458. COPY_SCALAR_FIELD(ctePlanId);
  459. COPY_SCALAR_FIELD(cteParam);
  460. return newnode;
  461. }
  462. /*
  463. * _copyWorkTableScan
  464. */
  465. static WorkTableScan *
  466. _copyWorkTableScan(const WorkTableScan *from)
  467. {
  468. WorkTableScan *newnode = makeNode(WorkTableScan);
  469. /*
  470. * copy node superclass fields
  471. */
  472. CopyScanFields((const Scan *) from, (Scan *) newnode);
  473. /*
  474. * copy remainder of node
  475. */
  476. COPY_SCALAR_FIELD(wtParam);
  477. return newnode;
  478. }
  479. /*
  480. * _copyForeignScan
  481. */
  482. static ForeignScan *
  483. _copyForeignScan(const ForeignScan *from)
  484. {
  485. ForeignScan *newnode = makeNode(ForeignScan);
  486. /*
  487. * copy node superclass fields
  488. */
  489. CopyScanFields((const Scan *) from, (Scan *) newnode);
  490. /*
  491. * copy remainder of node
  492. */
  493. COPY_NODE_FIELD(fdw_exprs);
  494. COPY_NODE_FIELD(fdw_private);
  495. COPY_SCALAR_FIELD(fsSystemCol);
  496. return newnode;
  497. }
  498. /*
  499. * CopyJoinFields
  500. *
  501. * This function copies the fields of the Join node. It is used by
  502. * all the copy functions for classes which inherit from Join.
  503. */
  504. static void
  505. CopyJoinFields(const Join *from, Join *newnode)
  506. {
  507. CopyPlanFields((const Plan *) from, (Plan *) newnode);
  508. COPY_SCALAR_FIELD(jointype);
  509. COPY_NODE_FIELD(joinqual);
  510. }
  511. /*
  512. * _copyJoin
  513. */
  514. static Join *
  515. _copyJoin(const Join *from)
  516. {
  517. Join *newnode = makeNode(Join);
  518. /*
  519. * copy node superclass fields
  520. */
  521. CopyJoinFields(from, newnode);
  522. return newnode;
  523. }
  524. /*
  525. * _copyNestLoop
  526. */
  527. static NestLoop *
  528. _copyNestLoop(const NestLoop *from)
  529. {
  530. NestLoop *newnode = makeNode(NestLoop);
  531. /*
  532. * copy node superclass fields
  533. */
  534. CopyJoinFields((const Join *) from, (Join *) newnode);
  535. /*
  536. * copy remainder of node
  537. */
  538. COPY_NODE_FIELD(nestParams);
  539. return newnode;
  540. }
  541. /*
  542. * _copyMergeJoin
  543. */
  544. static MergeJoin *
  545. _copyMergeJoin(const MergeJoin *from)
  546. {
  547. MergeJoin *newnode = makeNode(MergeJoin);
  548. int numCols;
  549. /*
  550. * copy node superclass fields
  551. */
  552. CopyJoinFields((const Join *) from, (Join *) newnode);
  553. /*
  554. * copy remainder of node
  555. */
  556. COPY_NODE_FIELD(mergeclauses);
  557. numCols = list_length(from->mergeclauses);
  558. if (numCols > 0)
  559. {
  560. COPY_POINTER_FIELD(mergeFamilies, numCols * sizeof(Oid));
  561. COPY_POINTER_FIELD(mergeCollations, numCols * sizeof(Oid));
  562. COPY_POINTER_FIELD(mergeStrategies, numCols * sizeof(int));
  563. COPY_POINTER_FIELD(mergeNullsFirst, numCols * sizeof(bool));
  564. }
  565. return newnode;
  566. }
  567. /*
  568. * _copyHashJoin
  569. */
  570. static HashJoin *
  571. _copyHashJoin(const HashJoin *from)
  572. {
  573. HashJoin *newnode = makeNode(HashJoin);
  574. /*
  575. * copy node superclass fields
  576. */
  577. CopyJoinFields((const Join *) from, (Join *) newnode);
  578. /*
  579. * copy remainder of node
  580. */
  581. COPY_NODE_FIELD(hashclauses);
  582. return newnode;
  583. }
  584. /*
  585. * _copyMaterial
  586. */
  587. static Material *
  588. _copyMaterial(const Material *from)
  589. {
  590. Material *newnode = makeNode(Material);
  591. /*
  592. * copy node superclass fields
  593. */
  594. CopyPlanFields((const Plan *) from, (Plan *) newnode);
  595. return newnode;
  596. }
  597. /*
  598. * _copySort
  599. */
  600. static Sort *
  601. _copySort(const Sort *from)
  602. {
  603. Sort *newnode = makeNode(Sort);
  604. /*
  605. * copy node superclass fields
  606. */
  607. CopyPlanFields((const Plan *) from, (Plan *) newnode);
  608. COPY_SCALAR_FIELD(numCols);
  609. COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
  610. COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
  611. COPY_POINTER_FIELD(collations, from->numCols * sizeof(Oid));
  612. COPY_POINTER_FIELD(nullsFirst, from->numCols * sizeof(bool));
  613. return newnode;
  614. }
  615. /*
  616. * _copyGroup
  617. */
  618. static Group *
  619. _copyGroup(const Group *from)
  620. {
  621. Group *newnode = makeNode(Group);
  622. CopyPlanFields((const Plan *) from, (Plan *) newnode);
  623. COPY_SCALAR_FIELD(numCols);
  624. COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
  625. COPY_POINTER_FIELD(grpOperators, from->numCols * sizeof(Oid));
  626. return newnode;
  627. }
  628. /*
  629. * _copyAgg
  630. */
  631. static Agg *
  632. _copyAgg(const Agg *from)
  633. {
  634. Agg *newnode = makeNode(Agg);
  635. CopyPlanFields((const Plan *) from, (Plan *) newnode);
  636. COPY_SCALAR_FIELD(aggstrategy);
  637. COPY_SCALAR_FIELD(numCols);
  638. if (from->numCols > 0)
  639. {
  640. COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
  641. COPY_POINTER_FIELD(grpOperators, from->numCols * sizeof(Oid));
  642. }
  643. COPY_SCALAR_FIELD(numGroups);
  644. return newnode;
  645. }
  646. /*
  647. * _copyWindowAgg
  648. */
  649. static WindowAgg *
  650. _copyWindowAgg(const WindowAgg *from)
  651. {
  652. WindowAgg *newnode = makeNode(WindowAgg);
  653. CopyPlanFields((const Plan *) from, (Plan *) newnode);
  654. COPY_SCALAR_FIELD(winref);
  655. COPY_SCALAR_FIELD(partNumCols);
  656. if (from->partNumCols > 0)
  657. {
  658. COPY_POINTER_FIELD(partColIdx, from->partNumCols * sizeof(AttrNumber));
  659. COPY_POINTER_FIELD(partOperators, from->partNumCols * sizeof(Oid));
  660. }
  661. COPY_SCALAR_FIELD(ordNumCols);
  662. if (from->ordNumCols > 0)
  663. {
  664. COPY_POINTER_FIELD(ordColIdx, from->ordNumCols * sizeof(AttrNumber));
  665. COPY_POINTER_FIELD(ordOperators, from->ordNumCols * sizeof(Oid));
  666. }
  667. COPY_SCALAR_FIELD(frameOptions);
  668. COPY_NODE_FIELD(startOffset);
  669. COPY_NODE_FIELD(endOffset);
  670. return newnode;
  671. }
  672. /*
  673. * _copyUnique
  674. */
  675. static Unique *
  676. _copyUnique(const Unique *from)
  677. {
  678. Unique *newnode = makeNode(Unique);
  679. /*
  680. * copy node superclass fields
  681. */
  682. CopyPlanFields((const Plan *) from, (Plan *) newnode);
  683. /*
  684. * copy remainder of node
  685. */
  686. COPY_SCALAR_FIELD(numCols);
  687. COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
  688. COPY_POINTER_FIELD(uniqOperators, from->numCols * sizeof(Oid));
  689. return newnode;
  690. }
  691. /*
  692. * _copyHash
  693. */
  694. static Hash *
  695. _copyHash(const Hash *from)
  696. {
  697. Hash *newnode = makeNode(Hash);
  698. /*
  699. * copy node superclass fields
  700. */
  701. CopyPlanFields((const Plan *) from, (Plan *) newnode);
  702. /*
  703. * copy remainder of node
  704. */
  705. COPY_SCALAR_FIELD(skewTable);
  706. COPY_SCALAR_FIELD(skewColumn);
  707. COPY_SCALAR_FIELD(skewInherit);
  708. COPY_SCALAR_FIELD(skewColType);
  709. COPY_SCALAR_FIELD(skewColTypmod);
  710. return newnode;
  711. }
  712. /*
  713. * _copySetOp
  714. */
  715. static SetOp *
  716. _copySetOp(const SetOp *from)
  717. {
  718. SetOp *newnode = makeNode(SetOp);
  719. /*
  720. * copy node superclass fields
  721. */
  722. CopyPlanFields((const Plan *) from, (Plan *) newnode);
  723. /*
  724. * copy remainder of node
  725. */
  726. COPY_SCALAR_FIELD(cmd);
  727. COPY_SCALAR_FIELD(strategy);
  728. COPY_SCALAR_FIELD(numCols);
  729. COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
  730. COPY_POINTER_FIELD(dupOperators, from->numCols * sizeof(Oid));
  731. COPY_SCALAR_FIELD(flagColIdx);
  732. COPY_SCALAR_FIELD(firstFlag);
  733. COPY_SCALAR_FIELD(numGroups);
  734. return newnode;
  735. }
  736. /*
  737. * _copyLockRows
  738. */
  739. static LockRows *
  740. _copyLockRows(const LockRows *from)
  741. {
  742. LockRows *newnode = makeNode(LockRows);
  743. /*
  744. * copy node superclass fields
  745. */
  746. CopyPlanFields((const Plan *) from, (Plan *) newnode);
  747. /*
  748. * copy remainder of node
  749. */
  750. COPY_NODE_FIELD(rowMarks);
  751. COPY_SCALAR_FIELD(epqParam);
  752. return newnode;
  753. }
  754. /*
  755. * _copyLimit
  756. */
  757. static Limit *
  758. _copyLimit(const Limit *from)
  759. {
  760. Limit *newnode = makeNode(Limit);
  761. /*
  762. * copy node superclass fields
  763. */
  764. CopyPlanFields((const Plan *) from, (Plan *) newnode);
  765. /*
  766. * copy remainder of node
  767. */
  768. COPY_NODE_FIELD(limitOffset);
  769. COPY_NODE_FIELD(limitCount);
  770. return newnode;
  771. }
  772. /*
  773. * _copyNestLoopParam
  774. */
  775. static NestLoopParam *
  776. _copyNestLoopParam(const NestLoopParam *from)
  777. {
  778. NestLoopParam *newnode = makeNode(NestLoopParam);
  779. COPY_SCALAR_FIELD(paramno);
  780. COPY_NODE_FIELD(paramval);
  781. return newnode;
  782. }
  783. /*
  784. * _copyPlanRowMark
  785. */
  786. static PlanRowMark *
  787. _copyPlanRowMark(const PlanRowMark *from)
  788. {
  789. PlanRowMark *newnode = makeNode(PlanRowMark);
  790. COPY_SCALAR_FIELD(rti);
  791. COPY_SCALAR_FIELD(prti);
  792. COPY_SCALAR_FIELD(rowmarkId);
  793. COPY_SCALAR_FIELD(markType);
  794. COPY_SCALAR_FIELD(noWait);
  795. COPY_SCALAR_FIELD(isParent);
  796. return newnode;
  797. }
  798. /*
  799. * _copyPlanInvalItem
  800. */
  801. static PlanInvalItem *
  802. _copyPlanInvalItem(const PlanInvalItem *from)
  803. {
  804. PlanInvalItem *newnode = makeNode(PlanInvalItem);
  805. COPY_SCALAR_FIELD(cacheId);
  806. COPY_SCALAR_FIELD(hashValue);
  807. return newnode;
  808. }
  809. /* ****************************************************************
  810. * primnodes.h copy functions
  811. * ****************************************************************
  812. */
  813. /*
  814. * _copyAlias
  815. */
  816. static Alias *
  817. _copyAlias(const Alias *from)
  818. {
  819. Alias *newnode = makeNode(Alias);
  820. COPY_STRING_FIELD(aliasname);
  821. COPY_NODE_FIELD(colnames);
  822. return newnode;
  823. }
  824. /*
  825. * _copyRangeVar
  826. */
  827. static RangeVar *
  828. _copyRangeVar(const RangeVar *from)
  829. {
  830. RangeVar *newnode = makeNode(RangeVar);
  831. COPY_STRING_FIELD(catalogname);
  832. COPY_STRING_FIELD(schemaname);
  833. COPY_STRING_FIELD(relname);
  834. COPY_SCALAR_FIELD(inhOpt);
  835. COPY_SCALAR_FIELD(relpersistence);
  836. COPY_NODE_FIELD(alias);
  837. COPY_LOCATION_FIELD(location);
  838. return newnode;
  839. }
  840. /*
  841. * _copyIntoClause
  842. */
  843. static IntoClause *
  844. _copyIntoClause(const IntoClause *from)
  845. {
  846. IntoClause *newnode = makeNode(IntoClause);
  847. COPY_NODE_FIELD(rel);
  848. COPY_NODE_FIELD(colNames);
  849. COPY_NODE_FIELD(options);
  850. COPY_SCALAR_FIELD(onCommit);
  851. COPY_STRING_FIELD(tableSpaceName);
  852. COPY_NODE_FIELD(viewQuery);
  853. COPY_SCALAR_FIELD(skipData);
  854. return newnode;
  855. }
  856. /*
  857. * We don't need a _copyExpr because Expr is an abstract supertype which
  858. * should never actually get instantiated. Also, since it has no common
  859. * fields except NodeTag, there's no need for a helper routine to factor
  860. * out copying the common fields...
  861. */
  862. /*
  863. * _copyVar
  864. */
  865. static Var *
  866. _copyVar(const Var *from)
  867. {
  868. Var *newnode = makeNode(Var);
  869. COPY_SCALAR_FIELD(varno);
  870. COPY_SCALAR_FIELD(varattno);
  871. COPY_SCALAR_FIELD(vartype);
  872. COPY_SCALAR_FIELD(vartypmod);
  873. COPY_SCALAR_FIELD(varcollid);
  874. COPY_SCALAR_FIELD(varlevelsup);
  875. COPY_SCALAR_FIELD(varnoold);
  876. COPY_SCALAR_FIELD(varoattno);
  877. COPY_LOCATION_FIELD(location);
  878. return newnode;
  879. }
  880. /*
  881. * _copyConst
  882. */
  883. static Const *
  884. _copyConst(const Const *from)
  885. {
  886. Const *newnode = makeNode(Const);
  887. COPY_SCALAR_FIELD(consttype);
  888. COPY_SCALAR_FIELD(consttypmod);
  889. COPY_SCALAR_FIELD(constcollid);
  890. COPY_SCALAR_FIELD(constlen);
  891. if (from->constbyval || from->constisnull)
  892. {
  893. /*
  894. * passed by value so just copy the datum. Also, don't try to copy
  895. * struct when value is null!
  896. */
  897. newnode->constvalue = from->constvalue;
  898. }
  899. else
  900. {
  901. /*
  902. * passed by reference. We need a palloc'd copy.
  903. */
  904. newnode->constvalue = datumCopy(from->constvalue,
  905. from->constbyval,
  906. from->constlen);
  907. }
  908. COPY_SCALAR_FIELD(constisnull);
  909. COPY_SCALAR_FIELD(constbyval);
  910. COPY_LOCATION_FIELD(location);
  911. return newnode;
  912. }
  913. /*
  914. * _copyParam
  915. */
  916. static Param *
  917. _copyParam(const Param *from)
  918. {
  919. Param *newnode = makeNode(Param);
  920. COPY_SCALAR_FIELD(paramkind);
  921. COPY_SCALAR_FIELD(paramid);
  922. COPY_SCALAR_FIELD(paramtype);
  923. COPY_SCALAR_FIELD(paramtypmod);
  924. COPY_SCALAR_FIELD(paramcollid);
  925. COPY_LOCATION_FIELD(location);
  926. return newnode;
  927. }
  928. /*
  929. * _copyAggref
  930. */
  931. static Aggref *
  932. _copyAggref(const Aggref *from)
  933. {
  934. Aggref *newnode = makeNode(Aggref);
  935. COPY_SCALAR_FIELD(aggfnoid);
  936. COPY_SCALAR_FIELD(aggtype);
  937. COPY_SCALAR_FIELD(aggcollid);
  938. COPY_SCALAR_FIELD(inputcollid);
  939. COPY_NODE_FIELD(aggdirectargs);
  940. COPY_NODE_FIELD(args);
  941. COPY_NODE_FIELD(aggorder);
  942. COPY_NODE_FIELD(aggdistinct);
  943. COPY_NODE_FIELD(aggfilter);
  944. COPY_SCALAR_FIELD(aggstar);
  945. COPY_SCALAR_FIELD(aggvariadic);
  946. COPY_SCALAR_FIELD(aggkind);
  947. COPY_SCALAR_FIELD(agglevelsup);
  948. COPY_LOCATION_FIELD(location);
  949. return newnode;
  950. }
  951. /*
  952. * _copyWindowFunc
  953. */
  954. static WindowFunc *
  955. _copyWindowFunc(const WindowFunc *from)
  956. {
  957. WindowFunc *newnode = makeNode(WindowFunc);
  958. COPY_SCALAR_FIELD(winfnoid);
  959. COPY_SCALAR_FIELD(wintype);
  960. COPY_SCALAR_FIELD(wincollid);
  961. COPY_SCALAR_FIELD(inputcollid);
  962. COPY_NODE_FIELD(args);
  963. COPY_NODE_FIELD(aggfilter);
  964. COPY_SCALAR_FIELD(winref);
  965. COPY_SCALAR_FIELD(winstar);
  966. COPY_SCALAR_FIELD(winagg);
  967. COPY_LOCATION_FIELD(location);
  968. return newnode;
  969. }
  970. /*
  971. * _copyArrayRef
  972. */
  973. static ArrayRef *
  974. _copyArrayRef(const ArrayRef *from)
  975. {
  976. ArrayRef *newnode = makeNode(ArrayRef);
  977. COPY_SCALAR_FIELD(refarraytype);
  978. COPY_SCALAR_FIELD(refelemtype);
  979. COPY_SCALAR_FIELD(reftypmod);
  980. COPY_SCALAR_FIELD(refcollid);
  981. COPY_NODE_FIELD(refupperindexpr);
  982. COPY_NODE_FIELD(reflowerindexpr);
  983. COPY_NODE_FIELD(refexpr);
  984. COPY_NODE_FIELD(refassgnexpr);
  985. return newnode;
  986. }
  987. /*
  988. * _copyFuncExpr
  989. */
  990. static FuncExpr *
  991. _copyFuncExpr(const FuncExpr *from)
  992. {
  993. FuncExpr *newnode = makeNode(FuncExpr);
  994. COPY_SCALAR_FIELD(funcid);
  995. COPY_SCALAR_FIELD(funcresulttype);
  996. COPY_SCALAR_FIELD(funcretset);
  997. COPY_SCALAR_FIELD(funcvariadic);
  998. COPY_SCALAR_FIELD(funcformat);
  999. COPY_SCALAR_FIELD(funccollid);
  1000. COPY_SCALAR_FIELD(inputcollid);
  1001. COPY_NODE_FIELD(args);
  1002. COPY_LOCATION_FIELD(location);
  1003. return newnode;
  1004. }
  1005. /*
  1006. * _copyNamedArgExpr *
  1007. */
  1008. static NamedArgExpr *
  1009. _copyNamedArgExpr(const NamedArgExpr *from)
  1010. {
  1011. NamedArgExpr *newnode = makeNode(NamedArgExpr);
  1012. COPY_NODE_FIELD(arg);
  1013. COPY_STRING_FIELD(name);
  1014. COPY_SCALAR_FIELD(argnumber);
  1015. COPY_LOCATION_FIELD(location);
  1016. return newnode;
  1017. }
  1018. /*
  1019. * _copyOpExpr
  1020. */
  1021. static OpExpr *
  1022. _copyOpExpr(const OpExpr *from)
  1023. {
  1024. OpExpr *newnode = makeNode(OpExpr);
  1025. COPY_SCALAR_FIELD(opno);
  1026. COPY_SCALAR_FIELD(opfuncid);
  1027. COPY_SCALAR_FIELD(opresulttype);
  1028. COPY_SCALAR_FIELD(opretset);
  1029. COPY_SCALAR_FIELD(opcollid);
  1030. COPY_SCALAR_FIELD(inputcollid);
  1031. COPY_NODE_FIELD(args);
  1032. COPY_LOCATION_FIELD(location);
  1033. return newnode;
  1034. }
  1035. /*
  1036. * _copyDistinctExpr (same as OpExpr)
  1037. */
  1038. static DistinctExpr *
  1039. _copyDistinctExpr(const DistinctExpr *from)
  1040. {
  1041. DistinctExpr *newnode = makeNode(DistinctExpr);
  1042. COPY_SCALAR_FIELD(opno);
  1043. COPY_SCALAR_FIELD(opfuncid);
  1044. COPY_SCALAR_FIELD(opresulttype);
  1045. COPY_SCALAR_FIELD(opretset);
  1046. COPY_SCALAR_FIELD(opcollid);
  1047. COPY_SCALAR_FIELD(inputcollid);
  1048. COPY_NODE_FIELD(args);
  1049. COPY_LOCATION_FIELD(location);
  1050. return newnode;
  1051. }
  1052. /*
  1053. * _copyNullIfExpr (same as OpExpr)
  1054. */
  1055. static NullIfExpr *
  1056. _copyNullIfExpr(const NullIfExpr *from)
  1057. {
  1058. NullIfExpr *newnode = makeNode(NullIfExpr);
  1059. COPY_SCALAR_FIELD(opno);
  1060. COPY_SCALAR_FIELD(opfuncid);
  1061. COPY_SCALAR_FIELD(opresulttype);
  1062. COPY_SCALAR_FIELD(opretset);
  1063. COPY_SCALAR_FIELD(opcollid);
  1064. COPY_SCALAR_FIELD(inputcollid);
  1065. COPY_NODE_FIELD(args);
  1066. COPY_LOCATION_FIELD(location);
  1067. return newnode;
  1068. }
  1069. /*
  1070. * _copyScalarArrayOpExpr
  1071. */
  1072. static ScalarArrayOpExpr *
  1073. _copyScalarArrayOpExpr(const ScalarArrayOpExpr *from)
  1074. {
  1075. ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
  1076. COPY_SCALAR_FIELD(opno);
  1077. COPY_SCALAR_FIELD(opfuncid);
  1078. COPY_SCALAR_FIELD(useOr);
  1079. COPY_SCALAR_FIELD(inputcollid);
  1080. COPY_NODE_FIELD(args);
  1081. COPY_LOCATION_FIELD(location);
  1082. return newnode;
  1083. }
  1084. /*
  1085. * _copyBoolExpr
  1086. */
  1087. static BoolExpr *
  1088. _copyBoolExpr(const BoolExpr *from)
  1089. {
  1090. BoolExpr *newnode = makeNode(BoolExpr);
  1091. COPY_SCALAR_FIELD(boolop);
  1092. COPY_NODE_FIELD(args);
  1093. COPY_LOCATION_FIELD(location);
  1094. return newnode;
  1095. }
  1096. /*
  1097. * _copySubLink
  1098. */
  1099. static SubLink *
  1100. _copySubLink(const SubLink *from)
  1101. {
  1102. SubLink *newnode = makeNode(SubLink);
  1103. COPY_SCALAR_FIELD(subLinkType);
  1104. COPY_NODE_FIELD(testexpr);
  1105. COPY_NODE_FIELD(operName);
  1106. COPY_NODE_FIELD(subselect);
  1107. COPY_LOCATION_FIELD(location);
  1108. return newnode;
  1109. }
  1110. /*
  1111. * _copySubPlan
  1112. */
  1113. static SubPlan *
  1114. _copySubPlan(const SubPlan *from)
  1115. {
  1116. SubPlan *newnode = makeNode(SubPlan);
  1117. COPY_SCALAR_FIELD(subLinkType);
  1118. COPY_NODE_FIELD(testexpr);
  1119. COPY_NODE_FIELD(paramIds);
  1120. COPY_SCALAR_FIELD(plan_id);
  1121. COPY_STRING_FIELD(plan_name);
  1122. COPY_SCALAR_FIELD(firstColType);
  1123. COPY_SCALAR_FIELD(firstColTypmod);
  1124. COPY_SCALAR_FIELD(firstColCollation);
  1125. COPY_SCALAR_FIELD(useHashTable);
  1126. COPY_SCALAR_FIELD(unknownEqFalse);
  1127. COPY_NODE_FIELD(setParam);
  1128. COPY_NODE_FIELD(parParam);
  1129. COPY_NODE_FIELD(args);
  1130. COPY_SCALAR_FIELD(startup_cost);
  1131. COPY_SCALAR_FIELD(per_call_cost);
  1132. return newnode;
  1133. }
  1134. /*
  1135. * _copyAlternativeSubPlan
  1136. */
  1137. static AlternativeSubPlan *
  1138. _copyAlternativeSubPlan(const AlternativeSubPlan *from)
  1139. {
  1140. AlternativeSubPlan *newnode = makeNode(AlternativeSubPlan);
  1141. COPY_NODE_FIELD(subplans);
  1142. return newnode;
  1143. }
  1144. /*
  1145. * _copyFieldSelect
  1146. */
  1147. static FieldSelect *
  1148. _copyFieldSelect(const FieldSelect *from)
  1149. {
  1150. FieldSelect *newnode = makeNode(FieldSelect);
  1151. COPY_NODE_FIELD(arg);
  1152. COPY_SCALAR_FIELD(fieldnum);
  1153. COPY_SCALAR_FIELD(resulttype);
  1154. COPY_SCALAR_FIELD(resulttypmod);
  1155. COPY_SCALAR_FIELD(resultcollid);
  1156. return newnode;
  1157. }
  1158. /*
  1159. * _copyFieldStore
  1160. */
  1161. static FieldStore *
  1162. _copyFieldStore(const FieldStore *from)
  1163. {
  1164. FieldStore *newnode = makeNode(FieldStore);
  1165. COPY_NODE_FIELD(arg);
  1166. COPY_NODE_FIELD(newvals);
  1167. COPY_NODE_FIELD(fieldnums);
  1168. COPY_SCALAR_FIELD(resulttype);
  1169. return newnode;
  1170. }
  1171. /*
  1172. * _copyRelabelType
  1173. */
  1174. static RelabelType *
  1175. _copyRelabelType(const RelabelType *from)
  1176. {
  1177. RelabelType *newnode = makeNode(RelabelType);
  1178. COPY_NODE_FIELD(arg);
  1179. COPY_SCALAR_FIELD(resulttype);
  1180. COPY_SCALAR_FIELD(resulttypmod);
  1181. COPY_SCALAR_FIELD(resultcollid);
  1182. COPY_SCALAR_FIELD(relabelformat);
  1183. COPY_LOCATION_FIELD(location);
  1184. return newnode;
  1185. }
  1186. /*
  1187. * _copyCoerceViaIO
  1188. */
  1189. static CoerceViaIO *
  1190. _copyCoerceViaIO(const CoerceViaIO *from)
  1191. {
  1192. CoerceViaIO *newnode = makeNode(CoerceViaIO);
  1193. COPY_NODE_FIELD(arg);
  1194. COPY_SCALAR_FIELD(resulttype);
  1195. COPY_SCALAR_FIELD(resultcollid);
  1196. COPY_SCALAR_FIELD(coerceformat);
  1197. COPY_LOCATION_FIELD(location);
  1198. return newnode;
  1199. }
  1200. /*
  1201. * _copyArrayCoerceExpr
  1202. */
  1203. static ArrayCoerceExpr *
  1204. _copyArrayCoerceExpr(const ArrayCoerceExpr *from)
  1205. {
  1206. ArrayCoerceExpr *newnode = makeNode(ArrayCoerceExpr);
  1207. COPY_NODE_FIELD(arg);
  1208. COPY_SCALAR_FIELD(elemfuncid);
  1209. COPY_SCALAR_FIELD(resulttype);
  1210. COPY_SCALAR_FIELD(resulttypmod);
  1211. COPY_SCALAR_FIELD(resultcollid);
  1212. COPY_SCALAR_FIELD(isExplicit);
  1213. COPY_SCALAR_FIELD(coerceformat);
  1214. COPY_LOCATION_FIELD(location);
  1215. return newnode;
  1216. }
  1217. /*
  1218. * _copyConvertRowtypeExpr
  1219. */
  1220. static ConvertRowtypeExpr *
  1221. _copyConvertRowtypeExpr(const ConvertRowtypeExpr *from)
  1222. {
  1223. ConvertRowtypeExpr *newnode = makeNode(ConvertRowtypeExpr);
  1224. COPY_NODE_FIELD(arg);
  1225. COPY_SCALAR_FIELD(resulttype);
  1226. COPY_SCALAR_FIELD(convertformat);
  1227. COPY_LOCATION_FIELD(location);
  1228. return newnode;
  1229. }
  1230. /*
  1231. * _copyCollateExpr
  1232. */
  1233. static CollateExpr *
  1234. _copyCollateExpr(const CollateExpr *from)
  1235. {
  1236. CollateExpr *newnode = makeNode(CollateExpr);
  1237. COPY_NODE_FIELD(arg);
  1238. COPY_SCALAR_FIELD(collOid);
  1239. COPY_LOCATION_FIELD(location);
  1240. return newnode;
  1241. }
  1242. /*
  1243. * _copyCaseExpr
  1244. */
  1245. static CaseExpr *
  1246. _copyCaseExpr(const CaseExpr *from)
  1247. {
  1248. CaseExpr *newnode = makeNode(CaseExpr);
  1249. COPY_SCALAR_FIELD(casetype);
  1250. COPY_SCALAR_FIELD(casecollid);
  1251. COPY_NODE_FIELD(arg);
  1252. COPY_NODE_FIELD(args);
  1253. COPY_NODE_FIELD(defresult);
  1254. COPY_LOCATION_FIELD(location);
  1255. return newnode;
  1256. }
  1257. /*
  1258. * _copyCaseWhen
  1259. */
  1260. static CaseWhen *
  1261. _copyCaseWhen(const CaseWhen *from)
  1262. {
  1263. CaseWhen *newnode = makeNode(CaseWhen);
  1264. COPY_NODE_FIELD(expr);
  1265. COPY_NODE_FIELD(result);
  1266. COPY_LOCATION_FIELD(location);
  1267. return newnode;
  1268. }
  1269. /*
  1270. * _copyCaseTestExpr
  1271. */
  1272. static CaseTestExpr *
  1273. _copyCaseTestExpr(const CaseTestExpr *from)
  1274. {
  1275. CaseTestExpr *newnode = makeNode(CaseTestExpr);
  1276. COPY_SCALAR_FIELD(typeId);
  1277. COPY_SCALAR_FIELD(typeMod);
  1278. COPY_SCALAR_FIELD(collation);
  1279. return newnode;
  1280. }
  1281. /*
  1282. * _copyArrayExpr
  1283. */
  1284. static ArrayExpr *
  1285. _copyArrayExpr(const ArrayExpr *from)
  1286. {
  1287. ArrayExpr *newnode = makeNode(ArrayExpr);
  1288. COPY_SCALAR_FIELD(array_typeid);
  1289. COPY_SCALAR_FIELD(array_collid);
  1290. COPY_SCALAR_FIELD(element_typeid);
  1291. COPY_NODE_FIELD(elements);
  1292. COPY_SCALAR_FIELD(multidims);
  1293. COPY_LOCATION_FIELD(location);
  1294. return newnode;
  1295. }
  1296. /*
  1297. * _copyRowExpr
  1298. */
  1299. static RowExpr *
  1300. _copyRowExpr(const RowExpr *from)
  1301. {
  1302. RowExpr *newnode = makeNode(RowExpr);
  1303. COPY_NODE_FIELD(args);
  1304. COPY_SCALAR_FIELD(row_typeid);
  1305. COPY_SCALAR_FIELD(row_format);
  1306. COPY_NODE_FIELD(colnames);
  1307. COPY_LOCATION_FIELD(location);
  1308. return newnode;
  1309. }
  1310. /*
  1311. * _copyRowCompareExpr
  1312. */
  1313. static RowCompareExpr *
  1314. _copyRowCompareExpr(const RowCompareExpr *from)
  1315. {
  1316. RowCompareExpr *newnode = makeNode(RowCompareExpr);
  1317. COPY_SCALAR_FIELD(rctype);
  1318. COPY_NODE_FIELD(opnos);
  1319. COPY_NODE_FIELD(opfamilies);
  1320. COPY_NODE_FIELD(inputcollids);
  1321. COPY_NODE_FIELD(largs);
  1322. COPY_NODE_FIELD(rargs);
  1323. return newnode;
  1324. }
  1325. /*
  1326. * _copyCoalesceExpr
  1327. */
  1328. static CoalesceExpr *
  1329. _copyCoalesceExpr(const CoalesceExpr *from)
  1330. {
  1331. CoalesceExpr *newnode = makeNode(CoalesceExpr);
  1332. COPY_SCALAR_FIELD(coalescetype);
  1333. COPY_SCALAR_FIELD(coalescecollid);
  1334. COPY_NODE_FIELD(args);
  1335. COPY_LOCATION_FIELD(location);
  1336. return newnode;
  1337. }
  1338. /*
  1339. * _copyMinMaxExpr
  1340. */
  1341. static MinMaxExpr *
  1342. _copyMinMaxExpr(const MinMaxExpr *from)
  1343. {
  1344. MinMaxExpr *newnode = makeNode(MinMaxExpr);
  1345. COPY_SCALAR_FIELD(minmaxtype);
  1346. COPY_SCALAR_FIELD(minmaxcollid);
  1347. COPY_SCALAR_FIELD(inputcollid);
  1348. COPY_SCALAR_FIELD(op);
  1349. COPY_NODE_FIELD(args);
  1350. COPY_LOCATION_FIELD(location);
  1351. return newnode;
  1352. }
  1353. /*
  1354. * _copyXmlExpr
  1355. */
  1356. static XmlExpr *
  1357. _copyXmlExpr(const XmlExpr *from)
  1358. {
  1359. XmlExpr *newnode = makeNode(XmlExpr);
  1360. COPY_SCALAR_FIELD(op);
  1361. COPY_STRING_FIELD(name);
  1362. COPY_NODE_FIELD(named_args);
  1363. COPY_NODE_FIELD(arg_names);
  1364. COPY_NODE_FIELD(args);
  1365. COPY_SCALAR_FIELD(xmloption);
  1366. COPY_SCALAR_FIELD(type);
  1367. COPY_SCALAR_FIELD(typmod);
  1368. COPY_LOCATION_FIELD(location);
  1369. return newnode;
  1370. }
  1371. /*
  1372. * _copyNullTest
  1373. */
  1374. static NullTest *
  1375. _copyNullTest(const NullTest *from)
  1376. {
  1377. NullTest *newnode = makeNode(NullTest);
  1378. COPY_NODE_FIELD(arg);
  1379. COPY_SCALAR_FIELD(nulltesttype);
  1380. COPY_SCALAR_FIELD(argisrow);
  1381. return newnode;
  1382. }
  1383. /*
  1384. * _copyBooleanTest
  1385. */
  1386. static BooleanTest *
  1387. _copyBooleanTest(const BooleanTest *from)
  1388. {
  1389. BooleanTest *newnode = makeNode(BooleanTest);
  1390. COPY_NODE_FIELD(arg);
  1391. COPY_SCALAR_FIELD(booltesttype);
  1392. return newnode;
  1393. }
  1394. /*
  1395. * _copyCoerceToDomain
  1396. */
  1397. static CoerceToDomain *
  1398. _copyCoerceToDomain(const CoerceToDomain *from)
  1399. {
  1400. CoerceToDomain *newnode = makeNode(CoerceToDomain);
  1401. COPY_NODE_FIELD(arg);
  1402. COPY_SCALAR_FIELD(resulttype);
  1403. COPY_SCALAR_FIELD(resulttypmod);
  1404. COPY_SCALAR_FIELD(resultcollid);
  1405. COPY_SCALAR_FIELD(coercionformat);
  1406. COPY_LOCATION_FIELD(location);
  1407. return newnode;
  1408. }
  1409. /*
  1410. * _copyCoerceToDomainValue
  1411. */
  1412. static CoerceToDomainValue *
  1413. _copyCoerceToDomainValue(const CoerceToDomainValue *from)
  1414. {
  1415. CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
  1416. COPY_SCALAR_FIELD(typeId);
  1417. COPY_SCALAR_FIELD(typeMod);
  1418. COPY_SCALAR_FIELD(collation);
  1419. COPY_LOCATION_FIELD(location);
  1420. return newnode;
  1421. }
  1422. /*
  1423. * _copySetToDefault
  1424. */
  1425. static SetToDefault *
  1426. _copySetToDefault(const SetToDefault *from)
  1427. {
  1428. SetToDefault *newnode = makeNode(SetToDefault);
  1429. COPY_SCALAR_FIELD(typeId);
  1430. COPY_SCALAR_FIELD(typeMod);
  1431. COPY_SCALAR_FIELD(collation);
  1432. COPY_LOCATION_FIELD(location);
  1433. return newnode;
  1434. }
  1435. /*
  1436. * _copyCurrentOfExpr
  1437. */
  1438. static CurrentOfExpr *
  1439. _copyCurrentOfExpr(const CurrentOfExpr *from)
  1440. {
  1441. CurrentOfExpr *newnode = makeNode(CurrentOfExpr);
  1442. COPY_SCALAR_FIELD(cvarno);
  1443. COPY_STRING_FIELD(cursor_name);
  1444. COPY_SCALAR_FIELD(cursor_param);
  1445. return newnode;
  1446. }
  1447. /*
  1448. * _copyTargetEntry
  1449. */
  1450. static TargetEntry *
  1451. _copyTargetEntry(const TargetEntry *from)
  1452. {
  1453. TargetEntry *newnode = makeNode(TargetEntry);
  1454. COPY_NODE_FIELD(expr);
  1455. COPY_SCALAR_FIELD(resno);
  1456. COPY_STRING_FIELD(resname);
  1457. COPY_SCALAR_FIELD(ressortgroupref);
  1458. COPY_SCALAR_FIELD(resorigtbl);
  1459. COPY_SCALAR_FIELD(resorigcol);
  1460. COPY_SCALAR_FIELD(resjunk);
  1461. return newnode;
  1462. }
  1463. /*
  1464. * _copyRangeTblRef
  1465. */
  1466. static RangeTblRef *
  1467. _copyRangeTblRef(const RangeTblRef *from)
  1468. {
  1469. RangeTblRef *newnode = makeNode(RangeTblRef);
  1470. COPY_SCALAR_FIELD(rtindex);
  1471. return newnode;
  1472. }
  1473. /*
  1474. * _copyJoinExpr
  1475. */
  1476. static JoinExpr *
  1477. _copyJoinExpr(const JoinExpr *from)
  1478. {
  1479. JoinExpr *newnode = makeNode(JoinExpr);
  1480. COPY_SCALAR_FIELD(jointype);
  1481. COPY_SCALAR_FIELD(isNatural);
  1482. COPY_NODE_FIELD(larg);
  1483. COPY_NODE_FIELD(rarg);
  1484. COPY_NODE_FIELD(usingClause);
  1485. COPY_NODE_FIELD(quals);
  1486. COPY_NODE_FIELD(alias);
  1487. COPY_SCALAR_FIELD(rtindex);
  1488. return newnode;
  1489. }
  1490. /*
  1491. * _copyFromExpr
  1492. */
  1493. static FromExpr *
  1494. _copyFromExpr(const FromExpr *from)
  1495. {
  1496. FromExpr *newnode = makeNode(FromExpr);
  1497. COPY_NODE_FIELD(fromlist);
  1498. COPY_NODE_FIELD(quals);
  1499. return newnode;
  1500. }
  1501. /* ****************************************************************
  1502. * relation.h copy functions
  1503. *
  1504. * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
  1505. * There are some subsidiary structs that are useful to copy, though.
  1506. * ****************************************************************
  1507. */
  1508. /*
  1509. * _copyPathKey
  1510. */
  1511. static PathKey *
  1512. _copyPathKey(const PathKey *from)
  1513. {
  1514. PathKey *newnode = makeNode(PathKey);
  1515. /* EquivalenceClasses are never moved, so just shallow-copy the pointer */
  1516. COPY_SCALAR_FIELD(pk_eclass);
  1517. COPY_SCALAR_FIELD(pk_opfamily);
  1518. COPY_SCALAR_FIELD(pk_strategy);
  1519. COPY_SCALAR_FIELD(pk_nulls_first);
  1520. return newnode;
  1521. }
  1522. /*
  1523. * _copyRestrictInfo
  1524. */
  1525. static RestrictInfo *
  1526. _copyRestrictInfo(const RestrictInfo *from)
  1527. {
  1528. RestrictInfo *newnode = makeNode(RestrictInfo);
  1529. COPY_NODE_FIELD(clause);
  1530. COPY_SCALAR_FIELD(is_pushed_down);
  1531. COPY_SCALAR_FIELD(outerjoin_delayed);
  1532. COPY_SCALAR_FIELD(can_join);
  1533. COPY_SCALAR_FIELD(pseudoconstant);
  1534. COPY_BITMAPSET_FIELD(clause_relids);
  1535. COPY_BITMAPSET_FIELD(required_relids);
  1536. COPY_BITMAPSET_FIELD(outer_relids);
  1537. COPY_BITMAPSET_FIELD(nullable_relids);
  1538. COPY_BITMAPSET_FIELD(left_relids);
  1539. COPY_BITMAPSET_FIELD(right_relids);
  1540. COPY_NODE_FIELD(orclause);
  1541. /* EquivalenceClasses are never copied, so shallow-copy the pointers */
  1542. COPY_SCALAR_FIELD(parent_ec);
  1543. COPY_SCALAR_FIELD(eval_cost);
  1544. COPY_SCALAR_FIELD(norm_selec);
  1545. COPY_SCALAR_FIELD(outer_selec);
  1546. COPY_NODE_FIELD(mergeopfamilies);
  1547. /* EquivalenceClasses are never copied, so shallow-copy the pointers */
  1548. COPY_SCALAR_FIELD(left_ec);
  1549. COPY_SCALAR_FIELD(right_ec);
  1550. COPY_SCALAR_FIELD(left_em);
  1551. COPY_SCALAR_FIELD(right_em);
  1552. /* MergeScanSelCache isn't a Node, so hard to copy; just reset cache */
  1553. newnode->scansel_cache = NIL;
  1554. COPY_SCALAR_FIELD(outer_is_left);
  1555. COPY_SCALAR_FIELD(hashjoinoperator);
  1556. COPY_SCALAR_FIELD(left_bucketsize);
  1557. COPY_SCALAR_FIELD(right_bucketsize);
  1558. return newnode;
  1559. }
  1560. /*
  1561. * _copyPlaceHolderVar
  1562. */
  1563. static PlaceHolderVar *
  1564. _copyPlaceHolderVar(const PlaceHolderVar *from)
  1565. {
  1566. PlaceHolderVar *newnode = makeNode(PlaceHolderVar);
  1567. COPY_NODE_FIELD(phexpr);
  1568. COPY_BITMAPSET_FIELD(phrels);
  1569. COPY_SCALAR_FIELD(phid);
  1570. COPY_SCALAR_FIELD(phlevelsup);
  1571. return newnode;
  1572. }
  1573. /*
  1574. * _copySpecialJoinInfo
  1575. */
  1576. static SpecialJoinInfo *
  1577. _copySpecialJoinInfo(const SpecialJoinInfo *from)
  1578. {
  1579. SpecialJoinInfo *newnode = makeNode(SpecialJoinInfo);
  1580. COPY_BITMAPSET_FIELD(min_lefthand);
  1581. COPY_BITMAPSET_FIELD(min_righthand);
  1582. COPY_BITMAPSET_FIELD(syn_lefthand);
  1583. COPY_BITMAPSET_FIELD(syn_righthand);
  1584. COPY_SCALAR_FIELD(jointype);
  1585. COPY_SCALAR_FIELD(lhs_strict);
  1586. COPY_SCALAR_FIELD(delay_upper_joins);
  1587. COPY_NODE_FIELD(join_quals);
  1588. return newnode;
  1589. }
  1590. /*
  1591. * _copyLateralJoinInfo
  1592. */
  1593. static LateralJoinInfo *
  1594. _copyLateralJoinInfo(const LateralJoinInfo *from)
  1595. {
  1596. LateralJoinInfo *newnode = makeNode(LateralJoinInfo);
  1597. COPY_BITMAPSET_FIELD(lateral_lhs);
  1598. COPY_BITMAPSET_FIELD(lateral_rhs);
  1599. return newnode;
  1600. }
  1601. /*
  1602. * _copyAppendRelInfo
  1603. */
  1604. static AppendRelInfo *
  1605. _copyAppendRelInfo(const AppendRelInfo *from)
  1606. {
  1607. AppendRelInfo *newnode = makeNode(AppendRelInfo);
  1608. COPY_SCALAR_FIELD(parent_relid);
  1609. COPY_SCALAR_FIELD(child_relid);
  1610. COPY_SCALAR_FIELD(parent_reltype);
  1611. COPY_SCALAR_FIELD(child_reltype);
  1612. COPY_NODE_FIELD(translated_vars);
  1613. COPY_SCALAR_FIELD(parent_reloid);
  1614. return newnode;
  1615. }
  1616. /*
  1617. * _copyPlaceHolderInfo
  1618. */
  1619. static PlaceHolderInfo *
  1620. _copyPlaceHolderInfo(const PlaceHolderInfo *from)
  1621. {
  1622. PlaceHolderInfo *newnode = makeNode(PlaceHolderInfo);
  1623. COPY_SCALAR_FIELD(phid);
  1624. COPY_NODE_FIELD(ph_var);
  1625. COPY_BITMAPSET_FIELD(ph_eval_at);
  1626. COPY_BITMAPSET_FIELD(ph_lateral);
  1627. COPY_BITMAPSET_FIELD(ph_needed);
  1628. COPY_SCALAR_FIELD(ph_width);
  1629. return newnode;
  1630. }
  1631. /* ****************************************************************
  1632. * parsenodes.h copy functions
  1633. * ****************************************************************
  1634. */
  1635. static RangeTblEntry *
  1636. _copyRangeTblEntry(const RangeTblEntry *from)
  1637. {
  1638. RangeTblEntry *newnode = makeNode(RangeTblEntry);
  1639. COPY_SCALAR_FIELD(rtekind);
  1640. COPY_SCALAR_FIELD(relid);
  1641. COPY_SCALAR_FIELD(relkind);
  1642. COPY_NODE_FIELD(subquery);
  1643. COPY_SCALAR_FIELD(security_barrier);
  1644. COPY_SCALAR_FIELD(jointype);
  1645. COPY_NODE_FIELD(joinaliasvars);
  1646. COPY_NODE_FIELD(functions);
  1647. COPY_SCALAR_FIELD(funcordinality);
  1648. COPY_NODE_FIELD(values_lists);
  1649. COPY_NODE_FIELD(values_collations);
  1650. COPY_STRING_FIELD(ctename);
  1651. COPY_SCALAR_FIELD(ctelevelsup);
  1652. COPY_SCALAR_FIELD(self_reference);
  1653. COPY_NODE_FIELD(ctecoltypes);
  1654. COPY_NODE_FIELD(ctecoltypmods);
  1655. COPY_NODE_FIELD(ctecolcollations);
  1656. COPY_NODE_FIELD(alias);
  1657. COPY_NODE_FIELD(eref);
  1658. COPY_SCALAR_FIELD(lateral);
  1659. COPY_SCALAR_FIELD(inh);
  1660. COPY_SCALAR_FIELD(inFromCl);
  1661. COPY_SCALAR_FIELD(requiredPerms);
  1662. COPY_SCALAR_FIELD(checkAsUser);
  1663. COPY_BITMAPSET_FIELD(selectedCols);
  1664. COPY_BITMAPSET_FIELD(modifiedCols);
  1665. COPY_NODE_FIELD(securityQuals);
  1666. return newnode;
  1667. }
  1668. static RangeTblFunction *
  1669. _copyRangeTblFunction(const RangeTblFunction *from)
  1670. {
  1671. RangeTblFunction *newnode = makeNode(RangeTblFunction);
  1672. COPY_NODE_FIELD(funcexpr);
  1673. COPY_SCALAR_FIELD(funccolcount);
  1674. COPY_NODE_FIELD(funccolnames);
  1675. COPY_NODE_FIELD(funccoltypes);
  1676. COPY_NODE_FIELD(funccoltypmods);
  1677. COPY_NODE_FIELD(funccolcollations);
  1678. COPY_BITMAPSET_FIELD(funcparams);
  1679. return newnode;
  1680. }
  1681. static WithCheckOption *
  1682. _copyWithCheckOption(const WithCheckOption *from)
  1683. {
  1684. WithCheckOption *newnode = makeNode(WithCheckOption);
  1685. COPY_STRING_FIELD(viewname);
  1686. COPY_NODE_FIELD(qual);
  1687. COPY_SCALAR_FIELD(cascaded);
  1688. return newnode;
  1689. }
  1690. static SortGroupClause *
  1691. _copySortGroupClause(const SortGroupClause *from)
  1692. {
  1693. SortGroupClause *newnode = makeNode(SortGroupClause);
  1694. COPY_SCALAR_FIELD(tleSortGroupRef);
  1695. COPY_SCALAR_FIELD(eqop);
  1696. COPY_SCALAR_FIELD(sortop);
  1697. COPY_SCALAR_FIELD(nulls_first);
  1698. COPY_SCALAR_FIELD(hashable);
  1699. return newnode;
  1700. }
  1701. static WindowClause *
  1702. _copyWindowClause(const WindowClause *from)
  1703. {
  1704. WindowClause *newnode = makeNode(WindowClause);
  1705. COPY_STRING_FIELD(name);
  1706. COPY_STRING_FIELD(refname);
  1707. COPY_NODE_FIELD(partitionClause);
  1708. COPY_NODE_FIELD(orderClause);
  1709. COPY_SCALAR_FIELD(frameOptions);
  1710. COPY_NODE_FIELD(startOffset);
  1711. COPY_NODE_FIELD(endOffset);
  1712. COPY_SCALAR_FIELD(winref);
  1713. COPY_SCALAR_FIELD(copiedOrder);
  1714. return newnode;
  1715. }
  1716. static RowMarkClause *
  1717. _copyRowMarkClause(const RowMarkClause *from)
  1718. {
  1719. RowMarkClause *newnode = makeNode(RowMarkClause);
  1720. COPY_SCALAR_FIELD(rti);
  1721. COPY_SCALAR_FIELD(strength);
  1722. COPY_SCALAR_FIELD(noWait);
  1723. COPY_SCALAR_FIELD(pushedDown);
  1724. return newnode;
  1725. }
  1726. static WithClause *
  1727. _copyWithClause(const WithClause *from)
  1728. {
  1729. WithClause *newnode = makeNode(WithClause);
  1730. COPY_NODE_FIELD(ctes);
  1731. COPY_SCALAR_FIELD(recursive);
  1732. COPY_LOCATION_FIELD(location);
  1733. return newnode;
  1734. }
  1735. static CommonTableExpr *
  1736. _copyCommonTableExpr(const CommonTableExpr *from)
  1737. {
  1738. CommonTableExpr *newnode = makeNode(CommonTableExpr);
  1739. COPY_STRING_FIELD(ctename);
  1740. COPY_NODE_FIELD(aliascolnames);
  1741. COPY_NODE_FIELD(ctequery);
  1742. COPY_LOCATION_FIELD(location);
  1743. COPY_SCALAR_FIELD(cterecursive);
  1744. COPY_SCALAR_FIELD(cterefcount);
  1745. COPY_NODE_FIELD(ctecolnames);
  1746. COPY_NODE_FIELD(ctecoltypes);
  1747. COPY_NODE_FIELD(ctecoltypmods);
  1748. COPY_NODE_FIELD(ctecolcollations);
  1749. return newnode;
  1750. }
  1751. static A_Expr *
  1752. _copyAExpr(const A_Expr *from)
  1753. {
  1754. A_Expr *newnode = makeNode(A_Expr);
  1755. COPY_SCALAR_FIELD(kind);
  1756. COPY_NODE_FIELD(name);
  1757. COPY_NODE_FIELD(lexpr);
  1758. COPY_NODE_FIELD(rexpr);
  1759. COPY_LOCATION_FIELD(location);
  1760. return newnode;
  1761. }
  1762. static ColumnRef *
  1763. _copyColumnRef(const ColumnRef *from)
  1764. {
  1765. ColumnRef *newnode = makeNode(ColumnRef);
  1766. COPY_NODE_FIELD(fields);
  1767. COPY_LOCATION_FIELD(location);
  1768. return newnode;
  1769. }
  1770. static ParamRef *
  1771. _copyParamRef(const ParamRef *from)
  1772. {
  1773. ParamRef *newnode = makeNode(ParamRef);
  1774. COPY_SCALAR_FIELD(number);
  1775. COPY_LOCATION_FIELD(location);
  1776. return newnode;
  1777. }
  1778. static A_Const *
  1779. _copyAConst(const A_Const *from)
  1780. {
  1781. A_Const *newnode = makeNode(A_Const);
  1782. /* This part must duplicate _copyValue */
  1783. COPY_SCALAR_FIELD(val.type);
  1784. switch (from->val.type)
  1785. {
  1786. case T_Integer:
  1787. COPY_SCALAR_FIELD(val.val.ival);
  1788. break;
  1789. case T_Float:
  1790. case T_String:
  1791. case T_BitString:
  1792. COPY_STRING_FIELD(val.val.str);
  1793. break;
  1794. case T_Null:
  1795. /* nothing to do */
  1796. break;
  1797. default:
  1798. elog(ERROR, "unrecognized node type: %d",
  1799. (int) from->val.type);
  1800. break;
  1801. }
  1802. COPY_LOCATION_FIELD(location);
  1803. return newnode;
  1804. }
  1805. static FuncCall *
  1806. _copyFuncCall(const FuncCall *from)
  1807. {
  1808. FuncCall *newnode = makeNode(FuncCall);
  1809. COPY_NODE_FIELD(funcname);
  1810. COPY_NODE_FIELD(args);
  1811. COPY_NODE_FIELD(agg_order);
  1812. COPY_NODE_FIELD(agg_filter);
  1813. COPY_SCALAR_FIELD(agg_within_group);
  1814. COPY_SCALAR_FIELD(agg_star);
  1815. COPY_SCALAR_FIELD(agg_distinct);
  1816. COPY_SCALAR_FIELD(func_variadic);
  1817. COPY_NODE_FIELD(over);
  1818. COPY_LOCATION_FIELD(location);
  1819. return newnode;
  1820. }
  1821. static A_Star *
  1822. _copyAStar(const A_Star *from)
  1823. {
  1824. A_Star *newnode = makeNode(A_Star);
  1825. return newnode;
  1826. }
  1827. static A_Indices *
  1828. _copyAIndices(const A_Indices *from)
  1829. {
  1830. A_Indices *newnode = makeNode(A_Indices);
  1831. COPY_NODE_FIELD(lidx);
  1832. COPY_NODE_FIELD(uidx);
  1833. return newnode;
  1834. }
  1835. static A_Indirection *
  1836. _copyA_Indirection(const A_Indirection *from)
  1837. {
  1838. A_Indirection *newnode = makeNode(A_Indirection);
  1839. COPY_NODE_FIELD(arg);
  1840. COPY_NODE_FIELD(indirection);
  1841. return newnode;
  1842. }
  1843. static A_ArrayExpr *
  1844. _copyA_ArrayExpr(const A_ArrayExpr *from)
  1845. {
  1846. A_ArrayExpr *newnode = makeNode(A_ArrayExpr);
  1847. COPY_NODE_FIELD(elements);
  1848. COPY_LOCATION_FIELD(location);
  1849. return newnode;
  1850. }
  1851. static ResTarget *
  1852. _copyResTarget(const ResTarget *from)
  1853. {
  1854. ResTarget *newnode = makeNode(ResTarget);
  1855. COPY_STRING_FIELD(name);
  1856. COPY_NODE_FIELD(indirection);
  1857. COPY_NODE_FIELD(val);
  1858. COPY_LOCATION_FIELD(location);
  1859. return newnode;
  1860. }
  1861. static TypeName *
  1862. _copyTypeName(const TypeName *from)
  1863. {
  1864. TypeName *newnode = makeNode(TypeName);
  1865. COPY_NODE_FIELD(names);
  1866. COPY_SCALAR_FIELD(typeOid);
  1867. COPY_SCALAR_FIELD(setof);
  1868. COPY_SCALAR_FIELD(pct_type);
  1869. COPY_NODE_FIELD(typmods);
  1870. COPY_SCALAR_FIELD(typemod);
  1871. COPY_NODE_FIELD(arrayBounds);
  1872. COPY_LOCATION_FIELD(location);
  1873. return newnode;
  1874. }
  1875. static SortBy *
  1876. _copySortBy(const SortBy *from)
  1877. {
  1878. SortBy *newnode = makeNode(SortBy);
  1879. COPY_NODE_FIELD(node);
  1880. COPY_SCALAR_FIELD(sortby_dir);
  1881. COPY_SCALAR_FIELD(sortby_nulls);
  1882. COPY_NODE_FIELD(useOp);
  1883. COPY_LOCATION_FIELD(location);
  1884. return newnode;
  1885. }
  1886. static WindowDef *
  1887. _copyWindowDef(const WindowDef *from)
  1888. {
  1889. WindowDef *newnode = makeNode(WindowDef);
  1890. COPY_STRING_FIELD(name);
  1891. COPY_STRING_FIELD(refname);
  1892. COPY_NODE_FIELD(partitionClause);
  1893. COPY_NODE_FIELD(orderClause);
  1894. COPY_SCALAR_FIELD(frameOptions);
  1895. COPY_NODE_FIELD(startOffset);
  1896. COPY_NODE_FIELD(endOffset);
  1897. COPY_LOCATION_FIELD(location);
  1898. return newnode;
  1899. }
  1900. static RangeSubselect *
  1901. _copyRangeSubselect(const RangeSubselect *from)
  1902. {
  1903. RangeSubselect *newnode = makeNode(RangeSubselect);
  1904. COPY_SCALAR_FIELD(lateral);
  1905. COPY_NODE_FIELD(subquery);
  1906. COPY_NODE_FIELD(alias);
  1907. return newnode;
  1908. }
  1909. static RangeFunction *
  1910. _copyRangeFunction(const RangeFunction *from)
  1911. {
  1912. RangeFunction *newnode = makeNode(RangeFunction);
  1913. COPY_SCALAR_FIELD(lateral);
  1914. COPY_SCALAR_FIELD(ordinality);
  1915. COPY_SCALAR_FIELD(is_rowsfrom);
  1916. COPY_NODE_FIELD(functions);
  1917. COPY_NODE_FIELD(alias);
  1918. COPY_NODE_FIELD(coldeflist);
  1919. return newnode;
  1920. }
  1921. static TypeCast *
  1922. _copyTypeCast(const TypeCast *from)
  1923. {
  1924. TypeCast *newnode = makeNode(TypeCast);
  1925. COPY_NODE_FIELD(arg);
  1926. COPY_NODE_FIELD(typeName);
  1927. COPY_LOCATION_FIELD(location);
  1928. return newnode;
  1929. }
  1930. static CollateClause *
  1931. _copyCollateClause(const CollateClause *from)
  1932. {
  1933. CollateClause *newnode = makeNode(CollateClause);
  1934. COPY_NODE_FIELD(arg);
  1935. COPY_NODE_FIELD(collname);
  1936. COPY_LOCATION_FIELD(location);
  1937. return newnode;
  1938. }
  1939. static IndexElem *
  1940. _copyIndexElem(const IndexElem *from)
  1941. {
  1942. IndexElem *newnode = makeNode(IndexElem);
  1943. COPY_STRING_FIELD(name);
  1944. COPY_NODE_FIELD(expr);
  1945. COPY_STRING_FIELD(indexcolname);
  1946. COPY_NODE_FIELD(collation);
  1947. COPY_NODE_FIELD(opclass);
  1948. COPY_SCALAR_FIELD(ordering);
  1949. COPY_SCALAR_FIELD(nulls_ordering);
  1950. return newnode;
  1951. }
  1952. static ColumnDef *
  1953. _copyColumnDef(const ColumnDef *from)
  1954. {
  1955. ColumnDef *newnode = makeNode(ColumnDef);
  1956. COPY_STRING_FIELD(colname);
  1957. COPY_NODE_FIELD(typeName);
  1958. COPY_SCALAR_FIELD(inhcount);
  1959. COPY_SCALAR_FIELD(is_local);
  1960. COPY_SCALAR_FIELD(is_not_null);
  1961. COPY_SCALAR_FIELD(is_from_type);
  1962. COPY_SCALAR_FIELD(storage);
  1963. COPY_NODE_FIELD(raw_default);
  1964. COPY_NODE_FIELD(cooked_default);
  1965. COPY_NODE_FIELD(collClause);
  1966. COPY_SCALAR_FIELD(collOid);
  1967. COPY_NODE_FIELD(constraints);
  1968. COPY_NODE_FIELD(fdwoptions);
  1969. COPY_LOCATION_FIELD(location);
  1970. return newnode;
  1971. }
  1972. static Constraint *
  1973. _copyConstraint(const Constraint *from)
  1974. {
  1975. Constraint *newnode = makeNode(Constraint);
  1976. COPY_SCALAR_FIELD(contype);
  1977. COPY_STRING_FIELD(conname);
  1978. COPY_SCALAR_FIELD(deferrable);
  1979. COPY_SCALAR_FIELD(initdeferred);
  1980. COPY_LOCATION_FIELD(location);
  1981. COPY_SCALAR_FIELD(is_no_inherit);
  1982. COPY_NODE_FIELD(raw_expr);
  1983. COPY_STRING_FIELD(cooked_expr);
  1984. COPY_NODE_FIELD(keys);
  1985. COPY_NODE_FIELD(exclusions);
  1986. COPY_NODE_FIELD(options);
  1987. COPY_STRING_FIELD(indexname);
  1988. COPY_STRING_FIELD(indexspace);
  1989. COPY_STRING_FIELD(access_method);
  1990. COPY_NODE_FIELD(where_clause);
  1991. COPY_NODE_FIELD(pktable);
  1992. COPY_NODE_FIELD(fk_attrs);
  1993. COPY_NODE_FIELD(pk_attrs);
  1994. COPY_SCALAR_FIELD(fk_matchtype);
  1995. COPY_SCALAR_FIELD(fk_upd_action);
  1996. COPY_SCALAR_FIELD(fk_del_action);
  1997. COPY_NODE_FIELD(old_conpfeqop);
  1998. COPY_SCALAR_FIELD(old_pktable_oid);
  1999. COPY_SCALAR_FIELD(skip_validation);
  2000. COPY_SCALAR_FIELD(initially_valid);
  2001. return newnode;
  2002. }
  2003. static DefElem *
  2004. _copyDefElem(const DefElem *from)
  2005. {
  2006. DefElem *newnode = makeNode(DefElem);
  2007. COPY_STRING_FIELD(defnamespace);
  2008. COPY_STRING_FIELD(defname);
  2009. COPY_NODE_FIELD(arg);
  2010. COPY_SCALAR_FIELD(defaction);
  2011. return newnode;
  2012. }
  2013. static LockingClause *
  2014. _copyLockingClause(const LockingClause *from)
  2015. {
  2016. LockingClause *newnode = makeNode(LockingClause);
  2017. COPY_NODE_FIELD(lockedRels);
  2018. COPY_SCALAR_FIELD(strength);
  2019. COPY_SCALAR_FIELD(noWait);
  2020. return newnode;
  2021. }
  2022. static XmlSerialize *
  2023. _copyXmlSerialize(const XmlSerialize *from)
  2024. {
  2025. XmlSerialize *newnode = makeNode(XmlSerialize);
  2026. COPY_SCALAR_FIELD(xmloption);
  2027. COPY_NODE_FIELD(expr);
  2028. COPY_NODE_FIELD(typeName);
  2029. COPY_LOCATION_FIELD(location);
  2030. return newnode;
  2031. }
  2032. static Query *
  2033. _copyQuery(const Query *from)
  2034. {
  2035. Query *newnode = makeNode(Query);
  2036. COPY_SCALAR_FIELD(commandType);
  2037. COPY_SCALAR_FIELD(querySource);
  2038. COPY_SCALAR_FIELD(queryId);
  2039. COPY_SCALAR_FIELD(canSetTag);
  2040. COPY_NODE_FIELD(utilityStmt);
  2041. COPY_SCALAR_FIELD(resultRelation);
  2042. COPY_SCALAR_FIELD(hasAggs);
  2043. COPY_SCALAR_FIELD(hasWindowFuncs);
  2044. COPY_SCALAR_FIELD(hasSubLinks);
  2045. COPY_SCALAR_FIELD(hasDistinctOn);
  2046. COPY_SCALAR_FIELD(hasRecursive);
  2047. COPY_SCALAR_FIELD(hasModifyingCTE);
  2048. COPY_SCALAR_FIELD(hasForUpdate);
  2049. COPY_NODE_FIELD(cteList);
  2050. COPY_NODE_FIELD(rtable);
  2051. COPY_NODE_FIELD(jointree);
  2052. COPY_NODE_FIELD(targetList);
  2053. COPY_NODE_FIELD(withCheckOptions);
  2054. COPY_NODE_FIELD(returningList);
  2055. COPY_NODE_FIELD(groupClause);
  2056. COPY_NODE_FIELD(havingQual);
  2057. COPY_NODE_FIELD(windowClause);
  2058. COPY_NODE_FIELD(distinctClause);
  2059. COPY_NODE_FIELD(sortClause);
  2060. COPY_NODE_FIELD(limitOffset);
  2061. COPY_NODE_FIELD(limitCount);
  2062. COPY_NODE_FIELD(rowMarks);
  2063. COPY_NODE_FIELD(setOperations);
  2064. COPY_NODE_FIELD(constraintDeps);
  2065. return newnode;
  2066. }
  2067. static InsertStmt *
  2068. _copyInsertStmt(const InsertStmt *from)
  2069. {
  2070. InsertStmt *newnode = makeNode(InsertStmt);
  2071. COPY_NODE_FIELD(relation);
  2072. COPY_NODE_FIELD(cols);
  2073. COPY_NODE_FIELD(selectStmt);
  2074. COPY_NODE_FIELD(returningList);
  2075. COPY_NODE_FIELD(withClause);
  2076. return newnode;
  2077. }
  2078. static DeleteStmt *
  2079. _copyDeleteStmt(const DeleteStmt *from)
  2080. {
  2081. DeleteStmt *newnode = makeNode(DeleteStmt);
  2082. COPY_NO

Large files files are truncated, but you can click here to view the full file