7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/executor/nodeMergejoin.c,v 1.23 1999/02/23 07:35:09 thomas Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/executor/nodeMergejoin.c,v 1.24 1999/02/24 10:20:07 momjian Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -288,7 +288,7 @@ MergeCompare(List *eqQual, List *compareQual, ExprContext *econtext)
288
288
*/
289
289
#ifdef EXEC_MERGEJOINDEBUG
290
290
void
291
- ExecMergeTupleDumpInner (ExprContext * econtext );
291
+ ExecMergeTupleDumpInner (ExprContext * econtext );
292
292
293
293
void
294
294
ExecMergeTupleDumpInner (ExprContext * econtext )
@@ -305,7 +305,7 @@ ExecMergeTupleDumpInner(ExprContext *econtext)
305
305
}
306
306
307
307
void
308
- ExecMergeTupleDumpOuter (ExprContext * econtext );
308
+ ExecMergeTupleDumpOuter (ExprContext * econtext );
309
309
310
310
void
311
311
ExecMergeTupleDumpOuter (ExprContext * econtext )
@@ -321,8 +321,7 @@ ExecMergeTupleDumpOuter(ExprContext *econtext)
321
321
outerSlot -> ttc_tupleDescriptor );
322
322
}
323
323
324
- void
325
- ExecMergeTupleDumpMarked (ExprContext * econtext ,
324
+ void ExecMergeTupleDumpMarked (ExprContext * econtext ,
326
325
MergeJoinState * mergestate );
327
326
328
327
void
@@ -342,7 +341,7 @@ ExecMergeTupleDumpMarked(ExprContext *econtext,
342
341
}
343
342
344
343
void
345
- ExecMergeTupleDump (ExprContext * econtext ,MergeJoinState * mergestate );
344
+ ExecMergeTupleDump (ExprContext * econtext ,MergeJoinState * mergestate );
346
345
347
346
void
348
347
ExecMergeTupleDump (ExprContext * econtext ,MergeJoinState * mergestate )
@@ -355,6 +354,7 @@ ExecMergeTupleDump(ExprContext *econtext, MergeJoinState *mergestate)
355
354
356
355
printf ("******** \n" );
357
356
}
357
+
358
358
#endif
359
359
360
360
/* ----------------------------------------------------------------
@@ -427,11 +427,14 @@ ExecMergeJoin(MergeJoin *node)
427
427
ExprContext * econtext ;
428
428
429
429
#ifdef ENABLE_OUTER_JOINS
430
- /* These should be set from the expression context!
431
- * - thomas 1999-02-20
430
+
431
+ /*
432
+ * These should be set from the expression context! - thomas
433
+ * 1999-02-20
432
434
*/
433
435
static bool isLeftJoin = true;
434
436
static bool isRightJoin = false;
437
+
435
438
#endif
436
439
437
440
/* ----------------
@@ -486,19 +489,19 @@ ExecMergeJoin(MergeJoin *node)
486
489
switch (mergestate -> mj_JoinState )
487
490
{
488
491
489
- /*********************************
492
+ /*
490
493
* EXEC_MJ_INITIALIZE means that this is the first time
491
- * ExecMergeJoin() has been called and so we have to initialize
492
- * the inner, outer and marked tuples as well as various stuff
493
- * in the expression context.
494
- ********************************* /
494
+ * ExecMergeJoin() has been called and so we have to
495
+ *initialize the inner, outer and marked tuples as well
496
+ *as various stuff in the expression context.
497
+ */
495
498
case EXEC_MJ_INITIALIZE :
496
499
MJ_printf ("ExecMergeJoin: EXEC_MJ_INITIALIZE\n" );
497
- /* ----------------
498
- * Note: at this point, if either of our inner or outer
499
- * tuples are nil, then the join ends immediately because
500
- * we know one of thesubplans is empty.
501
- *----------------
500
+
501
+ /*
502
+ * Note: at this point, if either of our inner or outer
503
+ * tuples are nil, then thejoin ends immediately because
504
+ *we know one of the subplans is empty.
502
505
*/
503
506
innerTupleSlot = ExecProcNode (innerPlan , (Plan * )node );
504
507
if (TupIsNull (innerTupleSlot ))
@@ -531,11 +534,12 @@ ExecMergeJoin(MergeJoin *node)
531
534
mergestate -> mj_JoinState = EXEC_MJ_SKIPINNER ;
532
535
break ;
533
536
534
- /*********************************
535
- * EXEC_MJ_JOINMARK means we have just found a new outer tuple
536
- * and a possible matching inner tuple. This is the case after
537
- * the INITIALIZE, SKIPOUTER or SKIPINNER states.
538
- *********************************/
537
+ /*
538
+ * EXEC_MJ_JOINMARK means we have just found a new outer
539
+ * tuple and a possible matching inner tuple. This is the
540
+ * case after the INITIALIZE, SKIPOUTER or SKIPINNER
541
+ * states.
542
+ */
539
543
case EXEC_MJ_JOINMARK :
540
544
MJ_printf ("ExecMergeJoin: EXEC_MJ_JOINMARK\n" );
541
545
ExecMarkPos (innerPlan );
@@ -545,15 +549,15 @@ ExecMergeJoin(MergeJoin *node)
545
549
mergestate -> mj_JoinState = EXEC_MJ_JOINTEST ;
546
550
break ;
547
551
548
- /*********************************
552
+ /*
549
553
* EXEC_MJ_JOINTEST means we have two tuples which might
550
554
* satisfy the merge clause, so we test them.
551
555
*
552
556
* If they do satisfy, then we join them and move on to the
553
557
* next inner tuple (EXEC_MJ_JOINTUPLES).
554
558
*
555
559
* If they do not satisfy then advance to next outer tuple.
556
- ********************************* /
560
+ */
557
561
case EXEC_MJ_JOINTEST :
558
562
MJ_printf ("ExecMergeJoin: EXEC_MJ_JOINTEST\n" );
559
563
@@ -566,11 +570,11 @@ ExecMergeJoin(MergeJoin *node)
566
570
mergestate -> mj_JoinState = EXEC_MJ_NEXTOUTER ;
567
571
break ;
568
572
569
- /*********************************
573
+ /*
570
574
* EXEC_MJ_JOINTUPLES means we have two tuples which
571
575
* satisified the merge clause so we join them and then
572
576
* proceed to get the next inner tuple (EXEC_NEXT_INNER).
573
- ********************************* /
577
+ */
574
578
case EXEC_MJ_JOINTUPLES :
575
579
MJ_printf ("ExecMergeJoin: EXEC_MJ_JOINTUPLES\n" );
576
580
mergestate -> mj_JoinState = EXEC_MJ_NEXTINNER ;
@@ -599,11 +603,11 @@ ExecMergeJoin(MergeJoin *node)
599
603
}
600
604
break ;
601
605
602
- /*********************************
603
- * EXEC_MJ_NEXTINNER means advance the inner scan to
604
- *the next tuple. If the tuple is not nil, we then
605
- *proceed to test it against the join qualification.
606
- ********************************* /
606
+ /*
607
+ * EXEC_MJ_NEXTINNER means advance the inner scan to the
608
+ * next tuple. If the tuple is not nil, we then proceed to
609
+ * test it against the join qualification.
610
+ */
607
611
case EXEC_MJ_NEXTINNER :
608
612
MJ_printf ("ExecMergeJoin: EXEC_MJ_NEXTINNER\n" );
609
613
@@ -621,21 +625,22 @@ ExecMergeJoin(MergeJoin *node)
621
625
mergestate -> mj_JoinState = EXEC_MJ_JOINTEST ;
622
626
break ;
623
627
624
- /*********************************
628
+ /*-------------------------------------------
625
629
* EXEC_MJ_NEXTOUTER means
626
630
*
627
- * outer inner
628
- * outer tuple - 5 5 - marked tuple
629
- * 5 5
630
- * 6 6 - inner tuple
631
- * 7 7
631
+ * outer inner
632
+ * outer tuple - 5 5 - marked tuple
633
+ * 5 5
634
+ * 6 6 - inner tuple
635
+ * 7 7
632
636
*
633
- * we know we just bumped into the
637
+ * we know we just bumped into the
634
638
* first inner tuple > current outer tuple
635
639
* so get a new outer tuple and then
636
640
* proceed to test it against the marked tuple
637
641
* (EXEC_MJ_TESTOUTER)
638
- *********************************/
642
+ *------------------------------------------------
643
+ */
639
644
case EXEC_MJ_NEXTOUTER :
640
645
MJ_printf ("ExecMergeJoin: EXEC_MJ_NEXTOUTER\n" );
641
646
@@ -657,7 +662,7 @@ ExecMergeJoin(MergeJoin *node)
657
662
mergestate -> mj_JoinState = EXEC_MJ_TESTOUTER ;
658
663
break ;
659
664
660
- /*********************************
665
+ /*--------------------------------------------------------
661
666
* EXEC_MJ_TESTOUTER If the new outer tuple and the marked
662
667
* tuple satisfy the merge clause then we know we have
663
668
* duplicates in the outer scan so we have to restore the
@@ -687,9 +692,10 @@ ExecMergeJoin(MergeJoin *node)
687
692
*7 12
688
693
*
689
694
*
690
- * new outer tuple > marked tuple
695
+ * new outer tuple > marked tuple
691
696
*
692
- *********************************/
697
+ *---------------------------------------------------------
698
+ */
693
699
case EXEC_MJ_TESTOUTER :
694
700
MJ_printf ("ExecMergeJoin: EXEC_MJ_TESTOUTER\n" );
695
701
@@ -731,11 +737,11 @@ ExecMergeJoin(MergeJoin *node)
731
737
*tuple didn't match the marked outer tuple then
732
738
*we may have the case:
733
739
*
734
- * outer inner
735
- * 4 4 - marked tuple
736
- * new outer - 5 4
737
- * 6 nil - inner tuple
738
- * 7
740
+ * outer inner
741
+ *4 4 - marked tuple
742
+ * new outer - 5 4
743
+ *6 nil - inner tuple
744
+ * 7
739
745
*
740
746
*which means that all subsequent outer tuples will be
741
747
*larger than our inner tuples.
@@ -760,22 +766,23 @@ ExecMergeJoin(MergeJoin *node)
760
766
}
761
767
break ;
762
768
763
- /*********************************
769
+ /*----------------------------------------------------------
764
770
* EXEC_MJ_SKIPOUTER means skip over tuples in the outer plan
765
771
* until we find an outer tuple > current inner tuple.
766
772
*
767
773
* For example:
768
774
*
769
- * outer inner
770
- * 5 5
771
- * 5 5
772
- * outer tuple - 6 8 - inner tuple
773
- * 7 12
774
- * 8 14
775
+ * outer inner
776
+ * 5 5
777
+ * 5 5
778
+ * outer tuple - 6 8 - inner tuple
779
+ * 7 12
780
+ * 8 14
775
781
*
776
782
* we have to advance the outer scan
777
783
* until we find the outer 8.
778
- *********************************/
784
+ *----------------------------------------------------------
785
+ */
779
786
case EXEC_MJ_SKIPOUTER :
780
787
MJ_printf ("ExecMergeJoin: EXEC_MJ_SKIPOUTER\n" );
781
788
/* ----------------
@@ -867,23 +874,24 @@ ExecMergeJoin(MergeJoin *node)
867
874
mergestate -> mj_JoinState = EXEC_MJ_JOINMARK ;
868
875
break ;
869
876
870
- /*********************************
877
+ /*-----------------------------------------------------------
871
878
* EXEC_MJ_SKIPINNER means skip over tuples in the inner plan
872
879
* until we find an inner tuple > current outer tuple.
873
880
*
874
881
* For example:
875
882
*
876
- * outer inner
877
- * 5 5
878
- * 5 5
879
- * outer tuple - 12 8 - inner tuple
880
- * 14 10
881
- * 17 12
883
+ * outer inner
884
+ * 5 5
885
+ * 5 5
886
+ * outer tuple - 12 8 - inner tuple
887
+ * 14 10
888
+ * 17 12
882
889
*
883
890
* we have to advance the inner scan
884
891
* until we find the inner 12.
885
892
*
886
- *********************************/
893
+ *-------------------------------------------------------
894
+ */
887
895
case EXEC_MJ_SKIPINNER :
888
896
MJ_printf ("ExecMergeJoin: EXEC_MJ_SKIPINNER\n" );
889
897
/* ----------------
@@ -997,11 +1005,13 @@ ExecMergeJoin(MergeJoin *node)
997
1005
break ;
998
1006
999
1007
#ifdef ENABLE_OUTER_JOINS
1000
- /*********************************
1001
- * EXEC_MJ_FILLINNER means we have an unmatched inner tuple
1002
- * which must be null-expanded into the projection tuple.
1003
- * get the next inner tuple and reset markers (EXEC_MJ_JOINMARK).
1004
- *********************************/
1008
+
1009
+ /*
1010
+ * EXEC_MJ_FILLINNER means we have an unmatched inner
1011
+ * tuple which must be null-expanded into the projection
1012
+ * tuple. get the next inner tuple and reset markers
1013
+ * (EXEC_MJ_JOINMARK).
1014
+ */
1005
1015
case EXEC_MJ_FILLINNER :
1006
1016
MJ_printf ("ExecMergeJoin: EXEC_MJ_FILLINNER\n" );
1007
1017
mergestate -> mj_JoinState = EXEC_MJ_JOINMARK ;
@@ -1046,11 +1056,12 @@ ExecMergeJoin(MergeJoin *node)
1046
1056
*/
1047
1057
break ;
1048
1058
1049
- /*********************************
1050
- * EXEC_MJ_FILLOUTER means we have an unmatched outer tuple
1051
- * which must be null-expanded into the projection tuple.
1052
- * get the next outer tuple and reset markers (EXEC_MJ_JOINMARK).
1053
- *********************************/
1059
+ /*
1060
+ * EXEC_MJ_FILLOUTER means we have an unmatched outer
1061
+ * tuple which must be null-expanded into the projection
1062
+ * tuple. get the next outer tuple and reset markers
1063
+ * (EXEC_MJ_JOINMARK).
1064
+ */
1054
1065
case EXEC_MJ_FILLOUTER :
1055
1066
MJ_printf ("ExecMergeJoin: EXEC_MJ_FILLOUTER\n" );
1056
1067
mergestate -> mj_JoinState = EXEC_MJ_JOINMARK ;
@@ -1095,10 +1106,10 @@ ExecMergeJoin(MergeJoin *node)
1095
1106
break ;
1096
1107
#endif
1097
1108
1098
- /*********************************
1099
- * if we get here it means our code is fouled up
1100
- *and so we just end the join prematurely.
1101
- ********************************* /
1109
+ /*
1110
+ * if we get here it means our code is fouled up and so we
1111
+ * just end the join prematurely.
1112
+ */
1102
1113
default :
1103
1114
elog (NOTICE ,"ExecMergeJoin: invalid join state. aborting" );
1104
1115
return NULL ;