Database Reference
In-Depth Information
Dynamic Tables
Dynamic tables in Cassandra are tables that, unlike static tables, do not map one
CQL row to one physical row on disk. When using a compound PRIMARY KEY ,
the storage system will create a single wide row for all the possible logical rows
that belong to the partition key of the table. This allows for very fast lookups and
slices of data belonging to that particular partition key and also ensures that all
pieces of data related to that partition key are stored near each other on disk and
on the same node. Listing 4.21 is a page-view-tracking database that tracks page
views by URL and rolls them up by hour. While this could have been created as a
static table, we used a compound PRIMARY KEY to ensure that all hour data for
a particular URL is kept on the same node and close on disk. This will ensure that
reads for that URL are much faster. Each physical row on disk in the Cassandra
storage system maps to several logical rows in CQL.
Listing 4.21 Example of Dynamic Table Data Storage
Click here to view code image
CREATE TABLE page_view_hour_rollups (
hour timestamp,
url text,
page_views bigint,
PRIMARY KEY (url, hour)
);
SELECT * FROM page_view_hour_rollups;
url
|
hour |
page_views
..................+..........................+...........
http://xmpl.com/1 | 2013-06-13 00:00:00+0000
| 351
http://xmpl.com/1 | 2013-06-13 02:00:00+0000
| 43
http://xmpl.com/1 | 2013-06-13 03:00:00+0000
| 914
http://xmpl.com/2 | 2013-06-13 01:00:00 +0000
| 9435
http://xmpl.com/2 | 2013-06-13 02:00:00+0000
|
183
 
Search WWH ::




Custom Search