alter table slim_shred ALTER COLUMN country TYPE varchar(50);
alter table slim_shred ALTER COLUMN version TYPE varchar(20);
4.4. 重新执行加载命令
再次执行命令,经过22分钟21秒加载完成
4.5. 执行查询SQL
执行以下SQL,经过59秒查询出结果,共921条
SELECT
first_open_date, country, event_name,
DATE_DIFF('d', retention_date, first_open_date) AS date_diff,
COUNT(DISTINCT first_uid) AS users,
COUNT(first_uid) AS events
FROM ((
SELECT
DATE(date_add('h',-8,date_add('us',event_timestamp,'1970-01-01'))) AS first_open_date,
country, user_pseudo_id AS first_uid
FROM slim_shred
WHERE event_name = '19d2da1d0d3c1cd08a318cbd5c04a3b0'
GROUP BY first_open_date, country, first_uid)
INNER JOIN (
SELECT
DATE(date_add('h',-8,date_add('us',event_timestamp,'1970-01-01'))) AS retention_date,
event_name, user_pseudo_id AS retention_uid
FROM slim_shred
WHERE event_name IN ('e37b4b622992267149d25437cbb75237')
GROUP BY retention_date, event_name, retention_uid)
ON first_uid = retention_uid)
GROUP BY first_open_date, country, event_name, date_diff
HAVING date_diff BETWEEN 0 AND 15
ORDER BY first_open_date, country, date_diff
The load failed because the country field exceeded 20 characters and the version field exceeded 10 characters.
4.3. Alter the Table Schema
alter table slim_shred ALTER COLUMN country TYPE varchar(50);
alter table slim_shred ALTER COLUMN version TYPE varchar(20);
4.4. Re-run the Load Command
Run the COPY command again. The load completed in 22 minutes and 21 seconds.
4.5. Run a Query
Execute the following SQL. The query returned 921 rows in 59 seconds.
SELECT
first_open_date, country, event_name,
DATE_DIFF('d', retention_date, first_open_date) AS date_diff,
COUNT(DISTINCT first_uid) AS users,
COUNT(first_uid) AS events
FROM ((
SELECT
DATE(date_add('h',-8,date_add('us',event_timestamp,'1970-01-01'))) AS first_open_date,
country, user_pseudo_id AS first_uid
FROM slim_shred
WHERE event_name = '19d2da1d0d3c1cd08a318cbd5c04a3b0'
GROUP BY first_open_date, country, first_uid)
INNER JOIN (
SELECT
DATE(date_add('h',-8,date_add('us',event_timestamp,'1970-01-01'))) AS retention_date,
event_name, user_pseudo_id AS retention_uid
FROM slim_shred
WHERE event_name IN ('e37b4b622992267149d25437cbb75237')
GROUP BY retention_date, event_name, retention_uid)
ON first_uid = retention_uid)
GROUP BY first_open_date, country, event_name, date_diff
HAVING date_diff BETWEEN 0 AND 15
ORDER BY first_open_date, country, date_diff
4.6. Re-run the Same Query
Running the same query again in a new window returned results in just 7 milliseconds (cached).