Skip to content

Commit

Permalink
Add MV for apps dash overview
Browse files Browse the repository at this point in the history
  • Loading branch information
ddxv committed Oct 19, 2023
1 parent 2cc3cb6 commit be84d27
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions pg-ddl/db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,77 @@ ORDER BY
;


CREATE MATERIALIZED VIEW mv_app_categories AS
WITH RankedApps AS (
SELECT
*,
ROW_NUMBER() OVER(PARTITION BY store
ORDER BY
installs DESC NULLS LAST,
review_count DESC NULLS LAST
) AS rn
FROM store_apps sa
WHERE
sa.release_date >= '{my_date}'
AND crawl_result = 1
)
SELECT *
FROM RankedApps
WHERE rn <= {limit}
;


--DROP MATERIALIZED VIEW new_weekly_apps;
CREATE MATERIALIZED VIEW apps_new_weekly AS
WITH RankedApps AS (
SELECT
*,
ROW_NUMBER() OVER(PARTITION BY store
ORDER BY
installs DESC NULLS LAST,
rating_count DESC NULLS LAST
) AS rn
FROM
store_apps sa
WHERE
sa.release_date >= current_date - INTERVAL '7 days'
AND crawl_result = 1
)
SELECT
*
FROM
RankedApps
WHERE
rn <= 100
;
REFRESH MATERIALIZED VIEW apps_new_weekly ;

CREATE MATERIALIZED VIEW apps_new_monthly AS
WITH RankedApps AS (
SELECT
*,
ROW_NUMBER() OVER(PARTITION BY store
ORDER BY
installs DESC NULLS LAST,
rating_count DESC NULLS LAST
) AS rn
FROM
store_apps sa
WHERE
sa.release_date >= current_date - INTERVAL '30 days'
AND crawl_result = 1
)
SELECT
*
FROM
RankedApps
WHERE
rn <= 100
;

REFRESH MATERIALIZED VIEW apps_new_monthly ;


CREATE OR REPLACE FUNCTION public.pg_stat_statements(showtext boolean, OUT userid oid, OUT dbid oid, OUT toplevel boolean, OUT queryid bigint, OUT query text, OUT plans bigint, OUT total_plan_time double precision, OUT min_plan_time double precision, OUT max_plan_time double precision, OUT mean_plan_time double precision, OUT stddev_plan_time double precision, OUT calls bigint, OUT total_exec_time double precision, OUT min_exec_time double precision, OUT max_exec_time double precision, OUT mean_exec_time double precision, OUT stddev_exec_time double precision, OUT rows bigint, OUT shared_blks_hit bigint, OUT shared_blks_read bigint, OUT shared_blks_dirtied bigint, OUT shared_blks_written bigint, OUT local_blks_hit bigint, OUT local_blks_read bigint, OUT local_blks_dirtied bigint, OUT local_blks_written bigint, OUT temp_blks_read bigint, OUT temp_blks_written bigint, OUT blk_read_time double precision, OUT blk_write_time double precision, OUT temp_blk_read_time double precision, OUT temp_blk_write_time double precision, OUT wal_records bigint, OUT wal_fpi bigint, OUT wal_bytes numeric, OUT jit_functions bigint, OUT jit_generation_time double precision, OUT jit_inlining_count bigint, OUT jit_inlining_time double precision, OUT jit_optimization_count bigint, OUT jit_optimization_time double precision, OUT jit_emission_count bigint, OUT jit_emission_time double precision)
RETURNS SETOF record
LANGUAGE c
Expand Down

0 comments on commit be84d27

Please sign in to comment.