SQL optimization newbie looking for tools/scripts [closed] - mysql

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I am new to sql query optimization and i would like to know if there is anyone can suggest a profiling and optimization tool that i can use.
I am trying to optimize queries running on mysql.
Thanks for any help.

Learn to use and understand EXPLAIN command.
Turn on slow query log and log query not using an index

Well, the first thing one should do is have MySQL describe your queries through the DESC command. This will allow you to see a detailed execution plan for the query. You should especially be interested in the columns describing what keys are used, as proper key usage can help a lot.
The way to describe a query is to simply prefix it with the DESC keyword. As an example:
DESC SELECT * FROM user WHERE name = 'foo';

Related

Most efficient Rails query method [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I've been looking into a few ways of writing efficient ActiveRecord queries and I thought I might put it out to gather a consensus on who thinks what might be best.
#page = #current_shop.pages.where(state: "home").first
At the moment, I've surmised that find_by_sql might be the best route?
Rails helpfully logs execution time for every query and a query of that form is usually quite simple. It's a dual-condition SELECT with a LIMIT applied.
find_by_sql is reserved for exceptional circumstances, not routine ones. In this case if you went the "raw query" route you might save, at best, a fraction of a millisecond. You'll also get back a raw query result, not a model, which you'll then have to do something with.
This is a classic case of premature optimization. If you have a measurable performance problem, as opposed to a suspected performance problem, then you might want to consider caching to avoid the database call entirely instead of trying to execute it slightly faster.

Strategies for understanding complicated SQL SELECT statements [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I've been trying to get my head round some very tricky SQL queries in MySQL (can range from nested queries, correlated sub queries, group concatenation, temporary tables and self joins). These are often very large and very complicated.
Recently I've been thinking of ways to try and improve the way I do this. Sometimes I try to think how a single record would be included in a dataset and follow how the keys bring together tables. Other times I think of the entire join table and mentally strip away rows according to the WHERE constraints.
Is it worthwhile looking at relational algebra to understand what is going on?
In summary, what strategies do you use for analysing large, complicated SQL queries?
For me, it was just experience. The more I had to interact with such large, complicated codes and the more questions I asked from professors, friends, coworkers, the better I came at being able to understand everything that is going on in a code.

Which of these MySQL query approach is faster? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Which of these query would be faster?
1) Complicated query with subqueries
2) Simple query without subqueries but leave the extra processing work to application
I am deciding on which approach to take. I do not have real code to test against at the moment. Can those with more experience provide the answer?
It depends on the rows in the table and the sub queries you are using. Check the manual for query optimizing.
visit http://dev.mysql.com/doc/refman/5.0/en/optimization.html

Any good boolean expression simplifiers out there? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I was refactoring old code and encountered several IF conditions that were way too complex and long and I'm certain they can be simplified. My guess is that those conditions grew so much because of later modifications.
Anyway, I was wondering if any of you know of a good online simplifier I can use. I'm not interested in any specific language, just a simplifier that would take in for example:
((A OR B) AND (!B AND C) OR C)
And give me a simplified version of the expression, if any.
I've looked at the other similar questions but none point me to a good simplifier.
Thanks.
You can try Wolfram Alpha as in this example based on your input:
http://www.wolframalpha.com/input/?i=((A%20OR%20B)%20AND%20(NOT%20B%20AND%20C)%20OR%20C)&t=crmtb01&f=rc
Try Logic Friday 1 It includes tools from the Univerity of California (Espresso and misII) and makes them usable with a GUI. You can enter boolean equations and truth tables as desired. It also features a graphical gate diagram input and output.
The minimization can be carried out two-level or multi-level. The two-level form yields a minimized sum of products. The multi-level form creates a circuit composed out of logical gates. The types of gates can be restricted by the user.
Your expression simplifies to C.
I found that The Boolean Expression Reducer is much easier to use than Logic Friday. Plus it doesn't require installation and is multi-platform (Java).
Also in Logic Friday the expression A | B just returns 3 entries in truth table; I expected 4.

Is there a good tool for MySQL that will help me optimise my queries and index settings? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I use MySQL in a fairly complex web site (PHP driven).
Ideally, there would be a tool I could use that would help me test the SQL queries I am using and suggest better table indexes that will improve performance and avoid table scans.
Failing that, something that will tell me exactly what each query is up to, so I can perform the optimisation myself.
Edit: a simple guide to understanding the output from EXPLAIN ... would also be useful.
Thank you.
Here's some info about EXPLAIN (referenced from the High Performance MySQL book from O'Reilly):
When you run an EXPLAIN on a query, it tells you everything MySQL knows about that query in the form of reports for each table involved in the query.
Each of these reports will tell you...
the ID of the table (in the query)
the table's role in a larger selection (if applicable, might just say SIMPLE if it's only one table)
the name of the table (duh)
the join type (if applicable, defaults to const)
a list of indexes on the table (or NULL if none), possible_keys
the name of the index that MySQL decided to use, key
the size of the key value (in bytes)
ref shows the cols or values used to match against the key
rows is the number of rows that MySQL thinks it needs to examine in order to satisfy the query. This should be kept as close to your calculated minimum as possible!
...then any extra information MySQL wishes to convey
The book is completely awesome at providing information like this, so if you haven't already, get your boss to sign off on a purchase.
Otherwise, I hope some more knowledgeable SO user can help :)
As a simplest thing, enable Slow Query Log and see what queries are slow, then try to analyze them as suggested.
EverSQL
https://www.eversql.com
It will analyse your slow queries and generate indexes and give you some tips.
There are probably query analzers out there, but for a simple first cut at it
use the mysql command line, and type "explain select * from foo where bar = 'abc'". Make sure your most common queries are using indexes, try to avoid sequential scans or sorts of big tables.
You should look into Maatkit, which is an open source toolkit for doing all sorts of MySQL tasks. Without more information about precisely what you're trying to tune, it's hard to tell you which tools you'd be using and how, but the documentation is excellent and it covers a lot of applications.
The tool I use for the rest of my sql tweaking (SQLyog) has a new version that includes a profiler, which is awesome! (I don't work for them - I just use their product)
http://www.webyog.com/en/screenshots_sqlyog.php