Skip to content

builtins: fix incorrect sqrdiff evaluation due to reuse of the results from previous iterations when used as a window function#55957

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
mneverov:windowed_aggregate_fix
Oct 26, 2020
Merged

builtins: fix incorrect sqrdiff evaluation due to reuse of the results from previous iterations when used as a window function#55957
craig[bot] merged 1 commit intocockroachdb:masterfrom
mneverov:windowed_aggregate_fix

Conversation

@mneverov
Copy link
Copy Markdown
Contributor

@mneverov mneverov commented Oct 25, 2020

builtins: fix incorrect sqrdiff evaluation due to reuse of the results from previous iterations when used as a window function

fixes #55944

Release note (bug fix): CockroachDB previously could incorrectly evaluate sqrdiff function when used as a window function in some cases, and now it is fixed.

@blathers-crl
Copy link
Copy Markdown

blathers-crl bot commented Oct 25, 2020

Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR.

My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI.

I was unable to automatically find a reviewer. You can try CCing one of the following members:

  • A person you worked with closely on this PR.
  • The person who created the ticket, or a CRDB organization member involved with the ticket (author, commenter, etc.).
  • Join our community slack channel and ask on #contributors.
  • Try find someone else from here.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@blathers-crl blathers-crl bot added O-community Originated from the community X-blathers-untriaged blathers was unable to find an owner labels Oct 25, 2020
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@mneverov mneverov changed the title builtins: fix aggregate functions for decimals WIP: builtins: fix aggregate functions for decimals Oct 25, 2020
@blathers-crl
Copy link
Copy Markdown

blathers-crl bot commented Oct 25, 2020

Thank you for updating your pull request.

Before a member of our team reviews your PR, I have some potential action items for you:

  • We notice you have more than one commit in your PR. We try break logical changes into separate commits, but commits such as "fix typo" or "address review commits" should be squashed into one commit and pushed with --force
  • When CI has completed, please ensure no errors have appeared.

I was unable to automatically find a reviewer. You can try CCing one of the following members:

  • A person you worked with closely on this PR.
  • The person who created the ticket, or a CRDB organization member involved with the ticket (author, commenter, etc.).
  • Join our community slack channel and ask on #contributors.
  • Try find someone else from here.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@mneverov mneverov force-pushed the windowed_aggregate_fix branch from 8be3cec to afc91f7 Compare October 25, 2020 18:40
@blathers-crl
Copy link
Copy Markdown

blathers-crl bot commented Oct 25, 2020

Thank you for updating your pull request.

My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI.

I was unable to automatically find a reviewer. You can try CCing one of the following members:

  • A person you worked with closely on this PR.
  • The person who created the ticket, or a CRDB organization member involved with the ticket (author, commenter, etc.).
  • Join our community slack channel and ask on #contributors.
  • Try find someone else from here.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@mneverov
Copy link
Copy Markdown
Contributor Author

@yuzefovich could you please take a look?
The root cause was that the result of the sqrdiff function was reused: tree.DDecimal{Decimal: a.sqrDiff} copies the pointer to the underlying slice of the a.sqrDiff.
Order within windowed aggregate functions does not affect order of the output when run on several nodes, i.e. the order of rows when running select sqrdiff(x) OVER (ORDER BY x) from t is unpredictable. As I understand from the other tests in this file this works as intended so I added the column x as well as order by x to the sql statement.

@mneverov mneverov changed the title WIP: builtins: fix aggregate functions for decimals builtins: fix aggregate functions for decimals Oct 25, 2020
@mneverov mneverov marked this pull request as ready for review October 25, 2020 19:59
@yuzefovich yuzefovich requested review from a team and yuzefovich October 26, 2020 15:20
Copy link
Copy Markdown
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

Thanks for finding the bug and fixing it! I only have some nits, but it :lgtm:

Re: ordering: yeah, ORDER BY within OVER() clause doesn't guarantee the ordering of the results, we need to have a query level ORDER BY clause for that.

nit: it'd be nice to include a short description of the bug into the commit message, and we also should add a release note (it'll be something like Release note (bug fix): CockroachDB previously could incorrectly evaluate sqrdiff function when used as a window function in some cases, and now it is fixed.).

Reviewed 3 of 3 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @mneverov)


pkg/sql/logictest/testdata/logic_test/aggregate, line 2862 at r1 (raw file):

0.522232967867094 3

# Regression test for window aggregate functions for decimals reuse the results

nit: this test should go into window logic test file.

nit: I'd slightly reword the comment to be a bit more specific - Regression test for window aggregate functions not making a deep copy of decimals on each iteration (#55944).

@mneverov mneverov force-pushed the windowed_aggregate_fix branch from afc91f7 to f6eefbe Compare October 26, 2020 16:53
@blathers-crl
Copy link
Copy Markdown

blathers-crl bot commented Oct 26, 2020

Thank you for updating your pull request.

My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

Copy link
Copy Markdown
Contributor Author

@mneverov mneverov 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 (and 1 stale) (waiting on @yuzefovich)


pkg/sql/logictest/testdata/logic_test/aggregate, line 2862 at r1 (raw file):

Previously, yuzefovich wrote…

nit: this test should go into window logic test file.

nit: I'd slightly reword the comment to be a bit more specific - Regression test for window aggregate functions not making a deep copy of decimals on each iteration (#55944).

moved to window, replaced the comment, thanks!

@mneverov mneverov changed the title builtins: fix aggregate functions for decimals builtins: fix incorrect sqrdiff evaluation due to reuse of the results from previous iterations when used as a window function Oct 26, 2020
@mneverov
Copy link
Copy Markdown
Contributor Author

@yuzefovich thanks for the review.
Could you please check if the commit message contains enough / proper info?

Copy link
Copy Markdown
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

Thanks, one last nit.

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


pkg/sql/logictest/testdata/logic_test/window, line 3866 at r2 (raw file):

{"1": "1", "2": "2", "3": "3", "4": "4", "5": "5"}

Regression test for window aggregate functions not making a deep copy of decimals on each iteration (#55944)

nit: missing # in the beginning and a period in the end.

…s from previous iterations when used as a window function

fixes cockroachdb#55944

Release note (bug fix): CockroachDB previously could incorrectly evaluate sqrdiff function when used as a window function in some cases, and now it is fixed.
@mneverov mneverov force-pushed the windowed_aggregate_fix branch from f6eefbe to 4bf1804 Compare October 26, 2020 17:06
Copy link
Copy Markdown
Contributor Author

@mneverov mneverov 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 (and 1 stale) (waiting on @yuzefovich)


pkg/sql/logictest/testdata/logic_test/window, line 3866 at r2 (raw file):

Previously, yuzefovich wrote…

nit: missing # in the beginning and a period in the end.

fixed thx

Copy link
Copy Markdown
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

Thanks!

bors r=yuzefovich

Reviewed 1 of 1 files at r3.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale)

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Oct 26, 2020

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-community Originated from the community X-blathers-untriaged blathers was unable to find an owner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql: windowed aggregate functions for decimals return unexpected results

3 participants