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

expression: fix infinity loop in timestampadd #54916

Merged
merged 6 commits into from
Jul 26, 2024

Conversation

xzhangxian1008
Copy link
Contributor

@xzhangxian1008 xzhangxian1008 commented Jul 25, 2024

What problem does this PR solve?

Issue Number: close #54908

Problem Summary:

What changed and how does it work?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

Fix the issue that `timestampadd` function enters into infinity loop when the first parameter is 'month' and the second parameter is a negative number.

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-triage-completed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 25, 2024
Copy link

tiprow bot commented Jul 25, 2024

Hi @xzhangxian1008. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@xzhangxian1008
Copy link
Contributor Author

/cc @windtalker @XuHuaiyu

@ti-chi-bot ti-chi-bot bot requested review from windtalker and XuHuaiyu July 25, 2024 11:35
Copy link

codecov bot commented Jul 25, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 74.5632%. Comparing base (ee64347) to head (24ae2b7).
Report is 15 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #54916        +/-   ##
================================================
+ Coverage   72.6924%   74.5632%   +1.8707%     
================================================
  Files          1557       1561         +4     
  Lines        438381     443201      +4820     
================================================
+ Hits         318670     330465     +11795     
+ Misses       100054      92977      -7077     
- Partials      19657      19759       +102     
Flag Coverage Δ
integration 48.1087% <0.0000%> (?)
unit 72.1762% <50.0000%> (+0.4912%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.9567% <ø> (-0.0089%) ⬇️
parser ∅ <ø> (∅)
br 46.2550% <ø> (+0.3641%) ⬆️

Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

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

	case "MONTH":
		if !validAddMonth(v, t.Year(), int(t.Month())) {
			return tb, true, nil
		}
		year, month := t.Year(), int(t.Month())
		targetMonth := month + int(v)
		// Adjust the year and month based on the total months calculated
		targetYear := year + (targetMonth-1)/12
		targetMonth = (targetMonth-1)%12 + 1
	
		// Handle cases where month might become negative or zero
		if targetMonth <= 0 {
			targetYear -= 1
			targetMonth += 12
		}
	
		targetDay := t.Day()
		// Try to create the target date
		tb = time.Date(targetYear, time.Month(targetMonth), targetDay, t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), t.Location())
		if tb.Month() != time.Month(targetMonth) {
			// If the day overflows (like trying to get Feb 30), adjust to the last day of the target month
			tb = time.Date(targetYear, time.Month(targetMonth+1), 0, t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), t.Location())
		}

pkg/expression/builtin_time.go Outdated Show resolved Hide resolved
@XuHuaiyu
Copy link
Contributor

release note needed

@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. release-note-none Denotes a PR that doesn't merit a release note. labels Jul 26, 2024
@xzhangxian1008
Copy link
Contributor Author

/cc @windtalker @XuHuaiyu

@ti-chi-bot ti-chi-bot bot requested a review from XuHuaiyu July 26, 2024 04:04
@ti-chi-bot ti-chi-bot bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 26, 2024
{"MONTH", -3, "2023-03-20", "2022-12-20 00:00:00"},
{"MONTH", -3, "2023-03-31", "2022-12-31 00:00:00"},
{"MONTH", -15, "2023-03-20", "2021-12-20 00:00:00"},
{"MONTH", -15, "2023-03-31", "2021-12-31 00:00:00"},
Copy link
Contributor

Choose a reason for hiding this comment

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

Add tests to test from 2020-02-29 to 2021-02-28 and from 2020-02-29 to 2019-02-28

Copy link
Contributor

Choose a reason for hiding this comment

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

And add some invalid input test cases

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And add some invalid input test cases

done

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 26, 2024
Copy link
Contributor

@windtalker windtalker left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot added needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. labels Jul 26, 2024
@xzhangxian1008
Copy link
Contributor Author

/run-check-issue-triage-complete

@ti-chi-bot ti-chi-bot bot merged commit a8d29c2 into pingcap:master Jul 26, 2024
23 checks passed
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jul 26, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-6.5: #54970.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.1: #54971.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #54972.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.1: #54973.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-5.4: #54974.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jul 26, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-6.1: #54975.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jul 26, 2024
morgo added a commit to morgo/tidb that referenced this pull request Jul 28, 2024
* upstream/master: (93 commits)
  disjoinset: add generic impl (pingcap#54917)
  planner: derive index filters for mv index paths (pingcap#54877)
  br: cli refactor backup error handling logic (pingcap#54697)
  expression: fix infinity loop in `timestampadd` (pingcap#54916)
  planner: import more expand test. (pingcap#54962)
  planner: use code-gen to generate CloneForPlanCache method for some operators (pingcap#54957)
  test: fix flaky test TestFailSchemaSyncer (pingcap#54958)
  planner: move logical show into logicalop pkg. (pingcap#54928)
  privilege: Remove TestAbnormalMySQLTable (pingcap#54925)
  resource_control: support unlimited keyword when setting the resource group (pingcap#54704)
  ddl: fix a data race on localRowCntListener Written() (pingcap#54484)
  lightning: fix SET SESSION on connection pool (pingcap#54927)
  planner: move logical mem-table to logicalop pkg. (pingcap#54903)
  table: Add `CachedTableSupport` and `TemporaryTableSupport` for `MutateContext` (pingcap#54900)
  executor: fix index_hash_join hang when context canceled (pingcap#54855)
  statistics: add metrics for unneeded analyze table (pingcap#54822)
  *: refine pipelined dml benchmarks (pingcap#54844)
  ddl: assign table IDs for jobs submitted to queue (pingcap#54880)
  *: avoid using Tables field of model.DBInfo, use API instead (pingcap#52302)
  planner: remove useless check (pingcap#54907)
  ...
ti-chi-bot bot pushed a commit that referenced this pull request Jul 29, 2024
ti-chi-bot bot pushed a commit that referenced this pull request Jul 31, 2024
hawkingrei pushed a commit to hawkingrei/tidb that referenced this pull request Aug 1, 2024
ti-chi-bot bot pushed a commit that referenced this pull request Aug 21, 2024
ti-chi-bot bot pushed a commit that referenced this pull request Aug 21, 2024
@xzhangxian1008 xzhangxian1008 deleted the fix-54908 branch September 23, 2024 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

timestampadd may get stuck when subtracting months
4 participants