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

span: use KeyColumns in span.Builder #76836

Merged
merged 4 commits into from
Feb 23, 2022

Conversation

RaduBerinde
Copy link
Member

@RaduBerinde RaduBerinde commented Feb 21, 2022

span: minor span.Builder cleanup

Release note: None

rowenc: move null PK check

EncodeIndexKey has a special NULL check for primary indexes. This
check is a bit out of left field in this code, which is meant to be
more generic.

This commit moves this check in the higher-level primary index
encoding routines and simplifies some related code. We no longer try
to plumb the null ColumnID, instead we figure it out when generating
the error.

Release note: None

span: use KeyColumns in span.Builder

This commit refactors span.Builder to use
IndexFetchSpec_KeyColumns instead of descriptors. This is in
preparation for replacing the JoinReader descriptor with an
IndexFetchSpec.

Release note: None

span: don't allocate span.Builder

This commit replaces MakeBuilder (which allocates a *Builder) with
an Init method. This should be more efficient and also simplifies
the code by removing the pool.

Release: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 of 4 files at r1, 2 of 2 files at r2, 7 of 7 files at r3, 10 of 10 files at r4, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @RaduBerinde)


pkg/sql/rowexec/inverted_joiner.go, line 457 at r3 (raw file):

					ij.indexRow[prefixIdx] = row[colIdx]
				}
				// TODO(mgartner): MakeKeyFromEncDatumsDeprecated will allocate and grow a

nit: I don't see MakeKeyFromEncDatumsDeprecated anywhere.


pkg/sql/span/span_builder.go, line 83 at r1 (raw file):

}

// SpanFromEncDatums encodes a span with prefixLen constraint columns from the

nit: prefixLen is no more.


pkg/sql/span/span_builder.go, line 263 at r2 (raw file):

	// We need to advance the end key if it is inclusive or the index is
	// inverted.
	if cs.EndBoundary() == constraint.IncludeBoundary || s.index.GetType() == descpb.IndexDescriptor_INVERTED {

This change seems like it doesn't belong to the third commit. It'd be good to extra it into a separate commit (maybe separate PR) with the corresponding reasoning, and probably get a sign-off on this from someone else.


pkg/sql/span/span_builder.go, line 98 at r3 (raw file):

	}

	makeKeyFromRow := func(r rowenc.EncDatumRow) (k roachpb.Key, cn bool, e error) {

nit: this function seems to not be very useful anymore, maybe delete it entirely?

@RaduBerinde
Copy link
Member Author


pkg/sql/span/span_builder.go, line 263 at r2 (raw file):

Previously, yuzefovich (Yahor Yuzefovich) wrote…

This change seems like it doesn't belong to the third commit. It'd be good to extra it into a separate commit (maybe separate PR) with the corresponding reasoning, and probably get a sign-off on this from someone else.

I was going to ask you about this check, which seems wrong/unnecessary. I believe you added it in 55bb02f Do you remember why?

Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @RaduBerinde)


pkg/sql/span/span_builder.go, line 263 at r2 (raw file):

Previously, RaduBerinde wrote…

I was going to ask you about this check, which seems wrong/unnecessary. I believe you added it in 55bb02f Do you remember why?

The logic was already present in AdjustEndKeyForInterleave which was removed in that commit, so I only inlined what was relevant.

Copy link
Member Author

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @RaduBerinde and @yuzefovich)


pkg/sql/span/span_builder.go, line 263 at r2 (raw file):

Previously, yuzefovich (Yahor Yuzefovich) wrote…

The logic was already present in AdjustEndKeyForInterleave which was removed in that commit, so I only inlined what was relevant.

Ah, I see. It looks like an early return path because inverted index can't be interleaved, but it failed to account for the inclusive flag. It looks like it has been there for a long time (since knz@21c2b80), before we could have exclusive boundaries for inverted indexes. I'll open up a separate PR to remove.

Copy link
Member Author

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TFTR!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @yuzefovich)


pkg/sql/span/span_builder.go, line 263 at r2 (raw file):

Previously, RaduBerinde wrote…

Ah, I see. It looks like an early return path because inverted index can't be interleaved, but it failed to account for the inclusive flag. It looks like it has been there for a long time (since knz@21c2b80), before we could have exclusive boundaries for inverted indexes. I'll open up a separate PR to remove.

Will rebase on top of #76865 when that merges.


pkg/sql/span/span_builder.go, line 98 at r3 (raw file):

Previously, yuzefovich (Yahor Yuzefovich) wrote…

nit: this function seems to not be very useful anymore, maybe delete it entirely?

It makes the four callsites less cluttered. I left it (but I did remove the unnamed return).

@RaduBerinde RaduBerinde force-pushed the span-builder-refactor branch 3 times, most recently from f1504a3 to 018dcec Compare February 22, 2022 17:41
EncodeIndexKey has a special NULL check for primary indexes. This
check is a bit out of left field in this code, which is meant to be
more generic.

This commit moves this check in the higher-level primary index
encoding routines and simplifies some related code. We no longer try
to plumb the null ColumnID, instead we figure it out when generating
the error.

Release note: None
This commit refactors span.Builder to use
`IndexFetchSpec_KeyColumn`s instead of descriptors. This is in
preparation for replacing the JoinReader descriptor with an
`IndexFetchSpec`.

Release note: None
This commit replaces `MakeBuilder` (which allocates a `*Builder`) with
an `Init` method.  This should be more efficient and also simplifies
the code by removing the pool.

Release: None
Copy link
Member Author

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RFAL (the last commit is new)

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @yuzefovich)


pkg/sql/span/span_builder.go, line 263 at r2 (raw file):

Previously, RaduBerinde wrote…

Will rebase on top of #76865 when that merges.

Done.

@RaduBerinde RaduBerinde requested a review from a team February 22, 2022 19:22
Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 16 of 16 files at r5, 2 of 2 files at r6, 7 of 7 files at r7, 11 of 11 files at r8, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @RaduBerinde)

@RaduBerinde
Copy link
Member Author

bors r+

@craig
Copy link
Contributor

craig bot commented Feb 22, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Feb 23, 2022

Build succeeded:

@craig craig bot merged commit 696cdd5 into cockroachdb:master Feb 23, 2022
@RaduBerinde RaduBerinde deleted the span-builder-refactor branch March 19, 2022 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants