pingcap / pingcap/tidb

The simple prepared query run out of 1 GiB memory with only 70 rows

Open
#66,301 3 comments 0 reactions 1 assignee Claimed by @qw4990 View on GitHub
contribution may-affects-7.1 may-affects-7.5 may-affects-8.1 may-affects-8.5 severity/major sig/planner 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)

Hi,

The following query triggers an error `Your query has been cancelled due to exceeding the allowed memory limit for a single SQL query. Please try narrowing your query scope or increase the tidb_mem_quota_query limit and try again.`, however, there are only 70 rows in `v0`

```
CREATE TABLE t72(c0 TEXT(417) );
INSERT INTO t72(c0)
WITH RECURSIVE cte AS (
SELECT 1 AS n
UNION ALL
SELECT n + 1 FROM cte WHERE n < 70
)
SELECT '' FROM cte;
CREATE ALGORITHM=MERGE VIEW v0(c0, c2) AS SELECT EXPORT_SET(548929658, t72.c0, CAST(t72.c0 AS BINARY)), '-1572719353' FROM t72;
SET @d = false;
SET @e = true;
PREPARE prepare_query FROM 'SELECT ((v0.c2)&(((v0.c0)>=((~ (?)))))) FROM v0 WHERE ?'; -- 1ms;
EXECUTE prepare_query USING @d,@e; -- Your query has been cancelled due to exceeding the allowed memory limit for a single SQL query. Please try narrowing your query scope or increase the tidb_mem_quota_query limit and try again.
```

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

No error.

### 3. What did you see instead (Required)

`Your query has been cancelled due to exceeding the allowed memory limit for a single SQL query. Please try narrowing your query scope or increase the tidb_mem_quota_query limit and try again.`

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

Release Version: v9.0.0-beta.2.pre-1118-gfc6f7b2e42\nEdition: Community\nGit Commit Hash: fc6f7b2e42be08957a9b80e5761bfa4793066353\nGit Branch: master\nUTC Build Time: 2026-01-26 12:27:51\nGoVersion: go1.25.6\nRace Enabled: false\nCheck Table Before Drop: false\nStore: unistore\nKernel Type: Classic

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.