----As per Simon Riggs suggestion: -------------------------------------- ----With Single column bigint index: --Schema create table tbl2(id1 int, id2 bigint, id3 int); create index idx2 on tbl2(id2); --Procedure to insert 1M data: insert into tbl2 values(1,generate_series(1, 1000000), 2); --Procedure to select data 1000 times (1000 times selected to make data more appropriate.) create or replace function select_data(count1 int) returns void AS $$ declare x int; Begin for i IN 1..count1 loop select count(*) into x from tbl2 where id2>990000; end loop; End; $$ language plpgsql; select select_data(1000); -------------------------------------- ----With Multiple column bigint index: create table tbl3(id1 int, id2 bigint, id3 bigint, id4 bigint); create index idx3 on tbl3(id2, id3, id4); insert into tbl3 values(1,generate_series(1, 1000000), generate_series(1, 1000000), generate_series(1, 1000000)); --Procedure to select data 1000 times (1000 times selected to make data more appropriate.) create or replace function select_data_multi_bigint(count1 int) returns void AS $$ declare x int; Begin for i IN 1..count1 loop select count(*) into x from tbl3 where id2>990000 and id3>990000 and id4>990000; end loop; End; $$ language plpgsql; select select_data_multi_bigint(1000); -------------------------------------- ---5 column index with mixed text and integers --Schema create table tbl4(id1 int, id2 varchar(10), id3 int, id4 varchar(10), id5 int, id6 int); create index idx4 on tbl4(id2, id3, id4, id5, id6); --Procedure to insert 1M data: create or replace function insert_data_mix_text_int(count1 int, count2 int) returns void AS $$ Begin for i IN 1..count1 loop insert into tbl4 values(i, 'a', i, 'a', i, i); end loop; for i IN count1+1..count2 loop insert into tbl4 values(i, 'b', i, 'b', i, i); end loop; End; $$ language plpgsql; select insert_data_mix_text_int(990000, 1000000); --Procedure to select data 1000 times (1000 times selected to make data more appropriate.) create or replace function select_data_mix_text_int(count1 int) returns void AS $$ declare x int; Begin for i IN 1..count1 loop select count(*) into x from tbl4 where id2>'a' and id3>990000 and id4>'a' and id5>990000 and id6>990000; end loop; End; $$ language plpgsql; select select_data_mix_text_int(1000);