If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Query optimization

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-23-04, 07:59
sanghmitra sanghmitra is offline
Registered User
 
Join Date: Feb 2004
Location: Bangalore
Posts: 5
Query optimization

Hi,

Any help, how to optimize the last query -

The tables on which the query is based on are as follows:
CREATE TABLE `if_srcport` (
`input_if` tinyint(3) unsigned default NULL,
`output_if` tinyint(3) unsigned default NULL,
`port` smallint(5) unsigned default NULL,
`pkts` int(10) unsigned default NULL,
`bytes` int(10) unsigned default NULL,
`flows` int(10) unsigned default NULL,
`time` datetime default NULL,
`routerip` varchar(15) default NULL
);


CREATE TABLE port (
proto TINYINT UNSIGNED NOT NULL,
port SMALLINT UNSIGNED,
name VARCHAR(255)
);



Query:

SELECT if_srcport.srcport,sum(if_srcport.pkts) pkts,sum(if_srcport.bytes) bytes,sum(if_srcport.flows) flows,port.name
FROM if_srcport left outer join port on if_srcport.srcport=port.port
WHERE if_srcport.routerip='202.3.75.249' and if_srcport.input_if=1
GROUP BY if_srcport.srcport
ORDER BY bytes DESC LIMIT 10;

But the problem is that this query is taking too much time.

Thanks
Reply With Quote
  #2 (permalink)  
Old 09-23-04, 08:39
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
alter table if_srcport add index (port), add index (routerip, input_if)
alter table port add index (port);

p.s. your GROUP BY should be GROUP BY if_srcport.srcport, port.name

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 09-23-04, 11:59
sanghmitra sanghmitra is offline
Registered User
 
Join Date: Feb 2004
Location: Bangalore
Posts: 5
Actually, I can not do schema change! Can I not optimize the query by modifying the query?

Thanks a lot.
Reply With Quote
  #4 (permalink)  
Old 09-23-04, 12:19
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by sanghmitra
Can I not optimize the query by modifying the query?
no, it's already optimized
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On