Skip to content

sql: remove public key column check when fetching#76788

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
RaduBerinde:no-public-col-check
Feb 20, 2022
Merged

sql: remove public key column check when fetching#76788
craig[bot] merged 1 commit intocockroachdb:masterfrom
RaduBerinde:no-public-col-check

Conversation

@RaduBerinde
Copy link
Copy Markdown
Member

This commit removes a check that fails creation of an IndexFetchSpec
if a key column is not public.

The only case where this comes up AFAICT is when we hit a duplicate
key error and try to fetch the row to get the values for the error
message. In this case, even though the column is not public, we know
that the row we care about exists in the index, or we wouldn't have
hit the error.

Release note: None

This commit removes a check that fails creation of an IndexFetchSpec
if a key column is not public.

The only case where this comes up AFAICT is when we hit a duplicate
key error and try to fetch the row to get the values for the error
message. In this case, even though the column is not public, we know
that the row we care about exists in the index, or we wouldn't have
hit the error.

Release note: None
@RaduBerinde RaduBerinde requested a review from postamar February 18, 2022 20:17
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

craig bot pushed a commit that referenced this pull request Feb 20, 2022
76795: rowenc: various improvements to IndexFetchSpec initialization r=RaduBerinde a=RaduBerinde

First commit is #76788.

#### catalog: store IndexFetchSpec key columns in table descriptor

We now cache the IndexFetchSpec_KeyAndSuffixColumns in the table
descriptor, making it cheaper to populate an IndexFetchSpec.

Release note: None

#### catalog: cleanup KeysPerRow

This change renames KeysPerRow to IndexKeysPerRow and changes the
argument to an IndexDescriptor, removing the error case.

Release note: None

#### catalog: cache family default columns in table descriptor

We now cache the `IndexFetchSpec_FamilyDefaultColumn`s in the table
descriptor, to avoid an allocation when creating an `IndexFetchSpec`.

Release note: None

#### rowenc: calculate key prefix length without allocating

We now calculate the key prefix length directly instead of creating a
throw-away key.

Release note: None

Co-authored-by: Radu Berinde <radu@cockroachlabs.com>
@craig craig bot merged commit 8397a9e into cockroachdb:master Feb 20, 2022
@RaduBerinde
Copy link
Copy Markdown
Member Author

Oops, I accidentally merged this with #76795. I'd still like a review, I can make any changes in another PR.

@RaduBerinde RaduBerinde deleted the no-public-col-check branch February 20, 2022 19:53
Copy link
Copy Markdown

@postamar postamar left a comment

Choose a reason for hiding this comment

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

if !col.Public() {
// Key columns must be public.
return fmt.Errorf("column %q (%d) is not public", col.GetName(), col.GetID())
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry it took me a while to look at this @RaduBerinde .

I'm really not sure how legit removing this check is. Any column which is not public is, by definition, not readable, and it seems to me that this function might be used to perform reads.

If that's not exclusively the case, and if UPSERTs are not considered to be reads, and this function is called to perform a write, then this column state check can be relaxed from "readable" to "writable".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The nuance here is that if an UPSERT fails because of a conflict on a non-public column, that particular conflicting row value is in a way readable (because it is influencing a user-visible outcome, in this case an error). It's really only a matter of whether we include it in the error message or not.

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