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: prevent crash on range scan on virtual index #56459

Merged
merged 1 commit into from Nov 10, 2020

Conversation

jordanlewis
Copy link
Member

Fixes #56440.

Previously, the database would panic when a user performed a range scan
against a virtual table that had a virtual index. For example, the
queries:

SELECT * FROM pg_catalog.pg_type WHERE oid IN (19, 20)
SELECT * FROM pg_catalog.pg_class WHERE oid BETWEEN 20 AND 50

would cause this crash, since both of those tables have virtual indexes
defined on their oid columns.

This crash is now corrected.

Release note (bug fix): prevent a crash, introduced in the 20.2 series,
caused by range scans over virtual tables with virtual indexes.

@jordanlewis jordanlewis requested review from RaduBerinde and a team November 9, 2020 20:48
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@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 @jordanlewis and @RaduBerinde)


pkg/sql/virtual_schema.go, line 572 at r1 (raw file):

		// from the end and use them as a filter for the remaining rows of the
		// table.
		currentConstraint := idxConstraint.Spans.Count() - 1

[nit] currentConstraintSpan or currentSpan


pkg/sql/virtual_schema.go, line 589 at r1 (raw file):

			// constraint span's value.
			found, err := virtualIndex.populate(ctx, constraintDatum, p, dbDesc,
				addRowIfPassesFilter(idxConstraint))

This is pretty strange, we use the entire constraint each time except during the fallback. Why don't we want to just check against the current Span rather than the entire constraint? Well.. I'm not sure I understand why we need to check at all, doesn't constraintDatum guarantee the results will be inside the single-key span?

Copy link
Member Author

@jordanlewis jordanlewis 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/virtual_schema.go, line 589 at r1 (raw file):

Previously, RaduBerinde wrote…

This is pretty strange, we use the entire constraint each time except during the fallback. Why don't we want to just check against the current Span rather than the entire constraint? Well.. I'm not sure I understand why we need to check at all, doesn't constraintDatum guarantee the results will be inside the single-key span?

You're right, I don't know why I did it this way. We want to cherry pick this, so I'm not going to change the behavior in this PR in case something more subtle goes wrong, but I'll open up another PR for it.

Previously, the database would panic when a user performed a range scan
against a virtual table that had a virtual index. For example, the
queries:

```
SELECT * FROM pg_catalog.pg_type WHERE oid IN (19, 20)
SELECT * FROM pg_catalog.pg_class WHERE oid BETWEEN 20 AND 50
```

would cause this crash, since both of those tables have virtual indexes
defined on their `oid` columns.

This crash is now corrected.

Release note (bug fix): prevent a crash, introduced in the 20.2 series,
caused by range scans over virtual tables with virtual indexes.
Copy link
Member

@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.

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained

@jordanlewis
Copy link
Member Author

bors r+

@craig
Copy link
Contributor

craig bot commented Nov 10, 2020

Build succeeded:

@craig craig bot merged commit f2b53d1 into cockroachdb:master Nov 10, 2020
@jordanlewis jordanlewis deleted the virtual-idx-range-crash branch November 12, 2020 15:35
@roncrdb
Copy link

roncrdb commented Nov 19, 2020

What release will include this fix?

@jordanlewis
Copy link
Member Author

It looks like I forgot to backport this to release-20.2, unfortunately. It will be in 20.2.2 or 20.2.3.

@roncrdb
Copy link

roncrdb commented Nov 19, 2020

@jordanlewis Thanks for the update.

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: virtual index range scans cause panic
4 participants