drop extension if exists pageinspect;
create extension pageinspect;

create or replace function random_str(p_len int) returns text as $$
declare
   v text;
begin

   v := '';

   loop
   
       v := v || md5(random()::text);
       
       if length(v) >= p_len then
           exit;
       end if;
       
   end loop;

   return substr(v, 1, p_len);

end;
$$ language plpgsql;

drop table if exists x;
create table x (a text, b text, c text);
insert into x select random_str(2000), random_str(1000), random_str(1000);

create index on x using brin (a,b,c);
delete from x;
vacuum x;

select * from brin_page_items(get_raw_page('x_a_b_c_idx', 2), 'x_a_b_c_idx'::regclass);

set enable_seqscan=off;

insert into x select random_str(10), random_str(10), random_str(10);

explain analyze select * from x where a = 'xxx';

select * from brin_page_items(get_raw_page('x_a_b_c_idx', 2), 'x_a_b_c_idx'::regclass);

vacuum x;

select * from brin_page_items(get_raw_page('x_a_b_c_idx', 2), 'x_a_b_c_idx'::regclass);
