diff --git a/updates/36/36017/ud/ddlview.sql b/updates/36/36017/ud/ddlview.sql index 75ea08a06..8dd7890ed 100644 --- a/updates/36/36017/ud/ddlview.sql +++ b/updates/36/36017/ud/ddlview.sql @@ -147,10 +147,11 @@ WITH FROM plan_psector_x_node pp JOIN selector_psector sp ON sp.cur_user = current_user AND sp.psector_id = pp.psector_id ), - node_state AS + node_selector AS ( - SELECT n.node_id - FROM node n + SELECT node.node_id + FROM node + JOIN selector_expl se ON (se.cur_user =current_user AND se.expl_id = node.expl_id) or (se.cur_user = current_user AND se.expl_id = node.expl_id2) JOIN selector_state s ON s.cur_user =current_user AND n.state =s.state_id left JOIN (SELECT node_id FROM node_psector WHERE p_state = 0) a using (node_id) where a.node_id is null union all @@ -266,9 +267,6 @@ WITH node.serial_number FROM node_state nn join node using (node_id) - JOIN selector_expl se ON se.cur_user =current_user AND se.expl_id IN (node.expl_id, node.expl_id2) - --JOIN selector_sector ss ON ss.cur_user = current_user AND ss.sector_id =node.sector_id - --JOIN selector_municipality sm ON sm.cur_user = current_user AND sm.muni_id =node.muni_id JOIN cat_node ON node.nodecat_id::text = cat_node.id::text JOIN cat_feature ON cat_feature.id::text = node.node_type::text JOIN exploitation ON node.expl_id = exploitation.expl_id @@ -311,10 +309,11 @@ AS WITH FROM plan_psector_x_arc pp JOIN selector_psector sp ON sp.cur_user = CURRENT_USER AND sp.psector_id = pp.psector_id ), - arc_state AS + arc_selector AS ( SELECT arc.arc_id FROM arc + JOIN selector_expl se ON ((se.cur_user = CURRENT_USER AND se.expl_id = arc.expl_id) OR (se.cur_user = CURRENT_USER and se.expl_id = arc.expl_id2)) JOIN selector_state s ON s.cur_user = CURRENT_USER AND arc.state = s.state_id left JOIN (SELECT arc_id FROM arc_psector WHERE p_state = 0) a using (arc_id) where a.arc_id is null union all @@ -476,11 +475,8 @@ AS WITH arc.brand_id, arc.model_id, arc.serial_number - FROM arc_state - join arc using (arc_id) - JOIN selector_expl se ON se.cur_user =current_user AND se.expl_id IN (arc.expl_id, arc.expl_id2) - --JOIN selector_municipality sm ON sm.cur_user = current_user AND sm.muni_id =arc.muni_id - JOIN selector_sector ss ON ss.cur_user = current_user AND ss.sector_id = arc.sector_id + FROM arc_selector + JOIN arc using (arc_id) JOIN cat_arc ON arc.arccat_id::text = cat_arc.id::text JOIN cat_feature ON arc.arc_type::text = cat_feature.id::text JOIN exploitation e on e.expl_id = arc.expl_id @@ -534,9 +530,10 @@ with FROM plan_psector_x_connec pp JOIN selector_psector sp ON sp.cur_user = current_user AND sp.psector_id = pp.psector_id ), - connec_state AS + connec_selector AS ( SELECT connec_id, arc_id FROM connec c + JOIN selector_expl se ON (se.cur_user =current_user AND se.expl_id = connec.expl_id) or (se.cur_user =current_user and se.expl_id = connec.expl_id2) JOIN selector_state ss ON ss.cur_user =current_user AND c.state =ss.state_id left join (SELECT connec_id, arc_id::varchar(16) FROM connec_psector WHERE p_state = 0) a using (connec_id, arc_id) where a.connec_id is null union all @@ -658,11 +655,8 @@ with connec.plot_code, connec.placement_type, connec.access_type - FROM connec_state nn - JOIN connec ON connec.connec_id = nn.connec_id - JOIN selector_expl se ON se.cur_user =current_user AND se.expl_id IN (connec.expl_id, connec.expl_id2) - --JOIN selector_municipality sm ON sm.cur_user = current_user AND sm.muni_id =connec.muni_id - JOIN selector_sector ss ON ss.cur_user = current_user AND ss.sector_id =connec.sector_id + FROM connec_state + JOIN connec USING (connec_id) JOIN cat_connec ON cat_connec.id::text = connec.connecat_id::text JOIN cat_feature ON cat_feature.id::text = connec.connec_type::text JOIN exploitation ON connec.expl_id = exploitation.expl_id @@ -721,9 +715,10 @@ with FROM plan_psector_x_gully pp JOIN selector_psector sp ON sp.cur_user = current_user AND sp.psector_id = pp.psector_id ), - gully_state AS + gully_selector AS ( SELECT gully_id, arc_id FROM gully g + JOIN selector_expl se ON (se.cur_user = current_user AND se.expl_id=gully.expl_id) OR se.cur_user = current_user AND se.expl_id=gully.expl_id2) JOIN selector_state ss ON ss.cur_user =current_user AND g.state =ss.state_id left join (SELECT gully_id, arc_id::varchar(16) FROM gully_psector WHERE p_state = 0) a using (gully_id, arc_id) where a.gully_id is null union all @@ -867,9 +862,6 @@ with gully.the_geom FROM inp_network_mode, gully_state nn JOIN gully ON gully.gully_id = nn.gully_id - JOIN selector_expl se ON se.cur_user =current_user AND se.expl_id IN (gully.expl_id, gully.expl_id2) - --JOIN selector_sector ss ON ss.cur_user = current_user AND ss.sector_id =arc.sector_id - JOIN selector_municipality sm ON sm.cur_user = current_user AND sm.muni_id =gully.muni_id JOIN cat_grate ON gully.gratecat_id::text = cat_grate.id::text JOIN exploitation ON gully.expl_id = exploitation.expl_id JOIN cat_feature ON gully.gully_type::text = cat_feature.id::text @@ -928,8 +920,7 @@ WITH SELECT l.link_id FROM link l JOIN selector_state s ON s.cur_user =current_user AND l.state =s.state_id - JOIN selector_sector se ON se.cur_user =current_user AND l.sector_id =se.sector_id - WHERE NOT EXISTS (SELECT link_id FROM link_psector WHERE p_state = 0) + left join (SELECT link_id FROM link_psector WHERE p_state = 0) a using (link_id) where a.link_id is null UNION ALL SELECT link_id FROM link_psector WHERE p_state = 1 ), @@ -971,9 +962,7 @@ WITH l.uncertain from inp_network_mode, link_state JOIN link l using (link_id) - JOIN selector_expl se ON se.cur_user =current_user AND se.expl_id IN (l.expl_id, l.expl_id2) - JOIN selector_sector ss ON ss.cur_user = current_user AND ss.sector_id =l.sector_id - --JOIN selector_municipality sm ON sm.cur_user = current_user AND sm.muni_id =l.muni_id + JOIN selector_expl se ON (se.cur_user =current_user AND se.expl_id = l.expl_id) OR (se.cur_user =current_user AND se.expl_id = l.expl_id2) JOIN exploitation ON l.expl_id = exploitation.expl_id JOIN ext_municipality mu ON l.muni_id = mu.muni_id JOIN sector_table ON l.sector_id = sector_table.sector_id diff --git a/updates/36/36017/utils/tablect.sql b/updates/36/36017/utils/tablect.sql index c6bbd8199..92f297adf 100644 --- a/updates/36/36017/utils/tablect.sql +++ b/updates/36/36017/utils/tablect.sql @@ -18,4 +18,6 @@ CREATE INDEX node_streetname2 ON node USING btree (streetname2); CREATE INDEX connec_streetname ON connec USING btree (streetname); CREATE INDEX connec_streetname2 ON connec USING btree (streetname2); +CREATE INDEX link_expl_id2 ON link USING btree (expl_id2); + diff --git a/updates/36/36017/ws/ddlview.sql b/updates/36/36017/ws/ddlview.sql index c19e13b42..77b147312 100644 --- a/updates/36/36017/ws/ddlview.sql +++ b/updates/36/36017/ws/ddlview.sql @@ -132,12 +132,13 @@ WITH FROM plan_psector_x_node pp JOIN selector_psector sp ON sp.cur_user = current_user AND sp.psector_id = pp.psector_id ), - node_state AS + node_selector AS ( - SELECT n.node_id - FROM node n - JOIN selector_state s ON s.cur_user =current_user AND n.state =s.state_id - left JOIN (SELECT node_id FROM node_psector WHERE p_state = 0) a using (node_id) where a.node_id is null + SELECT node_id + FROM node + JOIN selector_expl se ON (se.cur_user =current_user AND se.expl_id = node.expl_id) or (se.cur_user = current_user AND se.expl_id = node.expl_id2) + JOIN selector_state s ON s.cur_user =current_user AND node.state =s.state_id + LEFT JOIN (SELECT node_id FROM node_psector WHERE p_state = 0) a using (node_id) where a.node_id is null union all SELECT node_id FROM node_psector WHERE p_state = 1 ), @@ -264,11 +265,8 @@ WITH END AS inp_type, m.closed as closed_valve, m.broken as broken_valve - FROM node_state nn - JOIN node ON node.node_id = nn.node_id - JOIN selector_expl se ON se.cur_user =current_user AND se.expl_id IN (node.expl_id, node.expl_id2) - --JOIN selector_municipality sm ON sm.cur_user = current_user AND sm.muni_id =node.muni_id - --JOIN selector_sector ss ON ss.cur_user = current_user AND ss.sector_id = node.sector_id + FROM node_selector + JOIN node ON node.node_id = node_selector.node_id JOIN cat_node ON cat_node.id::text = node.nodecat_id::text JOIN cat_feature ON cat_feature.id::text = cat_node.nodetype_id::text JOIN value_state_type vst ON vst.id = node.state_type @@ -279,7 +277,7 @@ WITH LEFT JOIN dma_table ON dma_table.dma_id = node.dma_id LEFT JOIN dqa_table ON dqa_table.dqa_id = node.dqa_id LEFT JOIN node_add e ON e.node_id::text = node.node_id::text - LEFT JOIN man_valve m ON m.node_id = nn.node_id + LEFT JOIN man_valve m ON m.node_id = node.node_id ) SELECT n.* FROM node_selected n; @@ -319,10 +317,11 @@ AS WITH FROM plan_psector_x_arc pp JOIN selector_psector sp ON sp.cur_user = CURRENT_USER AND sp.psector_id = pp.psector_id ), - arc_state AS + arc_selector AS ( SELECT arc.arc_id - FROM arc + FROM arc + JOIN selector_expl se ON ((se.cur_user = CURRENT_USER AND se.expl_id = arc.expl_id) OR (se.cur_user = CURRENT_USER and se.expl_id = arc.expl_id2)) JOIN selector_state s ON s.cur_user = CURRENT_USER AND arc.state = s.state_id left JOIN (SELECT arc_id FROM arc_psector WHERE p_state = 0) a using (arc_id) where a.arc_id is null union all @@ -447,11 +446,8 @@ AS WITH WHEN arc.sector_id > 0 AND vst.is_operative = true AND arc.epa_type::text <> 'UNDEFINED'::character varying(16)::text THEN arc.epa_type ELSE NULL::character varying(16) END AS inp_type - FROM arc_state nn - JOIN arc ON arc.arc_id::text = nn.arc_id::text - JOIN selector_expl se ON se.cur_user = CURRENT_USER AND (se.expl_id = arc.expl_id OR se.expl_id = arc.expl_id2) - --JOIN selector_municipality sm ON sm.cur_user = CURRENT_USER AND sm.muni_id = arc.muni_id - --JOIN selector_sector ss ON ss.cur_user = current_user AND ss.sector_id = arc.sector_id + FROM arc_selector + JOIN arc ON arc.arc_id::text = arc_selector.arc_id::text JOIN cat_arc ON cat_arc.id::text = arc.arccat_id::text JOIN cat_feature ON cat_feature.id::text = cat_arc.arctype_id::text JOIN exploitation ON arc.expl_id = exploitation.expl_id @@ -519,10 +515,12 @@ WITH FROM plan_psector_x_connec pp JOIN selector_psector sp ON sp.cur_user = current_user AND sp.psector_id = pp.psector_id ), - connec_state AS + connec_selector AS ( - SELECT connec_id, arc_id FROM connec c - JOIN selector_state ss ON ss.cur_user =current_user AND c.state =ss.state_id + SELECT connec_id, arc_id + FROM connec + JOIN selector_expl se ON (se.cur_user =current_user AND se.expl_id = connec.expl_id) or (se.cur_user =current_user and se.expl_id = connec.expl_id2) + JOIN selector_state ss ON ss.cur_user =current_user AND connec.state =ss.state_id left join (SELECT connec_id, arc_id FROM connec_psector WHERE p_state = 0) a using (connec_id, arc_id) where a.connec_id is null union all SELECT connec_id, arc_id::varchar(16) FROM connec_psector WHERE p_state = 1 @@ -721,11 +719,8 @@ WITH date_trunc('second'::text, connec.lastupdate) AS lastupdate, connec.lastupdate_user, connec.the_geom - FROM inp_network_mode, connec_state nn + FROM inp_network_mode, connec_selector nn JOIN connec ON connec.connec_id = nn.connec_id - JOIN selector_expl se ON se.cur_user =current_user AND se.expl_id IN (connec.expl_id, connec.expl_id2) - --JOIN selector_sector ss ON ss.cur_user = current_user AND ss.sector_id =connec.sector_id - --JOIN selector_municipality sm ON sm.cur_user = current_user AND sm.muni_id =connec.muni_id JOIN cat_connec ON cat_connec.id::text = connec.connecat_id::text JOIN cat_feature ON cat_feature.id::text = cat_connec.connectype_id::text JOIN exploitation ON connec.expl_id = exploitation.expl_id @@ -782,7 +777,7 @@ WITH FROM plan_psector_x_connec pp JOIN selector_psector sp ON sp.cur_user = current_user AND sp.psector_id = pp.psector_id ), - link_state AS + link_selector as ( SELECT l.link_id FROM link l @@ -790,7 +785,7 @@ WITH left join (SELECT link_id FROM link_psector WHERE p_state = 0) a using (link_id) where a.link_id is null UNION ALL SELECT link_id FROM link_psector WHERE p_state = 1 - ), + ), link_selected as ( SELECT l.link_id, @@ -841,11 +836,9 @@ WITH THEN l.epa_type::character varying ELSE NULL::character varying(16) END AS inp_type - FROM inp_network_mode, link_state + FROM inp_network_mode, link_selector JOIN link l using (link_id) - JOIN selector_expl se ON se.cur_user =current_user AND se.expl_id IN (l.expl_id, l.expl_id2) - -- JOIN selector_sector ss ON ss.cur_user = current_user AND ss.sector_id = l.sector_id - --JOIN selector_municipality sm ON sm.cur_user = current_user AND sm.muni_id =l.muni_id + JOIN selector_expl se ON ((se.cur_user =current_user AND se.expl_id = l.expl_id) or (se.cur_user =current_user AND se.expl_id = l.expl_id2)) JOIN sector_table ON sector_table.sector_id = l.sector_id LEFT JOIN presszone_table ON presszone_table.presszone_id = l.presszone_id LEFT JOIN dma_table ON dma_table.dma_id = l.dma_id