@@ -3167,6 +3167,142 @@ SELECT count(*) FROM testjsonb WHERE j @? '$.bar';
31673167 0
31683168(1 row)
31693169
3170+ EXPLAIN (COSTS OFF)
3171+ SELECT * FROM testjsonb WHERE jsonb_path_match(j, '$.age == 25');
3172+ QUERY PLAN
3173+ --------------------------------------------------------------------------------
3174+ Seq Scan on testjsonb
3175+ Filter: jsonb_path_match(j, '($."age" == 25)'::jsonpath, '{}'::jsonb, false)
3176+ (2 rows)
3177+
3178+ EXPLAIN (COSTS OFF)
3179+ SELECT * FROM testjsonb WHERE jsonb_path_match(j, '$.age == 25', silent => true);
3180+ QUERY PLAN
3181+ -------------------------------------------------------------------------------
3182+ Bitmap Heap Scan on testjsonb
3183+ Filter: jsonb_path_match(j, '($."age" == 25)'::jsonpath, '{}'::jsonb, true)
3184+ -> Bitmap Index Scan on jidx
3185+ Index Cond: (j @@ '($."age" == 25)'::jsonpath)
3186+ (4 rows)
3187+
3188+ EXPLAIN (COSTS OFF)
3189+ SELECT * FROM testjsonb WHERE jsonb_path_match(j, '$.age == 25', vars => '{"age": 34 }', silent => true);
3190+ QUERY PLAN
3191+ ----------------------------------------------------------------------------------------
3192+ Bitmap Heap Scan on testjsonb
3193+ Filter: jsonb_path_match(j, '($."age" == 25)'::jsonpath, '{"age": 34}'::jsonb, true)
3194+ -> Bitmap Index Scan on jidx
3195+ Index Cond: (j @@ '($."age" == 25)'::jsonpath)
3196+ (4 rows)
3197+
3198+ EXPLAIN (COSTS OFF)
3199+ SELECT * FROM testjsonb WHERE jsonb_path_match(j, '$.age == $age', vars => '{"age": 25 }', silent => true);
3200+ QUERY PLAN
3201+ --------------------------------------------------------------------------------------------
3202+ Bitmap Heap Scan on testjsonb
3203+ Filter: jsonb_path_match(j, '($."age" == $"age")'::jsonpath, '{"age": 25}'::jsonb, true)
3204+ -> Bitmap Index Scan on jidx
3205+ Index Cond: (j @@ '($."age" == 25)'::jsonpath)
3206+ (4 rows)
3207+
3208+ EXPLAIN (COSTS OFF)
3209+ SELECT * FROM testjsonb WHERE jsonb_path_match(j, '$.age == $age', vars => '{"age": [25] }', silent => true);
3210+ QUERY PLAN
3211+ ----------------------------------------------------------------------------------------------
3212+ Seq Scan on testjsonb
3213+ Filter: jsonb_path_match(j, '($."age" == $"age")'::jsonpath, '{"age": [25]}'::jsonb, true)
3214+ (2 rows)
3215+
3216+ EXPLAIN (COSTS OFF)
3217+ SELECT * FROM testjsonb WHERE jsonb_path_match(j, '$.age == $x || $.age == $y', vars => '{"x": 25, "y": 34}', silent => true);
3218+ QUERY PLAN
3219+ --------------------------------------------------------------------------------------------------------------------
3220+ Bitmap Heap Scan on testjsonb
3221+ Filter: jsonb_path_match(j, '($."age" == $"x" || $."age" == $"y")'::jsonpath, '{"x": 25, "y": 34}'::jsonb, true)
3222+ -> Bitmap Index Scan on jidx
3223+ Index Cond: (j @@ '($."age" == 25 || $."age" == 34)'::jsonpath)
3224+ (4 rows)
3225+
3226+ EXPLAIN (COSTS OFF)
3227+ SELECT * FROM testjsonb t1, testjsonb t2 WHERE jsonb_path_match(t1.j, '$.age == $age', vars => t2.j, silent => true);
3228+ QUERY PLAN
3229+ ---------------------------------------------------------------------------------------------
3230+ Nested Loop
3231+ -> Seq Scan on testjsonb t2
3232+ -> Bitmap Heap Scan on testjsonb t1
3233+ Filter: jsonb_path_match(j, '($."age" == $"age")'::jsonpath, t2.j, true)
3234+ -> Bitmap Index Scan on jidx
3235+ Index Cond: (j @@ jsonpath_embed_vars('($."age" == $"age")'::jsonpath, t2.j))
3236+ (6 rows)
3237+
3238+ EXPLAIN (COSTS OFF)
3239+ SELECT * FROM testjsonb WHERE jsonb_path_exists(j, '$ ? (@.age == 25)');
3240+ QUERY PLAN
3241+ -----------------------------------------------------------------------------------
3242+ Seq Scan on testjsonb
3243+ Filter: jsonb_path_exists(j, '$?(@."age" == 25)'::jsonpath, '{}'::jsonb, false)
3244+ (2 rows)
3245+
3246+ EXPLAIN (COSTS OFF)
3247+ SELECT * FROM testjsonb WHERE jsonb_path_exists(j, '$ ? (@.age == 25)', silent => true);
3248+ QUERY PLAN
3249+ ----------------------------------------------------------------------------------
3250+ Bitmap Heap Scan on testjsonb
3251+ Filter: jsonb_path_exists(j, '$?(@."age" == 25)'::jsonpath, '{}'::jsonb, true)
3252+ -> Bitmap Index Scan on jidx
3253+ Index Cond: (j @? '$?(@."age" == 25)'::jsonpath)
3254+ (4 rows)
3255+
3256+ EXPLAIN (COSTS OFF)
3257+ SELECT * FROM testjsonb WHERE jsonb_path_exists(j, '$ ? (@.age == 25)', vars => '{"age": 34 }', silent => true);
3258+ QUERY PLAN
3259+ -------------------------------------------------------------------------------------------
3260+ Bitmap Heap Scan on testjsonb
3261+ Filter: jsonb_path_exists(j, '$?(@."age" == 25)'::jsonpath, '{"age": 34}'::jsonb, true)
3262+ -> Bitmap Index Scan on jidx
3263+ Index Cond: (j @? '$?(@."age" == 25)'::jsonpath)
3264+ (4 rows)
3265+
3266+ EXPLAIN (COSTS OFF)
3267+ SELECT * FROM testjsonb WHERE jsonb_path_exists(j, '$ ? (@.age == $age)', vars => '{"age": 25 }', silent => true);
3268+ QUERY PLAN
3269+ -----------------------------------------------------------------------------------------------
3270+ Bitmap Heap Scan on testjsonb
3271+ Filter: jsonb_path_exists(j, '$?(@."age" == $"age")'::jsonpath, '{"age": 25}'::jsonb, true)
3272+ -> Bitmap Index Scan on jidx
3273+ Index Cond: (j @? '$?(@."age" == 25)'::jsonpath)
3274+ (4 rows)
3275+
3276+ EXPLAIN (COSTS OFF)
3277+ SELECT * FROM testjsonb WHERE jsonb_path_exists(j, '$ ? (@.age == $age)', vars => '{"age": [25] }', silent => true);
3278+ QUERY PLAN
3279+ -------------------------------------------------------------------------------------------------
3280+ Seq Scan on testjsonb
3281+ Filter: jsonb_path_exists(j, '$?(@."age" == $"age")'::jsonpath, '{"age": [25]}'::jsonb, true)
3282+ (2 rows)
3283+
3284+ EXPLAIN (COSTS OFF)
3285+ SELECT * FROM testjsonb WHERE jsonb_path_exists(j, '$ ? (@.age == $x || $.age == $y)', vars => '{"x": 25, "y": 34}', silent => true);
3286+ QUERY PLAN
3287+ -----------------------------------------------------------------------------------------------------------------------
3288+ Bitmap Heap Scan on testjsonb
3289+ Filter: jsonb_path_exists(j, '$?(@."age" == $"x" || $."age" == $"y")'::jsonpath, '{"x": 25, "y": 34}'::jsonb, true)
3290+ -> Bitmap Index Scan on jidx
3291+ Index Cond: (j @? '$?(@."age" == 25 || $."age" == 34)'::jsonpath)
3292+ (4 rows)
3293+
3294+ EXPLAIN (COSTS OFF)
3295+ SELECT * FROM testjsonb t1, testjsonb t2 WHERE jsonb_path_exists(t1.j, '$ ? (@.age == $age)', vars => t2.j, silent => true);
3296+ QUERY PLAN
3297+ -----------------------------------------------------------------------------------------------
3298+ Nested Loop
3299+ -> Seq Scan on testjsonb t2
3300+ -> Bitmap Heap Scan on testjsonb t1
3301+ Filter: jsonb_path_exists(j, '$?(@."age" == $"age")'::jsonpath, t2.j, true)
3302+ -> Bitmap Index Scan on jidx
3303+ Index Cond: (j @? jsonpath_embed_vars('$?(@."age" == $"age")'::jsonpath, t2.j))
3304+ (6 rows)
3305+
31703306-- array exists - array elements should behave as keys (for GIN index scans too)
31713307CREATE INDEX jidx_array ON testjsonb USING gin((j->'array'));
31723308SELECT count(*) from testjsonb WHERE j->'array' ? 'bar';
0 commit comments