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: fix cached gists panic'ing after schema changes #76801

Merged
merged 1 commit into from
Feb 23, 2022

Conversation

cucaroach
Copy link
Contributor

Previously we didn't guard against out of bounds column ids in gists,
if a gist is created on a table and then that table drops columns we
would hit a runtime index out of bounds panic. By design gist decoding
is best effort and should silently ignore these columns when this
happens. The columns are used for equality conditions, ie:

         └── • lookup join
             │ table: broker@broker_pkey
             │ equality: (tr_s_symb) = (b_id)

So they are a nice to have. Doing anything more sophisticated would
dramatically increase the gist size so isn't worth it.

Fixes: #76800

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@cucaroach cucaroach marked this pull request as ready for review February 19, 2022 16:12
@cucaroach cucaroach requested a review from a team as a code owner February 19, 2022 16:12
----
• scan
table: t2@t2_pkey
spans: FULL SCAN
Copy link
Collaborator

Choose a reason for hiding this comment

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

How will the columns be displayed if they can't be decoded? Maybe this query should be a lookup join to test that case: SELECT * FROM t2 AS t2a INNER LOOKUP JOIN t2 AS t2b ON t2a.a = t2b.a and add an INDEX (a).

Name: string(col.ColName()),
Typ: col.DatumType(),
})
// Be defensive about bitset values because they may come from cached gists.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Might be helpful to explain that this guards against deleted columns.

@@ -655,8 +655,7 @@ func (opc *optPlanningCtx) runExecBuilder(
return nil
}

// DecodeGist Avoid an import cycle by keeping the cat out of the tree, RFC: is
// there a better way?
// DecodeGist Avoid an import cycle by keeping the cat out of the tree.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Avoids a call to the fire department too!

Copy link
Contributor Author

@cucaroach cucaroach 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 @cucaroach, @mgartner, and @RaduBerinde)


pkg/sql/opt/exec/explain/result_columns.go, line 204 at r1 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

nit: Might be helpful to explain that this guards against deleted columns.

👍


pkg/sql/opt/exec/execbuilder/testdata/explain_gist, line 86 at r1 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

How will the columns be displayed if they can't be decoded? Maybe this query should be a lookup join to test that case: SELECT * FROM t2 AS t2a INNER LOOKUP JOIN t2 AS t2b ON t2a.a = t2b.a and add an INDEX (a).

So if the column index is out of bounds you'll get a "_" in the plan. But its also possible they aren't out of bounds and now refer to a new column (even "rowid" or "crdb_mvcc_timestamp"). Not perfect but should be rare.

Previously we didn't guard against out of bounds column ids in gists,
if a gist is created on a table and then that table drops columns we
would hit a runtime index out of bounds panic. By design gist decoding
is best effort and should silently ignore these columns when this
happens. The columns are used for equality conditions, ie:

             └── • lookup join
                 │ table: broker@broker_pkey
                 │ equality: (tr_s_symb) = (b_id)

So they are a nice to have. Doing anything more sophisticated would
dramatically increase the gist size so isn't worth it.

Fixes: cockroachdb#76800

Release note: None
Copy link
Collaborator

@mgartner mgartner 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 2 of 3 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @cucaroach, @mgartner, and @RaduBerinde)

@cucaroach cucaroach requested a review from a team February 22, 2022 19:10
@cucaroach
Copy link
Contributor Author

bors r=mgartner

@craig
Copy link
Contributor

craig bot commented Feb 22, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Feb 23, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Feb 23, 2022

Build failed:

@cucaroach
Copy link
Contributor Author

bors r=mgartner

@craig
Copy link
Contributor

craig bot commented Feb 23, 2022

Build succeeded:

@craig craig bot merged commit 715520b into cockroachdb:master Feb 23, 2022
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.

sql: when a table drops a bunch of columns saved gists will runtime panic on decode
3 participants