Mysql query/server optimization
NickName:Matej Murn Ask DateTime:2015-04-07T18:08:10

Mysql query/server optimization

Recently I changed MySQL version to 5.6.23 from 5.5.8 and got stuck in some query performance issue. In old MySQL; query is executed in some reasonable time, but in new one freebsd server+mysql server becomes unresponsive. Linux command

[linux~] top

show mysql >100% wcpu when query is executed. If I execute each subquery seperately, results are fetched in seconds. At this moment mysql and apache needs to be restarted to continue with work.

So my problem is optimization of next query:

SELECT concat_ws('##', pos.name, 
( SELECT COUNT(*) FROM nalogi n 
WHERE n.other_createtime >= '2015-03-01 00:00:00' 
AND n.other_createtime <= '2015-03-31 23:59:59' 
AND n.nalog_invalid = 'N' AND n.other_pos = pos.id ), 
( SELECT COUNT(*) FROM nalogi n, posiljke_nalogi pn, posiljke p 
WHERE p.other_createtime >= '2015-03-01 00:00:00' 
AND p.other_createtime <= '2015-03-31 23:59:59' 
AND pn.nalogid = n.id 
AND pn.masterId = p.id 
AND p.path_from_type = 'center' 
AND n.nalog_invalid = 'N' 
AND (p.path_to_type = 'pos' OR p.path_to_type = 'customer') 
AND n.other_pos = pos.id )) 'entry' FROM spl_pos pos ORDER BY pos.id

Currently I am using indexes and caching of tables in memory. Any speed optimization or other advices are welcome.

I searched the net and found some good sources source1, source2 and many others which I already use in existing query. I also checked type of strings that I compare. Based on experiences I have some issues when selecting some rows with:

where x.field=field (slow)
where x.field="field" (much faster)

So I also checked for that, and date type too. Now I am almost without any more idea to try. I can provide additional data if needed.

Currently I am saving situation with executing queries seperately (which I would prefer to do in one query).

Copyright Notice:Content Author:「Matej Murn」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/29489001/mysql-query-server-optimization

More about “Mysql query/server optimization” related questions

Mysql query/server optimization

Recently I changed MySQL version to 5.6.23 from 5.5.8 and got stuck in some query performance issue. In old MySQL; query is executed in some reasonable time, but in new one freebsd server+mysql ser...

Show Detail

mysql update query optimization

I have a database with 200+ entries, and with a cronjob I'm updating the database every 5 minutes. All entries are unique. My code: for($players as $pl){ mysql_query("UPDATE rp_players SET sta...

Show Detail

MySQL Distinct Query with Subqueries optimization

I'm trying to take "Galt Barber on August 26 2006" advice here on distinct optimization: http://dev.mysql.com/doc/refman/5.0/en/distinct-optimization.html My query looks like: SELECT COUNT( `

Show Detail

Optimization MySQL for large table

Question concerning MySQL and optimization over large table. The MySQL server is running on a limited capacity server and we need to optimize it as much as possible. We are sampling data at a rate...

Show Detail

Is there any software to aid in MYSQL optimization?

I have a number of very long and fairly complex stored procedures in my local MYSQL database. I query the database through these stored procedures repeatedly at a high rate all day long. Time is v...

Show Detail

MySQL query optimization

$res (array)-> (count 50 (!) ) Example: ( [1] =&gt; Array ( [artistname] =&gt; Lady GaGa [songname] =&gt; Love Games [duration] =&gt; 3:31 ...

Show Detail

MySQL Index Optimization

I'm struggling with MySQL index optimization for some queries that should be simple but are taking forever. Rather than post the specific problem, I wanted to ask if there is an automated way of de...

Show Detail

MySQL - if condition optimization

Just wondering, how this query will be handled by MySQL, will sum() calculated twice if sum(credits) != NULL or does MySQL has optimization in place for such queries. select if(sum(credits)=NULL,...

Show Detail

MySQL Query Optimization and joins

I am wondering whether my query should run faster, and whether I can make it run faster with query optimization. I have two tables, tweets and nGrams which contain about 600,000 and 13.8 million rows

Show Detail

database optimization

I am using PHP and MySQL with IIS server. My site speed performance is very poor. Can someone suggest me good database optimization and query optimization techniques? This site has heavy traffic an...

Show Detail