By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
6 rows affected
| id |
|---|
| 100 |
| id |
|---|
| 100 |
| QUERY PLAN |
|---|
| Nested Loop (cost=0.27..16.32 rows=1 width=4) |
| Join Filter: (tbl.id = tbl_1.id) |
| -> Index Only Scan using foo on tbl (cost=0.13..8.15 rows=1 width=4) |
| Index Cond: ((name = 'value1'::text) AND (value = 1)) |
| -> Index Only Scan using foo on tbl tbl_1 (cost=0.13..8.15 rows=1 width=4) |
| Index Cond: ((name = 'value2'::text) AND (value = 2)) |
| QUERY PLAN |
|---|
| Nested Loop (cost=0.27..16.32 rows=1 width=4) |
| Join Filter: (t1.id = t2.id) |
| -> Index Only Scan using foo on tbl t1 (cost=0.13..8.15 rows=1 width=4) |
| Index Cond: ((name = 'value1'::text) AND (value = 1)) |
| -> Index Only Scan using foo on tbl t2 (cost=0.13..8.15 rows=1 width=4) |
| Index Cond: ((name = 'value2'::text) AND (value = 2)) |
| id |
|---|
| 100 |
| QUERY PLAN |
|---|
| GroupAggregate (cost=12.30..12.51 rows=1 width=4) |
| Group Key: id |
| Filter: ((count(*) FILTER (WHERE ((name = 'value1'::text) AND (value = 1))) = 1) AND (count(*) FILTER (WHERE ((name = 'value2'::text) AND (value = 2))) = 1)) |
| -> Sort (cost=12.30..12.32 rows=6 width=40) |
| Sort Key: id |
| -> Index Only Scan using foo on tbl (cost=0.13..12.22 rows=6 width=40) |
| id |
|---|
| 100 |
| QUERY PLAN |
|---|
| GroupAggregate (cost=12.29..12.31 rows=1 width=4) |
| Group Key: id |
| Filter: (count(DISTINCT value) = 2) |
| -> Sort (cost=12.29..12.30 rows=1 width=8) |
| Sort Key: id |
| -> Index Only Scan using foo on tbl (cost=0.13..12.28 rows=1 width=8) |
| Filter: (((name = 'value1'::text) AND (value = 1)) OR ((name = 'value2'::text) AND (value = 2))) |