Skip to content

*: forbid stale read in local temporary tables#26976

Closed
sylzd wants to merge 20 commits into
pingcap:masterfrom
sylzd:temp_table_25937
Closed

*: forbid stale read in local temporary tables#26976
sylzd wants to merge 20 commits into
pingcap:masterfrom
sylzd:temp_table_25937

Conversation

@sylzd
Copy link
Copy Markdown
Contributor

@sylzd sylzd commented Aug 6, 2021

What problem does this PR solve?

Issue Number: close #25937

Problem Summary:

What is changed and how it works?

Proposal: xxx

What's Changed:

  1. Fix the wrong information of stale read in local temporary tables.
  2. Added a test case for stale read in local temporary tables with TestInvalidReadTemporaryTable patched, which can reduce much replicated code.

How it Works:
snapshot does not exit in local temporary, so GetSnapshotInfoSchema can not work. I added a check afterGetSnapshotInfoSchema, whether normal table exits or not.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • 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

None

@ti-chi-bot
Copy link
Copy Markdown
Member

ti-chi-bot commented Aug 6, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • lcwangchao

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

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

Details

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 6, 2021
@github-actions github-actions Bot added the sig/execution SIG execution label Aug 6, 2021
Copy link
Copy Markdown
Contributor

@tisonkun tisonkun 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 your comment @sylzd !

Could you update the PR description? Also we'd better write a new test case for a PR instead of modifying existing cases unless you describe the reason clearly.

@ti-chi-bot
Copy link
Copy Markdown
Member

@tisonkun: Request changes is only allowed for the reviewers in list.

Details

In response to this:

Thanks for your comment @sylzd !

Could you update the PR description? Also we'd better write a new test case for a PR instead of modifying existing cases unless you describe the reason clearly.

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 ti-community-infra/tichi repository.

@sylzd
Copy link
Copy Markdown
Contributor Author

sylzd commented Aug 9, 2021

Thanks for your comment @sylzd !

Could you update the PR description? Also we'd better write a new test case for a PR instead of modifying existing cases unless you describe the reason clearly.

updated. @tisonkun

Comment thread sessionctx/variable/session.go Outdated
Comment thread planner/core/preprocess.go Outdated
@djshow832 djshow832 requested a review from lcwangchao August 9, 2021 08:37
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 11, 2021
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 11, 2021
Comment thread planner/core/preprocess.go
@ti-chi-bot ti-chi-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 12, 2021
@github-actions github-actions Bot added the sig/sql-infra SIG: SQL Infra label Aug 12, 2021
Comment thread sessionctx/variable/session.go Outdated
Comment thread planner/core/preprocess.go Outdated
@sylzd
Copy link
Copy Markdown
Contributor Author

sylzd commented Aug 13, 2021

/run-all-tests

@sylzd
Copy link
Copy Markdown
Contributor Author

sylzd commented Aug 13, 2021

/run-check_dev_2

Comment thread planner/core/preprocess.go
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Aug 13, 2021
@sylzd
Copy link
Copy Markdown
Contributor Author

sylzd commented Aug 13, 2021

/run-check_dev_2

Comment thread executor/executor_test.go Outdated
Comment thread executor/executor_test.go
tk.MustExec("drop table tmp6")
tk.MustExec("create table tmp6 (id int primary key);")
tk.MustQuery("select * from tmp6 as of timestamp(@a) where id=1;").Check(testkit.Rows("1"))
tk.MustQuery("select * from tmp4 as of timestamp(@a), tmp3 as of timestamp(@a) where tmp3.id=1;")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Check result?

Comment thread planner/core/preprocess.go Outdated
if p.err != nil {
return
}
p.InfoSchema = is.(infoschema.InfoSchema)
Copy link
Copy Markdown
Contributor

@tiancaiamao tiancaiamao Aug 13, 2021

Choose a reason for hiding this comment

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

What will happen if is is not a infoschema.InfoSchema
p.InfoSchema is nil and no error set, then maybe the code panic in some other place?

Comment thread session/session.go
}()

if execOption.SnapshotTS != 0 {
se.sessionVars.SnapshotInfoschema, err = getSnapshotInfoSchema(s, execOption.SnapshotTS)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why ExecRestrictedStmt need to consider the temporary table? it's usually used to execute some internal SQL statement, but no internal SQL will use the temporary table!
Can you ever construct a case that the infoschema obtained here visit the local temporary table?

if p.LastSnapshotTS != 0 {
dom := domain.GetDomain(p.ctx)
p.InfoSchema, p.err = dom.GetSnapshotInfoSchema(p.LastSnapshotTS)
is, err := p.ctx.GetSnapshotInfoSchema(p.LastSnapshotTS)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this the only place that needs to get the snapshot infoschema with the temporary table? If so, I prefer manually use

&infoschema.TemporaryTableAttachedInfoSchema{
		InfoSchema:           is,
        LocalTemporaryTables: local.(*infoschema.LocalTemporaryTables)
}

instead of expose a new method to the sessionctx.Context.

The bigger the interface, the weaker the abstraction – Rob Pike

@sylzd
Copy link
Copy Markdown
Contributor Author

sylzd commented Aug 16, 2021

/run-check_dev2

@tiancaiamao tiancaiamao changed the title *: Forbid stale read in local temporary tables *: forbid stale read in local temporary tables Aug 16, 2021
@sylzd sylzd force-pushed the temp_table_25937 branch from 1907d00 to 6ec93be Compare August 16, 2021 04:08
@sylzd sylzd closed this Aug 17, 2021
@sylzd sylzd deleted the temp_table_25937 branch August 17, 2021 11:45
@sylzd sylzd restored the temp_table_25937 branch August 17, 2021 11:45
@sylzd
Copy link
Copy Markdown
Contributor Author

sylzd commented Aug 17, 2021

duplicated with #27270

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

Labels

release-note-none Denotes a PR that doesn't merit a release note. sig/execution SIG execution sig/sql-infra SIG: SQL Infra size/M Denotes a PR that changes 30-99 lines, ignoring generated files. status/LGT1 Indicates that a PR has LGTM 1.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Forbid stale read in local temporary tables

6 participants