Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: wip fix hashjoiner error prop #51324

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions pkg/sql/rowexec/hashjoiner.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ const (
// other side. This only happens when executing a FULL OUTER, LEFT/RIGHT
// OUTER and ANTI joins (depending on which side we store).
hjEmittingUnmatched

hjStateForwardRight
hjStateForwardLeft
)

// hashJoiner performs a hash join. There is no guarantee on the output
Expand Down Expand Up @@ -223,6 +226,27 @@ func (h *hashJoiner) Start(ctx context.Context) context.Context {
return ctx
}

func (h *hashJoiner) forward(
side joinSide,
) (hashJoinerState, sqlbase.EncDatumRow, *execinfrapb.ProducerMetadata) {
row, meta, _, err := h.receiveNext(side)
if err != nil {
h.MoveToDraining(err)
return hjStateUnknown, nil, h.DrainHelper()
} else if meta != nil {
if meta.Err != nil {
h.MoveToDraining(nil)
return hjStateUnknown, nil, meta
}
return h.runningState, nil, meta
}
if row == nil {
h.MoveToDraining(err)
return hjStateUnknown, nil, h.DrainHelper()
}
return h.runningState, nil, nil
}

// Next is part of the RowSource interface.
func (h *hashJoiner) Next() (sqlbase.EncDatumRow, *execinfrapb.ProducerMetadata) {
for h.State == execinfra.StateRunning {
Expand All @@ -239,6 +263,10 @@ func (h *hashJoiner) Next() (sqlbase.EncDatumRow, *execinfrapb.ProducerMetadata)
h.runningState, row, meta = h.probeRow()
case hjEmittingUnmatched:
h.runningState, row, meta = h.emitUnmatched()
case hjStateForwardRight:
h.runningState, row, meta = h.forward(rightSide)
case hjStateForwardLeft:
h.runningState, row, meta = h.forward(leftSide)
default:
log.Fatalf(h.Ctx, "unsupported state: %d", h.runningState)
}
Expand Down Expand Up @@ -317,8 +345,13 @@ func (h *hashJoiner) build() (hashJoinerState, sqlbase.EncDatumRow, *execinfrapb
(h.joinType == sqlbase.InnerJoin ||
(h.joinType == sqlbase.LeftOuterJoin && side == leftSide) ||
(h.joinType == sqlbase.RightOuterJoin && side == rightSide)) {
h.MoveToDraining(nil /* err */)
return hjStateUnknown, nil, h.DrainHelper()
if side == leftSide {
return hjStateForwardRight, nil, nil
}
return hjStateForwardLeft, nil, nil
//h.MoveToDraining(nil /* err */)
//log.Warningf(h.Ctx, "hash joiner short circuiting into draining %p", h)
//return hjStateUnknown, nil, h.DrainHelper()
}
// We could skip hjConsumingStoredSide and move straight to
// hjReadingProbeSide apart from the fact that hjConsumingStoredSide
Expand Down