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 process (id INT, name VARCHAR(8))
INSERT INTO process VALUES
(1,'One'),
(2,'Two'),
(3,'Three')
3 rows affected
CREATE TABLE process_status (id INT, process_id INT, "date" DATE, status VARCHAR(8))
INSERT INTO process_status VALUES
(1,1,'2018-10-10','Start'),
(2,1,'2018-10-15','Running'),
(3,1,'2018-10-30','Running'),
(4,1,'2018-11-01','Running'),
(5,1,'2018-11-02','Error'),
(6,1,'2018-11-03','Error')
6 rows affected
SELECT DISTINCT t1.*
FROM process t1, process_status t2
WHERE t1.id = t2.process_id
AND t2.date < '2018-10-16'
AND t2.status IN ('Running', 'Error')
id | name |
---|---|
1 | One |