Created
October 24, 2022 13:51
-
-
Save jorgearimitsu/373a59d3d95da3d395e5fa7552473ec1 to your computer and use it in GitHub Desktop.
Type map query from rails 6.1.7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype | |
FROM pg_type as t | |
LEFT JOIN pg_range as r ON oid = rngtypid | |
WHERE | |
t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'text', 'varchar', 'char', 'name', 'bpchar', 'bool', 'bit', 'varbit', 'timestamptz', 'date', 'money', 'bytea', 'point', 'hstore', 'json', 'jsonb', 'cidr', 'inet', 'uuid', 'xml', 'tsvector', 'macaddr', 'citext', 'ltree', 'line', 'lseg', 'box', 'path', 'polygon', 'circle', 'time', 'timestamp', 'numeric', 'interval') | |
OR t.typtype IN ('r', 'e', 'd') | |
OR t.typinput = 'array_in(cstring,oid,integer)'::regprocedure | |
OR t.typelem != 0 |
Upgrading to PostgreSQL 14 improved the performance:
Hash Left Join (cost=1.24..19250.87 rows=306858 width=86) (actual time=0.016..138.272 rows=205837 loops=1)
Hash Cond: (t.oid = r.rngtypid)
Buffers: shared hit=9147
-> Seq Scan on pg_type t (cost=0.10..18444.22 rows=306858 width=82) (actual time=0.007..101.006 rows=205837 loops=1)
Filter: ((typname = ANY ('{int2,int4,int8,oid,float4,float8,text,varchar,char,name,bpchar,bool,bit,varbit,timestamptz,date,money,bytea,point,hstore,json,jsonb,cidr,inet,uuid,xml,tsvector,macaddr,citext,ltree,line,lseg,box,path,polygon,circle,time,timestamp,numeric,interval}'::name[])) OR (typtype = ANY ('{r,e,d}'::"char"[])) OR ((typinput)::oid = '750'::oid) OR (typelem <> '0'::oid))
Rows Removed by Filter: 184826
Buffers: shared hit=9146
-> Hash (cost=1.06..1.06 rows=6 width=8) (actual time=0.004..0.006 rows=6 loops=1)
Buckets: 1024 Batches: 1 Memory Usage: 9kB
Buffers: shared hit=1
-> Seq Scan on pg_range r (cost=0.00..1.06 rows=6 width=8) (actual time=0.002..0.003 rows=6 loops=1)
Buffers: shared hit=1
Planning:
Buffers: shared hit=12
Planning Time: 0.338 ms
Execution Time: 147.277 ms
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result using
EXPLAIN (ANALYZE, BUFFERS)