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
INSERT 0 6
cust_id | month_date | total_price | is_active |
---|---|---|---|
1 | 2022-01 | 3500 | active |
1 | 2022-02 | 0 | active |
1 | 2022-03 | 0 | active |
1 | 2022-04 | 0 | inactive |
1 | 2022-05 | 0 | inactive |
1 | 2022-06 | 300 | active |
1 | 2022-07 | 0 | active |
2 | 2022-01 | 0 | inactive |
2 | 2022-02 | 200 | active |
2 | 2022-03 | 0 | active |
2 | 2022-04 | 250 | active |
2 | 2022-05 | 0 | active |
2 | 2022-06 | 0 | active |
2 | 2022-07 | 0 | inactive |
3 | 2022-01 | 0 | inactive |
3 | 2022-02 | 0 | inactive |
3 | 2022-03 | 1600 | active |
3 | 2022-04 | 0 | active |
3 | 2022-05 | 0 | active |
3 | 2022-06 | 0 | inactive |
3 | 2022-07 | 0 | inactive |
SELECT 21