@@ -62,7 +62,6 @@ AggNode::AggNode(MemoryPool& pool, const AggInfo& aAggInfo, bool aDistinct, bool
6262 dialect1 (aDialect1),
6363 indexed (false )
6464{
65- addChildNode (arg, arg);
6665}
6766
6867DmlNode* AggNode::parse (thread_db* tdbb, MemoryPool& pool, CompilerScratch* csb, const UCHAR /* blrOp*/ )
@@ -86,7 +85,10 @@ DmlNode* AggNode::parse(thread_db* tdbb, MemoryPool& pool, CompilerScratch* csb,
8685
8786 const UCHAR count = csb->csb_blr_reader .getByte ();
8887
89- if (count != node->jrdChildNodes .getCount ())
88+ NodeRefsHolder holder (pool);
89+ node->getChildren (holder, false );
90+
91+ if (count != holder.refs .getCount ())
9092 PAR_error (csb, Arg::Gds (isc_funmismat) << name);
9193
9294 node->parseArgs (tdbb, csb, count);
@@ -146,7 +148,10 @@ bool AggNode::dsqlAggregateFinder(AggregateFinder& visitor)
146148 AutoSetRestore<USHORT> autoDeepestLevel (&visitor.deepestLevel , 0 );
147149 AutoSetRestore<bool > autoIgnoreSubSelects (&visitor.ignoreSubSelects , true );
148150
149- for (NodeRef** i = dsqlChildNodes.begin (); i != dsqlChildNodes.end (); ++i)
151+ NodeRefsHolder holder (visitor.getPool ());
152+ getChildren (holder, true );
153+
154+ for (NodeRef** i = holder.refs .begin (); i != holder.refs .end (); ++i)
150155 visitor.visit ((*i)->getExpr ());
151156
152157 localDeepestLevel = visitor.deepestLevel ;
@@ -175,7 +180,10 @@ bool AggNode::dsqlAggregateFinder(AggregateFinder& visitor)
175180
176181 AutoSetRestore<USHORT> autoDeepestLevel (&visitor.deepestLevel , localDeepestLevel);
177182
178- for (NodeRef** i = dsqlChildNodes.begin (); i != dsqlChildNodes.end (); ++i)
183+ NodeRefsHolder holder (visitor.getPool ());
184+ getChildren (holder, true );
185+
186+ for (NodeRef** i = holder.refs .begin (); i != holder.refs .end (); ++i)
179187 aggregate |= visitor.visit ((*i)->getExpr ());
180188 }
181189
@@ -188,9 +196,12 @@ bool AggNode::dsqlAggregate2Finder(Aggregate2Finder& visitor)
188196 return false ;
189197
190198 bool found = false ;
191- FieldFinder fieldFinder (visitor.checkScopeLevel , visitor.matchType );
199+ FieldFinder fieldFinder (visitor.getPool (), visitor.checkScopeLevel , visitor.matchType );
200+
201+ NodeRefsHolder holder (visitor.getPool ());
202+ getChildren (holder, true );
192203
193- for (NodeRef** i = dsqlChildNodes. begin (); i != dsqlChildNodes .end (); ++i)
204+ for (NodeRef** i = holder. refs . begin (); i != holder. refs .end (); ++i)
194205 found |= fieldFinder.visit ((*i)->getExpr ());
195206
196207 if (!fieldFinder.getField ())
@@ -234,13 +245,16 @@ bool AggNode::dsqlInvalidReferenceFinder(InvalidReferenceFinder& visitor)
234245
235246 if (!visitor.insideHigherMap )
236247 {
237- for (NodeRef** i = dsqlChildNodes.begin (); i != dsqlChildNodes.end (); ++i)
248+ NodeRefsHolder holder (visitor.getPool ());
249+ getChildren (holder, true );
250+
251+ for (NodeRef** i = holder.refs .begin (); i != holder.refs .end (); ++i)
238252 {
239253 // If there's another aggregate with the same scope_level or
240254 // an higher one then it's a invalid aggregate, because
241255 // aggregate-functions from the same context can't
242256 // be part of each other.
243- if (Aggregate2Finder::find (visitor.context ->ctx_scope_level ,
257+ if (Aggregate2Finder::find (visitor.getPool (), visitor. context ->ctx_scope_level ,
244258 FIELD_MATCH_TYPE_EQUAL, false , (*i)->getExpr ()))
245259 {
246260 // Nested aggregate functions are not allowed
@@ -260,7 +274,7 @@ bool AggNode::dsqlSubSelectFinder(SubSelectFinder& /*visitor*/)
260274
261275ValueExprNode* AggNode::dsqlFieldRemapper (FieldRemapper& visitor)
262276{
263- AggregateFinder aggFinder (visitor.dsqlScratch , false );
277+ AggregateFinder aggFinder (visitor.getPool (), visitor. dsqlScratch , false );
264278 aggFinder.deepestLevel = visitor.dsqlScratch ->scopeLevel ;
265279 aggFinder.currentLevel = visitor.currentLevel ;
266280
@@ -270,7 +284,10 @@ ValueExprNode* AggNode::dsqlFieldRemapper(FieldRemapper& visitor)
270284 return PASS1_post_map (visitor.dsqlScratch , this , visitor.context , visitor.windowNode );
271285 }
272286
273- for (NodeRef** i = dsqlChildNodes.begin (); i != dsqlChildNodes.end (); ++i)
287+ NodeRefsHolder holder (visitor.getPool ());
288+ getChildren (holder, true );
289+
290+ for (NodeRef** i = holder.refs .begin (); i != holder.refs .end (); ++i)
274291 (*i)->remap (visitor);
275292
276293 return this ;
@@ -297,6 +314,9 @@ void AggNode::setParameterName(dsql_par* parameter) const
297314
298315void AggNode::genBlr (DsqlCompilerScratch* dsqlScratch)
299316{
317+ NodeRefsHolder holder (dsqlScratch->getPool ());
318+ getChildren (holder, true );
319+
300320 if (aggInfo.blr ) // Is this a standard aggregate function?
301321 dsqlScratch->appendUChar ((distinct ? aggInfo.distinctBlr : aggInfo.blr ));
302322 else // This is a new window function.
@@ -306,7 +326,7 @@ void AggNode::genBlr(DsqlCompilerScratch* dsqlScratch)
306326
307327 unsigned count = 0 ;
308328
309- for (NodeRef** i = dsqlChildNodes. begin (); i != dsqlChildNodes .end (); ++i)
329+ for (NodeRef** i = holder. refs . begin (); i != holder. refs .end (); ++i)
310330 {
311331 if (**i)
312332 ++count;
@@ -315,7 +335,7 @@ void AggNode::genBlr(DsqlCompilerScratch* dsqlScratch)
315335 dsqlScratch->appendUChar (UCHAR (count));
316336 }
317337
318- for (NodeRef** i = dsqlChildNodes. begin (); i != dsqlChildNodes .end (); ++i)
338+ for (NodeRef** i = holder. refs . begin (); i != holder. refs .end (); ++i)
319339 {
320340 if (**i)
321341 GEN_expr (dsqlScratch, (*i)->getExpr ());
@@ -702,7 +722,7 @@ dsc* AvgAggNode::aggExecute(thread_db* tdbb, jrd_req* request) const
702722
703723AggNode* AvgAggNode::dsqlCopy (DsqlCompilerScratch* dsqlScratch) /* const*/
704724{
705- return FB_NEW_POOL (getPool ()) AvgAggNode (getPool (), distinct, dialect1,
725+ return FB_NEW_POOL (dsqlScratch-> getPool ()) AvgAggNode (dsqlScratch-> getPool (), distinct, dialect1,
706726 doDsqlPass (dsqlScratch, arg));
707727}
708728
@@ -717,7 +737,6 @@ ListAggNode::ListAggNode(MemoryPool& pool, bool aDistinct, ValueExprNode* aArg,
717737 : AggNode(pool, listAggInfo, aDistinct, false , aArg),
718738 delimiter(aDelimiter)
719739{
720- addChildNode (delimiter, delimiter);
721740}
722741
723742DmlNode* ListAggNode::parse (thread_db* tdbb, MemoryPool& pool, CompilerScratch* csb, const UCHAR blrOp)
@@ -840,7 +859,7 @@ AggNode* ListAggNode::dsqlCopy(DsqlCompilerScratch* dsqlScratch) /*const*/
840859{
841860 thread_db* tdbb = JRD_get_thread_data ();
842861
843- AggNode* node = FB_NEW_POOL (getPool ()) ListAggNode (getPool (), distinct,
862+ AggNode* node = FB_NEW_POOL (dsqlScratch-> getPool ()) ListAggNode (dsqlScratch-> getPool (), distinct,
844863 doDsqlPass (dsqlScratch, arg), doDsqlPass (dsqlScratch, delimiter));
845864
846865 dsc argDesc;
@@ -950,7 +969,7 @@ dsc* CountAggNode::aggExecute(thread_db* /*tdbb*/, jrd_req* request) const
950969
951970AggNode* CountAggNode::dsqlCopy (DsqlCompilerScratch* dsqlScratch) /* const*/
952971{
953- return FB_NEW_POOL (getPool ()) CountAggNode (getPool (), distinct, dialect1,
972+ return FB_NEW_POOL (dsqlScratch-> getPool ()) CountAggNode (dsqlScratch-> getPool (), distinct, dialect1,
954973 doDsqlPass (dsqlScratch, arg));
955974}
956975
@@ -1201,7 +1220,7 @@ dsc* SumAggNode::aggExecute(thread_db* /*tdbb*/, jrd_req* request) const
12011220
12021221AggNode* SumAggNode::dsqlCopy (DsqlCompilerScratch* dsqlScratch) /* const*/
12031222{
1204- return FB_NEW_POOL (getPool ()) SumAggNode (getPool (), distinct, dialect1,
1223+ return FB_NEW_POOL (dsqlScratch-> getPool ()) SumAggNode (dsqlScratch-> getPool (), distinct, dialect1,
12051224 doDsqlPass (dsqlScratch, arg));
12061225}
12071226
@@ -1292,7 +1311,8 @@ dsc* MaxMinAggNode::aggExecute(thread_db* /*tdbb*/, jrd_req* request) const
12921311
12931312AggNode* MaxMinAggNode::dsqlCopy (DsqlCompilerScratch* dsqlScratch) /* const*/
12941313{
1295- return FB_NEW_POOL (getPool ()) MaxMinAggNode (getPool (), type, doDsqlPass (dsqlScratch, arg));
1314+ return FB_NEW_POOL (dsqlScratch->getPool ()) MaxMinAggNode (dsqlScratch->getPool (),
1315+ type, doDsqlPass (dsqlScratch, arg));
12961316}
12971317
12981318
@@ -1501,7 +1521,8 @@ dsc* StdDevAggNode::aggExecute(thread_db* tdbb, jrd_req* request) const
15011521
15021522AggNode* StdDevAggNode::dsqlCopy (DsqlCompilerScratch* dsqlScratch) /* const*/
15031523{
1504- return FB_NEW_POOL (getPool ()) StdDevAggNode (getPool (), type, doDsqlPass (dsqlScratch, arg));
1524+ return FB_NEW_POOL (dsqlScratch->getPool ()) StdDevAggNode (dsqlScratch->getPool (),
1525+ type, doDsqlPass (dsqlScratch, arg));
15051526}
15061527
15071528
@@ -1525,7 +1546,6 @@ CorrAggNode::CorrAggNode(MemoryPool& pool, CorrType aType, ValueExprNode* aArg,
15251546 arg2(aArg2),
15261547 impure2Offset(0 )
15271548{
1528- addChildNode (arg2, arg2);
15291549}
15301550
15311551void CorrAggNode::parseArgs (thread_db* tdbb, CompilerScratch* csb, unsigned /* count*/ )
@@ -1763,7 +1783,7 @@ dsc* CorrAggNode::aggExecute(thread_db* tdbb, jrd_req* request) const
17631783
17641784AggNode* CorrAggNode::dsqlCopy (DsqlCompilerScratch* dsqlScratch) /* const*/
17651785{
1766- return FB_NEW_POOL (getPool ()) CorrAggNode (getPool (), type,
1786+ return FB_NEW_POOL (dsqlScratch-> getPool ()) CorrAggNode (dsqlScratch-> getPool (), type,
17671787 doDsqlPass (dsqlScratch, arg), doDsqlPass (dsqlScratch, arg2));
17681788}
17691789
@@ -1803,7 +1823,6 @@ RegrAggNode::RegrAggNode(MemoryPool& pool, RegrType aType, ValueExprNode* aArg,
18031823 arg2(aArg2),
18041824 impure2Offset(0 )
18051825{
1806- addChildNode (arg2, arg2);
18071826}
18081827
18091828void RegrAggNode::parseArgs (thread_db* tdbb, CompilerScratch* csb, unsigned /* count*/ )
@@ -2090,7 +2109,7 @@ dsc* RegrAggNode::aggExecute(thread_db* tdbb, jrd_req* request) const
20902109
20912110AggNode* RegrAggNode::dsqlCopy (DsqlCompilerScratch* dsqlScratch) /* const*/
20922111{
2093- return FB_NEW_POOL (getPool ()) RegrAggNode (getPool (), type,
2112+ return FB_NEW_POOL (dsqlScratch-> getPool ()) RegrAggNode (dsqlScratch-> getPool (), type,
20942113 doDsqlPass (dsqlScratch, arg), doDsqlPass (dsqlScratch, arg2));
20952114}
20962115
@@ -2104,7 +2123,6 @@ RegrCountAggNode::RegrCountAggNode(MemoryPool& pool, ValueExprNode* aArg, ValueE
21042123 : AggNode(pool, regrCountAggInfo, false , false , aArg),
21052124 arg2(aArg2)
21062125{
2107- addChildNode (arg2, arg2);
21082126}
21092127
21102128void RegrCountAggNode::parseArgs (thread_db* tdbb, CompilerScratch* csb, unsigned /* count*/ )
@@ -2183,7 +2201,7 @@ dsc* RegrCountAggNode::aggExecute(thread_db* tdbb, jrd_req* request) const
21832201
21842202AggNode* RegrCountAggNode::dsqlCopy (DsqlCompilerScratch* dsqlScratch) /* const*/
21852203{
2186- return FB_NEW_POOL (getPool ()) RegrCountAggNode (getPool (),
2204+ return FB_NEW_POOL (dsqlScratch-> getPool ()) RegrCountAggNode (dsqlScratch-> getPool (),
21872205 doDsqlPass (dsqlScratch, arg), doDsqlPass (dsqlScratch, arg2));
21882206}
21892207
0 commit comments