\r set session range_optimizer_max_mem_size=1024*1024*128; drop table if exists t; create table t(a int, b int,c int,d int,e int,f int, g int,primary key(a,b,c,d,e,g))engine=innodb; insert into t values(1,1,1,1,1,1,1),(2,2,2,2,2,2,2),(3,3,3,3,3,3,3); drop table if exists r; create table r(a serial,ranges int, memory int,query_lengt int); drop procedure if exists p; delimiter $ create procedure p(max_ranges int) begin declare v_j int default 0; declare v_i int default 0; truncate r; endme: begin repeat set v_i:=0; set @v_sql='select count(*) from t where '; repeat set @v_sql:=concat(@v_sql,'(a=',v_i,' and b=',v_i,' and c=',v_i,' and d=',v_i,' and e=',v_i,' and f=',v_i,' and g=',v_i,') or '); set v_i:=v_i+1; until v_i > v_j -1 end repeat; set @v_sql:=concat(@v_sql,'(a=',v_i,' and b=',v_i,' and c=',v_i,' and d=',v_i,' and e=',v_i,' and f=',v_i,' and g=',v_i,') into @a'); -- select @v_sql; prepare s from @v_sql; execute s; show warnings; deallocate prepare s; select HIGH_NUMBER_OF_BYTES_USED as range_memory from performance_schema.memory_summary_by_thread_by_event_name a,performance_schema.threads b where b.processlist_id=connection_id() and a.thread_id=b.thread_id and event_name='memory/sql/test_quick_select' into @mem; select v_j as 'ranges', @mem as 'range memory'; insert into r(ranges,memory,query_lengt) values(v_j,@mem,length(@v_sql)); if @mem >= @@range_optimizer_max_mem_size then select 'aborting due to limit hit!' as 'msg'; leave endme; end if; set v_j:=v_j+50; until v_j >= max_ranges end repeat; end endme; end $ delimiter ; call p(1000000); select ranges,memory,query_lengt from r order by a desc limit 10;