The same idea came up as Lorentz. And, despite the number of high key-value pairs, they seem to do the exact same thing:
t=> do
t-> $$
t$> declare
t$> _i int;
t$> _j jsonb;
t$> begin
t$> with n as (select generate_series(1,9999,1) g) select concat('{',string_agg(concat('"a',g,'":22'),','),',"c": "lorem"}')::jsonb into _j from n;
t$> for _r in 1..999999 loop
t$> select 1 into _i where _j @> '{"c": "lorem"}';
t$> end loop;
t$> end;
t$> $$
t-> ;
DO
Time: 2406.016 ms
t=>
t=> do
t-> $$
t$> declare
t$> _i int;
t$> _j jsonb;
t$> begin
t$> with n as (select generate_series(1,9999,1) g) select concat('{',string_agg(concat('"a',g,'":22'),','),',"c": "lorem"}')::jsonb into _j from n;
t$> for _r in 1..999999 loop
t$> select 1 into _i where _j->>'c' = 'lorem';
t$> end loop;
t$> end;
t$> $$
t-> ;
DO
Time: 2799.750 ms
source
share