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

opt: fix panic in GenerateInvertedIndexScans #60598

Merged
merged 1 commit into from
Feb 17, 2021

Conversation

mgartner
Copy link
Collaborator

This commit fixes a nil-pointer exception caused when empty index spans
were generated from a filter on an inverted column.

Fixes #59702

Release note (bug fix): A bug has been fixed that caused errors for some
queries on tables with GEOMETRY or GEOGRAPHY inverted indexes with
filters containing shapes with zero area.

@mgartner mgartner requested a review from rytaft February 15, 2021 23:51
@mgartner mgartner requested a review from a team as a code owner February 15, 2021 23:51
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

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


pkg/sql/opt/invertedidx/geo.go, line 528 at r1 (raw file):

	// spanExpr is the result of evaluating the geospatial relationship
	// represented by this geoInvertedExpr. It is nil prior to evaluation.
	spanExpr inverted.Expression

[nit] maybe change the name of this variable to invertedExpr now


pkg/sql/opt/invertedidx/geo.go, line 807 at r1 (raw file):

			if d, ok := nonIndexParam.(tree.Datum); ok {
				spanExpr = g.getSpanExpr(evalCtx.Ctx(), d, additionalParams, relationship, g.indexConfig)

[nit] extra blank line

Copy link
Collaborator Author

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

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


pkg/sql/opt/invertedidx/geo.go, line 528 at r1 (raw file):

Previously, rytaft (Rebecca Taft) wrote…

[nit] maybe change the name of this variable to invertedExpr now

Done.


pkg/sql/opt/invertedidx/geo.go, line 807 at r1 (raw file):

Previously, rytaft (Rebecca Taft) wrote…

[nit] extra blank line

Done.

Copy link
Collaborator

@rytaft rytaft left a comment

Choose a reason for hiding this comment

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

Like I mentioned in the other PR, if you can find an inverted join test case similar to the inverted filter case, that would be good to add (guessing it's just a matter of putting the constant argument you passed to st_intersects into a table and joining with it). Since the panic won't show up until execution time, it will probably need to be a logictest.

Reviewed 2 of 2 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @mgartner and @RaduBerinde)


pkg/sql/opt/invertedidx/geo.go, line 526 at r2 (raw file):

	additionalParams []tree.Datum

	// spanExpr is the result of evaluating the geospatial relationship

spanExpr -> invertedExpr

@mgartner mgartner force-pushed the 59702-fix-nil-span-expr branch 2 times, most recently from 78725a2 to 92e124a Compare February 16, 2021 02:19
Copy link
Collaborator Author

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

I found a reproduction for inverted joins that panics during optimization. 😄

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


pkg/sql/opt/invertedidx/geo.go, line 526 at r2 (raw file):

Previously, rytaft (Rebecca Taft) wrote…

spanExpr -> invertedExpr

Done.

@mgartner mgartner changed the title opt: fix panic in GenerateInvertedIndexScans opt: fix panic in GenerateInvertedIndexScans and GenerateInvertedJoins Feb 16, 2021
Copy link
Collaborator Author

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

I found a reproduction for inverted joins that panics during optimization. 😄

Nevermind... I was wrong.

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

Copy link
Collaborator

@rytaft rytaft left a comment

Choose a reason for hiding this comment

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

Lol oh well. Does the new test case you added panic during execution (before the change you made)?

Reviewed 2 of 2 files at r3.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @mgartner and @RaduBerinde)


pkg/sql/opt/xform/testdata/rules/join, line 5530 at r3 (raw file):

SELECT * FROM small
JOIN t59702
ON st_intersects(t59702.g, st_buffer(st_makepoint(1, 1)::GEOGRAPHY, 0)) AND small.m = t59702.k

Is this testing anything? It's just creating a lookup join, not an inverted join or inverted filter

@mgartner mgartner changed the title opt: fix panic in GenerateInvertedIndexScans and GenerateInvertedJoins opt: fix panic in GenerateInvertedIndexScans Feb 16, 2021
Copy link
Collaborator Author

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

Lol oh well. Does the new test case you added panic during execution (before the change you made)?

Yes, but only because the GenerateInvertedScans rule panicked, not the GenerateInvertedJoins rule. I've remove it.

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


pkg/sql/opt/xform/testdata/rules/join, line 5530 at r3 (raw file):

Previously, rytaft (Rebecca Taft) wrote…

Is this testing anything? It's just creating a lookup join, not an inverted join or inverted filter

I've removed it.

Copy link
Collaborator

@rytaft rytaft 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 3 of 3 files at r4.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @RaduBerinde)

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! 2 of 0 LGTMs obtained

This commit fixes a nil-pointer exception caused when empty index spans
were generated from a filter on an inverted column.

Fixes cockroachdb#59702

Release note (bug fix): A bug has been fixed that caused errors for some
queries on tables with GEOMETRY or GEOGRAPHY inverted indexes with
filters containing shapes with zero area.
@mgartner
Copy link
Collaborator Author

TFTRs!

bors r+

@craig
Copy link
Contributor

craig bot commented Feb 17, 2021

Build succeeded:

@craig craig bot merged commit db32968 into cockroachdb:master Feb 17, 2021
@mgartner mgartner deleted the 59702-fix-nil-span-expr branch February 17, 2021 00:44
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.

opt: v20.2.4: panic in GenerateInvertedIndexScans
4 participants