create extension if not exists btree_gist;

drop table if exists varbittmp;

CREATE TABLE varbittmp (a varbit);

insert into varbittmp
select repeat(i::bit(8)::text, j)::varbit from
  generate_series(0,255) i,
  generate_series(1,100) j;

insert into varbittmp select * from varbittmp;
insert into varbittmp select * from varbittmp;

vacuum analyze varbittmp;

select count(*) from varbittmp;

SELECT count(*) FROM varbittmp WHERE a > '11111';

CREATE INDEX varbitidx ON varbittmp USING GIST ( a );

select pg_size_pretty(pg_relation_size('varbittmp')) as table_size,
       pg_size_pretty(pg_indexes_size('varbittmp')) as index_size,
       pg_indexes_size('varbittmp') / 8192 as index_blocks;

explain (analyze, buffers)
SELECT count(*) FROM varbittmp WHERE a > '11111';
