Skip to content

Commit fde35f6

Browse files
authored
Fix #8437 - Segmentation fault when running query with partition by and subquery (#8438)
1 parent 8ee1ca8 commit fde35f6

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

src/dsql/ExprNodes.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10900,10 +10900,10 @@ static RegisterNode<SubQueryNode> regSubQueryNode({
1090010900
blr_via, blr_from, blr_average, blr_count, blr_maximum, blr_minimum, blr_total
1090110901
});
1090210902

10903-
SubQueryNode::SubQueryNode(MemoryPool& pool, UCHAR aBlrOp, RecordSourceNode* aDsqlRse,
10903+
SubQueryNode::SubQueryNode(MemoryPool& pool, UCHAR aBlrOp, SelectExprNode* aDsqlSelectExpr,
1090410904
ValueExprNode* aValue1, ValueExprNode* aValue2)
1090510905
: TypedNode<ValueExprNode, ExprNode::TYPE_SUBQUERY>(pool),
10906-
dsqlRse(aDsqlRse),
10906+
dsqlSelectExpr(aDsqlSelectExpr),
1090710907
value1(aValue1),
1090810908
value2(aValue2),
1090910909
subQuery(NULL),
@@ -10946,11 +10946,7 @@ void SubQueryNode::getChildren(NodeRefsHolder& holder, bool dsql) const
1094610946
{
1094710947
ValueExprNode::getChildren(holder, dsql);
1094810948

10949-
if (dsql)
10950-
holder.add(dsqlRse);
10951-
else
10952-
holder.add(rse);
10953-
10949+
holder.add(rse);
1095410950
holder.add(value1);
1095510951
holder.add(value2);
1095610952
}
@@ -10961,7 +10957,7 @@ string SubQueryNode::internalPrint(NodePrinter& printer) const
1096110957

1096210958
NODE_PRINT(printer, blrOp);
1096310959
NODE_PRINT(printer, ownSavepoint);
10964-
NODE_PRINT(printer, dsqlRse);
10960+
NODE_PRINT(printer, dsqlSelectExpr);
1096510961
NODE_PRINT(printer, rse);
1096610962
NODE_PRINT(printer, value1);
1096710963
NODE_PRINT(printer, value2);
@@ -10980,10 +10976,11 @@ ValueExprNode* SubQueryNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
1098010976

1098110977
const DsqlContextStack::iterator base(*dsqlScratch->context);
1098210978

10983-
RseNode* rse = PASS1_rse(dsqlScratch, nodeAs<SelectExprNode>(dsqlRse), false);
10979+
RseNode* rse = PASS1_rse(dsqlScratch, dsqlSelectExpr, false);
1098410980

10985-
SubQueryNode* node = FB_NEW_POOL(dsqlScratch->getPool()) SubQueryNode(dsqlScratch->getPool(), blrOp, rse,
10981+
SubQueryNode* node = FB_NEW_POOL(dsqlScratch->getPool()) SubQueryNode(dsqlScratch->getPool(), blrOp, dsqlSelectExpr,
1098610982
rse->dsqlSelectList->items[0], NullNode::instance());
10983+
node->rse = rse;
1098710984

1098810985
// Finish off by cleaning up contexts.
1098910986
dsqlScratch->context->clear(base);
@@ -10999,7 +10996,7 @@ void SubQueryNode::setParameterName(dsql_par* parameter) const
1099910996
void SubQueryNode::genBlr(DsqlCompilerScratch* dsqlScratch)
1100010997
{
1100110998
dsqlScratch->appendUChar(blrOp);
11002-
GEN_expr(dsqlScratch, dsqlRse);
10999+
GEN_expr(dsqlScratch, rse);
1100311000
GEN_expr(dsqlScratch, value1);
1100411001
GEN_expr(dsqlScratch, value2);
1100511002
}
@@ -11015,12 +11012,12 @@ void SubQueryNode::make(DsqlCompilerScratch* dsqlScratch, dsc* desc)
1101511012

1101611013
bool SubQueryNode::dsqlAggregateFinder(AggregateFinder& visitor)
1101711014
{
11018-
return !visitor.ignoreSubSelects && visitor.visit(dsqlRse);
11015+
return !visitor.ignoreSubSelects && visitor.visit(rse);
1101911016
}
1102011017

1102111018
bool SubQueryNode::dsqlAggregate2Finder(Aggregate2Finder& visitor)
1102211019
{
11023-
return visitor.visit(dsqlRse); // Pass only the rse.
11020+
return visitor.visit(rse); // Pass only the rse.
1102411021
}
1102511022

1102611023
bool SubQueryNode::dsqlSubSelectFinder(SubSelectFinder& /*visitor*/)
@@ -11030,13 +11027,13 @@ bool SubQueryNode::dsqlSubSelectFinder(SubSelectFinder& /*visitor*/)
1103011027

1103111028
bool SubQueryNode::dsqlFieldFinder(FieldFinder& visitor)
1103211029
{
11033-
return visitor.visit(dsqlRse); // Pass only the rse.
11030+
return visitor.visit(rse); // Pass only the rse.
1103411031
}
1103511032

1103611033
ValueExprNode* SubQueryNode::dsqlFieldRemapper(FieldRemapper& visitor)
1103711034
{
11038-
doDsqlFieldRemapper(visitor, dsqlRse);
11039-
value1 = nodeAs<RseNode>(dsqlRse)->dsqlSelectList->items[0];
11035+
doDsqlFieldRemapper(visitor, rse);
11036+
value1 = rse->dsqlSelectList->items[0];
1104011037
return this;
1104111038
}
1104211039

src/dsql/ExprNodes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,7 +1867,7 @@ class StrLenNode : public TypedNode<ValueExprNode, ExprNode::TYPE_STR_LEN>
18671867
class SubQueryNode : public TypedNode<ValueExprNode, ExprNode::TYPE_SUBQUERY>
18681868
{
18691869
public:
1870-
explicit SubQueryNode(MemoryPool& pool, UCHAR aBlrOp, RecordSourceNode* aDsqlRse = NULL,
1870+
explicit SubQueryNode(MemoryPool& pool, UCHAR aBlrOp, SelectExprNode* aDsqlSelectExpr = NULL,
18711871
ValueExprNode* aValue1 = NULL, ValueExprNode* aValue2 = NULL);
18721872

18731873
static DmlNode* parse(thread_db* tdbb, MemoryPool& pool, CompilerScratch* csb, const UCHAR blrOp);
@@ -1912,7 +1912,7 @@ class SubQueryNode : public TypedNode<ValueExprNode, ExprNode::TYPE_SUBQUERY>
19121912
virtual dsc* execute(thread_db* tdbb, jrd_req* request) const;
19131913

19141914
public:
1915-
NestConst<RecordSourceNode> dsqlRse;
1915+
NestConst<SelectExprNode> dsqlSelectExpr;
19161916
NestConst<RseNode> rse;
19171917
NestConst<ValueExprNode> value1;
19181918
NestConst<ValueExprNode> value2;

0 commit comments

Comments
 (0)