{"id":870,"date":"2018-07-04T23:27:45","date_gmt":"2018-07-04T21:27:45","guid":{"rendered":"http:\/\/www.rocworks.at\/wordpress\/?p=870"},"modified":"2018-07-04T23:29:03","modified_gmt":"2018-07-04T21:29:03","slug":"size-of-tables-in-postgresql-vs-apache-cassandra","status":"publish","type":"post","link":"https:\/\/www.rocworks.at\/wordpress\/?p=870","title":{"rendered":"Size of tables in PostgreSQL vs Apache Cassandra&#8230;"},"content":{"rendered":"<p>PostgreSQL table with ts+key as primary key:\u00a0 ~43GB<\/p>\n<p>PostgreSQL wide column table with ts as primary key : 247GB<br \/>\nCassandra wide column table with ts as primary\u00a0 key: 4.5GB<\/p>\n<p>Strange that in PostgreSQL a table with much less rows (but much more columns) needs a lot of more space (both tables store the same amount of data). )<\/p>\n<p>It seems that the Apache Cassandra Column Store can compress the columns pretty good &#8211; factor 10 less disk space!<\/p>\n<p>The source table in PostgreSQL (TimescaleDB) with a timestamp and a key column and 8 data columns had about 170 Mio rows.<\/p>\n<pre>CREATE TABLE candles\r\n(\r\n    instrument character varying(10) NOT NULL,\r\n    ts timestamp(3) without time zone NOT NULL,\r\n    o numeric,\r\n    h numeric,\r\n    l numeric,\r\n    c numeric,\r\n    primary key (instrument, ts)\r\n)<\/pre>\n<p>I needed to flatten the table so that i have just the timestamp as primary key and many columns and each column is of a type. It ends up in a table with about 1.6 Mio rows and many columns.<\/p>\n<pre>CREATE TYPE price AS (\r\n    o       float,\r\n    c       float,\r\n    h       float,\r\n    l       float,\r\n    volume  float\r\n);\r\n\r\nCREATE TABLE candles_wide\r\n(\r\n   ts timestamp(3) without time zone NOT NULL,\r\n   AU200_AUD price,\r\n   AUD_CAD price,\r\n   AUD_CHF price,\r\n   AUD_HKD price,\r\n   AUD_JPY price,\r\n   AUD_NZD price,\r\n   ... 124 columns<\/pre>\n<p>Apache Cassandra wide column store table with ts as primary key and many columns.<\/p>\n<pre>CREATE TABLE candles (ts timestamp,\r\n   AU200_AUD tuple&lt;float,float,float,float,float&gt;,    \r\n   AUD_CAD tuple&lt;float,float,float,float,float&gt;,  \r\n   AUD_CHF tuple&lt;float,float,float,float,float&gt;,  \r\n   ... 124 tuples<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PostgreSQL table with ts+key as primary key:\u00a0 ~43GB PostgreSQL wide column table with ts as primary key : 247GB Cassandra wide column table with ts as primary\u00a0 key: 4.5GB Strange that in PostgreSQL a table with much less rows (but &hellip; <a href=\"https:\/\/www.rocworks.at\/wordpress\/?p=870\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"class_list":["post-870","post","type-post","status-publish","format-standard","hentry","category-bigdatanosql"],"_links":{"self":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/870","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=870"}],"version-history":[{"count":2,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/870\/revisions"}],"predecessor-version":[{"id":872,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/870\/revisions\/872"}],"wp:attachment":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=870"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=870"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}