Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does hstore internally store the data?

I'm using the postgresql hstore extension and curious how the data is stored internally. Please point me to where I could look in the hstore source code to see the implementation details.

like image 244
Valentin V Avatar asked Dec 16 '22 17:12

Valentin V


1 Answers

hstore is part of the main PostgreSQL distribution, which is on http://git.postgresql.org/ and GitHub. Here is hstore in git head.

It looks like it's stored as a varlena, which means it's TOASTable like anything else. The downside is that the whole field needs to be read from disk - at least if it's compressed - to extract a key.

This also means that like any other normal field value, updating any part of the field requires that a new copy of the whole tuple (row) must be written to the table and the old one marked for expiry when it's no longer visible to any active transactions (see MVCC in the Pg manual). A big hstore is thus undesirable for data that will change frequently, since you'll need to rewrite the whole thing (and the row that contains it) whenever any part of it changes.

  • hstore.h
  • hstore_io.c

The sources don't seem to contain much in the way of comments to provide an overview of how hstore values are structured and stored, and it's a bit of a macro forest to take in quickly.

like image 97
Craig Ringer Avatar answered Dec 23 '22 17:12

Craig Ringer