performance - mysql improve view with subquery -
i need compare rows in same column, have following mysql query works giving expected result.
select x.aord, x.anode parent, x.bnode child (select a.ordinal aord, a.id_dt_graph_node_edge aid, a.id_dt_graph_node anode, b.ordinal bord, b.id_dt_graph_node_edge bid, b.id_dt_graph_node bnode dt_graph_node_edge join dt_graph_node_edge b on a.ordinal < b.ordinal) x left join (select a.ordinal aord, a.id_dt_graph_node_edge aid, a.id_dt_graph_node anode, b.ordinal bord, b.id_dt_graph_node_edge bid, b.id_dt_graph_node bnode dt_graph_node_edge join dt_graph_node_edge b on a.ordinal < b.ordinal) y on x.aord = y.aord , x.bord > y.bord y.bord null order x.aord, x.bord
i found it's impossible create view on query due error #1349. can suggest better way make such query, special focus on speed, query slow. thanks.
the reason why cannot create view
query because contains subquery on it. view
, according on docs, cannot contains subquery in select
query. workaround create view
first on subquery, example
create view firstsubquery select a.ordinal aord, a.id_dt_graph_node_edge aid, a.id_dt_graph_node anode, b.ordinal bord, b.id_dt_graph_node_edge bid, b.id_dt_graph_node bnode dt_graph_node_edge join dt_graph_node_edge b on a.ordinal < b.ordinal; create view secondsubquery select a.ordinal aord, a.id_dt_graph_node_edge aid, a.id_dt_graph_node anode, b.ordinal bord, b.id_dt_graph_node_edge bid, b.id_dt_graph_node bnode dt_graph_node_edge join dt_graph_node_edge b on a.ordinal < b.ordinal;
and join newly created view
on current query,
create view finalview select x.aord, x.anode parent, x.bnode child firstsubquery x left join secondsubquery y on x.aord = y.aord , x.bord > y.bord y.bord null order x.aord, x.bord
ps: views in mysql horrible
Comments
Post a Comment