个页面 (商业数据不能显示)
有大概7个左右分组查询语句 。(打开页面的时候,会出现6组数据 ,
每组数据都是select coun(*) ,sum(*) from a, b, c where . . group by a.id order by )
mysql 不是非常支持 group by 。 这样导致缓慢 。
7个sql例 : SELECT U.Id, A.curre,sum(A.blnce) Total FROM Account A,User U where A.userId=U.id group by U.pa我的初步想法是这些分组 sql 分别建立视图,
之后页面直接调用view。 不知可行否?
有大概7个左右分组查询语句 。(打开页面的时候,会出现6组数据 ,
每组数据都是select coun(*) ,sum(*) from a, b, c where . . group by a.id order by )
mysql 不是非常支持 group by 。 这样导致缓慢 。
7个sql例 : SELECT U.Id, A.curre,sum(A.blnce) Total FROM Account A,User U where A.userId=U.id group by U.pa我的初步想法是这些分组 sql 分别建立视图,
之后页面直接调用view。 不知可行否?
FROM Account A,User U
where A.userId=U.id
group by U.Id, A.curre,U.pa如果只是这两个表的联接查询,假设索引设置没有问题的话,应该速度不会慢的。
user的id是主键 ,他还需要建立索引吗 ?(索引里没有看到id)
SELECT U.Id, A.curre,U.pa,sum(A.blnce) Total
FROM Account A,User U
where A.userId=U.id
group by U.Id, A.curre,U.pa;用EXPLAIN看一下执行计划,另外看一下两个表的索引。
show index from table1;
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+--------------------------+--------------------------+---------+-------------------+-------+---------------------------------+
| 1 | SIMPLE | U | ALL | PRIMARY | NULL | NULL | NULL | 39941 | Using temporary; Using filesort |
| 1 | SIMPLE | A | ref | idx_accountEntity_userid | idx_accountEntity_userid | 4 | U.id | 1 | Using where |
+----+-------------+-------+------+--------------------------+--------------------------+---------+-------------------+-------+---------------------------------+
(主键好像没有必要再建立索引了吧???)
userId 在A表中也是唯一的?主键本身就是索引。