* MJEvalOuterValues * * Compute the values of the mergejoined expressions for the current * outer tuple. We also detect whether it's impossible for the current * outer tuple to match anything --- this is true if it yields a NULL * input, since we assume mergejoin operators are strict. If the NULL * is in the first join column, and that column sorts nulls last, then * we can further conclu
| 323 | * time we move to a new tuple. |
| 324 | */ |
| 325 | static MJEvalResult |
| 326 | MJEvalOuterValues(MergeJoinState *mergestate) |
| 327 | { |
| 328 | ExprContext *econtext = mergestate->mj_OuterEContext; |
| 329 | MJEvalResult result = MJEVAL_MATCHABLE; |
| 330 | int i; |
| 331 | MemoryContext oldContext; |
| 332 | |
| 333 | /* Check for end of outer subplan */ |
| 334 | if (TupIsNull(mergestate->mj_OuterTupleSlot)) |
| 335 | return MJEVAL_ENDOFJOIN; |
| 336 | |
| 337 | ResetExprContext(econtext); |
| 338 | |
| 339 | oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory); |
| 340 | |
| 341 | econtext->ecxt_outertuple = mergestate->mj_OuterTupleSlot; |
| 342 | |
| 343 | for (i = 0; i < mergestate->mj_NumClauses; i++) |
| 344 | { |
| 345 | MergeJoinClause clause = &mergestate->mj_Clauses[i]; |
| 346 | |
| 347 | clause->ldatum = ExecEvalExpr(clause->lexpr, econtext, |
| 348 | &clause->lisnull); |
| 349 | if (clause->lisnull && !clause->notdistinct) |
| 350 | { |
| 351 | /* match is impossible; can we end the join early? */ |
| 352 | if (i == 0 && !clause->ssup.ssup_nulls_first && |
| 353 | !mergestate->mj_FillOuter) |
| 354 | result = MJEVAL_ENDOFJOIN; |
| 355 | else if (result == MJEVAL_MATCHABLE) |
| 356 | result = MJEVAL_NONMATCHABLE; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | MemoryContextSwitchTo(oldContext); |
| 361 | |
| 362 | return result; |
| 363 | } |
| 364 | |
| 365 | /* |
| 366 | * MJEvalInnerValues |
no test coverage detected