postgresql - Physical size of int2, int4, int8 in PostgresSQL -


i not understand differents between storage size of ints (all types has fixed size)

in official manual see description:

the types smallint, integer, , bigint store whole numbers, is, numbers without fractional components, of various ranges. attempts store values outside of allowed range result in error.

the type integer common choice, offers best balance between range, storage size, , performance. smallint type used if disk space @ premium. bigint type designed used when range of integer type insufficient.

sql specifies integer types integer (or int), smallint, , bigint. type names int2, int4, , int8 extensions, used other sql database systems.

however simple test shows change type of column not change table size

create table test_big_table_int (   f_int integer );  insert test_big_table_int (f_int )     select ceil(random() * 1000)         generate_series(1,1000000);    select    pg_size_pretty(pg_total_relation_size(relid)) "size_of_table"  pg_catalog.pg_statio_user_tables   relname = 'test_big_table_int';  --"35 mb";    alter table test_big_table_int alter column f_int type bigint;    select    pg_size_pretty(pg_total_relation_size(relid)) "size_of_table"  pg_catalog.pg_statio_user_tables   relname = 'test_big_table_int'; --"35 mb";    alter table test_big_table_int alter column f_int type smallint;    select    pg_size_pretty(pg_total_relation_size(relid)) "size_of_table"  pg_catalog.pg_statio_user_tables   relname = 'test_big_table_int';  --"35 mb";"0 bytes" 

everytime size of table - 35mb. profit use integer or smallint insthead int8?

and second question - why postgee doing rewrite tuple while change type of int (int2<->int4<->int8)?


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -