Performance issue with views

Performance issue with views

am 18.03.2006 05:28:05 von Ilavajuthy Palanisamy

------_=_NextPart_001_01C64A44.80476252
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Need a solution, please help.=20

Hi,=20
I have tables in the name 'flowsummary_dateformat', these tables will be
created for every 1 hour. We are using MYSQL5.0.19.=20
The table description is given below. All these tables are INNODB
tables.=20

mysql> desc flowsummary_2006_03_10_23_00_00;=20
+------------------+--------------+------+-----+---------+-- -----+=20
| Field | Type | Null | Key | Default | Extra |=20
+------------------+--------------+------+-----+---------+-- -----+=20
| id | bigint(20) | NO | PRI | 0 | |=20
| userId | bigint(20) | NO | MUL | 0 | |=20
| startTime | bigint(20) | YES | MUL | | |=20
| endTime | bigint(20) | YES | MUL | | |=20
| bytesIn | bigint(20) | YES | | | |=20
| bytesOut | bigint(20) | YES | | | |=20
| packetsIn | bigint(20) | YES | | | |=20
| packetsOut | bigint(20) | YES | | | |=20
| flowCount | bigint(20) | YES | | | |=20
| lastUpdated | bigint(20) | YES | | | |=20
| entryStatus | int(11) | YES | | | |=20
| deviceId | int(11) | NO | MUL | 0 | |=20
| deviceSpecificId | bigint(20) | NO | | 0 | |=20
| sourcePort | int(11) | YES | | | |=20
| bandwidth | bigint(20) | YES | | | |=20
| destIp | varchar(15) | YES | | | |=20
| destPort | int(11) | YES | | | |=20
| appName | varchar(255) | YES | | | |=20
| appProtocol | int(11) | YES | | | |=20
| appIdType | int(11) | YES | | | |=20
| appCategory | varchar(30) | YES | | | |=20
| flowDirection | int(11) | YES | | | |=20
+------------------+--------------+------+-----+---------+-- -----+=20
22 rows in set (0.00 sec)=20

Like this we have 73 tables of total 1.6 million records. We are
creating a view out of these 73 tables and executing a query. We found
that the view behaves inconsistent in the below mentioned two queries.=20
These queries involves join with user table which is an innodb with 2000
records.=20

Query 1 which comes in 37 secs. Create view format and the query on this
view is given below.=20

create view flowsummaryview5 as=20
(SELECT
flowsummary_2006_03_09_00_00_00.appName,flowsummary_2006_03_ 09_00_00_00.
appProtocol,flowsummary_2006_03_09_00_00_00.destPort,flowsum mary_2006_03
_09_00_00_00.destIp,SUM(flowsummary_2006_03_09_00_00_00.byte sOut) as
a1,SUM(flowsummary_2006_03_09_00_00_00.bytesIn) as
a2,SUM(flowsummary_2006_03_09_00_00_00.packetsOut) as
a3,SUM(flowsummary_2006_03_09_00_00_00.packetsIn) as
a4,MIN(flowsummary_2006_03_09_00_00_00.startTime) as
a5,MAX(flowsummary_2006_03_09_00_00_00.endTime) as
a6,COUNT(flowsummary_2006_03_09_00_00_00.userId) as a7,usr.name FROM usr
JOIN flowsummary_2006_03_09_00_00_00 ON
usr.id=3Dflowsummary_2006_03_09_00_00_00.userId WHERE
(flowsummary_2006_03_09_00_00_00.startTime>0) GROUP BY
flowsummary_2006_03_09_00_00_00.appName,flowsummary_2006_03_ 09_00_00_00.
appProtocol,flowsummary_2006_03_09_00_00_00.destPort,flowsum mary_2006_03
_09_00_00_00.destIp,usr.name)=20
UNION=20
(SELECT
flowsummary_2006_03_10_23_00_00.appName,flowsummary_2006_03_ 10_23_00_00.
appProtocol,flowsummary_2006_03_10_23_00_00.destPort,flowsum mary_2006_03
_10_23_00_00.destIp,SUM(flowsummary_2006_03_10_23_00_00.byte sOut) as
a1,SUM(flowsummary_2006_03_10_23_00_00.bytesIn) as
a2,SUM(flowsummary_2006_03_10_23_00_00.packetsOut) as
a3,SUM(flowsummary_2006_03_10_23_00_00.packetsIn) as
a4,MIN(flowsummary_2006_03_10_23_00_00.startTime) as
a5,MAX(flowsummary_2006_03_10_23_00_00.endTime) as
a6,COUNT(flowsummary_2006_03_10_23_00_00.userId) as a7,usr.name FROM usr
JOIN flowsummary_2006_03_10_23_00_00 ON
usr.id=3Dflowsummary_2006_03_10_23_00_00.userId WHERE
(flowsummary_2006_03_10_23_00_00.startTime>0) GROUP BY
flowsummary_2006_03_10_23_00_00.appName,flowsummary_2006_03_ 10_23_00_00.
appProtocol,flowsummary_2006_03_10_23_00_00.destPort,flowsum mary_2006_03
_10_23_00_00.destIp,usr.name)=20
UNION=20
..=20
..=20
Till 73 tables=20

SELECT SQL_CALC_FOUND_ROWS appName, appProtocol, destPort, destIp,
sum(a1), sum(a2), sum(a3), sum(a4), min(a5), max(a6), count(a7), name
FROM flowsummaryview5 group by appName, appProtocol, destPort, destIp,
name limit 10;=20

*/*/*/*/*/***************************************=20


Query 2 very similar to the above except the select and group by has
additional two columns 'ipAddress' and 'macAddress', this query takes
very long time (several minutes) or never returning. The view creation
and its query are given below.=20

create view flowsummaryview6 as=20
(SELECT
flowsummary_2006_03_09_00_00_00.appName,flowsummary_2006_03_ 09_00_00_00.
appProtocol,flowsummary_2006_03_09_00_00_00.destPort,flowsum mary_2006_03
_09_00_00_00.destIp,SUM(flowsummary_2006_03_09_00_00_00.byte sOut) as
a1,SUM(flowsummary_2006_03_09_00_00_00.bytesIn) as
a2,SUM(flowsummary_2006_03_09_00_00_00.packetsOut) as
a3,SUM(flowsummary_2006_03_09_00_00_00.packetsIn) as
a4,MIN(flowsummary_2006_03_09_00_00_00.startTime) as
a5,MAX(flowsummary_2006_03_09_00_00_00.endTime) as
a6,COUNT(flowsummary_2006_03_09_00_00_00.userId) as
a7,usr.name,usr.ipAddress,usr.macAddress FROM usr JOIN
flowsummary_2006_03_09_00_00_00 ON
usr.id=3Dflowsummary_2006_03_09_00_00_00.userId WHERE
(flowsummary_2006_03_09_00_00_00.startTime>0) GROUP BY
flowsummary_2006_03_09_00_00_00.appName,flowsummary_2006_03_ 09_00_00_00.
appProtocol,flowsummary_2006_03_09_00_00_00.destPort,flowsum mary_2006_03
_09_00_00_00.destIp,usr.name,usr.ipAddress,usr.macAddress)=2 0
UNION=20
(SELECT
flowsummary_2006_03_10_23_00_00.appName,flowsummary_2006_03_ 10_23_00_00.
appProtocol,flowsummary_2006_03_10_23_00_00.destPort,flowsum mary_2006_03
_10_23_00_00.destIp,SUM(flowsummary_2006_03_10_23_00_00.byte sOut) as
a1,SUM(flowsummary_2006_03_10_23_00_00.bytesIn) as
a2,SUM(flowsummary_2006_03_10_23_00_00.packetsOut) as
a3,SUM(flowsummary_2006_03_10_23_00_00.packetsIn) as
a4,MIN(flowsummary_2006_03_10_23_00_00.startTime) as
a5,MAX(flowsummary_2006_03_10_23_00_00.endTime) as
a6,COUNT(flowsummary_2006_03_10_23_00_00.userId) as
a7,usr.name,usr.ipAddress,usr.macAddress FROM usr JOIN
flowsummary_2006_03_10_23_00_00 ON
usr.id=3Dflowsummary_2006_03_10_23_00_00.userId WHERE
(flowsummary_2006_03_10_23_00_00.startTime>0) GROUP BY
flowsummary_2006_03_10_23_00_00.appName,flowsummary_2006_03_ 10_23_00_00.
appProtocol,flowsummary_2006_03_10_23_00_00.destPort,flowsum mary_2006_03
_10_23_00_00.destIp,usr.name,usr.ipAddress,usr.macAddress)=2 0
..=20
..=20
Till 73 tables=20


SELECT appName, appProtocol, destPort, destIp, sum(a1), sum(a2),
sum(a3), sum(a4), min(a5), max(a6), count(a7), name, ipAddress,
macAddress FROM flowsummaryview4 group by appName, appProtocol,
destPort, destIp, name, ipAddress, macAddress limit 10;=20

The show processlist, for the good case shows 'copy to tmp table',
'sorting'. For bad case it shows 'copy to tmp table', copy from HEAP to
MYISAM', 'Sending data' and 'sorting' and it never completes.=20

/*******************************************/=20

Also we changed all the above 73 tables to MYISAM and found the query is
faster. So we created 72 tables as MYISAM and created a MERGE out of it.
Now created a VIEW out of this merge and the remaining one INNODB table,
now the query executed on this view is also not returning. The query on
the single table takes around 7 secs and the query on the MERGE table
takes 1.50 mins, so logically the view should have taken ~2 mins, but it
is never returning.=20

Also we tried the above view creation out of 3 tables (same format) of
total 9 million records, the query returns within 2 mins.=20

It would be great if any one suggests a solution for this problem.=20

We can't cant go with MYISAM tables because the tables are getting
locked during update and the subsequent queries are waiting.=20


Ila.


------_=_NextPart_001_01C64A44.80476252--