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

planner: fix compatibility bug for window function #11488

Merged
merged 8 commits into from
Jul 31, 2019

Conversation

lzmhhh123
Copy link
Contributor

@lzmhhh123 lzmhhh123 commented Jul 29, 2019

What problem does this PR solve?

Fix #11010, #11001, #11002, #11011.

What is changed and how it works?

The error judging should not be involved in the build function. It caused the wrong frame like the default frame to check. That's a fault.

Check List

Tests

  • Unit test
  • Integration test

Code changes

  • None

Related changes

  • Need to cherry-pick to the release branch
  • Need to change common test

@codecov
Copy link

codecov bot commented Jul 29, 2019

Codecov Report

Merging #11488 into master will decrease coverage by 0.4649%.
The diff coverage is 0%.

@@               Coverage Diff               @@
##             master     #11488       +/-   ##
===============================================
- Coverage   81.8068%   81.3418%   -0.465%     
===============================================
  Files           424        424               
  Lines         92738      90920     -1818     
===============================================
- Hits          75866      73956     -1910     
- Misses        11538      11639      +101     
+ Partials       5334       5325        -9

@codecov
Copy link

codecov bot commented Jul 29, 2019

Codecov Report

Merging #11488 into master will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #11488   +/-   ##
===========================================
  Coverage   81.3703%   81.3703%           
===========================================
  Files           425        425           
  Lines         91526      91526           
===========================================
  Hits          74475      74475           
  Misses        11717      11717           
  Partials       5334       5334

@winoros
Copy link
Member

winoros commented Jul 29, 2019

I think the codes are not special for DENSE_RANK. It seems that it would influence all window functions?

@lzmhhh123
Copy link
Contributor Author

@winoros Yes. It is better to change the description.

@lzmhhh123 lzmhhh123 changed the title planner: fix compatibility bug for DENSE_RANK window function planner: fix compatibility bug for window function Jul 29, 2019
Copy link
Member

@winoros winoros left a comment

Choose a reason for hiding this comment

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

lgtm

if end.Type == ast.Following && !end.UnBounded {
return spec, false, ErrWindowRangeFrameOrderType.GenWithStackByArgs(getWindowName(spec.Name.O))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Your code is for frame validation, is that suitable to be put in handleDefaultFrame?

Copy link
Contributor

Choose a reason for hiding this comment

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

Besides, the ErrWindowRangeFrameOrderType error is needFrame irrelevant, considering this case

SELECT FIRST_VALUE(fieldA) OVER w1 AS 'dense_rank', fieldA, fieldB  FROM ( SELECT `col_time` AS fieldA, `col_time` AS fieldB FROM `table20_int_autoinc` ) as t     WINDOW w1 AS ( PARTITION BY fieldB  ORDER BY fieldB DESC, fieldA DESC  RANGE BETWEEN CURRENT ROW AND 1 FOLLOWING);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, the handleDefaultFrame is a function to remove the invalidated frames. So it's reasonable to put it here.

Copy link
Contributor

Choose a reason for hiding this comment

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

And there are much more frame validations in buildWindowFunctionFrame.

Copy link
Contributor

Choose a reason for hiding this comment

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

The reasonable order for building a window function is

  1. build from ast
  2. validate
  3. handleDefaultFrame

May also fix #11001 #11002, and make #11011 easy to fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now, the frame validations are after groupWindowFuncs. We have to handleDefaultFrame in groupWindowFuncs. It hard to move this validation to buildWindowFunctionFrame...

@lzmhhh123
Copy link
Contributor Author

/rebuild

@lzmhhh123
Copy link
Contributor Author

/run-all-tests

@lzmhhh123 lzmhhh123 added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 29, 2019
@lzmhhh123 lzmhhh123 removed the status/LGT1 Indicates that a PR has LGTM 1. label Jul 30, 2019
@lzmhhh123 lzmhhh123 requested review from winoros and SunRunAway July 30, 2019 06:54
@lzmhhh123
Copy link
Contributor Author

/run-all-tests

Copy link
Contributor

@alivxxx alivxxx left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@SunRunAway SunRunAway left a comment

Choose a reason for hiding this comment

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

LGTM

@SunRunAway SunRunAway added status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. labels Jul 30, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Jul 30, 2019

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented Jul 30, 2019

@lzmhhh123 merge failed.

@lzmhhh123
Copy link
Contributor Author

/run-all-tests

@lzmhhh123
Copy link
Contributor Author

/run-common-test tidb-test=pr/869

1 similar comment
@lzmhhh123
Copy link
Contributor Author

/run-common-test tidb-test=pr/869

@lzmhhh123
Copy link
Contributor Author

/run-common-test tidb-test=pr/869
/run-integration-common-test tidb-test=pr/869

1 similar comment
@lzmhhh123
Copy link
Contributor Author

/run-common-test tidb-test=pr/869
/run-integration-common-test tidb-test=pr/869

@lzmhhh123 lzmhhh123 added status/all tests passed status/can-merge Indicates a PR has been approved by a committer. and removed status/can-merge Indicates a PR has been approved by a committer. labels Jul 31, 2019
@lzmhhh123
Copy link
Contributor Author

/run-all-tests

1 similar comment
@sre-bot
Copy link
Contributor

sre-bot commented Jul 31, 2019

/run-all-tests

@sre-bot sre-bot merged commit 13778fe into pingcap:master Jul 31, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Jul 31, 2019

cherry pick to release-3.0 failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug. type/compatibility
Projects
None yet
5 participants