vendredi 9 mai 2008
Combien coà »te un tuple avec PostgreSQL?
Par david techer, vendredi 9 mai 2008 à 10:10 :: PostGIS et PostgreSQL
Question au combien intéressante!
Soit la table test qui contient deux champs:
- id: de type entier sur 4 octets;
- data: varchar de longueur 20.
CREATE TABLE test(id int4,data varchar(20));Au mieux, on dirait qu'un tuple coà »tera 24 octets et en fait non! Faisant une simple insertion
INSERT INTO test VALUES (1,'Beautiful Ewa Sonnet');Examinons les champs:
- un entier occupe 4 octect dont pour le moment taille >=4
- le champs data est de type varchar(20). Il faut compter 20 octets pour stocker le texte et 4 octets pour stocker la taille (sizeof(int4)) (cf. type valerna de PostgreSQL) soit 24 octet à  prendre en compte pour ce champs.
pg_column_size()
vient confirmer nos dires
SELECT pg_column_size(id),pg_column_size(data) from test; pg_column_size | pg_column_size ----------------+---------------- 4 | 24 (1 row)Donc pour le moment taille est supérieur à  28=4+24 octets Or d'après [1] et [2), il faut aussi prendre en compte la taille prise par les champs des colonnes systèmes (sans les oids car je n'ai pas créé ma table en les invoquant)
SELECT tableoid,xmin,xmax,cmin,cmax,ctid from test; tableoid | xmin | xmax | cmin | cmax | ctid ----------+-------+------+------+------+------- 205658 | 62456 | 0 | 0 | 0 | (0,1) (1 row)
SOURCES
- [1] Wiki de Guillaume LELARGE http://wiki.guillaume.lelarge.info/trac.cgi/wiki/AutoVacuum
- [2]Document de PostgreSQL en français http://docs.postgresqlfr.org/8.1/ddl-system-columns.html