Skip to content

Commit

Permalink
Merge pull request cockroachdb#108821 from yuzefovich/backport23.1.9-…
Browse files Browse the repository at this point in the history
…rc-105931

release-23.1.9-rc: colexec: don't infinite loop cross-join with zero-column left input
  • Loading branch information
yuzefovich authored Aug 16, 2023
2 parents bdce8e2 + 01f26f7 commit f5421eb
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
50 changes: 50 additions & 0 deletions pkg/sql/colexec/colexecjoin/crossjoiner.eg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions pkg/sql/colexec/colexecjoin/crossjoiner_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,32 @@ func buildFromLeftBatch(b *crossJoinerBase, currentBatch coldata.Batch, sel []in
colexecerror.InternalError(errors.AssertionFailedf("unhandled type %s", b.left.types[colIdx].String()))
}
}
// If there are no columns projected from the left input, simply advance the
// cross-joiner state according to the number of input rows.
if len(b.left.types) == 0 {
outStartIdx := destStartIdx
for bs.curSrcStartIdx < leftSrcEndIdx && outStartIdx < outputCapacity {
// Repeat each row leftNumRepeats times.
// {{/* toAppend will always be positive. */}}
toAppend := leftNumRepeats - bs.numRepeatsIdx
if outStartIdx+toAppend > outputCapacity {
// We don't have enough space to repeat the current
// value the required number of times, so we'll have
// to continue from here on the next call.
toAppend = outputCapacity - outStartIdx
bs.numRepeatsIdx += toAppend
} else {
// We fully processed the current tuple for the
// current column, and before moving on to the next
// one, we need to reset numRepeatsIdx (so that the
// next tuple would be repeated leftNumRepeats
// times).
bs.curSrcStartIdx++
bs.numRepeatsIdx = 0
}
outStartIdx += toAppend
}
}
}

// buildFromLeftInput builds part of the output of a cross join that comes from
Expand Down
15 changes: 15 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/cross_join
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,18 @@ SELECT *
)
WHERE r < .01
LIMIT 1

# Regression test for #105882 - don't infinite loop when the left input has
# no columns.
statement ok
CREATE TABLE t105882 (c0 INT);
UPSERT INTO t105882 (c0) VALUES(1);

query I
SELECT (
SELECT count(t2.rowid) FROM t105882 t2
WHERE ((t1.rowid) IN (SELECT max(t3.rowid) FROM t105882 t3))
)
FROM t105882 t1;
----
1

0 comments on commit f5421eb

Please sign in to comment.