pingcap / pingcap/tidb

MAX_EXECUTION_TIME does not always return 3024

Open
#68,097 3 comments 0 reactions 0 assignees View on GitHub
contribution first-time-contributor severity/moderate sig/execution type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

```
CREATE TABLE categories (
category_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL UNIQUE,
description VARCHAR(255)
);

CREATE TABLE books (
book_id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
author VARCHAR(255) NOT NULL,
isbn VARCHAR(20) UNIQUE,
category_id INT,
price DECIMAL(8,2) NOT NULL,
stock_quantity INT DEFAULT 0,
published_year YEAR,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (category_id) REFERENCES categories(category_id)
);

-- =========================================
-- Categories
-- =========================================
INSERT INTO categories (name, description) VALUES
('Fiction', 'Novels and literary fiction'),
('Non-Fiction', 'Essays, history, science, biography'),
('Fantasy', 'Magic, mythical worlds, epic quests'),
('Sci-Fi', 'Speculative and science-based fiction'),
('Mystery', 'Detective stories and thrillers'),
('Romance', 'Love stories and relationships'),
('Biography', 'Lives of real people'),
('Self-Help', 'Personal development and wellbeing');

-- =========================================
-- 50 Books
-- =========================================
INSERT INTO books (title, author, isbn, category_id, price, stock_quantity, published_year) VALUES
('The Great Gatsby', 'F. Scott Fitzgerald', '9780743273565', 1, 12.99, 15, 1925),
('Sapiens: A Brief History of Humankind', 'Yuval Noah Harari', '9780062316097', 2, 18.50, 8, 2011),
('To Kill a Mockingbird', 'Harper Lee', '9780061120084', 1, 14.99, 22, 1960),
('1984', 'George Orwell', '9780451524935', 1, 10.99, 30, 1949),
('Pride and Prejudice', 'Jane Austen', '9780141439518', 6, 9.99, 18, 2023),
('The Hobbit', 'J.R.R. Tolkien', '9780547928227', 3, 13.50, 25, 1937),
('The Lord of the Rings', 'J.R.R. Tolkien', '9780544003415', 3, 29.99, 12, 1954),
('Dune', 'Frank Herbert', '9780441172719', 4, 16.99, 14, 1965),
('Foundation', 'Isaac Asimov', '9780553293357', 4, 11.99, 10, 1951),
('The Hitchhiker''s Guide to the Galaxy', 'Douglas Adams', '9780345391803', 4, 12.50, 20, 1979),
('Brave New World', 'Aldous Huxley', '9780060850524', 4, 13.25, 17, 1932),
('Fahrenheit 451', 'Ray Bradbury', '9781451673319', 4, 10.50, 16, 1953),
('The Catcher in the Rye', 'J.D. Salinger', '9780316769488', 1, 11.75, 13, 1951),
('The Da Vinci Code', 'Dan Brown', '9780307474278', 5, 14.50, 21, 2003),
('Angels & Demons', 'Dan Brown', '9781416524793', 5, 13.99, 19, 2000),
('Gone Girl', 'Gillian Flynn', '9780307588371', 5, 15.25, 11, 2012),
('The Girl with the Dragon Tattoo', 'Stieg Larsson', '9780307454546', 5, 14.99, 9, 2005),
('Sherlock Holmes: The Complete Novels', 'Arthur Conan Doyle', '9780553212419', 5, 19.99, 7, 1992),
('Murder on the Orient Express', 'Agatha Christie', '9780062693662', 5, 12.99, 18, 1934),
('And Then There Were None', 'Agatha Christie', '9780062073488', 5, 12.50, 15, 1939),
('A Game of Thrones', 'George R.R. Martin', '9780553593716', 3, 16.50, 24, 1996),
('A Clash of Kings', 'George R.R. Martin', '9780553579901', 3, 16.50, 20, 1998),
('The Name of the Wind', 'Patrick Rothfuss', '9780756404741', 3, 15.99, 14, 2007),
('Mistborn: The Final Empire', 'Brandon Sanderson', '9780765350381', 3, 14.99, 16, 2006),
('The Way of Kings', 'Brandon Sanderson', '9780765365279', 3, 19.99, 12, 2010),
('American Gods', 'Neil Gaiman', '9780062572233', 3, 15.50, 13, 2001),
('Good Omens', 'Neil Gaiman & Terry Pratchett', '9780060853983', 3, 14.50, 11, 1990),
('Educated', 'Tara Westover', '9780399590504', 7, 17.99, 19, 2018),
('Becoming', 'Michelle Obama', '9781524763138', 7, 19.50, 22, 2018),
('Steve Jobs', 'Walter Isaacson', '9781451648539', 7, 18.75, 10, 2011),
('The Diary of a Young Girl', 'Anne Frank', '9780553296983', 7, 9.99, 25, 1947),
('Long Walk to Freedom', 'Nelson Mandela', '9780316548182', 7, 17.25, 8, 1994),
('Atomic Habits', 'James Clear', '9780735211292', 8, 16.99, 35, 2018),
('The 7 Habits of Highly Effective People','Stephen R. Covey', '9781451639612', 8, 15.99, 28, 1989),
('How to Win Friends and Influence People','Dale Carnegie', '9780671027032', 8, 13.99, 32, 1936),
('Think and Grow Rich', 'Napoleon Hill', '9781585424337', 8, 12.99, 18, 1937),
('The Subtle Art of Not Giving a F*ck', 'Mark Manson', '9780062457714', 8, 15.50, 24, 2016),
('Man''s Search for Meaning', 'Viktor E. Frankl', '9780807014295', 8, 11.99, 20, 1946),
('A Brief History of Time', 'Stephen Hawking', '9780553380163', 2, 14.99, 14, 1988),
('Cosmos', 'Carl Sagan', '9780345539434', 2, 16.50, 10, 1980),
('The Selfish Gene', 'Richard Dawkins', '9780198788607', 2, 15.99, 9, 1976),
('Guns, Germs, and Steel', 'Jared Diamond', '9780393354324', 2, 17.50, 12, 1997),
('Thinking, Fast and Slow', 'Daniel Kahneman', '9780374533557', 2, 16.99, 17, 2011),
('Outliers', 'Malcolm Gladwell', '9780316017930', 2, 14.50, 19, 2008),
('Pride and Prejudice and Zombies', 'Seth Grahame-Smith', '9781594743344', 1, 12.99, 6, 2009),
('The Notebook', 'Nicholas Sparks', '9781455582877', 6, 11.99, 14, 1996),
('Me Before You', 'Jojo Moyes', '9780143124542', 6, 13.50, 16, 2012),
('Outlander', 'Diana Gabaldon', '9780440242505', 6, 15.99, 11, 1991),
('The Time Traveler''s Wife', 'Audrey Niffenegger', '9780156029438', 6, 14.25, 9, 2003),
('It Ends with Us', 'Colleen Hoover', '9781501110368', 6, 14.99, 26, 2016);
```

Then repeat several times (forced slow query not used in prod)

```
SET SESSION max_execution_time = 1;
SET SESSION tidb_distsql_scan_concurrency = 1; -- Force serial processing to make it "wait" longer

BEGIN;

-- We use a massive cross join but filter on a non-indexed calculation.
-- This forces TiDB to keep several "Coprocessor" requests open to TiKV.
SELECT /*+ MAX_EXECUTION_TIME(1) IGNORE_INDEX(b, c) */ COUNT(*)
FROM books b, categories c, books b2
WHERE SHA2(b.title, 512) = SHA2(c.name, 512)
AND b2.book_id > 0;

ROLLBACK;
```

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

`[2026-04-28 10:17:41] [HY000][3024] Query execution was interrupted, maximum statement execution time exceeded`

### 3. What did you see instead (Required)
Both
`[2026-04-28 10:17:40] [HY000][1105] context canceled` and
`[2026-04-28 10:17:41] [HY000][3024] Query execution was interrupted, maximum statement execution time exceeded`
```
[2026/04/28 10:07:00.692 +00:00] [WARN] [expensivequery.go:97] ["execution timeout, kill it"] [costTime=1.422042ms] [maxExecutionTime=1ms] [processInfo="{id:2098014, user:abc, host:localhost:33178, db:STORE, command:Query, time:0, state:in transaction; autocommit, info:/* ApplicationName=IntelliJ IDEA 2026.1.1 */ SELECT /*+ MAX_EXECUTION_TIME(1) IGNORE_INDEX(b, c) */ }"]
2026-04-28T10:07:00.693127840Z [2026/04/28 10:07:00.692 +00:00] [INFO] [server.go:913] [kill] [conn=2098014] [query=true] [maxExecutionTime=true] [runawayExceed=false]
2026-04-28T10:07:00.693239882Z [2026/04/28 10:07:00.693 +00:00] [WARN] [sqlkiller.go:61] ["kill initiated"] ["connection ID"=2098014] [reason="[executor:3024]Query execution was interrupted, maximum statement execution time exceeded"]
2026-04-28T10:07:00.693255715Z [2026/04/28 10:07:00.693 +00:00] [WARN] [coprocessor.go:1249] ["copIteratorWork meet panic"] [r="[executor:3024]Query execution was interrupted, maximum statement execution time exceeded"] ["stack trace"="github.com/pingcap/tidb/pkg/store/copr.(*copIteratorWorker).handleTask.func1\n\t/workspace/source/tidb/pkg/store/copr/coprocessor.go:1251\nruntime.gopanic\n\t/usr/local/go/src/runtime/panic.go:783\ngithub.com/pingcap/tidb/pkg/util/memory.(*Tracker).Consume\n\t/workspace/source/tidb/pkg/util/memory/tracker.go:507\ngithub.com/pingcap/tidb/pkg/store/copr.(*copIteratorWorker).checkRespOOM\n\t/workspace/source/tidb/pkg/store/copr/coprocessor.go:1060\ngithub.com/pingcap/tidb/pkg/store/copr.(*copIteratorWorker).handleCopResponse\n\t/workspace/source/tidb/pkg/store/copr/coprocessor.go:1592\ngithub.com/pingcap/tidb/pkg/store/copr.(*copIteratorWorker).handleCopPagingResult\n\t/workspace/source/tidb/pkg/store/copr/coprocessor.go:1485\ngithub.com/pingcap/tidb/pkg/store/copr.(*copIteratorWorker).handleTaskOnce\n\t/workspace/source/tidb/pkg/store/copr/coprocessor.go:1412\ngithub.com/pingcap/tidb/pkg/store/copr.(*copIteratorWorker).handleTask\n\t/workspace/source/tidb/pkg/store/copr/coprocessor.go:1262\ngithub.com/pingcap/tidb/pkg/store/copr.(*copIteratorWorker).run\n\t/workspace/source/tidb/pkg/store/copr/coprocessor.go:850"]
2026-04-28T10:07:00.693263548Z [2026/04/28 10:07:00.693 +00:00] [INFO] [coprocessor.go:2072] ["a killed signal is received in copIteratorWorker"] [signal=2]
2026-04-28T10:07:00.693264798Z [2026/04/28 10:07:00.693 +00:00] [WARN] [sqlkiller.go:137] ["kill finished"] [conn=2098014]
2026-04-28T10:07:00.693600090Z [2026/04/28 10:07:00.693 +00:00] [INFO] [conn.go:1189] ["command dispatched failed"] [conn=2098014] [session_alias=] [connInfo="id:2098014, addr:localhost:33178 status:11, collation:utf8mb4_0900_ai_ci, user:root"] [command=Query] [status="inTxn:1, autocommit:1"] [sql="/* ApplicationName=IntelliJ IDEA 2026.1.1 */ SELECT /*+ MAX_EXECUTION_TIME(1) IGNORE_INDEX(b, c) */ COUNT(*) FROM books b, categories c, books b2 WHERE SHA2(b.title, 512) = SHA2(c.name, 512) AND b2.book_id > 0"] [txn_mode=PESSIMISTIC] [timestamp=465927096415289344] [err="context canceled\ngithub.com/pingcap/errors.Trace\n\t/root/go/pkg/mod/github.com/pingcap/errors@v0.11.5-0.20250523034308-74f78ae071ee/juju_adaptor.go:15\ngithub.com/pingcap/tidb/pkg/store/copr.(*copIterator).Next\n\t/workspace/source/tidb/pkg/store/copr/coprocessor.go:1113\ngithub.com/pingcap/tidb/pkg/distsql.(*selectResult).fetchRespWithIntermediateResults\n\t/workspace/source/tidb/pkg/distsql/select_result.go:392\ngithub.com/pingcap/tidb/pkg/distsql.(*selectResult).fetchResp\n\t/workspace/source/tidb/pkg/distsql/select_result.go:356\ngithub.com/pingcap/tidb/pkg/distsql.(*selectResult).Next\n\t/workspace/source/tidb/pkg/distsql/select_result.go:482\ngithub.com/pingcap/tidb/pkg/executor.(*tableResultHandler).nextChunk\n\t/workspace/source/tidb/pkg/executor/table_reader.go:612\ngithub.com/pingcap/tidb/pkg/executor.(*TableReaderExecutor).Next\n\t/workspace/source/tidb/pkg/executor/table_reader.go:331\ngithub.com/pingcap/tidb/pkg/executor/internal/exec.Next\n\t/workspace/source/tidb/pkg/executor/internal/exec/executor.go:456\ngithub.com/pingcap/tidb/pkg/executor.(*ProjectionExec).unParallelExecute\n\t/workspace/source/tidb/pkg/executor/projection.go:218\ngithub.com/pingcap/tidb/pkg/executor.(*ProjectionExec).Next\n\t/workspace/source/tidb/pkg/executor/projection.go:205\ngithub.com/pingcap/tidb/pkg/executor/internal/exec.Next\n\t/workspace/source/tidb/pkg/executor/internal/exec/executor.go:456\ngithub.com/pingcap/tidb/pkg/executor/join.(*probeSideTupleFetcherBase).fetchProbeSideChunks\n\t/workspace/source/tidb/pkg/executor/join/hash_join_base.go:172\ngithub.com/pingcap/tidb/pkg/executor/join.(*HashJoinV1Exec).fetchAndProbeHashTable.func1\n\t/workspace/source/tidb/pkg/executor/join/hash_join_v1.go:230\ngithub.com/pingcap/tidb/pkg/util.(*WaitGroupWrapper).RunWithRecover.func1\n\t/workspace/source/tidb/pkg/util/wait_group_wrapper.go:189\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1693"]
```
In production I had normal SELECT and the result was same (context canceled + 1105)
```
[2026/04/27 11:28:25.309 +00:00] [Warn] [sqlkiller.go:61] ["kill initiated"] ["connection ID"=2468122246] [reason="[executor:3024]Query execution was interrupted, maximum statement execution time exceeded"]
[2026/04/27 11:28:25.309 +00:00] [Warn] [index_lookup_join.go:512] ["innerWorker panicked"] [conn=2468122246] [session_alias=] [recover="[executor:3024]Query execution was interrupted, maximum statement execution time exceeded"] [stack="github.com/pingcap/tidb/pkg/executor/join.(*innerWorker).run.func1\n\t/workspace/source/tidb/pkg/executor/join/index_lookup_join.go:512\nruntime.gopanic\n\t/usr/local/go/src/runtime/panic.go:791\ngithub.com/pingcap/tidb/pkg/util/memory.(*Tracker).Consume\n\t/workspace/source/tidb/pkg/util/memory/tracker.go:507\ngithub.com/pingcap/tidb/pkg/executor/join.(*innerWorker).constructLookupContent\n\t/workspace/source/tidb/pkg/executor/join/index_lookup_join.go:593\ngithub.com/pingcap/tidb/pkg/executor/join.(*innerWorker).handleTask\n\t/workspace/source/tidb/pkg/executor/join/index_lookup_join.go:553\ngithub.com/pingcap/tidb/pkg/executor/join.(*innerWorker).run\n\t/workspace/source/tidb/pkg/executor/join/index_lookup_join.go:530"]
```

The problem is that 1105 causes connection close for MySQL driver.

### 4. What is your TiDB version? (Required)

Release Version: v8.5.5
Edition: Community
Git Commit Hash: 1fa258b833ff113883beeba40bc130be7ce66610
Git Branch: HEAD
UTC Build Time: 2026-01-14 22:20:57
GoVersion: go1.25.5
Race Enabled: false
Check Table Before Drop: false
Store: unistore

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.