Showing posts with label schema. Show all posts
Showing posts with label schema. Show all posts

Sunday, March 30, 2014

Redshift sample schema from AWS web site

Below are the sample schemas that can be used when getting started with AWS Redshift. More information can be found here: http://docs.aws.amazon.com/redshift/latest/gsg/getting-started.html

create table users(
     userid integer not null distkey sortkey,
     username char(8),
     firstname varchar(30),
     lastname varchar(30),
     city varchar(30),
     state char(2),
     email varchar(100),
     phone char(14),
     likesports boolean,
     liketheatre boolean,
     likeconcerts boolean,
     likejazz boolean,
     likeclassical boolean,
     likeopera boolean,
     likerock boolean,
     likevegas boolean,
     likebroadway boolean,
     likemusicals boolean);

create table venue(
     venueid smallint not null distkey sortkey,
     venuename varchar(100),
     venuecity varchar(30),
     venuestate char(2),
     venueseats integer);

create table category(
     catid smallint not null distkey sortkey,
     catgroup varchar(10),
     catname varchar(10),
     catdesc varchar(50));

create table date(
     dateid smallint not null distkey sortkey,
     caldate date not null,
     day character(3) not null,
     week smallint not null,
     month character(5) not null,
     qtr character(5) not null,
     year smallint not null,
     holiday boolean default('N'));

create table event(
     eventid integer not null distkey,
     venueid smallint not null,
     catid smallint not null,
     dateid smallint not null sortkey,
     eventname varchar(200),
     starttime timestamp);

create table listing(
     listid integer not null distkey,
     sellerid integer not null,
     eventid integer not null,
     dateid smallint not null  sortkey,
     numtickets smallint not null,
     priceperticket decimal(8,2),
     totalprice decimal(8,2),
     listtime timestamp);

create table sales(
     salesid integer not null,
     listid integer not null distkey,
     sellerid integer not null,
     buyerid integer not null,
     eventid integer not null,
     dateid smallint not null sortkey,
     qtysold smallint not null,
     pricepaid decimal(8,2),
     commission decimal(8,2),

     saletime timestamp);

Tuesday, July 23, 2013

Redshift schema migration


Indexes, foreign keys, primary keys, and arrays are not supported in Redshift. The distribution key, which determines how your data is distributed across the cluster, is a very important part of the schema definition. Check all queries for the table and choose the column that gets joined most frequently for the distribution key to get the best performance. You can only specify one distribution key and if you are joining against multiple columns on a large scale, you might notice a performance degradation. Also, specify the columns your range queries use the most as sort key on your table (can be multi columns in sort key), as it will help with the performance.