MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / CrossJoin

Method CrossJoin

src/jrd/optimizer/Optimizer.cpp:171–264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169 {
170 public:
171 CrossJoin(Optimizer* opt, RiverList& rivers, JoinType joinType)
172 : River(opt->getCompilerScratch(), nullptr, rivers)
173 {
174 fb_assert(joinType != OUTER_JOIN);
175
176 const auto csb = opt->getCompilerScratch();
177 Optimizer::ConjunctIterator iter(opt->getBaseConjuncts());
178
179 // Save states of the underlying streams and restore them afterwards
180
181 StreamStateHolder stateHolder(csb, m_streams);
182 stateHolder.deactivate();
183
184 // Generate record source objects
185
186 const FB_SIZE_T riverCount = rivers.getCount();
187
188 if (riverCount == 1)
189 {
190 const auto subRiver = rivers.pop();
191 const auto subRsb = subRiver->getRecordSource();
192 subRiver->activate(csb);
193 m_rsb = opt->applyBoolean(subRsb, iter);
194 }
195 else
196 {
197 HalfStaticArray<RecordSource*, OPT_STATIC_ITEMS> rsbs(riverCount);
198
199 if (joinType == INNER_JOIN)
200 {
201 // Reorder input rivers according to their possible inter-dependencies
202
203 while (rivers.hasData())
204 {
205 const auto orgCount = rsbs.getCount();
206
207 for (auto& subRiver : rivers)
208 {
209 subRiver->activate(csb);
210
211 if (subRiver->isComputable(csb))
212 {
213 auto subRsb = subRiver->getRecordSource();
214 subRsb = opt->applyBoolean(subRsb, iter);
215
216 rsbs.add(subRsb);
217 rivers.remove(&subRiver);
218 break;
219 }
220
221 subRiver->deactivate(csb);
222 }
223
224 if (rsbs.getCount() == orgCount)
225 break;
226 }
227
228 if (rivers.hasData())

Callers

nothing calls this directly

Calls 15

NestedLoopJoinClass · 0.85
getCompilerScratchMethod · 0.80
getBaseConjunctsMethod · 0.80
getRecordSourceMethod · 0.80
applyBooleanMethod · 0.80
isComputableMethod · 0.80
deactivateMethod · 0.45
getCountMethod · 0.45
popMethod · 0.45
activateMethod · 0.45
hasDataMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected