#!/bin/sh for power in 7; do table=junk${power} echo "-- table $table"; echo "drop index if exists ${table}_gin_idx" | psql -qtAX if [[ 1 -eq 1 ]]; then time perl -E' sub ss{ join"",@_[ map{rand @_} 1 .. shift ] }; say( q({{order_code, "0165-02675-4565"}, {email, ).q(").ss(4,"a".."z").q(@test.com"}, {price, "15"}, {title, "Mt Thing XYZ"}}) ) for 1 .. 1e'"${power};" \ | psql -aqXc " drop table if exists $table; create table $table(id serial, data jsonb, txt text); copy $table(txt) from stdin; update $table set data = cast(json_object(cast(txt as text[][])) as jsonb); alter table $table drop column txt; " fi echo "table $table limit 3" | psql -qX # show a few rows echo "select count(*) from $table " | psql -qX # show rowcount echo " select * from $table where data @> '{\"email\": \"abcd@test.com\"}'; -- cold cache (possibly) select * from $table where data @> '{\"email\": \"abcd@test.com\"}'; -- warm cache explain analyze select * from $table where data @> '{\"email\": \"abcd@test.com\"}'; -- explain " | psql echo "create index ${table}_gin_idx on $table using gin (data); analyze $table; " | psql echo " select * from $table where data @> '{\"email\": \"abcd@test.com\"}'; -- cold cache (possibly) select * from $table where data @> '{\"email\": \"abcd@test.com\"}'; -- warm cache explain analyze select * from $table where data @> '{\"email\": \"abcd@test.com\"}'; -- explain " | psql echo "\dti+ ${table}*" | psql -qX done