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 4
id | data |
---|---|
2 | [{"value": "CEO Staff"}] |
4 | [{"value": "CEO Staff"}] |
SELECT 2
ERROR: syntax error at or near "$foo" of jsonpath input LINE 4: WHERE jsonb_path_exists(data, '$[*].value ? (@ like_regex $... ^
id | data |
---|---|
2 | [{"value": "CEO Staff"}] |
4 | [{"value": "CEO Staff"}] |
SELECT 2
id | data |
---|---|
2 | [{"value": "CEO Staff"}] |
4 | [{"value": "CEO Staff"}] |
SELECT 2
id | data |
---|---|
2 | [{"value": "CEO Staff"}] |
4 | [{"value": "CEO Staff"}] |
SELECT 2
CREATE INDEX
SET
QUERY PLAN |
---|
Bitmap Heap Scan on tbl (cost=17.30..21.32 rows=1 width=36) |
Recheck Cond: (data @? (format('$[*].value ? (@ like_regex %s flag "i")'::text, '"CEO"'))::jsonpath) |
-> Bitmap Index Scan on tbl_data_idx (cost=0.00..17.30 rows=1 width=0) |
Index Cond: (data @? (format('$[*].value ? (@ like_regex %s flag "i")'::text, '"CEO"'))::jsonpath) |
EXPLAIN
QUERY PLAN |
---|
Seq Scan on tbl (cost=10000000000.00..10000000001.05 rows=1 width=36) |
Filter: jsonb_path_exists(data, '$[*]."value"?(@ == $"foo")'::jsonpath, '{"foo": "CEO Staff"}'::jsonb, false) |
JIT: |
Functions: 2 |
Options: Inlining true, Optimization true, Expressions true, Deforming true |
EXPLAIN