tidb icon indicating copy to clipboard operation
tidb copied to clipboard

Refine memory usage of RowContainer

Open guo-shaoge opened this issue 8 months ago • 0 comments

Enhancement

RowContainer is used for spilling during execution of TiDB operator execution.

But there are lots of temp small objects allocated during spilling. Check heap_tidb_10.71.222.131_4000_1719544680.txt (PS rename to heap.proto to use it)

The alloc space indicates huge number of chunk.NewReaderWithCache and io.NewSectionReader is called. image

But actually after GC, the memory usage is small(check inuse space of heap file). This means we can use cache to reduce the allocation of above small object. image

Following is reproduce sqls:

 drop table if exists t0;
  drop table if exists t1;
  create table t0(c1 int);
  insert into t0 values (1), (2), (3), (4);
  set cte_max_recursion_depth = 10000000;
  set tidb_mem_quota_query = 3<<30;
  set global tidb_mem_oom_action = 'cancel';
  create table t1(c1 int, c2 int);
  insert into t1 values(1, 1), (1, 1), (2, 2), (2, 2), (3, 3), (3, 3), (4, 4), (4, 4);
  explain analyze with recursive cte1 as (select c1 from t0 union all select cte1.c1 from cte1 inner join t1 on cte1.c1 = t1.c1) select * from cte1;

guo-shaoge avatar Jun 28 '24 03:06 guo-shaoge