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

some result is incorrect when plan cache enabled #48165

Closed
lcwangchao opened this issue Nov 1, 2023 · 0 comments · Fixed by #48413
Closed

some result is incorrect when plan cache enabled #48165

lcwangchao opened this issue Nov 1, 2023 · 0 comments · Fixed by #48413
Assignees

Comments

@lcwangchao
Copy link
Collaborator

lcwangchao commented Nov 1, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

> create table t(a int);
> insert into t values(1);
> prepare s from "select * from tx where tidb_parse_tso(a) > unix_timestamp()";
> execute s;

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

The result should be the same with query without prepare execute

TiDB root@127.0.0.1:test> select * from tx where tidb_parse_tso(a) > unix_timestamp();
+---+
| a |
+---+
| 1 |
+---+
1 row in set
Time: 0.006s

TiDB root@127.0.0.1:test> select * from tx where tidb_parse_tso(a) > unix_timestamp();
+---+
| a |
+---+
| 1 |
+---+
1 row in set

3. What did you see instead (Required)

The are different

TiDB root@127.0.0.1:test> select * from tx where tidb_parse_tso(a) > unix_timestamp();
+---+
| a |
+---+
| 1 |
+---+
1 row in set
Time: 0.006s

TiDB root@127.0.0.1:test> execute s;
+---+
| a |
+---+
+---+
0 rows in set
Time: 0.003s

And then if I disable plan cache, the session panics:

TiDB root@127.0.0.1:test> set @@tidb_enable_prepared_plan_cache=0;
Query OK, 0 rows affected
Time: 0.001s
TiDB root@127.0.0.1:test> execute s;
(1105, 'runtime error: invalid memory address or nil pointer dereference')

stack:

[2023/11/01 14:05:42.490 +08:00] [ERROR] [conn.go:965] ["connection running loop panic"] [conn=3391094944] [session_alias=] [lastSQL="execute s"] [err="runtime error: invalid memory address or nil pointer dereference"] [stack="github.com/pingcap/tidb/pkg/server.(*clientConn).Run.func1\n\t/Users/pingcap/workspace/build-common/go/src/github.com/pingcap/tidb/pkg/server/conn.go:968\nruntime.gopanic\n\t/usr/local/go1.21/src/runtime/panic.go:914\ngithub.com/pingcap/tidb/pkg/executor.(*Compiler).Compile.func1\n\t/Users/pingcap/workspace/build-common/go/src/github.com/pingcap/tidb/pkg/executor/compiler.go:55\nruntime.gopanic\n\t/usr/local/go1.21/src/runtime/panic.go:914\nruntime.panicmem\n\t/usr/local/go1.21/src/runtime/panic.go:261\nruntime.sigpanic\n\t/usr/local/go1.21/src/runtime/signal_unix.go:861\ngithub.com/pingcap/tidb/pkg/planner/core.getCachedPlan\n\t/Users/pingcap/workspace/build-common/go/src/github.com/pingcap/tidb/pkg/planner/core/plan_cache.go:264\ngithub.com/pingcap/tidb/pkg/planner/core.GetPlanFromSessionPlanCache\n\t/Users/pingcap/workspace/build-common/go/src/github.com/pingcap/tidb/pkg/planner/core/plan_cache.go:204\ngithub.com/pingcap/tidb/pkg/planner.OptimizeExecStmt\n\t/Users/pingcap/workspace/build-common/go/src/github.com/pingcap/tidb/pkg/planner/optimize.go:552\ngithub.com/pingcap/tidb/pkg/planner.Optimize\n\t/Users/pingcap/workspace/build-common/go/src/github.com/pingcap/tidb/pkg/planner/optimize.go:180\ngithub.com/pingcap/tidb/pkg/executor.(*Compiler).Compile\n\t/Users/pingcap/workspace/build-common/go/src/github.com/pingcap/tidb/pkg/executor/compiler.go:100\ngithub.com/pingcap/tidb/pkg/session.(*session).ExecuteStmt\n\t/Users/pingcap/workspace/build-common/go/src/github.com/pingcap/tidb/pkg/session/session.go:2210\ngithub.com/pingcap/tidb/pkg/server.(*TiDBContext).ExecuteStmt\n\t/Users/pingcap/workspace/build-common/go/src/github.com/pingcap/tidb/pkg/server/driver_tidb.go:292\ngithub.com/pingcap/tidb/pkg/server.(*clientConn).handleStmt\n\t/Users/pingcap/workspace/build-common/go/src/github.com/pingcap/tidb/pkg/server/conn.go:2009\ngithub.com/pingcap/tidb/pkg/server.(*clientConn).handleQuery\n\t/Users/pingcap/workspace/build-common/go/src/github.com/pingcap/tidb/pkg/server/conn.go:1800\ngithub.com/pingcap/tidb/pkg/server.(*clientConn).dispatch\n\t/Users/pingcap/workspace/build-common/go/src/github.com/pingcap/tidb/pkg/server/conn.go:1287\ngithub.com/pingcap/tidb/pkg/server.(*clientConn).Run\n\t/Users/pingcap/workspace/build-common/go/src/github.com/pingcap/tidb/pkg/server/conn.go:1066\ngithub.com/pingcap/tidb/pkg/server.(*Server).onConn\n\t/Users/pingcap/workspace/build-common/go/src/github.com/pingcap/tidb/pkg/server/server.go:701"]

4. What is your TiDB version? (Required)

nighly build, I'm not sure whether it affects released versions

TiDB root@127.0.0.1:test> select tidb_version();
+-----------------------------------------------------------+
| tidb_version()                                            |
+-----------------------------------------------------------+
| Release Version: v7.6.0-alpha                             |
| Edition: Community                                        |
| Git Commit Hash: 30288c77c7e84a9c596a8145dca27748468f9e51 |
| Git Branch: heads/refs/tags/v7.6.0-alpha                  |
| UTC Build Time: 2023-10-27 14:25:48                       |
| GoVersion: go1.21.3                                       |
| Race Enabled: false                                       |
| Check Table Before Drop: false                            |
| Store: tikv                                               |
+-----------------------------------------------------------+
1 row in set
Time: 0.002s
@lcwangchao lcwangchao added type/bug The issue is confirmed as a bug. severity/major labels Nov 1, 2023
@ti-chi-bot ti-chi-bot bot added may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.5 labels Nov 1, 2023
@lcwangchao lcwangchao added sig/planner SIG: Planner and removed may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.5 labels Nov 1, 2023
ti-chi-bot bot pushed a commit that referenced this issue Nov 8, 2023
…omparing datetime column with `unix_timestamp` (#48413)

close #48165
ti-chi-bot bot pushed a commit that referenced this issue Nov 9, 2023
…omparing datetime column with `unix_timestamp` (#48413) (#48455)

close #48165
ti-chi-bot bot pushed a commit that referenced this issue May 14, 2024
…omparing datetime column with unix_timestamp (#48413) (#53266)

close #41918, close #48165
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants