COPY with automatical compression
To apply automatic compression to an empty table, regardless of its current compression encodings, run the COPY command with the COMPUPDATE option set to ON. To disable automatic compression, run the COPY command with the COMPUPDATE option set to OFF.

Change diststyle of table

1

2

CREATE TALBLE userseven DISTSTYLE EVEN AS

SELECT *FROM users;

Show storage space of columns

1

2

3

4

5

6

select col,max(blocknum)

from stv_blocklistb,stv_tbl_permp

where(b.tbl=p.id)andname='lineorder'

andcol<17

group by name,col

order by col;

Change current environment in SQL Editor

1

2

3

set query_group totest;

set session authorization'adminwlm';

set wlm_query_slot_count to3;/* override current level */

Primary key and foreign key
Amazon Redshift does not enforce primary key and foreign key constraints, but the query optimizer uses them when it generates query plans. If you set primary keys and foreign keys, your application must maintain the validity of the keys.

Distribution info in EXPLAIN
DS_DIST_NONE
No redistribution is required, because corresponding slices are collocated on the compute nodes. You will typically have only one DS_DIST_NONE step, the join between the fact table and one dimension table.
DS_DIST_ALL_NONE
No redistribution is required, because the inner join table used DISTSTYLE ALL. The entire table is located on every node.
DS_DIST_INNER
The inner table is redistributed.
DS_DIST_OUTER
The outer table is redistributed.
DS_BCAST_INNER
A copy of the entire inner table is broadcast to all the compute nodes.
DS_DIST_ALL_INNER
The entire inner table is redistributed to a single slice because the outer table uses DISTSTYLE ALL.
DS_DIST_BOTH
Both tables are redistributed.

Create Like

1

2

3

4

create table likesales(like sales);

insert into likesales(select *from sales);

drop table sales;

alter table likesales rename tosales;

Interleaved skew

1

2

3

4

5

select tbl astbl_id,stv_tbl_perm.name astable_name,

col,interleaved_skew,last_reindex

from svv_interleaved_columns,stv_tbl_perm

where svv_interleaved_columns.tbl=stv_tbl_perm.id

andinterleaved_skew isnotnull;

The value for interleaved_skew is a ratio that indicates the amount of skew. A value of 1 means there is no skew. If the skew is greater than 1.4, a VACUUM REINDEX will usually improve performance unless the skew is inherent in the underlying set.

Data Join
* Nested Loop : The least optimal join, a nested loop is used mainly for cross-joins (Cartesian products) and some inequality joins.
* Hash Join and Hash Typically faster than a nested loop join, a hash join and hash are used for inner joins and left and right outer joins. These operators are used when joining tables where the join columns are not both distribution keys and sort keys. The hash operator creates the hash table for the inner table in the join; the hash join operator reads the outer table, hashes the joining column, and finds matches in the inner hash table.
* Merge Join Typically the fastest join, a merge join is used for inner joins and outer joins. The merge join is not used for full joins. This operator is used when joining tables where the join columns are both distribution keys and sort keys, and when less than 20 percent of the joining tables are unsorted. It reads two sorted tables in order and finds the matching rows. To view the percent of unsorted rows, query the SVV_TABLE_INFO (p. 786) system table.

wlm_query_slot_count
You can temporarily override the amount of memory assigned to a query by setting the wlm_query_slot_count parameter to specify the number of slots allocated to the query. By default, WLM queues have a concurrency level of 5

SELECT gender,COUNT(gender)FROM employee WHERE first_name SIMILAR TO'%ein%'GROUP BY gender;

analyze_threshold_percent
To reduce processing time and improve overall system performance, Amazon Redshift skips analyzing a table if the percentage of rows that have changed since the last ANALYZE command run is lower than the analyze threshold specified by the analyze_threshold_percent parameter. By default, analyze_threshold_percent is 10

COPY from DynamoDB
Setting READRATIO to 100 or higher will enable Amazon Redshift to consume the entirety of the DynamoDB table’s provisioned throughput, which will seriously degrade the performance of concurrent read operations against the same table during the COPY session. Write traffic will be unaffected.

Different databases in Redshift
After you have created the TICKIT database, you can connect to the new database from your SQL client. Use the same connection parameters as you used for your current connection, but change the database name to tickit.

Interleaved Sort Key
A maximum of eight columns can be specified for an interleaved sort key.