A question about the storeSide of hashjoiner

sql

(jemy Lan) #1

(CockroachDB version 2.1.2)

When building a hashjoiner, if sql.distsql.temp_storage.workmem is not enough, the storeSide will be set to the side of AddRow() function was being executed at that moment, then jump to “hjConsumingStoredSide” state. The consumeStoredSide() function will fully consume the storeSide. The storeSide is probably left or right.

(pkg/sql/distsqlrun/hashjoiner.go:build())

So it doesn’t look like the comments in “hjConsumingStoredSide” that It will fully consume the right side. (maybe is left side)


(Alfonso Subiotto Marqués) #2

@xiaolanzao66 you’re correct that the comment is not correct, and there are cases where we will move to consumer the left side. However, note that we buffer at most hashJoinerInitialBufferSize in either row container (4MiB) so if that limit is hit before a memory limit in AddRow (by default 64MiB), we will always consume the right side:

		leftUsage := h.rows[leftSide].MemUsage()
		rightUsage := h.rows[rightSide].MemUsage()

		if leftUsage >= h.initialBufferSize && rightUsage >= h.initialBufferSize {
			// Both sides have reached the buffer size limit. Move on to storing and
			// fully consuming the right side.
			log.VEventf(h.Ctx, 1, "buffer phase found no short stream with buffer size %d", h.initialBufferSize)
			return setStoredSideTransition(rightSide)
		}

So in practice it will usually be the right side, unless workmem is less than 4MiB. Feel free to submit a PR to change the comment!