Slide 36
Slide 36 text
json path
Beware of the where condition
idi =# EXPLAIN ANALYZE
SELECT DISTINCT
jsonb_path_query (data , ’$.childs ’) as childs ,
jsonb_path_query (data ,’$.name ’) as parent
FROM
jsb_tab
WHERE
jsonb_exists (data ,’childs ’)
;
QUERY PLAN
-- -----------------------------------------------
HashAggregate (cost =4042604.29..4103437.46 rows =1667376 width =64) (actual time =315.686..316.815 rows =1 loops
=1)
Group Key: ( jsonb_path_query (data , ’$." childs"’:: jsonpath , ’{}’::jsonb , false)), ( jsonb_path_query (data , ’$
." name"’:: jsonpath , ’{}’::jsonb , fals e))
Planned Partitions: 64 Batches: 1 Memory Usage: 1561 kB
-> Gather (cost =1000.00..3857629.76 rows =1667376 width =64) (actual time =0.222..315.428 rows =1000 loops =1)
Workers Planned: 2
Workers Launched: 2
-> ProjectSet (cost =0.00..3689892.16 rows =694740000 width =64) (actual time =206.875..311.481 rows =333
loops =3)
-> Parallel Seq Scan on jsb_tab (cost =0.00..209244.76 rows =694740 width =257) (actual time
=206.872..310.993 rows =333 loops =3)
Filter: jsonb_exists (data , ’childs ’:: text)
Rows Removed by Filter: 1666333
Planning Time: 0.103 ms
Execution Time: 316.907 ms
(12 rows)
Federico Campoli (Kamedata) Leveraging jsonb in PostgreSQL 17 for max performance A quick look to JSONB 36 / 55