Unix Technical Forum

Tools for optimizing mysql query

This is a discussion on Tools for optimizing mysql query within the MySQL forums, part of the Database Server Software category; --> I have googled a lot, but couldn't find it. But, I hope that there will be a tool for ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 07:19 AM
R. Rajesh Jeba Anbiah
 
Posts: n/a
Default Tools for optimizing mysql query

I have googled a lot, but couldn't find it. But, I hope that there
will be a tool for query optimization (a tool that can automatically
detect the flaw in the query and suggest rewriting). If anyone of you
know any tools, kindly post here. TIA

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 07:19 AM
Markus Popp
 
Posts: n/a
Default Re: Tools for optimizing mysql query

Use the EXPLAIN keyword in front of your SELECT statements - that tell's you
exactly how MySQL executes the query.

Markus


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 07:19 AM
R. Rajesh Jeba Anbiah
 
Posts: n/a
Default Re: Tools for optimizing mysql query

Markus Popp wrote:
> Use the EXPLAIN keyword in front of your SELECT statements - that tell's you
> exactly how MySQL executes the query.


Thanks for your advice. I know, EXPLAIN.. but what I'm looking for
is a tool that can automatically optimize query statements.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 07:19 AM
Axel Schwenke
 
Posts: n/a
Default Re: Tools for optimizing mysql query

"R. Rajesh Jeba Anbiah" <ng4rrjanbiah@rediffmail.com> wrote:
> Markus Popp wrote:
>> Use the EXPLAIN keyword in front of your SELECT statements - that tell's you
>> exactly how MySQL executes the query.

>
> Thanks for your advice. I know, EXPLAIN.. but what I'm looking for
> is a tool that can automatically optimize query statements.


This "tool" is named BRAIN and it's installed on all of the HUMAN
hardware on delivery. However it needs training to master some of
the more complex tasks.

SCNR


XL
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 07:19 AM
Bill Karwin
 
Posts: n/a
Default Re: Tools for optimizing mysql query

"R. Rajesh Jeba Anbiah" <ng4rrjanbiah@rediffmail.com> wrote in message
news:1139018189.443513.81980@g44g2000cwa.googlegro ups.com...
> what I'm looking for is a tool that can automatically optimize query
> statements.


Optimizing queries is a combination of choosing the right SQL syntax,
clearly, but also depends heavily on choices in the database schema and
server configuration. You can often get some improvement from changing SQL
query syntax, but much more improvement from adding indexes, or redesigning
the relationships between tables. You can also improve performance
dramatically through choices in MySQL configuration, including resizing
server-side caches, choices between storage engines, etc. Even hardware
choices on the server host can be more important than optimizing SQL syntax.

The best choices for performance also depend on how you need to use the
database. For instance, you might gain a lot of benefit from using MySQL's
query cache (http://dev.mysql.com/doc/refman/5.0/...ry-cache.html), but
only if you use certain types of queries and if the database is unchanging
most of the time. This is something that a query analyzer tool would not be
able to know.

There's a whole chapter in the MySQL documentation about improving
performance. Only some of the suggestions have to do with query syntax.
You should read the whole chapter if you are tasked with designing
high-performance applications with MySQL.
http://dev.mysql.com/doc/refman/5.0/...imization.html

I also advise people on matters of performance improvement to be sure they
are addressing the right part of the problem. The database queries may not
be the bottleneck in your system at all.

For example, once I was asked to "speed up the database" in a web
application. After running the application in a profiler, I found that the
app was spending 80% of its processing time parsing its generated HTML to
auto-populate form fields. The processing time for database operations was
insignificant in comparison.

Regards,
Bill K.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 07:20 AM
R. Rajesh Jeba Anbiah
 
Posts: n/a
Default Re: Tools for optimizing mysql query

Bill Karwin wrote:
> "R. Rajesh Jeba Anbiah" <ng4rrjanbiah@rediffmail.com> wrote in message
> news:1139018189.443513.81980@g44g2000cwa.googlegro ups.com...
> > what I'm looking for is a tool that can automatically optimize query
> > statements.


<snip>
> You can often get some improvement from changing SQL
> query syntax, but much more improvement from adding indexes, or redesigning
> the relationships between tables. You can also improve performance
> dramatically through choices in MySQL configuration, including resizing
> server-side caches, choices between storage engines, etc.

<snip lot of great info>

Thanks for your generous lengthy response. I have some knowledge on
optimization as I have already gone through the manual, optimization
articles and "High performance MySQL" by Jeremy et al.

What I realised is that if there is a tool to suggest rewriting of
queries, it would help junior or even programmers. Say, an OR
condition in query might ignore any index and will result in complete
table scan--the workaround is to use UNION. So, if there is any such
tool to suggest such things or even automatically rewrite such queries
and could compare the difference, it will be of great help. I'd thought
there must be such tool exist; but unfortunately, it doesn't seem so.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-28-2008, 07:20 AM
R. Rajesh Jeba Anbiah
 
Posts: n/a
Default Re: Tools for optimizing mysql query

Bill Karwin wrote:
> "R. Rajesh Jeba Anbiah" <ng4rrjanbiah@rediffmail.com> wrote in message
> news:1139018189.443513.81980@g44g2000cwa.googlegro ups.com...
> > what I'm looking for is a tool that can automatically optimize query
> > statements.


<snip>
> You can often get some improvement from changing SQL
> query syntax, but much more improvement from adding indexes, or redesigning
> the relationships between tables. You can also improve performance
> dramatically through choices in MySQL configuration, including resizing
> server-side caches, choices between storage engines, etc.

<snip lot of great info>

Thanks for your generous lengthy response. I have some knowledge on
optimization as I have already gone through the manual, optimization
articles and "High performance MySQL" by Jeremy et al.

What I realised is that if there is a tool to suggest rewriting of
queries, it would help junior or even programmers. Say, an OR
condition in query might ignore any index and will result in complete
table scan--the workaround is to use UNION. So, if there is any such
tool to suggest such things or even automatically rewrite such queries
and could compare the difference, it will be of great help. I'd thought
there must be such tool exist; but unfortunately, it doesn't seem so.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-28-2008, 07:20 AM
R. Rajesh Jeba Anbiah
 
Posts: n/a
Default Re: Tools for optimizing mysql query

Bill Karwin wrote:
> "R. Rajesh Jeba Anbiah" <ng4rrjanbiah@rediffmail.com> wrote in message
> news:1139018189.443513.81980@g44g2000cwa.googlegro ups.com...
> > what I'm looking for is a tool that can automatically optimize query
> > statements.


<snip>
> You can often get some improvement from changing SQL
> query syntax, but much more improvement from adding indexes, or redesigning
> the relationships between tables. You can also improve performance
> dramatically through choices in MySQL configuration, including resizing
> server-side caches, choices between storage engines, etc.

<snip lot of great info>

Thanks for your generous lengthy response. I have some knowledge on
optimization as I have already gone through the manual, optimization
articles and "High performance MySQL" by Jeremy et al.

What I realised is that if there is a tool to suggest rewriting of
queries, it would help junior or even programmers. Say, an OR
condition in query might ignore any index and will result in complete
table scan--the workaround is to use UNION. So, if there is any such
tool to suggest such things or even automatically rewrite such queries
and could compare the difference, it will be of great help. I'd thought
there must be such tool exist; but unfortunately, it doesn't seem so.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-28-2008, 07:20 AM
Gordon Burditt
 
Posts: n/a
Default Re: Tools for optimizing mysql query

> Thanks for your generous lengthy response. I have some knowledge on
>optimization as I have already gone through the manual, optimization
>articles and "High performance MySQL" by Jeremy et al.
>
> What I realised is that if there is a tool to suggest rewriting of
>queries, it would help junior or even programmers. Say, an OR
>condition in query might ignore any index and will result in complete
>table scan--the workaround is to use UNION. So, if there is any such
>tool to suggest such things or even automatically rewrite such queries
>and could compare the difference, it will be of great help. I'd thought
>there must be such tool exist; but unfortunately, it doesn't seem so.


You really can't optimize one query. You need to collectively
optimize all of them together. You can make one query which you
use once a year at tax time faster by adding an index or two which
slows down every insert, which might be done at the rate of thousands
an hour. There is a good chance that adding the index is *NOT* a
good tradeoff for overall performance.

If it *is* possible to just re-write one query, as in the example
above with OR vs. UNION, wouldn't it be a good idea to put this
code in the server?

Gordon L. Burditt
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-28-2008, 07:20 AM
R. Rajesh Jeba Anbiah
 
Posts: n/a
Default Re: Tools for optimizing mysql query

Gordon Burditt wrote:
<snip>
> You really can't optimize one query. You need to collectively
> optimize all of them together. You can make one query which you
> use once a year at tax time faster by adding an index or two which
> slows down every insert, which might be done at the rate of thousands
> an hour. There is a good chance that adding the index is *NOT* a
> good tradeoff for overall performance.


Yes. But, what am I expecting in the case of optimization is
"something is better than nothing" logic.

> If it *is* possible to just re-write one query, as in the example
> above with OR vs. UNION, wouldn't it be a good idea to put this
> code in the server?


Yup.. :-)

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:09 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com