Note that there are some explanatory texts on larger screens.

plurals
  1. POMysql Group by query is taking long time
    primarykey
    data
    text
    <p>I have a table "Words" in mysql database. This table contains 2 fields. word(VARCHAR(256)) and p_id(INTEGER). Create table statement for the table:</p> <pre><code>CREATE TABLE `Words` ( `word` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `p_id` int(11) NOT NULL DEFAULT '0', KEY `word_i` (`word`(255)) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; </code></pre> <p>Sample entries in the table are:</p> <pre><code>+------+------+ | word | p_id | +------+------+ | a | 1 | | a | 2 | | b | 1 | | a | 4 | +------+------+ </code></pre> <p>This table contains 30+ million entries in it. I am running a group by query and it is taking 90+ minutes for running that query. The group by query I am running is:</p> <pre><code>SELECT word,group_concat(p_id) FROM Words group by word; </code></pre> <p>To optimize this problem, I sent all the data in the table into a text file using the following query.</p> <pre><code>SELECT p_id,word FROM Words INTO OUTFILE "/tmp/word_map.txt"; </code></pre> <p>After that I wrote a Perl script to read all the content in the file and parse that and make a hash out of it. It took very less time compared to the Group by query(&lt;3min).In the end hash has 14million keys(words). It is occupying a lot of memory.So Is there any way to improve the performance of Group BY query so that I don't need to go through all the above mentioned steps?</p> <p>EDT: I am adding the my.cnf file entries below.</p> <pre><code>[mysqld] datadir=/media/data/.mysql_data/mysql tmpdir=/media/data/.mysql_tmp_data innodb_log_file_size=5M socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 group_concat_max_len=4M max_allowed_packet=20M [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid tmpdir=/media/data/.mysql_tmp_data/ </code></pre> <p>Thanks,</p> <p>Vinod</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload