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 t1 (id int, A varchar(100), B varchar(100), C varchar(100));
CREATE TABLE
create table t2 (id int, A varchar(100), B varchar(100), C varchar(100));
CREATE TABLE
insert into t1 values (1,'xx','r','g');
insert into t1 values (2,'cc','r','g');
insert into t1 values (5,'d','g','e');
INSERT 0 1
INSERT 0 1
INSERT 0 1
insert into t2 values (101,'jyj','u','j');
insert into t2 values (5,'y','jku','u');
insert into t2 values (12,'y','r','j');
INSERT 0 1
INSERT 0 1
INSERT 0 1
SELECT id, A, B, C
FROM t1
UNION ALL
SELECT id, A, B, C
FROM t2
WHERE t2.id IN (SELECT id FROM t1);
id | a | b | c |
---|---|---|---|
1 | xx | r | g |
2 | cc | r | g |
5 | d | g | e |
5 | y | jku | u |
SELECT 4