Skip to content

opt: don't mark st_makeline and st_extend as non-null#86722

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
DrewKimball:geom
Aug 25, 2022
Merged

opt: don't mark st_makeline and st_extend as non-null#86722
craig[bot] merged 1 commit intocockroachdb:masterfrom
DrewKimball:geom

Conversation

@DrewKimball
Copy link
Copy Markdown
Collaborator

st_makeline can take arguments of type POINT, MULTIPOINT, and
LINESTRING. Other types cause it to return null (even if the input is
non-null). Similarly, st_extent returns null when the input geometry is
non-null, but empty.

This commit prevents these two aggregate functions from being marked as
non-null, since doing so can lead to incorrect results in the cases
mentioned above.

Fixes #84957

Release justification: low-risk fix to bug that can lead to incorrect results

Release note (bug fix): Fixed a longstanding bug that could cause the optimizer
to produce an incorrect plan when aggregate functions st_makeline or
st_extent were called with invalid-type and empty inputs respectively.

`st_makeline` can take arguments of type `POINT`, `MULTIPOINT`, and
`LINESTRING`. Other types cause it to return null (even if the input is
non-null). Similarly, `st_extent` returns null when the input geometry is
non-null, but empty.

This commit prevents these two aggregate functions from being marked as
non-null, since doing so can lead to incorrect results in the cases
mentioned above.

Fixes cockroachdb#84957

Release justification: low-risk fix to bug that can lead to incorrect results

Release note (bug fix): Fixed a longstanding bug that could cause the optimizer
to produce an incorrect plan when aggregate functions `st_makeline` or
`st_extent` were called with invalid-type and empty inputs respectively.
@DrewKimball DrewKimball requested a review from a team as a code owner August 24, 2022 01:18
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Contributor

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


pkg/sql/opt/operator.go line 388 at r1 (raw file):

	case VarianceOp, StdDevOp, CorrOp, CovarSampOp, RegressionInterceptOp,
		RegressionR2Op, RegressionSlopeOp, STExtentOp, STMakeLineOp:
		// These aggregations can return NULL even with non-null input values.

Oh nice, we already have a mechanism for this. Good find!

@DrewKimball
Copy link
Copy Markdown
Collaborator Author

TFTR!

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Aug 24, 2022

Build failed (retrying...):

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Aug 25, 2022

Build succeeded:

@craig craig bot merged commit 2787ff1 into cockroachdb:master Aug 25, 2022
@DrewKimball
Copy link
Copy Markdown
Collaborator Author

blathers backport 22.1

@rytaft
Copy link
Copy Markdown
Collaborator

rytaft commented Sep 28, 2022

let's also do 21.2

blathers backport 21.2

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.

roachtest: tlp failed on complex join condition involving geometry

4 participants