I’m a beginner in data structures and algorithms, and I’m not sure how to apply them in practice to specific problems. I want to query book_name & user_id, as well as VP and UV, and I’ve used multi-layer nested subqueries. Although the logic is fine, the time complexity is too high. How should I solve this?
SELECT
Q.book_name,
Q.user_id,
total_vp.VP,
total_uv.UV
FROM
(
SELECT*
FROM
(
SELECT
user_id,
ext_map['book_name'] AS book_name,
ext_map['strategy_name'] AS strategy_name
FROM
dws.dws_clt_video_event_log_simple_hour
WHERE
dt = '02024060700'
LIMIT 1000
) AS q
WHERE (q.strategy_name = 'foru-base' OR q.strategy_name = 'foru-test1')
) Q
INNER JOIN (
SELECT
ext_map['book_name'] AS book_name,
COUNT(*) AS VP
FROM
dws.dws_clt_video_event_log_simple_hour
GROUP BY
ext_map['book_name']
) AS total_vp
ON Q.book_name = total_vp.book_name
INNER JOIN (
SELECT
ext_map['book_name'] AS book_name,
COUNT(DISTINCT user_id) AS UV
FROM
dws.dws_clt_video_event_log_simple_hour
GROUP BY
ext_map['book_name']
) AS total_uv
ON Q.book_name = total_uv.book_name
I hope to be able to get the results within ten minutes, but I don’t know how to operate.
INFO : 2024-06-11 19:01:48,721 Stage-25_0: 45/45 Finished Stage-26_0: 1417(+8)/25125 Stage-27_0: 0/25125 Stage-28_0: 0/2199 Stage-29_0: 0/1099
INFO : 2024-06-11 19:01:49,723 Stage-25_0: 45/45 Finished Stage-26_0: 1418(+8)/25125 Stage-27_0: 0/25125 Stage-28_0: 0/2199 Stage-29_0: 0/1099
user24147317 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.