[前][次][番号順一覧][スレッド一覧]

mysql:15762

From: Tomohiro 'Tomo-p' KATO <Tomohiro 'Tomo-p' KATO <tomop@xxxxxxxxxx>>
Date: Wed, 25 Apr 2012 19:05:25 +0900
Subject: [mysql 15762] Re: 行列変換を行う処理を高速化するには?

 こんばんは。かとうです。

On 12/04/25 18:25, 中川 貴 wrote:
> ただ、そうすると索引検索で集計対象が100件程度なのに処理が遅すぎる気がするのですが。

  そうですね。こちらでも20万レコード生成して試しましたがすぐ終わり
 ました。


*環境
- MySQL 5.5.14
- innodb_buffer_pool_size=402653184
- read_buffer_size=131072
- read_rnd_buffer_size=262144
- sort_buffer_size=2097152

*テーブル
CREATE TABLE `test` (
  `pk` int(11) NOT NULL DEFAULT '0',
  `sycd` int(11) DEFAULT NULL,
  `nm` varchar(32) DEFAULT NULL,
  `cd` int(11) DEFAULT NULL,
  `sc` int(11) DEFAULT NULL,
  `npdt` varchar(8) DEFAULT NULL,
  `yymm` varchar(6) DEFAULT NULL,
  `dd` varchar(2) DEFAULT NULL,
  PRIMARY KEY (`pk`),
  KEY `idx1` (`sycd`,`yymm`,`nm`,`dd`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

*投入SQL
SELECT
  nm,
  sum(case when dd = '01' then 1 else 0 end) as 'h101',
  ...
  sum(case when dd = '31' then 1 else 0 end) as 'h131'
FROM test
  WHERE sycd=1 AND yymm='201110'
  GROUP BY nm;

*実行結果
+------+------+------+------+
| nm   | h101 |  ... | h131 |
+------+------+------+------+
| 1    |    1 |  ... |    0 |
...
+------+------+------+------+
10 rows in set (0.00 sec)

*explain結果
+----+-------------+-------+------+---------------+------+---------+-------------+------+--------------------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref         | rows | Extra                    |
+----+-------------+-------+------+---------------+------+---------+-------------+------+--------------------------+
|  1 | SIMPLE      | test  | ref  | idx1          | idx1 | 26      | const,const |  256 | Using where; Using index |
+----+-------------+-------+------+---------------+------+---------+-------------+------+--------------------------+
1 row in set (0.00 sec)

-- 
    __________________________________________________
  _/_/  Tomohiro "Tomo-p" KATO  <tomop@xxxxxxxxxx>
 _/_/  Team Gedoh Network  http://www.teamgedoh.net/
_/_/  Key fingerprint = A6D8 3981 3575 9F00 EFC3  9C2B F03A 5383 9287 74D9

[前][次][番号順一覧][スレッド一覧]

     15742 2012-04-20 09:36 [ram <ram@xxxxxxxxxx>] 行列変換を行う処理を高速化するには?    
     15743 2012-04-20 11:12 ┣[中川 貴 <takashi.nak]                                       
     15744 2012-04-20 13:58 ┃┗[ram <ram@xxxxxxxxxx>]                                     
     15745 2012-04-20 15:24 ┃ ┗[中川 貴 <takashi.nak]                                   
     15747 2012-04-20 17:58 ┃  ┗[ram <ram@xxxxxxxxxx>]                                 
     15748 2012-04-20 22:05 ┃   ┣[Tsubasa Tanaka <yoku]                               
     15749 2012-04-21 01:06 ┃   ┃┗[Tsubasa Tanaka <yoku]                             
     15750 2012-04-21 02:05 ┃   ┃ ┗[Tsubasa Tanaka <yoku]                           
     15753 2012-04-23 15:39 ┃   ┃  ┗[ram <ram@xxxxxxxxxx>]                         
     15756 2012-04-25 14:54 ┃   ┗[中川 貴 <takashi.nak]                               
     15758 2012-04-25 16:34 ┃    ┗[ram <ram@xxxxxxxxxx>]                             
     15759 2012-04-25 17:09 ┃     ┗[中川 貴 <takashi.nak]                           
     15760 2012-04-25 17:18 ┃      ┗[Tomohiro 'Tomo-p' KA]                         
     15761 2012-04-25 18:25 ┃       ┗[中川 貴 <takashi.nak]                       
->   15762 2012-04-25 19:05 ┃        ┗[Tomohiro 'Tomo-p' KA]                     
     15752 2012-04-23 14:17 ┗[<gotou1213@xxxxxxxxx]                                       
     15754 2012-04-23 19:53  ┗[ram <ram@xxxxxxxxxx>]                                     
     15755 2012-04-24 13:50   ┗[<gotou1213@xxxxxxxxx]                                   
     15757 2012-04-25 15:39    ┗[ram <ram@xxxxxxxxxx>]                                 
     15765 2012-04-26 14:12     ┗[<gotou1213@xxxxxxxxx]