It is unreasonable that insertstmt use 2GB memory #17961
Description
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
drop table if exists t2;
create table t2(a int);
insert into t2 values(1), (2), (3);
insert into t2 select * from t2;
insert into t2 select * from t2;
insert into t2 select * from t2;
insert into t2 select * from t2;
insert into t2 select * from t2;
insert into t2 select * from t2;
insert into t2 select * from t2;
insert into t2 select * from t2;
insert into t2 select * from t2;
insert into t2 select * from t2;
insert into t2 select * from t2;
insert into t2 select * from t2;
insert into t2 select * from t2;
insert into t2 select * from t2;
insert into t2 select * from t2;
insert into t2 select * from t2;
insert into t2 select * from t2;
set tidb_mem_quota_query=2048576000;
insert into t2 select * from t2;
set tidb_mem_quota_query=3145728;
select * from t2;
2. What did you expect to see? (Required)
3. What did you see instead (Required)
[2020/06/11 18:54:19.940 +08:00] [WARN] [expensivequery.go:167] [expensive_query] [cost_time=9.994891607s] [cop_time=8.989254832s] [request_count=1] [num_cop_tasks=1] [process_avg_time=0s] [process_p90_time=0s] [process_max_time=0s] [process_max_addr=store1] [wait_avg_time=0s] [wait_p90_time=0s] [wait_max_time=0s] [wait_max_addr=store1] [stats=t2:pseudo] [conn_id=1] [user=root] [database=test] [table_ids="[199]"] [txn_start_ts=417299916375982080] [mem_max="2206531584 Bytes (2.05499267578125 GB)"] [sql="insert into t2 select * from t2"]
[2020/06/11 18:54:44.853 +08:00] [WARN] [expensivequery.go:167] [expensive_query] [cost_time=19.994681507s] [stats=t2:pseudo] [conn_id=1] [user=root] [database=test] [table_ids="[199]"] [txn_start_ts=417299920285335552] [mem_max="6463618 Bytes (6.164186477661133 MB)"] [sql="select * from t2"]
4. Affected version (Required)
Release Version: v4.0.0-54-gef315c143-dirty
Edition: Community
Git Commit Hash: ef315c143b2ea558ecdeadd1036e35517c8e944e
Git Branch: release-4.0
UTC Build Time: 2020-06-11 06:56:00
GoVersion: go1.13.1
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false