id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY <derived2> ALL \N \N \N \N 77561 Using where 2 DERIVED a ALL \N \N \N \N 40329 3 UNION c ALL \N \N \N \N 36832 \N UNION RESULT <union2,3> ALL \N \N \N \N \N
视图分2种 1:create view v1 as select id,name from a union all select id,name from b;这样没有对原表有统计信息的,视图是原表数据的,那么就可以用到原表的索引2:create view v2 as select id,sum(grade) as grade from a union ... 用到了统计函数的,就不能用到原表的索引。
你的create view 语句是什么?
视图语句是 create view v1 as select id,name from a union all select id,name from b; 把2个表中我想要的数据 存到一个视图里面查询语句是 select * from v1 where id=?这样查询 既不会查询a表的索引。也不会用b表的索引
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL \N \N \N \N 77561 Using where
2 DERIVED a ALL \N \N \N \N 40329
3 UNION c ALL \N \N \N \N 36832
\N UNION RESULT <union2,3> ALL \N \N \N \N \N
视图分2种
1:create view v1 as select id,name from a union all select id,name from b;这样没有对原表有统计信息的,视图是原表数据的,那么就可以用到原表的索引2:create view v2 as select id,sum(grade) as grade from a union ...
用到了统计函数的,就不能用到原表的索引。
视图语句是
create view v1 as select id,name from a union all select id,name from b;
把2个表中我想要的数据 存到一个视图里面查询语句是
select * from v1 where id=?这样查询 既不会查询a表的索引。也不会用b表的索引