不会慢吧 视图还是转化成事实表的select * from (select * from A union all select * from B) tmp where tmp.C=xxx; 这个慢吗
是的,非常慢。 单独查秒杀,用了union all 要十多秒
explain显示没有使用到索引!
你用的SQL语句是什么? 贴出以供分析。
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `view_c` AS select C,c1 from A union all select C,C2 from B A、B为物理表且字段C都有索引 select *from view_c where C=xxx 使用这个语句时速度非常慢
select C,c1 from A where C=xxx union all select C,C2 from B where C=xxx看一下速度如何。 另外贴出 show index from A; show index from B; explain select *from view_c where C=xxx;以供分析。
show index from A; show index from B; explain select *from view_c where C=xxx; 以供分析。 另外请贴文本,不要贴图。
(select * from A union all select * from B) tmp
where tmp.C=xxx;
这个慢吗
select *from view_c where C=xxx
使用这个语句时速度非常慢
union all
select C,C2 from B where C=xxx看一下速度如何。
另外贴出
show index from A;
show index from B;
explain select *from view_c where C=xxx;以供分析。
另外请贴文本,不要贴图。