Skip to content

Commit dee5dd5

Browse files
committed
Further refactoringof the joins: move common code into the base class
1 parent 8332d4f commit dee5dd5

File tree

5 files changed

+156
-385
lines changed

5 files changed

+156
-385
lines changed

src/jrd/recsrc/FullOuterJoin.cpp

Lines changed: 20 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,16 @@ using namespace Jrd;
4040
FullOuterJoin::FullOuterJoin(CompilerScratch* csb,
4141
RecordSource* arg1, RecordSource* arg2,
4242
const StreamList& checkStreams)
43-
: Join(csb, JoinType::OUTER),
44-
m_arg1(arg1),
45-
m_arg2(arg2),
43+
: Join(csb, 2, JoinType::OUTER),
4644
m_checkStreams(csb->csb_pool, checkStreams)
4745
{
48-
fb_assert(m_arg1 && m_arg2);
46+
fb_assert(arg1 && arg2);
4947

5048
m_impure = csb->allocImpure<Impure>();
5149
m_cardinality = arg1->getCardinality() + arg2->getCardinality();
50+
51+
m_args.add(arg1);
52+
m_args.add(arg2);
5253
}
5354

5455
void FullOuterJoin::internalOpen(thread_db* tdbb) const
@@ -58,52 +59,52 @@ void FullOuterJoin::internalOpen(thread_db* tdbb) const
5859

5960
impure->irsb_flags = irsb_open | irsb_first;
6061

61-
m_arg1->open(tdbb);
62+
m_args[0]->open(tdbb);
6263
}
6364

6465
void FullOuterJoin::close(thread_db* tdbb) const
6566
{
66-
Request* const request = tdbb->getRequest();
67+
const auto request = tdbb->getRequest();
6768

6869
invalidateRecords(request);
6970

70-
Impure* const impure = request->getImpure<Impure>(m_impure);
71+
const auto impure = request->getImpure<Impure>(m_impure);
7172

7273
if (impure->irsb_flags & irsb_open)
7374
{
7475
impure->irsb_flags &= ~irsb_open;
7576

76-
if (impure->irsb_flags & irsb_first)
77-
m_arg1->close(tdbb);
78-
else
79-
m_arg2->close(tdbb);
77+
Join::close(tdbb);
8078
}
8179
}
8280

8381
bool FullOuterJoin::internalGetRecord(thread_db* tdbb) const
8482
{
8583
JRD_reschedule(tdbb);
8684

87-
Request* const request = tdbb->getRequest();
88-
Impure* const impure = request->getImpure<Impure>(m_impure);
85+
const auto request = tdbb->getRequest();
86+
const auto impure = request->getImpure<Impure>(m_impure);
8987

9088
if (!(impure->irsb_flags & irsb_open))
9189
return false;
9290

91+
const auto arg1 = m_args[0];
92+
const auto arg2 = m_args[1];
93+
9394
if (impure->irsb_flags & irsb_first)
9495
{
95-
if (m_arg1->getRecord(tdbb))
96+
if (arg1->getRecord(tdbb))
9697
return true;
9798

9899
impure->irsb_flags &= ~irsb_first;
99-
m_arg1->close(tdbb);
100-
m_arg2->open(tdbb);
100+
arg1->close(tdbb);
101+
arg2->open(tdbb);
101102
}
102103

103104
// We should exclude matching records from the right-joined (second) record source,
104105
// as they're already returned from the left-joined (first) record source
105106

106-
while (m_arg2->getRecord(tdbb))
107+
while (arg2->getRecord(tdbb))
107108
{
108109
bool matched = false;
109110

@@ -123,25 +124,11 @@ bool FullOuterJoin::internalGetRecord(thread_db* tdbb) const
123124
return false;
124125
}
125126

126-
bool FullOuterJoin::refetchRecord(thread_db* /*tdbb*/) const
127-
{
128-
return true;
129-
}
130-
131-
WriteLockResult FullOuterJoin::lockRecord(thread_db* tdbb) const
132-
{
133-
SET_TDBB(tdbb);
134-
135-
status_exception::raise(Arg::Gds(isc_record_lock_not_supp));
136-
}
137-
138127
void FullOuterJoin::getLegacyPlan(thread_db* tdbb, string& plan, unsigned level) const
139128
{
140129
level++;
141130
plan += "JOIN (";
142-
m_arg1->getLegacyPlan(tdbb, plan, level);
143-
plan += ", ";
144-
m_arg2->getLegacyPlan(tdbb, plan, level);
131+
Join::getLegacyPlan(tdbb, plan, level);
145132
plan += ")";
146133
}
147134

@@ -152,39 +139,5 @@ void FullOuterJoin::internalGetPlan(thread_db* tdbb, PlanEntry& planEntry, unsig
152139
planEntry.lines.add().text = "Full Outer Join";
153140
printOptInfo(planEntry.lines);
154141

155-
if (recurse)
156-
{
157-
++level;
158-
m_arg1->getPlan(tdbb, planEntry.children.add(), level, recurse);
159-
m_arg2->getPlan(tdbb, planEntry.children.add(), level, recurse);
160-
}
161-
}
162-
163-
void FullOuterJoin::markRecursive()
164-
{
165-
m_arg1->markRecursive();
166-
m_arg2->markRecursive();
167-
}
168-
169-
void FullOuterJoin::findUsedStreams(StreamList& streams, bool expandAll) const
170-
{
171-
m_arg1->findUsedStreams(streams, expandAll);
172-
m_arg2->findUsedStreams(streams, expandAll);
173-
}
174-
175-
bool FullOuterJoin::isDependent(const StreamList& streams) const
176-
{
177-
return m_arg1->isDependent(streams) || m_arg2->isDependent(streams);
178-
}
179-
180-
void FullOuterJoin::invalidateRecords(Request* request) const
181-
{
182-
m_arg1->invalidateRecords(request);
183-
m_arg2->invalidateRecords(request);
184-
}
185-
186-
void FullOuterJoin::nullRecords(thread_db* tdbb) const
187-
{
188-
m_arg1->nullRecords(tdbb);
189-
m_arg2->nullRecords(tdbb);
142+
Join::getPlan(tdbb, planEntry, level, recurse);
190143
}

0 commit comments

Comments
 (0)