By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Help with an interesting Postgres question: Why isn't an Index Only Scan used on a partition accessed via the parent table?.
CREATE TABLE tablename (
name text,
col1 int,
col2 int,
col3 int,
col4 int,
col5 int
);
WITH generator AS (
SELECT array_agg(gen.i ORDER BY random()) AS numbers
FROM generate_series(1, 5) gen(i) -- range of numbers
CROSS
JOIN generate_series(1, 5) rows(i) -- number of rows
GROUP BY rows.i
)
INSERT INTO tablename
(name, col1, col2, col3, col4, col5)
SELECT substr(md5(random()::text), 0, 15) AS name
, gen.numbers[1]
, gen.numbers[2]
, gen.numbers[3]
, gen.numbers[4]
, gen.numbers[5]
FROM generator gen
5 rows affected
SELECT * FROM tablename
name | col1 | col2 | col3 | col4 | col5 |
---|---|---|---|---|---|
3cef3ab73e5490 | 1 | 5 | 2 | 3 | 4 |
589a71e4041878 | 1 | 3 | 4 | 2 | 5 |
c3f0aab14da6e4 | 5 | 2 | 3 | 4 | 1 |
7a13a7d0a457de | 5 | 1 | 2 | 4 | 3 |
7617526841eec9 | 3 | 5 | 4 | 2 | 1 |