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 potential panic when generating hints in statement summary #46312

Merged
merged 3 commits into from
Aug 24, 2023

Conversation

jackysp
Copy link
Member

@jackysp jackysp commented Aug 22, 2023

What problem does this PR solve?

Issue Number: close #46311

Problem Summary:
Use empty slices to init PlannerSelectBlockAsName to avoid panic when dereferencing.

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  1. create a cluster
  2. run script like
func main() {
	cfg := &config{}
	cfg.parse()
	connStr := cfg.db + "?maxAllowedPacket=512000000&charset=utf8mb4&parseTime=True&loc=Local&allowAllFiles=true"
	var wg sync.WaitGroup
	for i := 0; i < 100; i++ {
		wg.Add(1)
		go func() {
			db, err := sql.Open("mysql", connStr)
			if err != nil {
				log.Fatal(err)
			}
			defer db.Close()

			stmt, err := db.Prepare("select t.i, t.j from t, t1 where t.k = 0")
			if err != nil {
				log.Fatal(err)
			}

			stmt1, err := db.Prepare("select t.i, t.j from t, t1 where t.i = 0")
			if err != nil {
				log.Fatal(err)
			}

			for {
				rs, err := stmt.Query()
				if err != nil {
					log.Println(err)
					break
				}
				for rs.Next() {
					var i int
					var j int
					err = rs.Scan(&i, &j)
					if err != nil {
						log.Println(err)
						break
					}
					log.Println(i, j)
				}
				rs.Close()

				rs1, err := stmt1.Query()
				if err != nil {
					log.Println(err)
					break
				}
				for rs1.Next() {
					var i int
					var j int
					err = rs1.Scan(&i, &j)
					if err != nil {
						log.Println(err)
						break
					}
					log.Println(i, j)
				}
				rs1.Close()
			}
			wg.Done()
		}()
	}
	wg.Wait()
}
  1. check the panic log in tidb-server (I cannot reproduce the panic mentioned in the issue before PR.)
  • No code

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.

None

@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/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Aug 22, 2023
@jackysp
Copy link
Member Author

jackysp commented Aug 22, 2023

/run-all-tests

@jackysp jackysp requested a review from hawkingrei August 22, 2023 09:12
@codecov
Copy link

codecov bot commented Aug 22, 2023

Codecov Report

Merging #46312 (d31289b) into master (dd593b2) will decrease coverage by 0.2634%.
Report is 26 commits behind head on master.
The diff coverage is 100.0000%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #46312        +/-   ##
================================================
- Coverage   73.3535%   73.0902%   -0.2634%     
================================================
  Files          1284       1314        +30     
  Lines        393272     405247     +11975     
================================================
+ Hits         288479     296196      +7717     
- Misses        86425      90505      +4080     
- Partials      18368      18546       +178     
Flag Coverage Δ
integration 26.0501% <100.0000%> (?)
unit 73.7880% <100.0000%> (+0.4345%) ⬆️

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

Components Coverage Δ
dumpling 54.0444% <ø> (ø)
parser 85.0850% <ø> (+0.0182%) ⬆️
br 48.0667% <ø> (-4.1817%) ⬇️

@jackysp
Copy link
Member Author

jackysp commented Aug 22, 2023

/retest

@hawkingrei
Copy link
Member

/retest

Signed-off-by: Jack Yu <[email protected]>
Signed-off-by: Jack Yu <[email protected]>
@jackysp
Copy link
Member Author

jackysp commented Aug 23, 2023

/check-issue-triage-complete

1 similar comment
@jackysp
Copy link
Member Author

jackysp commented Aug 23, 2023

/check-issue-triage-complete

@jackysp
Copy link
Member Author

jackysp commented Aug 23, 2023

/run-check-issue-triage-complete

@ti-chi-bot ti-chi-bot bot added the needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. label Aug 23, 2023
@jackysp jackysp requested review from hawkingrei and bb7133 August 23, 2023 06:41
@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 24, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Aug 24, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Defined2014, hawkingrei

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [Defined2014,hawkingrei]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 24, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Aug 24, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-08-24 00:42:42.183131577 +0000 UTC m=+1369326.732147549: ☑️ agreed by hawkingrei.
  • 2023-08-24 02:00:55.592762268 +0000 UTC m=+1374020.141778255: ☑️ agreed by Defined2014.

@jackysp
Copy link
Member Author

jackysp commented Aug 24, 2023

/retest

@jackysp jackysp merged commit 0564dcf into pingcap:master Aug 24, 2023
@ti-chi-bot
Copy link
Member

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

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-7.1 Should cherry pick this PR to release-7.1 branch. release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SQL panic in statement summary when generating hints
4 participants