From 1097ce5fceb02665f8d005750cb22e0d58de3e67 Mon Sep 17 00:00:00 2001 From: William Perron Date: Sun, 7 Jan 2024 12:59:59 -0500 Subject: [PATCH] use table instead of view for better perf --- availability.sql | 6 ------ .../20240107175720_update_claimables.down.sql | 15 +++++++++++++++ .../20240107175720_update_claimables.up.sql | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) delete mode 100644 availability.sql create mode 100644 migrations/20240107175720_update_claimables.down.sql create mode 100644 migrations/20240107175720_update_claimables.up.sql diff --git a/availability.sql b/availability.sql deleted file mode 100644 index d86d4c8..0000000 --- a/availability.sql +++ /dev/null @@ -1,6 +0,0 @@ -SELECT count(distinct name) -FROM claimables -LEFT JOIN claims ON claimables.name = claims.val AND claimables.typ = claims.claim_type -WHERE claims.val IS NULL -AND claimables.typ = 'area' -AND claimables.name LIKE '%bay%'; diff --git a/migrations/20240107175720_update_claimables.down.sql b/migrations/20240107175720_update_claimables.down.sql new file mode 100644 index 0000000..c634686 --- /dev/null +++ b/migrations/20240107175720_update_claimables.down.sql @@ -0,0 +1,15 @@ +drop table claimables; +create view if not exists claimables as + with + trades as (select distinct trade_node from provinces where trade_node != ''), + areas as (select distinct area from provinces where area != ''), + regions as (select distinct region from provinces where region != '') + select 'trade' as typ, provinces.trade_node as name, name as province, id + from provinces inner join trades on trades.trade_node = provinces.trade_node + union + select 'area' as typ, provinces.area as name, name as province, id + from provinces inner join areas on areas.area = provinces.area + union + select 'region' as typ, provinces.region as name, name as province, id + from provinces inner join regions on regions.region = provinces.region +; diff --git a/migrations/20240107175720_update_claimables.up.sql b/migrations/20240107175720_update_claimables.up.sql new file mode 100644 index 0000000..e24a5c8 --- /dev/null +++ b/migrations/20240107175720_update_claimables.up.sql @@ -0,0 +1,15 @@ +drop view claimables; +create table if not exists claimables as + with + trades as (select distinct trade_node from provinces where trade_node != ''), + areas as (select distinct area from provinces where area != ''), + regions as (select distinct region from provinces where region != '') + select 'trade' as typ, provinces.trade_node as name, name as province, id + from provinces inner join trades on trades.trade_node = provinces.trade_node + union + select 'area' as typ, provinces.area as name, name as province, id + from provinces inner join areas on areas.area = provinces.area + union + select 'region' as typ, provinces.region as name, name as province, id + from provinces inner join regions on regions.region = provinces.region +;