M
M
Muhammad2016-01-08 23:01:13
PostgreSQL
Muhammad, 2016-01-08 23:01:13

Does it make sense to use SMALLINT instead of INT (PostgreSQL)?

What is the real benefit of such a replacement, if I am sure that the size of SMALLINT is enough for me?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melkij, 2016-01-08
@muhammad_97

int is always 4 bytes, smallint is always 2 bytes.
Less bytes are occupied by data - it means that more data will enter the same amount of memory on a piece of iron, and less data will need to be run through disks. Less disk work is always a plus in DBMS performance.
At the same time, the data takes up less space in both tables and indexes.
But this is if you have the order of integer data, and not just a few million rows. What is saving ten megabytes of data on a machine with several tens of gigabytes of memory?
Otherwise, the use of appropriate types is a courtesy, a manifestation of professionalism and an extra way not to accidentally shoot yourself in the foot (by mistake, writing down something completely strange will no longer work).

D
Dimonchik, 2016-01-08
@dimonchik2013

speed will give
naturally, has
field types for the same and were invented to inform the DBMS engine about the maximum memory costs - from this the optimizer builds mechanisms for JOINs, indexes, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question