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

Got error when stale read with scalar subquery #31954

Closed
lcwangchao opened this issue Jan 25, 2022 · 1 comment · Fixed by #33812
Closed

Got error when stale read with scalar subquery #31954

lcwangchao opened this issue Jan 25, 2022 · 1 comment · Fixed by #33812
Labels
affects-5.4 This bug affects 5.4.x versions. affects-6.0 severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@lcwangchao
Copy link
Collaborator

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create table t1(id int primary key, v int);
select * from t1 as of timestamp now() where id=(select id from t1 as of timestamp now() where id=1); --error
select (select * from t1 as of timestamp now() where id =1); --error

2. What did you expect to see? (Required)

no error

3. What did you see instead (Required)

(8024, 'invalid transaction')

4. What is your TiDB version? (Required)

master

mysql> select tidb_version();
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: None
Edition: Community
Git Commit Hash: None
Git Branch: None
UTC Build Time: None
GoVersion: go1.16.3
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

But I think it happens in all versions

@lcwangchao lcwangchao added type/bug The issue is confirmed as a bug. sig/execution SIG execution severity/major labels Jan 25, 2022
@lcwangchao
Copy link
Collaborator Author

lcwangchao commented Jan 25, 2022

error stack:

github.com/pingcap/errors.AddStack
	/Users/wangchao/go/pkg/mod/github.com/pingcap/errors@v0.11.5-0.20211224045212-9687c2b0f87c/errors.go:174
github.com/pingcap/tidb/session.(*session).Txn
	/Users/wangchao/Code/pingcap/tidb/session/session.go:2224
github.com/pingcap/tidb/executor.(*executorBuilder).getSnapshotTS
	/Users/wangchao/Code/pingcap/tidb/executor/builder.go:1504
github.com/pingcap/tidb/executor.(*executorBuilder).buildPointGet
	/Users/wangchao/Code/pingcap/tidb/executor/point_get.go:51
github.com/pingcap/tidb/executor.(*executorBuilder).build
	/Users/wangchao/Code/pingcap/tidb/executor/builder.go:180
github.com/pingcap/tidb/executor.(*executorBuilder).buildMaxOneRow
	/Users/wangchao/Code/pingcap/tidb/executor/builder.go:1894
github.com/pingcap/tidb/executor.(*executorBuilder).build
	/Users/wangchao/Code/pingcap/tidb/executor/builder.go:256
github.com/pingcap/tidb/executor.init.1.func1
	/Users/wangchao/Code/pingcap/tidb/executor/executor.go:1212
github.com/pingcap/tidb/planner/core.(*expressionRewriter).handleScalarSubquery
	/Users/wangchao/Code/pingcap/tidb/planner/core/expression_rewriter.go:1011
github.com/pingcap/tidb/planner/core.(*expressionRewriter).Enter
	/Users/wangchao/Code/pingcap/tidb/planner/core/expression_rewriter.go:401
github.com/pingcap/tidb/parser/ast.(*SubqueryExpr).Accept
	/Users/wangchao/Code/pingcap/tidb/parser/ast/expressions.go:391
github.com/pingcap/tidb/parser/ast.(*BinaryOperationExpr).Accept
	/Users/wangchao/Code/pingcap/tidb/parser/ast/expressions.go:217
github.com/pingcap/tidb/planner/core.(*PlanBuilder).rewriteExprNode
	/Users/wangchao/Code/pingcap/tidb/planner/core/expression_rewriter.go:200
github.com/pingcap/tidb/planner/core.(*PlanBuilder).rewriteWithPreprocess
	/Users/wangchao/Code/pingcap/tidb/planner/core/expression_rewriter.go:146
github.com/pingcap/tidb/planner/core.(*PlanBuilder).rewrite
	/Users/wangchao/Code/pingcap/tidb/planner/core/expression_rewriter.go:114
github.com/pingcap/tidb/planner/core.(*PlanBuilder).buildSelection
	/Users/wangchao/Code/pingcap/tidb/planner/core/logical_plan_builder.go:985
github.com/pingcap/tidb/planner/core.(*PlanBuilder).buildSelect
	/Users/wangchao/Code/pingcap/tidb/planner/core/logical_plan_builder.go:3627
github.com/pingcap/tidb/planner/core.(*PlanBuilder).Build
	/Users/wangchao/Code/pingcap/tidb/planner/core/planbuilder.go:716
github.com/pingcap/tidb/planner.optimize
	/Users/wangchao/Code/pingcap/tidb/planner/optimize.go:332
github.com/pingcap/tidb/planner.Optimize
	/Users/wangchao/Code/pingcap/tidb/planner/optimize.go:211
github.com/pingcap/tidb/executor.(*Compiler).Compile
	/Users/wangchao/Code/pingcap/tidb/executor/compiler.go:77
github.com/pingcap/tidb/session.(*session).ExecuteStmt
	/Users/wangchao/Code/pingcap/tidb/session/session.go:1735
github.com/pingcap/tidb/server.(*TiDBContext).ExecuteStmt
	/Users/wangchao/Code/pingcap/tidb/server/driver_tidb.go:220
github.com/pingcap/tidb/server.(*clientConn).handleStmt
	/Users/wangchao/Code/pingcap/tidb/server/conn.go:1977
github.com/pingcap/tidb/server.(*clientConn).handleQuery
	/Users/wangchao/Code/pingcap/tidb/server/conn.go:1846
github.com/pingcap/tidb/server.(*clientConn).dispatch
	/Users/wangchao/Code/pingcap/tidb/server/conn.go:1341
github.com/pingcap/tidb/server.(*clientConn).Run
	/Users/wangchao/Code/pingcap/tidb/server/conn.go:1091
github.com/pingcap/tidb/server.(*Server).onConn
	/Users/wangchao/Code/pingcap/tidb/server/server.go:554
runtime.goexit
	/usr/local/go/src/runtime/asm_arm64.s:1130"]

@jebter jebter added the affects-5.4 This bug affects 5.4.x versions. label Jan 25, 2022
ti-chi-bot pushed a commit that referenced this issue Apr 25, 2022
espresso98 pushed a commit to espresso98/tidb that referenced this issue Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.4 This bug affects 5.4.x versions. affects-6.0 severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants