@@ -716,18 +716,18 @@ func (i *crossJoinIterator) Close(ctx *sql.Context) (err error) {
716716// +---+---+
717717// cond is passed to the filter iter to be evaluated.
718718type lateralJoinIterator struct {
719- lIter sql.RowIter
720- rIter sql.RowIter
721- rNode sql.Node
722- cond sql.Expression
723- b sql.NodeExecBuilder
724- pRow sql.Row
725- lRow sql.Row
726- rRow sql.Row
727- rowSize int
728- scopeLen int
729- jType plan.JoinType
730- foundMatch bool
719+ primary sql.RowIter
720+ secondary sql.RowIter
721+ secondaryNode sql.Node
722+ cond sql.Expression
723+ b sql.NodeExecBuilder
724+ parentRow sql.Row
725+ primaryRow sql.Row
726+ secondaryRow sql.Row
727+ rowSize int
728+ scopeLen int
729+ jType plan.JoinType
730+ foundMatch bool
731731}
732732
733733func newLateralJoinIter (ctx * sql.Context , b sql.NodeExecBuilder , j * plan.JoinNode , row sql.Row ) (sql.RowIter , error ) {
@@ -755,105 +755,105 @@ func newLateralJoinIter(ctx *sql.Context, b sql.NodeExecBuilder, j *plan.JoinNod
755755 }
756756
757757 return sql .NewSpanIter (span , & lateralJoinIterator {
758- pRow : row ,
759- lIter : l ,
760- rNode : j .Right (),
761- cond : j .Filter ,
762- jType : j .Op ,
763- rowSize : len (row ) + len (j .Left ().Schema ()) + len (j .Right ().Schema ()),
764- scopeLen : j .ScopeLen ,
765- b : b ,
758+ parentRow : row ,
759+ primary : l ,
760+ secondaryNode : j .Right (),
761+ cond : j .Filter ,
762+ jType : j .Op ,
763+ rowSize : len (row ) + len (j .Left ().Schema ()) + len (j .Right ().Schema ()),
764+ scopeLen : j .ScopeLen ,
765+ b : b ,
766766 }), nil
767767}
768768
769- func (i * lateralJoinIterator ) loadLeft (ctx * sql.Context ) error {
770- if i .lRow == nil {
771- lRow , err := i .lIter .Next (ctx )
769+ func (i * lateralJoinIterator ) loadPrimary (ctx * sql.Context ) error {
770+ if i .primaryRow == nil {
771+ lRow , err := i .primary .Next (ctx )
772772 if err != nil {
773773 return err
774774 }
775- i .lRow = lRow
775+ i .primaryRow = lRow
776776 i .foundMatch = false
777777 }
778778 return nil
779779}
780780
781- func (i * lateralJoinIterator ) buildRight (ctx * sql.Context ) error {
782- if i .rIter == nil {
783- prepended , _ , err := transform .Node (i .rNode , plan .PrependRowInPlan (i .lRow , true ))
781+ func (i * lateralJoinIterator ) buildSecondary (ctx * sql.Context ) error {
782+ if i .secondary == nil {
783+ prepended , _ , err := transform .Node (i .secondaryNode , plan .PrependRowInPlan (i .primaryRow , true ))
784784 if err != nil {
785785 return err
786786 }
787- iter , err := i .b .Build (ctx , prepended , i .lRow )
787+ iter , err := i .b .Build (ctx , prepended , i .primaryRow )
788788 if err != nil {
789789 return err
790790 }
791- i .rIter = iter
791+ i .secondary = iter
792792 }
793793 return nil
794794}
795795
796- func (i * lateralJoinIterator ) loadRight (ctx * sql.Context ) error {
797- if i .rRow == nil {
798- rRow , err := i .rIter .Next (ctx )
796+ func (i * lateralJoinIterator ) loadSecondary (ctx * sql.Context ) error {
797+ if i .secondaryRow == nil {
798+ sRow , err := i .secondary .Next (ctx )
799799 if err != nil {
800800 return err
801801 }
802- i .rRow = rRow [len (i .lRow ):]
802+ i .secondaryRow = sRow [len (i .primaryRow ):]
803803 }
804804 return nil
805805}
806806
807- func (i * lateralJoinIterator ) buildRow (lRow , rRow sql.Row ) sql.Row {
807+ func (i * lateralJoinIterator ) buildRow (primaryRow , secondaryRow sql.Row ) sql.Row {
808808 row := make (sql.Row , i .rowSize )
809- copy (row , lRow )
810- copy (row [len (lRow ):], rRow )
809+ copy (row , primaryRow )
810+ copy (row [len (primaryRow ):], secondaryRow )
811811 return row
812812}
813813
814814func (i * lateralJoinIterator ) removeParentRow (r sql.Row ) sql.Row {
815- copy (r [i .scopeLen :], r [len (i .pRow ):])
816- r = r [:len (r )- len (i .pRow )+ i .scopeLen ]
815+ copy (r [i .scopeLen :], r [len (i .parentRow ):])
816+ r = r [:len (r )- len (i .parentRow )+ i .scopeLen ]
817817 return r
818818}
819819
820820func (i * lateralJoinIterator ) reset (ctx * sql.Context ) (err error ) {
821- if i .rIter != nil {
822- err = i .rIter .Close (ctx )
823- i .rIter = nil
821+ if i .secondary != nil {
822+ err = i .secondary .Close (ctx )
823+ i .secondary = nil
824824 }
825- i .lRow = nil
826- i .rRow = nil
825+ i .primaryRow = nil
826+ i .secondaryRow = nil
827827 return
828828}
829829
830830func (i * lateralJoinIterator ) Next (ctx * sql.Context ) (sql.Row , error ) {
831831 for {
832- if err := i .loadLeft (ctx ); err != nil {
832+ if err := i .loadPrimary (ctx ); err != nil {
833833 return nil , err
834834 }
835- if err := i .buildRight (ctx ); err != nil {
835+ if err := i .buildSecondary (ctx ); err != nil {
836836 return nil , err
837837 }
838- if err := i .loadRight (ctx ); err != nil {
838+ if err := i .loadSecondary (ctx ); err != nil {
839839 if errors .Is (err , io .EOF ) {
840840 if ! i .foundMatch && i .jType == plan .JoinTypeLateralLeft {
841- res := i .buildRow (i .lRow , nil )
842- if rerr := i .reset (ctx ); rerr != nil {
843- return nil , rerr
841+ res := i .buildRow (i .primaryRow , nil )
842+ if resetErr := i .reset (ctx ); resetErr != nil {
843+ return nil , resetErr
844844 }
845845 return i .removeParentRow (res ), nil
846846 }
847- if rerr := i .reset (ctx ); rerr != nil {
848- return nil , rerr
847+ if resetErr := i .reset (ctx ); resetErr != nil {
848+ return nil , resetErr
849849 }
850850 continue
851851 }
852852 return nil , err
853853 }
854854
855- row := i .buildRow (i .lRow , i .rRow )
856- i .rRow = nil
855+ row := i .buildRow (i .primaryRow , i .secondaryRow )
856+ i .secondaryRow = nil
857857 if i .cond != nil {
858858 if res , err := sql .EvaluateCondition (ctx , i .cond , row ); err != nil {
859859 return nil , err
@@ -868,18 +868,18 @@ func (i *lateralJoinIterator) Next(ctx *sql.Context) (sql.Row, error) {
868868}
869869
870870func (i * lateralJoinIterator ) Close (ctx * sql.Context ) error {
871- var lerr , rerr error
872- if i .lIter != nil {
873- lerr = i .lIter .Close (ctx )
871+ var pErr , sErr error
872+ if i .primary != nil {
873+ pErr = i .primary .Close (ctx )
874874 }
875- if i .rIter != nil {
876- rerr = i .rIter .Close (ctx )
875+ if i .secondary != nil {
876+ sErr = i .secondary .Close (ctx )
877877 }
878- if lerr != nil {
879- return lerr
878+ if pErr != nil {
879+ return pErr
880880 }
881- if rerr != nil {
882- return rerr
881+ if sErr != nil {
882+ return sErr
883883 }
884884 return nil
885885}
0 commit comments