DO $$

  DECLARE

    big_part_count int = 300;
    big_part_size int = 100 * 1000;

    small_part_count int = 50;
    small_part_size int = 30 * 1000;

BEGIN

  DROP TABLE IF EXISTS big_table CASCADE;
  DROP TABLE IF EXISTS small_table CASCADE;
  DROP TABLE IF EXISTS big_table_without_parts CASCADE;
  DROP TABLE IF EXISTS small_table_without_parts CASCADE;

  CREATE TABLE big_table(i int, date timestamp not null default now());
  CREATE INDEX idx_big_i on big_table(i);
  FOR i in 1..big_part_count LOOP
    EXECUTE 'create table big_table_part_' || i || '(like big_table, check( i >= ' || (1 + big_part_size * i) || ' AND i <= ' || ( big_part_size * (i+1) ) || ' )) inherits(big_table)';
    EXECUTE 'CREATE INDEX idx_big_table_part_' || i || ' on big_table_part_' || i || '(i)';
    EXECUTE 'INSERT INTO big_table_part_' || i || ' SELECT * FROM generate_series(' || 1 + (big_part_size * i) ||',' || big_part_size * (i+1)  || ')';
  END LOOP;

  CREATE TABLE small_table(i int);
  CREATE INDEX idx_small_i on small_table(i);
  FOR i in 1..small_part_count LOOP
    EXECUTE 'create table small_table_part_' || i || '(like small_table, check ( i >= '  || (1 + (small_part_size * i)) || ' AND i <= ' || (small_part_size * (i+1)) || ' )) inherits(small_table)';
    EXECUTE 'CREATE INDEX idx_small_table_part_' || i || ' on small_table_part_' || i || '(i)';
    EXECUTE 'INSERT INTO small_table_part_' || i || ' SELECT * FROM generate_series(' || 1 + (small_part_size * i) ||',' || small_part_size * (i+1)  || ')';
  END LOOP;

  CREATE TABLE big_table_without_parts(like big_table including all);
  CREATE TABLE small_table_without_parts(like small_table including all);
  EXECUTE 'INSERT INTO big_table_without_parts SELECT * FROM generate_series(1,' || big_part_size * big_part_count || ')';
  EXECUTE 'INSERT INTO small_table_without_parts SELECT * FROM generate_series(1,' || small_part_size * small_part_count || ')';

END
$$;
